# Makefile for program - wdmrx
#
# History:  95/12/05 kmflynn

# Usage:  make [bindir=path_to_install_to] [install] [| tee makeout]
#
# Examples:  make
#            make install bindir=/usr/opt/bin
#            make install bindir=$HOME/bin

# 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 OpgDbg to: OptM to generate optimized code
#                       DbgF to generate debug code)
DbgF   = -g
OptM   = -OM
OptDbg =
FFLAGS = -u $(OptDbg)

# Compiler name
F77 = f77

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

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

program = wdmrx
Objects = wdmrx.o

LibDir  = ../../lib
Libs    = $(LibDir)/wdmlib.a $(LibDir)/adwdmlib.a $(LibDir)/utillib.a

bindir  = ../../bin
binary  = ../../bin
binMake = $(binary)/$(program)
binInst = $(bindir)/$(program)
 
# Rules
all: $(binary) $(binMake) install
	@echo "\n"Done making all for wdmrx, files are now up to date."\n"

# program dependencies
$(binMake):  $(Objects) $(Libs)
	$(F77) $(Objects) $(Libs) -o $@
$(binary):
	@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`/pgm/$(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:
wdmrx.o:  fversn.inc

# end of make
