
# GNU Makefile -- requires gnumake
#
# Variables "mpi" should be defined if library is compiled with mpi support.

ifdef mpi
all: libsodesmpi.a
else
all: libsodes.a
endif

#########################################################################
# Setup the environment
#########################################################################

# Root directory for installation
INSTALLDIR=$(HOME)
# Directory for installation
LIBDIR=$(INSTALLDIR)/lib
# Directory for include files (module definitions)
INCLDIR=$(INSTALLDIR)/include

# Define Fortran compiler
ifdef mpi
FC = mpxlf
else
FC = xlf
endif

# Flags for Fortran compiler
FFLAGS = -qfree=F90 -O -qmaxmem=-1

# Define preprocessor and flags
CPP = /lib/cpp
CPPFLAGS = -P

# Define module extension
modext = mod

# If dtime function is defined then set variable DTIME equal to
# name of function (as seen from Fortran) and define DTIMEDEFINED
defs += -DDTIMEDEFINED -DDTIME=DTIME_

# If mpi is defined then define name of mpi Fortran includefile and
# define MPI
ifdef mpi
  defs += -DMPI -DMPIINCLUDEFILE="'mpif90.AIX.h'"
endif

# If QMR is allowed then define QMR
#defs += -DQMR

# If functions can not be optional arguments then define NOOPTIONALFNK
#defs += -DNOOPTIONALFNK

#########################################################################
# Actual makefile
#########################################################################

# Cancel implicit rule for making .o files from module files.
%.o : %.$(modext)

%.f : %.f90
	$(CPP) $(CPPFLAGS) $(defs) $< > $@

sodes.o: sodes.f defines.o genmatrix.o blas.o lapack.o
genmatrix.o: genmatrix.f defines.o lapack.o blas.o qmrpack.o
genmatrix.$(modext): genmatrix.o
sodes.$(modext): sodes.o

libsodesmpi.a(%.o): %.o
	ar -cr libsodesmpi.a $?

libsodes.a(%.o): %.o
	ar -cr libsodes.a $?

libsodesmpi.a: libsodesmpi.a(sodes.o genmatrix.o defines.o lapack.o \
	blas.o qmrpack.o)

libsodes.a: libsodes.a(sodes.o genmatrix.o defines.o lapack.o \
	blas.o qmrpack.o)

install:
	-cp libsodes.a $(LIBDIR)
	-cp libsodesmpi.a $(LIBDIR)
	-cp *.$(modext) $(INCLDIR)
	-cp *.h $(INCLDIR)

clean:
	rm -f *.o *.f *.$(modext) *.a
