#  makefile.join		Nov 04
#    (from makefile.nm)

# Assumes jgofs distribution 1.5 or later 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

# See makefile.nm (from which this presumably came) for comments.

#  15 May 09.  Remove USE_DOUBLE.  WJS
#  29 Apr 09.  WJS
#	Fix doc - this file has always assumed a jgofs 2.0 distribution
#	even when we didn't know that's what it was going to be called.

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

METHOD_NAME = join
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}/join.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} \
		-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}
