#		makefile.makenetcdf 		Jun 05
#		  Stuff about non-existent library comes from matlab stuff
#   3 Dec 12  WJS
#	Version of netcdf installed on gb11 apparently now "does" run-time
#    loading.  Older versions used a static library.  Run-time loading in
#    its most general case requires fooling w/LD_LIBRARY_PATH.  Heartily
#    tired of this (see makefile.matlab and possibly other matlab stuff),
#    decided to use  -rpath  instead
#	New netcdf library itself needs a new library (libhdf5, approx)
#    It was installed (don't know when, or as part of what package)
#    in /usr/local/lib.  The library requirement must either be attended to in
#    this file, or, at the "system" level, /usr/local/lib must be in some
#    search path or other.  On gb11, Eric put /usr/local/lib in /etc/ld.so.conf
#    and "ran 'ldconfig' to generate a new /etc/ld.so.cache file", so code is
#    NOT in here 

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

BIN = ${BINDIR}/makenetcdf
BIN_TEST = ${BINDIR}/testnetcdf

#	Files which need to be compiled in order to build makenetcdf
OBJ =   ${SRCDIR}/makenetcdf.c 
OBJ_TEST = ${SRCDIR}/testnetcdf.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} \
		 ${NETCDFINCDIR}/netcdf.h 

#	libraries required
LIB_LIST = ${LIBDIR}/jgofs.a
LIBDIR_LIST = -L${NETCDFLIBDIR}
RUNTIME_LIBDIR_LIST = -Wl,-rpath,${NETCDFLIBDIR}
SYSLIB_LIST = -lnetcdf

#	Method-specific compilation flags
METHOD_CFLAGS = -g

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

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

include ${MASTERINCDIR}/h_file_dependency_macros.include

all: ${BIN} ${BIN_TEST}

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

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

${BIN_TEST}:${OBJ_TEST} ${NETCDFINCDIR}/netcdf.h ${CONFIG_FILE}

	@-test -d ${BINDIR} || mkdir ${BINDIR}
	test ${NETCDFLIBDIR} && \
		$(CC) \
			${CFLAGS} ${METHOD_CFLAGS} \
			-I${NETCDFINCDIR} \
			${OBJ_TEST} \
			${LIBDIR_LIST} \
			${RUNTIME_LIBDIR_LIST} \
			${SYSLIB_LIST} \
		-o $@ 

/netcdf.h:
	@-echo "Not making ${BIN} or ${BIN_TEST}
	@-echo "Appropriate netcdf library not provided"
	@-echo "Please ignore make errors related to ${BIN} or ${BIN_TEST}"
