# "master" makefile for defgb derivatives

# 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.

# METHOD must be a pre-defined make symbol.
# 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 has been executed first in context of
#	   this process (ie, source jgofs_root/build-env)
#	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 along with METHOD

# 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

#  26 Jun 03.  HAS_OUTER_INTEREST_ENTRY.  WJS
#  15 Aug 99.  Compile in a test jdb.  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

METHBINDIR  = ../../methods
OUTERSRCDIR = .
LIBDIR  = ../lib
SRCDIR = .
#	Next directory anticipates a directory for commonly #included
#	.h files.  Not sure what's going to be in here.  Search this file
#	for INCDIR to see what latest assumption is...
INCDIR = .
#	Next directory is location for outer_brev files that are not
#	needed for outer.  We assume that outer_brev is distributed with
#	defgb until/unless it becomes outer, whereupon OUTERBREVDIR
#	can be replaced by OUTERSRCDIR & INCDIR (or other stuff - LIBDIR?
#	USER_LIBDIR?)
OUTERBREVDIR = .

#	Files which need to be compiled in order to build defgb
OBJ = ${OUTERSRCDIR}/outer.c \
      ${OUTERBREVDIR}/outer_utils.c \
      ${SRCDIR}/defgb.c \
      ${SRCDIR}/ioopen_routines.c \
      ${SRCDIR}/ioreadrec_routines.c \
      ${SRCDIR}/defgb_utils.c \
      ${SRCDIR}/path_info_routines.c \
      ${SRCDIR}/jdb.c \
      ${SRCDIR}/startchild_defgb.c

#	.h files (or other included files) on which inner or outer depend
#	This list is used for dependency only - I_LIST and the source
#	code control which files are actually used in the compilation.
#	Be nice if we could tie the 2 together, wouldn't it?!
# Note: I didn't bother to formally include default.h and innerdefault.h
#    into inner.  I eyeballed the relevant values to make sure defgb.h
#    is compatible. Assumption is that *default.h will change w/next
#    JGOFS release
INCLUDED_FILES = ${SRCDIR}/defgb_outer_default.h \
		 ${INCDIR}/path_info_routines.h \
		 ${OUTERBREVDIR}/outer.h \
		 ${SRCDIR}/defgb.h
#	List of directories from .h files in INCLUDED_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${INCDIR} -I${OUTERBREVDIR} -I${SRCDIR}

#	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

#	Compile-time constants
SWITCHES = -DOPTIONS='"${SRCDIR}/defgb_outer_default.h"' \
	   -DMYADDR='"${MYADDR}"' \
	   -DOPTIONSERVER='"${OPTIONSERVER}"' \
	   -DINFOSERVER='"${INFOSERVER}"' \
	   -DDIRSERVER='"${DIRSERVER}"' \
	   -DUSE_DOUBLE \
	   -DHAS_OUTER_INTEREST_ENTRY  \
	   -DQUOTENOLINK

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

all: ${METHBINDIR}/${METHOD}

${METHBINDIR}/${METHOD}:${OBJ} ${INCLUDED_FILES} ${LIB_LIST}
	@- test -d ${METHBINDIR} || mkdir ${METHBINDIR}
	if [ "$(BUTTONIMAGESDIR)" ];\
	then \
		$(CC) \
			${CFLAGS} ${ADDL_CFLAGS} \
			${SWITCHES} ${ADDL_SWITCHES} \
			-DBUTTONIMAGESDIR='"${BUTTONIMAGESDIR}"' \
			${I_LIST} \
			${OBJ} \
			${LIB_LIST} ${SYS_LIBS} \
		-o $@ ;\
	else \
		$(CC) \
			${CFLAGS} ${ADDL_CFLAGS} \
			${SWITCHES} ${ADDL_SWITCHES} \
			${I_LIST} \
			${OBJ} \
			${LIB_LIST} ${SYS_LIBS} \
		-o $@ ;\
	fi
