# Makefile for program - wdimex
#
# 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 = wdimex
Objects = wdimex.o wdimez.o
Sadwdm  = cdrloc.inc cfbuff.inc

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

bindir  = ../../bin
binary  = ../../bin
binMake = $(binary)/$(program)
binInst = $(bindir)/$(program)
 
# Rules
all: includes $(binary) $(binMake) install
	@echo "\n"Done making all for wdimex, 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`/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"
includes:
	@for inc in $(Sadwdm) ; do                                      \
	   if [ -f $$inc ] ; then                                       \
	     if diff $$inc ../adwdm/$$inc ; then                        \
	        continue ;                                              \
	     else                                                       \
	        echo "NOTICE:--different $$inc appended to ERROR.inc" ; \
	        echo ;                                                  \
	        echo "different $$inc, `date`" >> ERROR.inc ;           \
	        cat $$inc >> ERROR.inc ;                                \
	        rm $$inc ;                                              \
	        cp ../adwdm/$$inc . ;                                   \
	     fi ;                                                       \
	   else                                                         \
	     echo "NOTICE:--copying missing $$inc from ../adwdm" ;      \
	     cp ../adwdm/$$inc . ;                                      \
	   fi ;                                                         \
	done

# Define object file dependencies:
wdimex.o: fversn.inc cdrloc.inc cfbuff.inc

# end of make
