# 
# gmake makefile for ISLAND module 
#
# NOTE Must use gmake not make.
# The user must set the environmental variable "CPU" to be
# one of the following:
#
# G95      for the g95.org Fortran compiler
# FUJITSU  for the Lahey Fujitsu F90/F95 compiler
# IBM      for the standard compiler on IBM/AIX workstations
# SOL      for the standard compiler on Sun Solaris workstations
# SGI      for the standard compiler on SGI IRIX workstations
# HP       for the standard compiler on Hewlett Packard workstations
#
#       For example, in the Bourne shell on an SGI workstation, type:
#
#  export CPU=SGI
#
#       If you are using the C-shell on an SGI workstation, type
#
#  setenv CPU SGI
#
# Use `gmake clean' to remove all binaries.
#
# environment variable CPU is used to set platform-dependent make variables.
#
ifeq ($(CPU),)
   # CPU is undefined; default to FUJITSU.
   WARNcpu = 2
   CPU = FUJITSU
endif
ifeq ($(filter $(CPU), INTEL, G95, FUJITSU, IBM SOL SGI HP),)
   ERRcpu = 2
endif

#
#
# Compilation/linking flags for Inter Fortran
#
ifeq ($(CPU),INTEL)
  FC      = ifort
  FFLAGS  = -O3 -xP -r8 -mp -static 
  COMPILE = $(FC) $(FFLAGS) -c
  LINK    = $(FC)
endif
#
#
# Compilation/linking flags for G95
#
ifeq ($(CPU),G95)
   FC=g95
   FFLAGS= -r8
#    FFLAGS= -fbounds-check -ftrace=full
   COMPILE = $(FC) $(FFLAGS) -c
   LINK    = $(FC)
endif
#
# Compilation/linking flags for LINUX
#
ifeq ($(CPU),FUJITSU)
   FC=lf95
   FFLAGS=--ap --dbl --tpp
#    FFLAGS=--ap --dbl -g --tpp --fix --chk a,e,s,u
   COMPILE = $(FC) $(FFLAGS) -c
   LINK    = $(FC)
endif
#
# For IBM/AIX compilers, the compilation flags are (in order):
#   - Optimization (level 1 out of 3)
#   - Default real-variable size is 8 bytes
#   - Default integer-variable size is 4 bytes
#   - No limit on the executable's memory usage
#     (works with the -O flag to give greater optimization)
#   - Input files are written in fixed-format fortran, lines 72 chars long
#   - Compile only (linking is done in a seperate step)
#
ifeq ($(CPU),IBM)
   FFLAGS  = -O -qrealsize=8 -qintsize=4 -qmaxmem=-1
   FFLAGS2 = -qfixed=72 -c
   COMPILE = $(FC) $(FFLAGS) $(FFLAGS2)
   LINK    = $(FC) $(FFLAGS)
endif
#
# For Solaris compilers, these compilation flags are (in order):
#
ifeq ($(CPU),SOL)
   FFLAGS  = -fixed -r8const -xtypemap=real:64 -O4
#   FFLAGS  = -O4 -Nx600 -Nn2000 -r8 -i4 -fixed
   FFLAGS2 = -c
   FC=f90
   COMPILE = $(FC) $(FFLAGS) $(FFLAGS2)
   LINK    = $(FC) $(FFLAGS)
endif
# For SGI compilers, these compilation flags are (in order):
#
ifeq ($(CPU),SGI)
   FFLAGS  = -default64 -O
   FFLAGS2 = -c
   FC=f90
   COMPILE = $(FC) $(FFLAGS) $(FFLAGS2)
   LINK    = $(FC) $(FFLAGS)
endif
#
# For HP workstations (dmc)
#
ifeq ($(CPU),HP)
   FFLAGS = -O3 +autodbl4
   FFLAGS2 = -c
   FC=f90
   COMPILE = $(FC) $(FFLAGS) $(FFLAGS2)
   LINK    = $(FC) $(FFLAGS)
endif

#
# Targets and Rules
#

output : input test_island
	./test_island
	head output
	tail -34 output

test_island: islmod.o island.o zero_finder.o islmathlib.o lsode.o dode.o test_island.o
	$(LINK) -o test_island islmod.o island.o zero_finder.o islmathlib.o lsode.o dode.o test_island.o

islmod.o:	islmod.f
	$(COMPILE) -o islmod.o islmod.f

island.o:	island.f islmod.o
	$(COMPILE) -o island.o islmod.o island.f

#blas_routines.o:	blas_routines.f
#	$(COMPILE) -o blas_routines.o blas_routines.f

islmathlib.o:	islmathlib.f
	$(COMPILE) -o islmathlib.o islmathlib.f

#lapack_routines_1.o:	lapack_routines_1.f
#	$(COMPILE) -o lapack_routines_1.o lapack_routines_1.f

#lapack_routines_2.o:	lapack_routines_2.f
#	$(COMPILE) -o lapack_routines_2.o lapack_routines_2.f

lsode.o:	lsode.f
	$(COMPILE) -o lsode.o lsode.f

dode.o:	dode.f
	$(COMPILE) -o dode.o dode.f

zero_finder.o:	zero_finder.f
	$(COMPILE) -o zero_finder.o zero_finder.f

test_island.o:	test_island.f
	$(COMPILE) -o test_island.o test_island.f

cputst:
  ifeq ($(ERRcpu),2)
	@echo CPU=$(CPU) is not yet implemented in edge makefile.
	@exit 2
  endif
  ifeq ($(WARNcpu),2)
	@echo CPU defaulted, CPU=IBM assumed.
  endif

clean:
	@rm *.o *.mod test_island

