#
# Makefile for the examples of the exp4 Package
# 
# This distribution includes some example drivers for the core-integrator.
# Description of possible targets:
#   * vdpex:    An example of the Van Der Pol equation
#               dimension is 2. That's the reason why this example is
#               integrated by Exp4Ex.
#   * laser:    An example of the 'laser' described in the paper.
#   * bruss2d:  The Brusselator example in 2D (N=100 => dim of equation 20000)
#               integrated by Exp4. The jacobian is programmed.
#
#   * clean:    removes all objects and executables
#   * allclean: clean and removes ftypes.h. 'make allclean' if you want to
#               take the package onto an other machine.
#
# Locations to edit the Makefile:
#
# *  First of all, the blas library. You need the FORTRAN version. If
#    you have an (optimized) Fortran blas library fill in the
#    path. Otherwise you have to compile one available at 
#    http://www.netlib.org/blas/index.html.
BLASLIB         = -lblas
#BLASLIB         = -L/path/to/blas/lib -lblas
#BLASLIB         = -l/path/to/blas/lib/blas.a
# *  You need a FORTRAN version of lapack. If you have an (optimized)
#    Fortran lapack library fill in the path. Otherwise you have to
#    compile one available at http://www.netlib.org/lapack/index.html.
LAPACKLIB       = -llapack
#LAPACKLIB       = -L/path/to/lapack/lib -llapack
#LAPACKLIB       = -l/path/to/lapack/lib/lapack.a
#
# I hope you don't need that ...
DEBUGFLAGS	= ##-g

# cc flags for compiling. We need an ANSI C compiler, add a flag,
# that switches this mode on.
CFLAGS		= -O -ansi
# Other compilers may use for example -Xa (Sun's cc)
#CFLAGS          = -O -Xa

# C compiler to use
CC		= gcc

# linker to use (the same compiler as used to build the LAPACK routines)
LD		= g77

# If g77 doesn't work use gcc. Then you have to add the FORTRAN
# libraries to the FLIBS variable. Since these are FORTRAN standard
# libraries, you have to specify them explicitly, when using gcc.
#FLIBS		= -lf2c
#FLIBS		= -lF77 -lI77

# linkerflags, on most systems not necessary.
LDFLAGS		=


# libs to use
LIBS		= $(LAPACKLIB) $(BLASLIB) $(FLIBS) -lm -lc

# This library is used by the laser example.
FFTPACKDIR	= fftpack
FFTPACKLIB	= $(FFTPACKDIR)/libfftpack.a
FFTPACKLIBS	= -L$(FFTPACKDIR) -lfftpack

# The main library.
EXP4DIR		= ../exp4
EXP4LIB		= -L$(EXP4DIR) -lexp4
EXP4LIBA	= $(EXP4DIR)/libexp4.a

# Set search path for include files.
INCPATH		= -I$(EXP4DIR) -I$(FFTPACKDIR)
INCLUDES	= $(EXP4DIR)/ftypes.h $(EXP4DIR)/fblas.h $(EXP4DIR)/exp4.h \
			$(FFTPACKDIR)/fft.h

# The brusselator example in 2D. For details see: Hairer, Noersett,
# Wanner: Solving Ordinary Differential Equations II, p 159.
# Springer-Verlag 1991.
BRUSS2DS	= bruss2d_simple
BRUSS2DSOBJ	= bruss2d_simple.o
BRUSS2D		= bruss2d
BRUSS2DOBJ	= bruss2d.o

# The famous Van der Pol equation. For details see: Hairer, Noersett,
# Wanner: Solving Ordinary Differential Equations II, p 157.
# Springer-Verlag 1991.
VDPEXS		= vdpex_simple
VDPEXSOBJ	= vdpex_simple.o
VDPEX		= vdpex
VDPEXOBJ	= vdpex.o

# This is a time-dependent Schroedinger equation. It models an
# atom/molecule interacting with a high intensity laser. For details
# see Peskin, Kosloff, Moiseyev: "Polynomial propagators for the
# (t,t') method", J. Chem. Phys., Vol. 100, No. 12, p8849-8855.
LASERS		= laser_simple
LASERSOBJ	= laser_simple.o
LASER		= laser
LASEROBJ	= laser.o

ALL_EXAMPLES	= $(VDPEX) $(BRUSS2D) $(LASER) $(VDPEXS) $(BRUSS2DS) $(LASERS)

MAKEFILE	= Makefile

RM		= rm -f

.PHONY:		Usage clean allclean
.SUFFIXES:
.SUFFIXES: 	.o .c


.DONE:;		@echo "done\n"

Usage:
	@echo
	@echo "Possible targets:"
	@echo "make $(EXP4LIBA) ... compile the EXP4 main library."
	@echo "make AllExamples ... compile all Examples."
	@echo "make $(BRUSS2D) ... compile the Brusselator example 2D."
	@echo "make $(BRUSS2DS) ... compile the Brusselator example 2D." \
	"Simple driver."
	@echo "make $(VDPEX) ... compile the Van der Pol equation" \
	"(no Krylov techniques)."
	@echo "make $(VDPEXS) ... compile the Van der Pol equation" \
	"Simple driver."
	@echo "      (no Krylov techniques)."
	@echo "make $(LASER) ... compile the Laser example."
	@echo "make $(LASERS) ... compile the Laser example. Simple driver."
	@echo "make clean ... delete objects, libraries and executables."
	@echo "make allclean ... clean and remove $(EXP4DIR)/ftypes.h."
	@echo

AllExamples:	$(ALL_EXAMPLES)

$(EXP4LIBA)::
		cd $(EXP4DIR) ; $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" libexp4.a


$(BRUSS2D):	$(EXP4LIBA) $(BRUSS2DOBJ)
		$(LD) $(LDFLAGS) -o $@ $(BRUSS2DOBJ) $(EXP4LIB) $(LIBS)

$(BRUSS2DS):	$(EXP4LIBA) $(BRUSS2DSOBJ)
		$(LD) $(LDFLAGS) -o $@ $(BRUSS2DSOBJ) $(EXP4LIB) $(LIBS)

$(VDPEX):	$(EXP4LIBA) $(VDPEXOBJ)
		$(LD) $(LDFLAGS) -o $@ $(VDPEXOBJ) $(EXP4LIB) $(LIBS)

$(VDPEXS):	$(EXP4LIBA) $(VDPEXSOBJ)
		$(LD) $(LDFLAGS) -o $@ $(VDPEXSOBJ) $(EXP4LIB) $(LIBS)

$(LASER):	$(EXP4LIBA) $(FFTPACKLIB) $(LASEROBJ)
		$(LD) $(LDFLAGS) -o $@ $(LASEROBJ) $(FFTPACKLIBS) \
			$(EXP4LIB) $(LIBS)

$(LASERS):	$(EXP4LIBA) $(FFTPACKLIB) $(LASERSOBJ)
		$(LD) $(LDFLAGS) -o $@ $(LASERSOBJ) $(FFTPACKLIBS) \
			$(EXP4LIB) $(LIBS)

$(FFTPACKLIB)::
		cd $(FFTPACKDIR) ; $(MAKE) FFLAGS="$(CFLAGS)" libfftpack.a


clean:
		@$(RM) *.o *.a *.out *~ $(ALL_EXAMPLES) core
		cd $(FFTPACKDIR) ; $(MAKE) clean
		cd $(EXP4DIR) ; $(MAKE) clean

allclean:	clean
		cd $(EXP4DIR) ; $(MAKE) allclean

.c.o:
		$(CC) -c $(CFLAGS) $(INCPATH) $<

bruss2d.o::		$(INCLUDES) $(MAKEFILE)
bruss2d_simple.o::	$(INCLUDES) $(MAKEFILE)
laser.o::		$(INCLUDES) $(MAKEFILE)
laser_simple.o::	$(INCLUDES) $(MAKEFILE)
sparse.o::		$(INCLUDES) $(MAKEFILE)
vdpex.o:: 		$(INCLUDES) $(MAKEFILE)
vdpex_simple.o::	$(INCLUDES) $(MAKEFILE)
