#
# makefile for IFS/PPPL model module
# by Lynda Lodestro, LLNL and Aaron J Redd, Lehigh University
# for IBM RS/6000 system running AIX v4, or
#     Solaris system
#
SHELL    = csh                       # csh always exists
SHELLuse = /bin/tcsh                 # this makefile intends to use tcsh

ifeq ($(shell if !( -e $(SHELLuse) ) echo 2),2)
   ERRsh = 2
else
   SHELL = $(SHELLuse)
endif

#
# environment variable CPU is used to set platform-dependent make variables.
#
ifeq ($(CPU),)
   # CPU is undefined; default to IBM.
   CPU = IBM
endif
ifeq ($(filter $(CPU), IBM SOL SGI),)
   ERRcpu = 2
endif

#
# Compilation/linking flags
#
# 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
endif
#
# For Solaris compilers, these compilation flags are (in order):
#
ifeq ($(CPU),SOL)
   FFLAGS  = -O4 -Nx600 -Nn2000
   FFLAGS2 = -c
endif
# For SGI compilers, these compilation flags are (in order):
#
ifeq ($(CPU),SGI)
   FFLAGS  = -default64
   FFLAGS2 = -c
   FC=f90
endif

#
# Compiling and Linking commands
#
COMPILE = $(FC) $(FFLAGS) $(FFLAGS2)
LINK    = $(FC) $(FFLAGS)

#
# Targets and Rules
#

xip xtverb::	shtst cputst
        # without any rule, make tries to build c code
	@echo 


xip::	driver.o ifspppl_model.o stripx.o
	$(LINK) -o xip driver.o stripx.o ifspppl_model.o

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

ifspppl_model.o:	ifspppl_model.tex xtverb
	touch ifspppl_model.f
	rm ifspppl_model.f
	-xtverb < ifspppl_model.tex > ifspppl_model.f
	$(COMPILE) -o ifspppl_model.o ifspppl_model.f

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

xtverb::	xtverb.f
	$(COMPILE) -o xtverb.o xtverb.f
	$(LINK) -o xtverb xtverb.o

shtst:
  # if SHELLuse does not exist, give user instructions what to fix in what file
  ifeq ($(ERRsh),2)
	@echo $(SHELLuse) does not exist. \
	Fix variable SHELLuse in ifspppl makefile.
	@exit(2)
  endif

cputst:
  ifeq ($(ERRcpu),2)
	@echo CPU=$(CPU) is not yet implemented in ifspppl makefile.
	@exit(2)
  endif
