#		makemat.include
#	Needs defns for M_INCDIR, M_LIBDIR and E_NAME 
#	from either environment or previously defined make macro.
#	  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

#  18 Jun 08.  WJS
#	Add $ARCH_SWITCH
#  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
LIB_LIST = ${LIBDIR}/jgofs.a
LIBDIR_LIST = -L${M_LIBDIR}
SYSLIB_LIST = -lm -lmat -lmx

#	Method-specific compilation flags
METHOD_CFLAGS = -g ${ARCH_SWITCH}

#	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} \
			${SYSLIB_LIST} \
		-o $@ 

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

