# makefile.trigram   Mar 99  WJS
#	Builds trigram_util, test_trigram & test_trigram_fortran
#	executables.  all option builds trigram_util; the test programs
#	are for testing the functions.
#	May be run standalone if FC & CC symbols are provided (usually
#	via a  source build-env  command)

#  17 Jul 04.  WJS
#     Add dependency on build-env.pl (${CONFIG_FILE}).  Could also put in
#	h_file_dependency.include, but existing coding looks pretty good...
#  24 Apr 04.  WJS
#	Assume images should go in ../../bin (where trigram_util 
#	  lives on OOserver, which is only place so far that uses it)
#	error_exit_defn.h defns now in core.h, so xOPTIONS_FILE needed
#	  here
#	Move of stuff to lib means a dependency on the lib (only the
#	  routines we use, but who knows how to do that?)
#  18 Feb 04.  WJS
#	Assume more stuff is in library.
#	Assume test_trigram.c & .f in SRCDIR
#	Assume this is being run from XXXsrc/YYY
#	Take INCDIR and LIBDIR from standard locations
#	Require user defn of CC and FC symbols (usually from build-env)
#		[Begin v 1.2]
#
#  22 Apr 99.  WJS
#	Add INCDIR, SRCDIR & error_exit_defn.h
#		[Begin v 1.1]

#  BINDIR is where executables should end up
#  INCDIR is where various "system" .h files live
#  LIBDIR is location of "system" library containing trigram routines
#  SRCDIR is where the program sources are (and where their object
#	files will end up)
BINDIR = ../../bin
INCDIR = ../include
LIBDIR = ../lib
SRCDIR = .
LIBNAME = jgofs.a

DOPTIONS_FILE = ${INCDIR}/default.h
IOPTIONS_FILE = ${INCDIR}/inner.h

CFLAGS = -g
FFLAGS = -g
LIB = ${LIBDIR}/${LIBNAME}

INCLUDED_FILES = ${INCDIR}/core.h \
		 ${DOPTIONS_FILE} \
		 ${IOPTIONS_FILE}

I_LIST = -I ${SRCDIR} -I ${INCDIR}
LIB_LIST = ${LIB}
SWITCHES = -DOPTIONS='"${DOPTIONS_FILE}"' -DINNEROPTIONS='"${IOPTIONS_FILE}"'

all: ${BINDIR}/trigram_util ${CONFIG_FILE}

${BINDIR}/trigram_util: ${SRCDIR}/trigram_util.o ${LIB_LIST} ${CONFIG_FILE}
	$(CC) ${CFLAGS} \
		${SRCDIR}/trigram_util.o \
		${LIB_LIST} \
		-o $@

${BINDIR}/test_trigram: ${SRCDIR}/test_trigram.o ${LIB_LIST} ${CONFIG_FILE}
	$(CC) ${CFLAGS} \
		${SRCDIR}/test_trigram.o \
		${LIB_LIST} \
		-o $@

${BINDIR}/test_trigram_fortran: ${SRCDIR}/test_trigram_fortran.o \
				${SRCDIR}/trigram_fortran.o \
				${LIB_LIST} \
				${CONFIG_FILE}
	$(FC) ${FFLAGS} \
		${SRCDIR}/test_trigram_fortran.o \
		${SRCDIR}/trigram_fortran.o \
		${LIB_LIST} \
		-o $@

${SRCDIR}/trigram_util.o: ${SRCDIR}/trigram_util.c ${INCLUDED_FILES} ${CONFIG_FILE}
	$(CC) ${CFLAGS} \
		-c ${SRCDIR}/trigram_util.c \
		${SWITCHES} \
		${I_LIST} \
		-o $@

${SRCDIR}/test_trigram.o: ${SRCDIR}/test_trigram.c ${CONFIG_FILE}
	$(CC) ${CFLAGS} \
		-c ${SRCDIR}/test_trigram.c \
		${I_LIST} \
		-o $@

${SRCDIR}/test_trigram_fortran.o: ${SRCDIR}/test_trigram_fortran.f ${CONFIG_FILE}
	$(FC) ${FFLAGS} \
		-c ${SRCDIR}/test_trigram_fortran.f \
		-o $@

${SRCDIR}/trigram_fortran.o: ${SRCDIR}/trigram_fortran.c \
			     ${INCLUDED_FILES} \
			     ${CONFIG_FILE}
	$(CC) ${CFLAGS} \
		-c ${SRCDIR}/trigram_fortran.c \
		${I_LIST} \
		-o $@
