# makefile for jgofs.a library 
#    Also makes some "standalone" .o files in lib directory
#    Also makes core.h, path_info.h & utils.h .h files in include directory
#	Requires write access to .h file directories (as well as jgofs.a's
#	directory)

#	NOTE: core.h includes OPTIONS, so each compilation of something
#	that uses core.h must also -DOPTIONS=

#   8 Jun 09.  WJS
#	Change some comments
#  20 May 09.  WJS
#	Split parse into jgofs_selection_parser and jgofs_selection_tester
#	  NB: Old parse module must be removed from library manually
#	Get rid of 14 Feb precision stuff
#	Add iovaldouble_stub
#  25 Apr 09.  WJS
#	varnames_in_selection
#  14 Feb 09.  WJS
#	Address complete botch of parse make with regard to precision
#	We need a single and double precision version which calling program
#	   must select at compile time.  To help w/this, separated non-
#	   precision dependent code into another module
#  24 Jan 08.  WJS
#	Add tcp.h to list of "HT_H_FILES".  Too lazy to do things
#	  accurately.  2 HT*.h files depend on tcp.h, as do all 3 HT*.c
#	  files.
#  25 Oct 07.  WJS
#	parse
#	Add dependency of dct on core.h
#   2 Sep 04.  WJS
#	query_string_routines
#   1 Sep 04.  WJS
#	Comment change
#	err_stub_methods routine
#  30 Aug 04.  WJS
#	jdbfuncdefns.h
#  26 Aug 04.  WJS
#	Add debug flag to compiles
#	Mods for dct now that it uses core.h
#	err_stub routine
#  20 Jul 04.  WJS
#	Use h_file_dependency_macros.include
#	Make "master" .h files depend on ${CONFIG_FILE}, too
#   7 Jul 04.  WJS
#	Make everything except "master" .h files depend on ${CONFIG_FILE} 
#	  (build-env.pl) whether things need it or not.  This allows forced makes
#  13 Feb 04.  WJS
#	Rework to allow build w/some files in a test directory w/others
#	  from "master" directory.  If master = test (default), can be
#	  used to build master (assuming all source files are listed).
#	Among other things:
#	  explicit compilation for each .o file	
#	  play w/dependencies on .h files
#	  parametrization of library name and *OPTIONS files
#	  make parametrization of directory names consistent (no trailing / -
#	    some day I'll change METHOD_ROOT in jdb & dct!!!)
#	-I_LIST to deal w/new uses of .h files (notably core.h)
#	  Moves 3 .h files to INCDIR
#	Include startchild, outer_utils & utils (former defgb_utils), which
#	  were not in jgofs.a as of Feb 04)
#
# modified from option server make file for use with new jdb routine.
#	September 22, 1999.  rcg
# modified for additional dependencies, jdb v1.0b September 10, 1999 clh
# updated for v1.5 JGOFS software clh, November 3, 1998
#

SRCDIR = .

#   Next is where library will be built
LIBDIR = .

#   Next is where core.h, path_info.h, and utils.h will be put
#   (INCDIR would be used for library-routine-specific .h files that
#   wouldn't be shared w/non-library routines.  We have none of those at the moment)
MASTERINCDIR = ../include

#   Next is location of the "real" jgofs.a, its component sources
#   and their component .h files.  Note that a file we might want to fiddle
#   with in a test directory (eg, HTTCP.c) benefits from getting .h
#   files from MASTERSRCDIR
MASTERSRCDIR = .

#   Next is location of jgofs-maintainer-alterable files (typically
#   default.h and inner.h)
MAINTAINER_INCDIR = ../include

LIBNAME = jgofs.a

LIB = ${LIBDIR}/${LIBNAME}

DEBUG = -g

OPTIONS = ${MAINTAINER_INCDIR}/default.h
INNEROPTIONS = ${MAINTAINER_INCDIR}/inner.h

CORE_H = ${MASTERINCDIR}/core.h
PARSE_H = ${MASTERINCDIR}/parse.h
QUERY_STRING_H = ${MASTERINCDIR}/query_string_routines.h
PATH_INFO_H = ${MASTERINCDIR}/path_info_routines.h
UTILS_H = ${MASTERINCDIR}/utils.h
JDBFUNCDEFNS_H = ${MASTERINCDIR}/jdbfuncdefns.h
H_INCLUDE_NAME = h_file_dependency_macros.include
H_INCLUDE = ${MASTERINCDIR}/${H_INCLUDE_NAME}
H_INCLUDE_SOURCE = ${SRCDIR}/${H_INCLUDE_NAME}

include ${H_INCLUDE_SOURCE}

all: ${LIB} \
     ${CORE_H} ${PARSE_H} ${QUERY_STRING_H} \
				${PATH_INFO_H} ${UTILS_H} ${JDBFUNCDEFNS_H} \
     err_stub.o \
     err_stub_methods.o \
     iovaldouble_stub.o \
     ${H_INCLUDE} \
     ${CONFIG_FILE}

#############################  .h files  ##########################
${CORE_H}: ${SRCDIR}/core.h ${CONFIG_FILE}
	cp ${SRCDIR}/core.h ${CORE_H}
${PARSE_H}: ${SRCDIR}/parse.h ${CONFIG_FILE}
	cp ${SRCDIR}/parse.h ${PARSE_H}
${QUERY_STRING_H}: ${SRCDIR}/query_string_routines.h ${CONFIG_FILE}
	cp ${SRCDIR}/query_string_routines.h ${QUERY_STRING_H}
${PATH_INFO_H}: ${SRCDIR}/path_info_routines.h ${CONFIG_FILE}
	cp ${SRCDIR}/path_info_routines.h ${PATH_INFO_H}
${UTILS_H}: ${SRCDIR}/utils.h ${CONFIG_FILE}
	cp ${SRCDIR}/utils.h ${UTILS_H}
${JDBFUNCDEFNS_H}: ${SRCDIR}/jdbfuncdefns.h ${CONFIG_FILE}
	cp ${SRCDIR}/jdbfuncdefns.h ${JDBFUNCDEFNS_H}
${H_INCLUDE}: ${H_INCLUDE_SOURCE} ${CONFIG_FILE}
	cp ${H_INCLUDE_SOURCE} ${H_INCLUDE}

#############################  jgofs.a  ###########################
I_LIST = -I ${SRCDIR} -I ${MASTERSRCDIR} \
	 -I ${MASTERINCDIR} -I{MAINTAINER_INCDIR}

DATA_SYS_OBJS = \
		${SRCDIR}/dct.o \
		${SRCDIR}/jdb.o \
		${SRCDIR}/HTParse.o \
		${SRCDIR}/HTString.o \
		${SRCDIR}/HTTCP.o    \
		${SRCDIR}/jgofs_selection_parser.o \
		${SRCDIR}/jgofs_selection_tester.o \
		${SRCDIR}/outer_utils.o \
		${SRCDIR}/path_info_routines.o \
		${SRCDIR}/parse_utils.o \
		${SRCDIR}/query_string_routines.o \
		${SRCDIR}/startchild.o \
		${SRCDIR}/utils.o \
		${SRCDIR}/varnames_in_selection.o

HT_H_FILES =	${MASTERSRCDIR}/HTAccess.h \
		${MASTERSRCDIR}/HTAlert.h \
		${MASTERSRCDIR}/HTAnchor.h \
		${MASTERSRCDIR}/HTAtom.h \
		${MASTERSRCDIR}/HTFormat.h \
		${MASTERSRCDIR}/HTList.h \
		${MASTERSRCDIR}/HTParse.h \
		${MASTERSRCDIR}/HTStream.h \
		${MASTERSRCDIR}/HTString.h \
		${MASTERSRCDIR}/HTUtils.h \
		${MASTERSRCDIR}/tcp.h



${SRCDIR}/dct.o:${SRCDIR}/dct.c ${CORE_H_DEPENDS} ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} ${I_LIST} \
		-DOBJECT_ROOT='"${JGOFSDIR}/objects"' \
	 	-DMETHOD_ROOT='"${JGOFSDIR}/methods/"' \
		-DOPTIONS='"${OPTIONS}"' \
	   -c ${SRCDIR}/dct.c

#   Account for VMS not allowing mixed case filenames.  Sigh.
${SRCDIR}/HTTCP.c: ${SRCDIR}/httcp.c ${CONFIG_FILE}
	cp ${SRCDIR}/httcp.c ${SRCDIR}/HTTCP.c
#   Not sure all HTx.c routines depend on all HTx.h files
${SRCDIR}/HTParse.o: ${MASTERSRCDIR}/HTParse.c ${HT_H_FILES} ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} ${I_LIST} -c ${MASTERSRCDIR}/HTParse.c
${SRCDIR}/HTString.o: ${MASTERSRCDIR}/HTString.c ${HT_H_FILES} ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} ${I_LIST} -c ${MASTERSRCDIR}/HTString.c
${SRCDIR}/HTTCP.o: ${SRCDIR}/HTTCP.c ${HT_H_FILES} ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} ${I_LIST} -c ${SRCDIR}/HTTCP.c

${SRCDIR}/jdb.o: ${SRCDIR}/jdb.c ${CORE_H_DEPENDS} ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} ${I_LIST} \
		-DOBJECT_ROOT='"${JGOFSDIR}/objects"' \
		-DMETHOD_ROOT='"${JGOFSDIR}/methods/"' \
		-DOPTIONS='"${OPTIONS}"' \
		-DINNEROPTIONS='"${INNEROPTIONS}"' \
	   -c ${SRCDIR}/jdb.c

${SRCDIR}/outer_utils.o: ${SRCDIR}/outer_utils.c ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} -c ${SRCDIR}/outer_utils.c

${SRCDIR}/path_info_routines.o: \
	    ${SRCDIR}/path_info_routines.c ${PATH_INFO_H_DEPENDS} ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} ${I_LIST} \
		-DOPTIONS='"${OPTIONS}"' \
		-DINNEROPTIONS='"${INNEROPTIONS}"' \
	   -c ${SRCDIR}/path_info_routines.c

${SRCDIR}/jgofs_selection_parser.o: \
	    ${SRCDIR}/jgofs_selection_parser.c ${PARSE_H_DEPENDS} ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} ${I_LIST} \
		-DOPTIONS='"${OPTIONS}"' \
		-DINNEROPTIONS='"${INNEROPTIONS}"' \
	   -c ${SRCDIR}/jgofs_selection_parser.c \
	   -o ${SRCDIR}/jgofs_selection_parser.o
${SRCDIR}/jgofs_selection_tester.o: \
	    ${SRCDIR}/jgofs_selection_tester.c ${PARSE_H_DEPENDS} ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} ${I_LIST} \
		-DOPTIONS='"${OPTIONS}"' \
		-DINNEROPTIONS='"${INNEROPTIONS}"' \
	   -c ${SRCDIR}/jgofs_selection_tester.c \
	   -o ${SRCDIR}/jgofs_selection_tester.o
${SRCDIR}/parse_utils.o: \
	    ${SRCDIR}/parse_utils.c ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} -c ${SRCDIR}/parse_utils.c

${SRCDIR}/query_string_routines.o: \
    ${SRCDIR}/query_string_routines.c ${QUERY_STRING_H_DEPENDS} ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} ${I_LIST} \
		-DOPTIONS='"${OPTIONS}"' \
		-DINNEROPTIONS='"${INNEROPTIONS}"' \
	   -c ${SRCDIR}/query_string_routines.c

${SRCDIR}/startchild.o:${SRCDIR}/startchild.c ${CORE_H_DEPENDS} ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} ${I_LIST} \
		-DOPTIONS='"${OPTIONS}"' \
		-DINNEROPTIONS='"${INNEROPTIONS}"' \
	   -c ${SRCDIR}/startchild.c

${SRCDIR}/utils.o: ${SRCDIR}/utils.c ${UTILS_H_DEPENDS} ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} ${I_LIST} \
		-DOPTIONS='"${OPTIONS}"' \
		-DINNEROPTIONS='"${INNEROPTIONS}"' \
	   -c ${SRCDIR}/utils.c

${SRCDIR}/varnames_in_selection.o: \
	    ${SRCDIR}/varnames_in_selection.c ${PARSE_H_DEPENDS} ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} ${I_LIST} \
		-DOPTIONS='"${OPTIONS}"' \
		-DINNEROPTIONS='"${INNEROPTIONS}"' \
	   -c ${SRCDIR}/varnames_in_selection.c \
	   -o ${SRCDIR}/varnames_in_selection.o

${SRCDIR}/err_stub.o: ${SRCDIR}/err_stub.c ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} \
	   -c ${SRCDIR}/err_stub.c

${SRCDIR}/err_stub_methods.o: ${SRCDIR}/err_stub_methods.c ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} \
	   -c ${SRCDIR}/err_stub_methods.c

${SRCDIR}/iovaldouble_stub.o: ${SRCDIR}/iovaldouble_stub.c ${CONFIG_FILE}
	$(CC) ${CFLAGS} ${DEBUG} \
	   -c ${SRCDIR}/iovaldouble_stub.c


${LIB}: $(DATA_SYS_OBJS) ${CONFIG_FILE}
	$(AR) $@ $(DATA_SYS_OBJS)
	$(RANLIB) $@
	@echo "Finished building $@"



clean:
	-rm ${DATA_SYS_OBJS} ${LIB}
