# Makefile for library - newaqt
#
# 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 = newaqtlib.a
Objects = agmap.o  damap.o  grmap.o  utmap.o  wdmap.o  utplot.o prwplt.o \
          wsgutl.o ucirea.o uciwrt.o hspsta.o          \
          ucimod.o wsgsim.o utdir.o  dspeci.o \
          tsplot.o utclas.o sgdate.o durani.o wsgsys.o \
          sglist.o sgtabl.o mapseg.o tsfreq.o sturbn.o hget.o   utwin.o
Saide   = pmesfl.inc
Sgraph  = cplotb.inc pbfmax.inc ptsmax.inc
Swaide  = ctslst.inc

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

# Rules
all: includes $(binary) $(libMake) install
	@echo "\nDone making all for newaqt, 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 $(Saide) ; do                                       \
	   if [ -f $$inc ] ; then                                       \
	     if diff $$inc ../aide/$$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 ../aide/$$inc . ;                                    \
	     fi ;                                                       \
	   else                                                         \
	     echo "NOTICE:--copying missing $$inc from ../aide" ;       \
	     cp ../aide/$$inc . ;                                       \
	   fi ;                                                         \
	done
	@for inc in $(Sgraph) ; do                                      \
	   if [ -f $$inc ] ; then                                       \
	     if diff $$inc ../graph/$$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 ../graph/$$inc . ;                                   \
	     fi ;                                                       \
	   else                                                         \
	     echo "NOTICE:--copying missing $$inc from ../graph" ;      \
	     cp ../graph/$$inc . ;                                      \
	   fi ;                                                         \
	done
	@for inc in $(Swaide) ; do                                      \
	   if [ -f $$inc ] ; then                                       \
	     if diff $$inc ../waide/$$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 ../waide/$$inc . ;                                   \
	     fi ;                                                       \
	   else                                                         \
	     echo "NOTICE:--copying missing $$inc from ../waide" ;      \
	     cp ../waide/$$inc . ;                                      \
	   fi ;                                                         \
	done

# Define object file dependencies:
agmap.o:    pmxmap.inc pmxcls.inc pmxwin.inc cmaprm.inc
damap.o:    cmapdt.inc cstaid.inc pmxsen.inc
dspeci.o:   pmxcls.inc pmxts.inc
durani.o:   pmxdur.inc pbfmax.inc  ptsmax.inc cplotb.inc
grmap.o:    cstaid.inc
hget.f:     pmesfl.inc
mapseg.o:   pmxseg.inc cmpseg.inc pmxani.inc
prwplt.o:   pmxsen.inc
sgdate.o:   cdate.inc  pmxdat.inc
sglist.o:   ctslst.inc
tsplot.o:   pmaxd.inc  pmxwin.inc pbfmax.inc  ptsmax.inc cplotb.inc
ucirea.o:   fversn.inc
utclas.o:   cclas.inc  pmxcls.inc pmxts.inc
utdir.o:    ctsdir.inc pmxts.inc  pmesfl.inc
utmap.o:    cmap.inc   cmaprm.inc pmxmap.inc
utwin.o:    pmxwin.inc cwindo.inc
wsgsim.o:   ctsdir.inc pmxts.inc
wsgsys.o:   pmxdat.inc pmxseg.inc cmaprm.inc pmxani.inc pmxwin.inc
wsgutl.o:   pmxmap.inc pmxseg.inc pmxwin.inc
utplot.o:   ptsmax.inc

cclas.inc:  pmxcls.inc pmxts.inc
cdate.inc:  pmxdat.inc
cmap.inc:   pmxmap.inc
ctsdir.inc: pmxts.inc

# end of make
