# makefile for Ottaviani-Horton-Erba transport model
# by Arnold, Lehigh University
# for IBM RS/6000 system running AIX v4, the Solaris system,
#    the SGI IRIX system or the DEC alpha system
# [modified dmc 11 Nov 1998] -- 
#    (a) single or double precision build can be done for any of
#        DEC, IBM, SGI, SOL.
#    (b) use `gmake clean' to remove all binaries.
#
SHELL    = csh                       # csh always exists
SHELLuse = /bin/tcsh                 # this makefile intends to use tcsh
# If tcsh is another location, e.g., /usr/local/bin/tcsh, correct line above

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.
   WARNcpu = 2
   CPU = IBM
endif
ifeq ($(filter $(CPU), IBM SOL SGI DEC IBM_R4 SOL_R4 SGI_R4 DEC_R4),)
   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
ifeq ($(CPU),IBM_R4)
   FFLAGS  = -O -qmaxmem=-1
   FFLAGS2 = -qfixed=72 -c
endif
#
# For Solaris compilers, these compilation flags are (in order):
#
ifeq ($(CPU),SOL)
   FFLAGS  = -O4 -r8 -i4 -Nx600 -Nn2000
   FFLAGS2 = -c
endif
ifeq ($(CPU),SOL_R4)
   FFLAGS  = -O4 -Nx600 -Nn2000
   FFLAGS2 = -c
endif
#
# For SGI compilers, these compilation flags are (in order):
#
ifeq ($(CPU),SGI)
   FFLAGS  = -O -r8 -i4
   FFLAGS2 = -c
   FC=f90
endif
ifeq ($(CPU),SGI_R4)
   FFLAGS  = -O
   FFLAGS2 = -c
   FC=f90
endif
#
# For DEC-alpha workstations (dmc)
#
ifeq ($(CPU),DEC)
   FFLAGS  = -O -r8 -i4
   FFLAGS2 = -c
endif
ifeq ($(CPU),DEC_R4)
   FFLAGS  = -O
   FFLAGS2 = -c
endif
#
# Compiling and Linking commands
#
COMPILE = $(FC) $(FFLAGS) $(FFLAGS2)
LINK    = $(FC) $(FFLAGS)

#
# Targets and Rules
#

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


xohe::	driver.o ohe_model.o stripx.o
	$(LINK) -o xohe driver.o stripx.o ohe_model.o

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

ohe_model.o:	ohe_model.tex xtverb
	touch ohe_model.f
	rm ohe_model.f
	-xtverb < ohe_model.tex > ohe_model.f
	$(COMPILE) -o ohe_model.o ohe_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
  ifeq ($(WARNcpu),2)
	@echo CPU defaulted, CPU=IBM assumed.
  endif

clean:
	@rm *.o xohe xtverb
