# Makefile for library - graph
#
# 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

# Object files, installation specific
# where grsy[dg ux].o (dg - Prior gks, ux - Xgks)
ObjDG   = grsydg.o
ObjXgks = grsyux.o
ObjVrsn = $(ObjDG)

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

library = graphlib.a
libraryX= graphlibx.a
Objects = grcomn.o grutil.o grdata.o graxis.o grtext.o grgks.o  \
          grcaxe.o grccrv.o grclay.o grcmeg.o grcvar.o grmark.o

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

# Rules
allp: $(binary) $(libMake) install
	@echo "\nDone making all for graph (Prior) files are now up-to-date.\n"
allx: $(binary) $(libMakeX) installx
	@echo "\nDone making all for graph (Xgks), files are now up-to-date.\n"

# Library and utility dependencies:
$(libMake):   $(Objects) $(ObjVrsn)
	@echo "\n" making $(libMake)
	ar $(ArOpt) $@ $?
	$(SymTbl)
$(libMakeX):   $(Objects) $(ObjXgks)
	@echo "\n" making $(libMakeX)
	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
installx:
# Create directory for binary file, if necessary
	@if [ ! -d $(libdir) ]   ; then        \
	   mkdir $(libdir) ;                   \
	   echo  Created directory $(libdir) ; \
	fi
	@if [ ! -s $(libMakeX) ] ; then                               \
	   echo library $(libMakex) 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 $(libInstX) ;                                \
	      cd ../..; ln -s `pwd`/lib/$(libraryX) $(libInstX); \
	      chmod 644 $(libInstX) ;                            \
	      echo "\n"Library $(libInstX) has been updated.;    \
	   fi ; \
	fi
clean:
	@if [ $(libdir) != $(binary) ] ; then \
	   rm -f $(libInst)  ;                \
	   rm -f $(libInstX) ;                \
	   fi
	rm -f *.o $(libMake) $(libMakeX)
	@echo Removed files generated by make."\n"

# Define object file dependencies:
grcaxe.o: ptsmax.inc cplot.inc
grccrv.o: ptsmax.inc cplot.inc
grclay.o: ptsmax.inc cplot.inc
grcmeg.o: ptsmax.inc cplot.inc
grcomn.o: ptsmax.inc cplot.inc  pbfmax.inc cplotb.inc
grcvar.o: ptsmax.inc cplot.inc
grdata.o: ptsmax.inc cplot.inc  pbfmax.inc cplotb.inc
grgks.o:  ptsmax.inc cplot.inc  cgracm.inc cgrapm.inc fversn.inc
grtext.o: ptsmax.inc cplot.inc

gksint.o: lkagks.inc gksprm.inc

# end of make
