# Makefile for library - wdm
#
# History:  95/12/05 kmflynn

# Usage:  make [libdir=path_to_install_to] [install] [| tee makeout]
#
# Examples:  make 
#            make install libdir=/usr/lib
#            make install libdir=$HOME/lib

# 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 names
F77    = f77

# symbol table for library archive may need to be explicitly built;
# System V ar does this automatically, BSD ar does not
BSD    = ranlib $@
SYS_V  =
SymTbl = $(SYS_V)

# library archive options
#    r - replace the named files in the archive file
#    v - give a verbose file-by-file description of the making
#    c - suppress the message that is produced by default when
#        the archive file is created
#    q - quickly append the named files to the end of the
#        archive file
ArOpt = rv

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

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

library = wdmlib.a
Objects = wdbtch.o wdatrb.o wdatm2.o wdsptm.o wdimpt.o wdexpt.o \
          wdtms2.o wdtms1.o wdtble.o wdtbl2.o wddlg.o  wdatru.o \
          tsbufr.o wdtms3.o wdmid.o
Sadwdm  = cfbuff.inc cdrloc.inc

libdir  = ../../lib
binary  = ../../lib
libMake = $(binary)/$(library)
libInst = $(libdir)/$(library)

# Rules
all: includes $(binary) $(libMake) install
	@echo "\nDone making all for wdm, files are now up-to-date.\n"

# Library and utility dependencies:
$(libMake):   $(Objects)
	@echo "\n" making $(libMake)
	ar $(ArOpt) $@ $?
	$(SymTbl)
$(binary):
	@if [ ! -d $(binary) ]   ; then        \
	   mkdir $(binary)  ;                  \
	   echo Created directory $(binary) ;  \
        fi
install:
# Create directory for binary file, if necessary
	@if [ ! -d $(libdir) ]   ; then        \
	   mkdir $(libdir) ;                   \
	   echo  Created directory $(libdir) ; \
	fi
# Link executable to libdir if installing elsewhere
	@if [ ! -s $(libMake) ] ; then                              \
	   echo library $(libMake) does not exist, ;                \
	   echo use one of the following commands to generate it:;  \
	   echo "     make" ;  echo "     make all" ;               \
	else                                                        \
	   if [ $(libdir) != $(binary) ] ; then                     \
	      rm -f $(libInst) ;                               \
	      cd ../..; ln -s `pwd`/lib/$(library) $(libInst); \
	      chmod 644 $(libInst) ;                           \
	      echo "\n"Library $(libInst) has been updated.;   \
	   fi ; \
	fi
clean:
	@if [ $(libdir) != $(binary) ] ; then rm -f $(libInst) ; fi
	rm -f *.o $(libMake)
	@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:
tsbufr.o: ctsbuf.inc
wdatrb.o: fversn.inc cfbuff.inc cdrloc.inc
wdbtch.o: cfbuff.inc cdrloc.inc
wddlg.o:  cfbuff.inc
wdexpt.o: ctblab.inc cfbuff.inc
wdmid.o:  cwdmid.inc
wdsptm.o: cfbuff.inc
wdtble.o: cfbuff.inc
wdtms1.o: cwtsds.inc cfbuff.inc
wdtms2.o: cfbuff.inc
wdtms3.o: cwtsds.inc cfbuff.inc

# end of make
