#  makefile.deci			Dec 06
#    (from makefile.math)

# 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

#  29 Aug 14.  Make -g a "global" flag instead of an inner flag so outer gets 
#		compiled w/debug.  WJS
#  15 May 09.  Remove USE_DOUBLE.  WJS

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

METHOD_NAME = decimator
METHOD = ${METHBINDIR}/${OPT}${METHOD_NAME}

#	next 2 macros needed by outer_make_macro.include
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 
#	the decimator
OBJ = ${SRCDIR}/deci.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 = ${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

#	Inner-specific compilation flags
METHOD_CFLAGS =

#	Inner/outer compilation flags
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}
