#		makemat.include
#	Needs defns for M_INCDIR, M_LIBDIR and E_NAME 
#	from either environment or previously defined make macro.
#	M_SYSLIBDIR is optional (used to handle situation if matlab
#	requires a particular version of a system library directory)
#	  The make macro SETNAME_SWITCH may also be previously defined.
#	It sets the value of the c macro USE_MXSETNAME.  If the make
#	macro is undefined, the c macro is defined as FALSE.  If the c,
#	macro is to be TRUE, the make macro can be defined as 
#	the string "-DUSE_MXSETNAME".  The make macro can also take other
#	forms such as "-DUSE_MXSETNAME=0" or "-DUSE_MXSETNAME=1", etc.
#	See below to decide what value is needed

#   8 Apr 12.  WJS
#	Library locations and requirements changed yet again w/ matlab 7.1.
#    Further, matlab 7.1 requires a particular version of libstdc++ of which 
#    they provide a copy in case your OS doesn't match ... and it doesn't
#    (to be fair, this seems to be an issue of libstdc++ version compatibility,
#    not a matlab issue)
#	Decided to include particular runtime shared library names in the image
#    rather than expect them from the environment (LD_LIBRARY_PATH).  This is
#    required to deal w/the libstdc++ thing (although matlab recommends using
#    LD_LIBRARY_PATH at both link and run time ... therefore putting their
#    libstc++ in the search list for ALL images).  It also allows getting rid
#    of setting LD_LIBRARY_PATH at runtime in all cases.  The downside occurs
#    if you run the image on a box NOT where it was linked (eg, if it's served
#    by NFS).  Will try to live w/that
#	NB: there are what seem to me to be general inconsistencies about switch
#    format among switches and between compiler and linker switches.  For example,
#    the linker will accept a  -R  switch not followed by a directory, whereas the
#    compiler does not seem to like a "bare"  -L  switch.  It's also not clear
#    which switches accept a list of following parameters and which accept only
#    one (requiring repeats of the switch name).  There may also be a difference
#    if a single-letter switch name is or is not separated from what follows by
#    a blank.

#  31 May 08.  WJS
#	Too bad the "assumptions in next paragraph" (below) turn out to be
#    a complete guess.  The API changed w/matlab 6.5; possibly other
#    versions, too.  For our purposes, we seem to be able to get away
#    with one switch.  The old mxSetName & matPutArray stuff was replaced
#    by matPutVariable.  The makemat.c source was modified to make a
#    compile-time decision about what to do based on the value of the
#    macro USE_MXSETNAME, which is to be TRUE if the old stuff is wanted
#    and FALSE if the new stuff is wanted.  w/no definition, the c code
#    defaults to FALSE.
#  18 Jun 05.  WJS
#	Write this as an "include" file so we can easily make different
#    versions of makemat (if assumptions in next paragraph stay true!)
#	Address the issues outlined in March.  Decided to make different
#    executables per matlab version.  Since we want to use the same 
#    make file for each, some stuff needs to come from "outside"
#	Add CONFIG_FILE dependency
#   5 Mar 05.  WJS
#	Get defgb_utils stuff from jgofs.a
#	Put in some relative locations for non-MATLAB defns
#	MATLAB lib defns still in flux.  A list of values is in env var M_LIST
#    (set by XXXbuild-env.pl; we'd want MATLAB_LIB_LOC),
#    but haven't tackled parsing said list.  Further, we are not 
#    really coordinated w/makematlab.pl, which eventually is supposed to 
#    allow user to select which matlab to use.  Value here is used at 
#    compile time, so implicit assumption has to be that all MATLAB libs 
#    have same defns, are compatible, etc.  Doesn't seem reasonable -
#    surely only upward compatibility is assured.  Also doesn't seem
#    to make sense to compile w/oldest lib but regularly run w/newest one.
#    Finally, we need both lib loc and include directories here - what's
#    defined is the lib loc.  Dare we define a root and assume MATLAB
#    will leave the structure the same?  (Note, btw, the relationship
#    between the include file and the library in regard to the issue
#    of runtime selection of library.  If they're coupled, how can
#    runtime selection be properly accomplished?)
#   

# March 23, 2004.  Edited from WJS version for inclusion in optserver.
# Decided to not generalize entries, to await overhaul of optserver and
# other stuff.  Deliberately using the older versions of defg_utils etc.
# RCG/WJS

BINDIR  = ../../bin
LIBDIR = ../lib
MASTERINCDIR = ../include
SRCDIR = .

BIN = ${BINDIR}/${E_NAME}

#	Files which need to be compiled in order to build stats
OBJ =   ${SRCDIR}/makemat.c 

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

#	.h files (or other included files) on which inner or outer depend
INCLUDED_FILES = ${OPTIONS} \
		 ${INNEROPTIONS} \
		 ${M_INCDIR}/matrix.h \
		 ${M_INCDIR}/mat.h 

#	libraries required.  Note that many names include _LIST.  In fact,
#	it's possible that each element of a list may require its own
#	copy of its switch, leading to syntax changes, etc.  Note also
#	that while  -rpath  seems to be happy w/o an "argument",  -L  doesn't
#	  Actually getting away from syntax issues, note that ${M_SYSLIBDIR}
#	really ought to be on LIBDIR_LIST, too.  I think what's happening is
#	that at compile time, the system default "SYSLIBDIR" is used, but
#	at run-time, ${M_SYSLIBDIR} is used.  Works at the moment because
#	the "special" library is a matlab-required version of the system default
#	and therefore presumably has the same compile-time symbol defns
LIB_LIST = ${LIBDIR}/jgofs.a
LIBDIR_LIST = -L${M_LIBDIR}
RUNTIME_LIBDIR_LIST = -Wl,-rpath,${M_LIBDIR}
RUNTIME_MATLAB-SPECIAL_SYSLIBDIR = -Wl,-rpath,${M_SYSLIBDIR}
SYSLIB_LIST = -lm -lmat -lmx

#	Method-specific compilation flags
METHOD_CFLAGS = -g

#	Compilation switches
SWITCHES = -DOPTIONS='"${OPTIONS}"' \
	   -DINNEROPTIONS='"${INNEROPTIONS}"' \
	   ${SETNAME_SWITCH}

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

include ${MASTERINCDIR}/h_file_dependency_macros.include

all: ${BIN}

${BIN}:${OBJ} ${INCLUDED_FILES} ${LIB_LIST} ${CONFIG_FILE}

	@-test -d ${BINDIR} || mkdir ${BINDIR}
	test ${M_LIBDIR} && \
		$(CC) \
			${CFLAGS} ${METHOD_CFLAGS} \
			${SWITCHES} \
			-DBUTTONIMAGESDIR='"${BUTTONIMAGESDIR}"' \
			-I${SRCDIR} \
			-I${M_INCDIR} \
			-I${MASTERINCDIR} \
			${OBJ} \
			${LIB_LIST} \
			${LIBDIR_LIST} \
			${RUNTIME_LIBDIR_LIST} \
			${RUNTIME_MATLAB-SPECIAL_SYSLIBDIR} \
			${SYSLIB_LIST} \
		-o $@ 

/matrix.h:
	@-echo "Not making ${BIN}-appropriate matlab library not provided"
	@-echo "Please ignore make errors related to ${BIN}"
/mat.h:

