# For defgb 3.0 et seq; assumes jgofs 1.5 distribution and that this file,
#    along with the defgb sources, is in src/* under the jgofs root.
#    See below if this is not the case.
#    Further assumes that src/methods/outer.c includes .brev capability.
#    that src/include exists and contains "appropriate" .h files,
#    including the ones for outer.c

# A certain set of compilation constants for outer is assumed (see SWITCHES
#    defn below).  Additional constants can be specified by defining
#    ADDL_SWITCHES.  Different constants require redefinition of the
#    SWITCHES symbol (on command line or in environment along with the
#    -e make switch) or specification in ADDL_SWITCHES plus knowledge
#    about how multiple constant defns are handled.
# Flags for the compilation/load come from 3 sources.  The CC symbol
#    typically includes some flags.  CFLAGS is defined here.
#    ADDL_CFLAGS may be defined externally.  See comments for
#    ADDL_SWITCHES, above

# This file can be run standalone if:
#	1) METHOD is defined on make command line
#	2) jgofs_root/build-env.pl has been executed first in context of
#	   this process 
#	3) jgofs.a library has already been built
#    Note: can be used to create an image in any directory from any
#	directory by specifying any or all of METHBINDIR, OUTERSRCDIR,
#	LIBDIR, & SRCDIR on the command line

# If there is trouble porting the jgofs.a jdb routines, defgb
# can be built without them by specifying the compilation switch
#	-DREAD_OBJECTS=FALSE
# If there is trouble porting the startchild_defgb routine, defgb
# can be built without it by specifying the compilation switch
#	-DREAD_COMMANDS=FALSE
# See defgb_switches.doc for details about compilation switches
# See param1.doc for information about what defgb functionality is
# lost when these switches are specified

#  30 Aug 04.  WJS
#	JGFUNCDEFNS_H_DEPENDS.
#	UTILS_H_DEPENDS belongs w/DEGB_H_DEPENDS as things are presently
#	  coded
#  17 Jul 04.  WJS
#	Return to the more precise distinction between compilation and linking
#	  courtesy of gcc's preference.  Libraries (and dependencies on
#	  libraries) belong in link commands (and image dependencies), not
#	  compilation commands (and object dependencies)
#   7 Jul 04.  WJS
#	master_makefile.defgb becomes makefile.defgb
#	Mods to take advantage of new build stuff (add ${CONFIG_FILE}, etc
#	  dependencies; build optdefgb, etc).  CONFIG_FILE (eg, build-env)
#	  is used to force builds in addition to its natural dependency role
#	Mod to use outer_make_macros.include
#  28 Apr 04.  WJS
#	Typo fixes
#	Get outer.h from OUTERINCDIR & define that to OUTERSRCDIR
#	Add utils.h dependency
#	INCDIR to TESTINCDIR
#  13 Feb 04.  WJS
#	defgb_utils in library, too
#	Allow two INCDIRs for testing.  MASTERINCDIR stays src/include
#  10 Feb 04.  WJS
#	Assume startchild_defgb, path_info_routines, &
#      outer_utils are in library.
#	Separate compilation for outer.o, taking outer.c and its support
#      files from src/methods, etc instead of .   Among other things,
#      OUTERBREVDIR is gone.
#   9 Jul 03.  Create per-method outer object file on logic that each
#	method compilation could have different -D switches.  WJS
#  24 Dec 02.  HAS_OUTER_INTEREST_ENTRY.  WJS
#   7 Jan 99.  USE_DOUBLE.  WJS
#   3 Dec 98.  Remove METHOD_PROTOTYPE.  WJS
#  17 Nov 98.  Add CLH mods anticipating include directory & testing for
#	existence of method directory before attempting creation.  WJS
#  11 Nov 98.  outer.h; outer_utils.c.  Taken from outer_brev's directory
#	for now.  Presumably will cause no harm if plain outer is being
#	used.  WJS
#  13 May 98.  Take outer.c from defgb distribution directory instead of from
#	JGOFS distribution location.  Assumption is that outer in defgb
#	distribution is outer_brev.  WJS
#  30 Jan 98.  ADDL_*S; SYS_LIBS
#	       Change METHOD_CFLAGS to CFLAGS. (Note: CFLAGS used to be
#	set in build or someplace (see the makefile for jgofs.a), but
#	doesn't seem to be set any more, so I glommed it)
#	       Put -lm in SYS_LIBS instead of CFLAGS.
#	       Typo fixes.  WJS
#  30 Sep 97.  A bit less defgb-specific.  Add SRCDIR, too
#  11 Sep 97.  More comments
#  11 Aug 97.  Change for use as include file.
#	       Remove incorrect build-env dependency.
#	       Parametrize various "components".  WJS
#  31 Jul 97.  Non-standard default.h (bigger TOKEN size for outer) and
#	appropriate -I switch to find it in defgb's directory while
#	compiling outer in its directory.
#	       Dependency on build-env so changes to *SERVER constants, etc,
#	will cause rebuilding.  WJS
#  24 Jul 97.  Add PATH_INFO_routines.  WJS

METHOD = defgb

METHBINDIR  = ../../methods
OUTERSRCDIR = ../methods
LIBDIR  = ../lib
SRCDIR = .

#   Set to place w/no .h files.  To use, define location when make file invoked
#   This location searched first.  NB: it's not in any dependencies
TESTINCDIR = /
#   where lib .h files are (or other .h files that are NOT in this distribution)
MASTERINCDIR = ../include
#   where outer.h is
OUTERINCDIR = OUTERSRCDIR
#   local .h files expected in SRCDIR

PER_METHOD_OUTER = ${SRCDIR}/outer_${METHOD}
OUTER_SOURCE = ${PER_METHOD_OUTER}.c
OUTER_OBJECT = ${PER_METHOD_OUTER}.o

#	Files which need to be compiled in order to build defgb
OBJ = ${SRCDIR}/defgb.c \
      ${SRCDIR}/ioopen_routines.c \
      ${SRCDIR}/ioreadrec_routines.c

#	List of directories in which we might find .h files, separated by -Is 
#	Order of specification is significant.
#	No problem if no .h files in a directory and/or if a directory
#	  does not exist.
#	(-I ${SRCDIR} is default; included here to show syntax)
#	(Could get rid of -Is if I knew how to parse in make.  Sigh)
I_LIST = -I${TESTINCDIR} -I${OUTERINCDIR} -I${SRCDIR} -I${MASTERINCDIR} 

#	libraries required
LIB_LIST = ${LIBDIR}/jgofs.a
#		(Seems to me that all -l directives should be here.  However,
#		 turns out that -lm MUST be here... for fabs but not for
#		 pow, which was found w/a -lm at the beginning!)
#		(Turns out it was needed here for pow on HP...)
SYS_LIBS = -lm

#	Method-specific compilation flags
CFLAGS = -g

OPTIONS = ${MASTERINCDIR}/default.h
DEFGB_OUTER_SWITCHES = \
	   -DUSE_DOUBLE \
	   -DHAS_OUTER_INTEREST_ENTRY

INNEROPTIONS = ${MASTERINCDIR}/inner.h
INNER_SWITCHES = -DOPTIONS='"${OPTIONS}"' \
		 -DINNEROPTIONS='"${INNEROPTIONS}"'

include ${MASTERINCDIR}/h_file_dependency_macros.include
include ${OUTERSRCDIR}/outer_make_macros.include

#######################

all: ${METHBINDIR}/${OPT}${METHOD} ${CONFIG_FILE}

OUTER_COMPILE =	${OUTER_COMPILE_SWITCHES} \
		${DEFGB_OUTER_SWITCHES} \
		-c ${OUTER_SOURCE} \
		-o ${OUTER_OBJECT}

DEFGB_H_DEPENDS = ${SRCDIR}/defgb.h \
		  ${PATH_INFO_H_DEPENDS} \
		  ${UTILS_H_DEPENDS}

${METHBINDIR}/${OPT}${METHOD}:${OBJ} ${OUTER_OBJECT} \
			      ${LIB_LIST} ${OUTER_LIB_LIST} \
			      ${DEFGB_H_DEPENDS} \
			      ${JGFUNCDEFNS_H_DEPENDS} \
			      ${CONFIG_FILE}
	@- test -d ${METHBINDIR} || mkdir ${METHBINDIR}
	$(CC) \
		${CFLAGS} ${ADDL_CFLAGS} \
		${INNER_SWITCHES} ${ADDL_SWITCHES} \
		${I_LIST} \
		${OBJ} ${OUTER_OBJECT} \
		${LIB_LIST} ${OUTER_LIB_LIST} ${SYS_LIBS} \
	-o $@

${OUTER_OBJECT}:${OUTER_SOURCE} \
		${OUTER_H_DEPENDS} \
		${CONFIG_FILE}
	$(CC) ${OUTER_COMPILE}

${OUTER_SOURCE}:${OUTERSRCDIR}/outer.c ${CONFIG_FILE}
	cp ${OUTERSRCDIR}/outer.c ${OUTER_SOURCE}
