# 
# Unix Makefile for MODFLOW 
# Last modified 00/05/02, mcrouse
#
# Usage:
# make [BINDIR=path_to_install_to] [install] [| tee makeout]
#
# Examples of values for path_to_install_to are:
#    make BINDIR=/usr/opt/bin
#    make BINDIR=$HOME/bin
#
# If BINDIR is specified, the executable is linked to the specified
# directory.  The default value of BINDIR is ../bin.  Note, the installer
# must have sufficient access rights to delete and then create a link for
# the file modflow in the directory that BINDIR is set to.  If 'install'
# is specified only this link is made (executable must already exist in
# the $(BDir) directory).  If 'install' is not specified, the source
# is recompiled according to the make dependency rules in this file.

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

# Fortran compiler flags (Solaris):
#   -Bstatic - require static linking (no shared libraries)
#   -O       - optimization
# (Note: set FFLAGS to: OptM to generate optimized code
#                       DbgF to generate debug code)
DG      = -O -save
Solaris = -O
SGI     = -O -32 -static
OptM    = $(Solaris)
DbgF    = -C -g
FFLAGS  = $(OptM)

# Compiler name
F77    = g77

# link editor flags for linking in Fortran library statically under Solaris
LDFLAGS = -O

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

PGM    = modflw96
OBJS   = modflw96.o bas5.o bcf5.o sip5.o pcg2.o sor5.o wel5.o riv5.o \
         hfb1.o drn5.o ghb5.o evt5.o rch5.o utl5.o str1.o ibs1.o \
         chd1.o gfd1.o tlk1.o de45.o res1.o fhb1.o

# Default location to link executables on installation
BINDIR = ../bin
BDir   = ../bin
EXE    = $(BDir)/$(PGM)
BIN    = $(BINDIR)/$(PGM)

# Rules
all: chkdir $(EXE) install
	@echo; echo Done making all, files are now up-to-date.

$(EXE): $(OBJS)
	@echo
	$(F77) $(FFLAGS) $(OBJS) $(LDFLAGS) -o $@
	strip $@

chkdir:
# Create directory for binary, if necessary
	@if [ ! -d $(BDir) ]; then \
		mkdir $(BDir); echo Created directory $(BDir); fi
install:
# Create directory for binary, if necessary
	@if [ ! -d $(BINDIR) ]; then \
		mkdir $(BINDIR); echo Created directory $(BINDIR); fi

# Link executable to BINDIR
	@if [ ! -s $(EXE) ]; then \
		echo Executable $(EXE) does not exist,; \
		echo use one of the following commands to generate it:; \
		echo "      make"; echo "      make all"; \
	else \
		if [ $(BINDIR) != $(BDir) ]; then \
			rm -f $(BIN); \
			cd ..; ln -s `pwd`/bin/$(PGM) $(BIN); \
			chmod 755 $(BIN); \
			echo; echo Executable $(BIN) has been updated.; \
			echo; echo Be sure directory $(BINDIR) is in your PATH.; \
		else \
			cd $(BDir); echo; echo Be sure directory `pwd` is in your PATH.; \
		fi; \
	fi

clean:
	@if [ $(BINDIR) != $(BDir) ]; \
		then rm -f $(BIN); \
	fi
	rm -f $(EXE) *.o
	@echo; echo Removed files generated by make.

# object code dependencies
cinmod.o:    APPROC.INC CULVRT.INC CULFLW.INC FCNCN2.INC
culdmp.o:    APPROC.INC CULVRT.INC CULFLW.INC FCNCN2.INC
culrat.o:    APPROC.INC CULVRT.INC CULFLW.INC FCNCN2.INC
discharg.o:  CULVRT.INC CULFLW.INC QTYP12.INC
icvprp.o:    APPROC.INC CULVRT.INC CULFLW.INC
ixsprp.o:    APPROC.INC CULFLW.INC
