#  makefile.nm			Jul 04
#    (from makefile.rs)

# Assumes jgofs 1.5 distribution and that this file,
#    along with the sources, is in src/* under the jgofs root.

# Can be run standalone if:
#	1) jgofs_root/build-env.pl has been executed first in context of
#	   this process (eg,
#		jgofs_root/build-env.pl -sh > /tmp/build-env.sh
#		source /tmp/build-env.sh
#	   )
#	2) jgofs.a library has already been built


#  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
#	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
#  12 Feb 04.  WJS
#	Assume lots of stuff in library.
#	Assume src/methods/outer.c is outer_brev; exeunt OUTERBREVDIR
#	Compile w/debug support
#  23 Jul 03.  WJS
#	Correct OUTERSRCDIR and INCDIR for existing tree structure.
#	Per suspicion voiced in comment, INNERDEFAULT needs mod, too
#    (Interestingly, comment itself caused trouble on Bob's box and I
#    removed it.  make was including the whitespace before the # as part
#    of the filespec.  Don't know how it ever worked...)
#  29 Jan 99.  WJS
#	Correct OUTERSRCDIR and INCDIR for 1.5 tree structure.

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

METHOD_NAME = nm
METHOD = ${METHBINDIR}/${OPT}${METHOD_NAME}

#	next 2 macros needed by outer_make_macro.include
#	Not really clear what should be defined in terms of what
#	  (eg, should INCDIR (where nm looks for its include files)
#	  be set = to MASTERINCDIR (where things like core.h are
#	  stored) w/ MASTER defined above)
OUTERINCDIR = ${OUTERSRCDIR}
MASTERINCDIR = ${INCDIR}

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

#	Non-outer files which need to be compiled in order to build nm
OBJ = ${SRCDIR}/nm.c

#       .h files (or other included files) on which inner depends
#	OPTIONS, INNEROPTIONS macros needed by outer_make_macro.include
INNEROPTIONS = ${INCDIR}/inner.h
OPTIONS = ${INCDIR}/default.h
INCLUDED_FILES = ${OPTIONS} ${INNEROPTIONS}

#	List of directories from .h files in INCLUDED_FILES, separated by
#	-Is (-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${SRCDIR}

#	libraries required.  SYSLIB list needs leading hyphens
LIB_LIST = ${LIBDIR}/jgofs.a
SYSLIB_LIST =

#	Method-specific compilation flags
METHOD_CFLAGS = -g

#	Inner compilation switches
SWITCHES = -DOPTIONS='"${OPTIONS}"' \
	   -DINNEROPTIONS='"${INNEROPTIONS}"'

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

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

all: ${METHOD} ${CONFIG_FILE}

${METHOD}:${OBJ} ${OUTER_OBJECT} \
	  ${LIB_LIST} ${OUTER_LIB_LIST} \
	  ${INCLUDED_FILES} \
	  ${CONFIG_FILE}
	@- test -d ${METHBINDIR} || mkdir ${METHBINDIR}
	$(CC) \
		${CFLAGS} ${METHOD_CFLAGS} \
		${SWITCHES} \
		${I_LIST} \
		${OBJ} ${OUTER_OBJECT} ${OUTER_LIB_LIST} \
		${LIB_LIST} ${SYSLIB_LIST} \
	-o $@

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

${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}
