#  makefile.math			Jul 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


#  15 May 09.  Remove USE_DOUBLE.  WJS
#  21 Jul 05.  WJS
#	Remove the -NOTOPLINKS spec.  Obsolete after we added capability
#	  for per-button control (normally done by env vars in object
#	  defns)
#  17 Jul 04.  WJS
#	Complete replacement of makefile.math by makefile.nm, mostly to
#	  implement 7 Jul comment (from makefile.nm - other comments from
#	  original makefile.math)
#   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
#  11 Jan 99.  WJS
#	Changes for outer_brev (including USE_DOUBLE switch)
#  21 Nov 98.  WJS
#	Change method name back to math so it won't conflict w/Chris' real
#	makefile for optmath.
#  17 Nov 98.  WJS
#	Typo fix to CLH mod.  Mods to comments
#	Took out clean option
#     Nov 98.  CLH (comment by WJS)
#	Add directory for #include files.
#	Don't try to make methods directory if it already exists
#	Add clean option
#   7 May 98.  WJS
#	Correct typo in I_LIST.  Correct comment.
#  21 Apr 98.  WJS
#	Define OO_OUTER in case outer_brev is being used
#  15 Apr 98.  WJS
#	Switch method name to optmath
#   3 Apr 98.  WJS
#	makefile.math (comments below from make_method.jgofs15)
#   3 Apr 98.  WJS
#	Use I_LIST instead of individual -Is
#	Fix typo which omitted METHOD_CFLAGS from non-BUTTONIMAGESDIR case
#   2 Oct 97.  WJS
#	Fix typo in -I switch.  Add -I to look in INCDIR

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

METHOD_NAME = math
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 math 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 math
OBJ = ${SRCDIR}/math.c ${SRCDIR}/mathexw.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 = ${SRCDIR}/jgmath.h ${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 = -lm

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