#defgb		WJS  10 Jun 96
#  (temporary make file attempting location-independent build;
#	that is, can say 
#		make -f makefile.defgb
#	without preceding cd.
#	Needs defns of SOURCEDIR, OBJDIR, METHDIR, LIBDIR, LIBSRC & CONTRIB)
#  This makefile used for defgb version 2.7 et seq.  See defgb.c for
#	correct corresponding versions of other routines
#	startchild_defgb should be the same for all.
#
#	26 Mar 97.  Typo in startchild_defgb compilation.  WJS
#	17 Mar 97.  Use outerw_url.c instead of outerw.c  120 buffer size
#		(and void's) only differences (in ~wsass, anyway).  WJS
#	 1 Jan 97.  defgb_utils.  WJS
#	10 Dec 96.  METHOD_PROTOTYPE replaces METHODSWITCH variable
#		and METHOD compilation switch (NOT METHOD variable,
#		conflict with which caused METHODSWITCH, etc)
#		    METHOD_NAME defaults to METHOD.  WJS
#	 1 Aug 96.  Change default for METHDIR & SOURCEDIR to .
#		    Add METHOD and METHODSWITCH variables.
#		    -lm switches to find pow function.
#		    Move comments in here from makefile.defmet.  WJS
#	19 Jul 96.  ioreadrec_routines; defgb.  WJS
#
#
#	Notes about naming object files.
#	  Any object file that receives a compile-time parameter must be
#	named differently from any other object file produced from the same
#	source but with a different value of the compile-time parameter
#	To be safe, we suggest unique names whenever a compile-time parameter
#	is specified.
#	  Often no compile-time parameters are specified to a routine which
#	could accept them (and thus could produce a different object file
#	from some other make file).  To assist in distinguishing which
#	object files need different names, look at the .h files required
#	by the sources.  defgb.h contains parameters configurable at compile-
#	time.  Therefore, sources which need it should be compiled into 
#	object files of different names whether or not compile-time parameters
#	are specified in this make file
#	  Documentation for compile-time parameters is available.  WJS 
#	(wsass@whoi.edu) has two files-defgb_switches.doc and 
#	outer_switches.doc.  Not sure where copies reside on master globec
#	server
#	

# Method name is in variable METHOD, which is also used in building separate
#   object file names where needed.  Controls METHOD_NAME compilation
#   switch.
# See defgb_switches documentation for meaning of METHOD_PROTOTYPE variable/
#   compilation switch
# Method is built in METHDIR
# TESTDIR and CONTRIB are 2 directories where sources and objects reside
#   Idea is to look in TESTDIR first, then CONTRIB.  Objects end up in
#   directories corresponding to the source from which they came.
# LIBDIR is where the object/image libraries reside; LIBSRC is where 
#   "master" include files reside.  These should be "readonly" to this
#   makefile

METHOD=defgb
METHOD_PROTOTYPE=DEFGB

SOURCEDIR=.
METHDIR=.
TESTDIR=/export/home/wsass
CONTRIB=/data/globec/contrib
LIBDIR=/data/globec/lib
LIBSRC=/data/globec/libsrc

# Note that make looks in current directory before using VPATH
# VPATH is a path for all dependencies (object, source, library, etc)
#   VPATH is very tricky.
#   Example 1: you have the old defgb in contrib.  You want to build a
#	new test version in testdir.  You put the tar file in testdir,
#	unpack it, and make.  make looks for any .o files it needs.  There
#	are none in testdir, but it finds them all in contrib.  To see if
#	it should rebuild them, make looks for the sources from which they
#	came/will come.  It finds these sources in testdir & remakes the
#	master objects from the new sources.
#   Example 2: you consider 
#	x.o : x.c
#		cc -c x.c  
#			to be the same as 
#	x.o : x.c
#		cc -c x.c -o x.o
#	However, in the first case, the object file always goes in the
#	directory where the source file came from even if the compilation
#	is happening based on a .o from a different directory.  In the 
#	second case, the .o that gets rebuilt IS the .o whose date caused
#	make to do the compilation.
#   NB: I am a novice at make, so all this may be well known
VPATH=${SOURCEDIR}:${TESTDIR}:${CONTRIB}:${LIBDIR}

CC=cc -DSOL -DSVR4 -lnsl -lsocket -lm -g

#

all: ${METHDIR}/${METHOD}

${METHDIR}/${METHOD}: ${METHOD}.o \
		  ioopen_routines_${METHOD}.o \
		  ioreadrec_routines.o \
		  outerw_${METHOD}.o \
		  defgb_utils.o \
	          startchild_defgb.o \
		  jgofs.a
	${CC} outerw_${METHOD}.o \
	      ${METHOD}.o \
	      ioopen_routines_${METHOD}.o \
	      ioreadrec_routines.o \
	      defgb_utils.o \
	      startchild_defgb.o \
	      jgofs.a \
	      -o $@

#	-I${VPATH} takes care of situation where only defgb.h changes (ie,
#	is in TESTDIR).  Its existence will force a rebuild, but the
#	source will come from CONTRIB, and the #include rules for c will
#	look for defgb.h there, using the unchanged one (I think!)
${METHOD}.o: defgb.c defgb.h
	${CC} -DMETHOD_PROTOTYPE=${METHOD_PROTOTYPE} \
		-DMETHOD_NAME='"${METHOD}"' \
		-I${VPATH} \
		-c defgb.c \
		-o ${METHOD}.o

ioopen_routines_${METHOD}.o: ioopen_routines.c defgb.h
	${CC} -DMETHOD_PROTOTYPE=${METHOD_PROTOTYPE} \
		-DMETHOD_NAME='"${METHOD}"' \
		-I${VPATH} \
		-c ioopen_routines.c \
		-o ioopen_routines_${METHOD}.o

defgb.h: defgb_nonconfigurable.h
	touch defgb.h

ioreadrec_routines.o: ioreadrec_routines.c defgb_nonconfigurable.h
	${CC} -I${VPATH} \
		-c ioreadrec_routines.c \
		-o ioreadrec_routines.o

defgb_utils.o: defgb_utils.c defgb_nonconfigurable.h
	${CC} -I${VPATH} \
		-c defgb_utils.c \
		-o defgb_utils.o

outerw_${METHOD}.o: outerw_url.c
	${CC} -DQUOTENOLINK \
	      -DOPTIONHOST='"//optserv1.whoi.edu"' \
	      -DMYADDR='"//globec.whoi.edu"' \
	      -c outerw_url.c \
	      -o outerw_${METHOD}.o \
	      -I${LIBSRC}

startchild_defgb.o: startchild_defgb.c
	${CC} -c startchild_defgb.c \
	      -o startchild_defgb.o
