# Makefile for HSPF version 11
#
# History:  96/03/05 kmflynn

# Usage:  make install [BINDIR=bin_path]

# pathname
WrdA = /usr/opt/wrdapp

# Compiler flags (Fortran - Green Hills):
#    C - check subranges and array bounds
#    u - default data type for undeclareds is undefined
#    g - generate source level symbolic debug information
#   OM - optimization
# (NOTE: set OptDbg to: OptM to generate optimized code
#                       DbgF to generate debug code)
DbgF   = -g
OptM   = -OM
OptDbg =
FFLAGS = -C -u $(OptDbg)

# Compiler name
F77 = f77

# this description file uses the Bourne shell
SHELL = /bin/sh
shCmd = sh

# include hec dss libraries [NO or YES]
Libs = $(LibsNO)

#*******************************************************************
#***** You should not need to modify anything below this line. *****
#*******************************************************************

# library directory
library = $(WrdA)/lib3.0
LibDir  = $(library)/lib

program = hspf

Objects = hspfbat.o  hspsta.o
LibsYES = $(LibDir)/hspflib.a $(LibDir)/hspdsslib.a $(LibDir)/hspflib.a \
          $(LibDir)/wdmlib.a  $(LibDir)/adwdmlib.a  $(LibDir)/utillib.a \
          $(LibDir)/heclib.a
LibsNO  = $(LibDir)/hspflib.a $(LibDir)/hspnodsslib.a $(LibDir)/hspflib.a \
          $(LibDir)/wdmlib.a  $(LibDir)/adwdmlib.a  $(LibDir)/utillib.a

BINDIR  = ../bin
binary  = ../bin
binMake = $(binary)/$(program)
binInst = $(BINDIR)/$(program)

# Rules
all:  first $(binMake) install
	@echo "\n"Done making all for hspf, files are now up to date."\n"

# program dependencies
$(binMake):  $(Objects) $(Libs)
	$(F77) $(Objects) $(Libs) -o $@

first:
	@if [ ! -d $(binary) ]   ; then        \
	   mkdir $(binary)  ;                  \
	   echo Created directory $(binary) ;  \
	fi
install:
# Create directory for binary file, if necessary
	@if [ ! -d $(BINDIR) ]   ; then        \
	   mkdir $(BINDIR) ;                   \
	   echo  Created directory $(BINDIR) ; \
	fi
# Link executable to BINDIR if installing elsewhere
	@if [ ! -s $(binMake) ] ; then                              \
	   echo program $(binMake) does not exist, ;                \
	   echo use one of the following commands to generate it:;  \
	   echo "     make" ;  echo "     make all" ;               \
	else                                                        \
	   if [ $(BINDIR) != $(binary) ] ; then                     \
	      rm -f $(binInst) ;                                    \
	      cd .. ; ln -s `pwd`/bin/$(program) $(binInst);        \
	      chmod 644 $(binInst) ;                                \
	      echo "\n"Program $(binInst) has been updated.;        \
	   fi ; \
	fi
clean:
	@if [ $(BINDIR) != $(binary) ] ; then rm -f $(binInst) ; fi
	rm -f *.o $(binMake)
	@echo Removed files generated by make."\n"

# Define object file dependencies:
hspfbat.o: versn.inc fhsmes.inc pmesfl.inc

# end of make
