# -*- makefile -*-
# This file contains special make rules to generate codelets.
# Most of this file requires GNU make .

COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(CODELET_OPTIM)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
	$(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(CODELET_OPTIM)

CODLIST = codlist.c
CODELET_NAME=codelet_

# rule to build codlist
$(CODLIST): Makefile
	(								\
	echo "#include \"ifftw.h\"";					\
	echo;								\
	for i in $(ALL_CODELETS) NIL; do				\
	   if test "$$i" != NIL; then					\
	     j=`basename $$i | sed -e 's/[.][cS]$$//g'`;		\
             echo "extern void X($(CODELET_NAME)$$j)(planner *);";	\
           fi								\
	done;								\
	echo;								\
	echo;								\
	echo "extern const solvtab $(SOLVTAB_NAME);";		        \
	echo "const solvtab $(SOLVTAB_NAME) = {";		        \
	for i in $(ALL_CODELETS) NIL; do				\
	   if test "$$i" != NIL; then					\
	     j=`basename $$i | sed -e 's/[.][cS]$$//g'`;		\
	     echo "   SOLVTAB(X($(CODELET_NAME)$$j)),";			\
	   fi								\
	done;								\
	echo "   SOLVTAB_END";						\
	echo "};";							\
	) >$@

# only delete codlist.c in maintainer-mode, since it is included in the dist
# FIXME: is there a way to delete in 'make clean' only when builddir != srcdir?
maintainer-clean-local:
	rm -f $(CODLIST)

if MAINTAINER_MODE

INDENT = indent -kr -cs -i5 -l800 -fca -nfc1 -sc -sob -cli4 -TR -Tplanner -TV
TWOVERS = sh ${top_srcdir}/support/twovers.sh
GENFFTDIR = ${top_builddir}/genfft
K7GENFFTDIR = ${top_builddir}/genfft-k7
GEN_NOTW = ${GENFFTDIR}/gen_notw
GEN_NOTW_C = ${GENFFTDIR}/gen_notw_c
K7GEN_NOTW = ${K7GENFFTDIR}/gen_notw
GEN_TWIDDLE = ${GENFFTDIR}/gen_twiddle
GEN_TWIDDLE_C = ${GENFFTDIR}/gen_twiddle_c
K7GEN_TWIDDLE = ${K7GENFFTDIR}/gen_twiddle
GEN_TWIDSQ = ${GENFFTDIR}/gen_twidsq
GEN_TWIDSQ_C = ${GENFFTDIR}/gen_twidsq_c
GEN_R2HC = ${GENFFTDIR}/gen_r2hc
GEN_HC2R = ${GENFFTDIR}/gen_hc2r
GEN_HC2HC = ${GENFFTDIR}/gen_hc2hc
GEN_R2R = ${GENFFTDIR}/gen_r2r
PRELUDE_DFT = ${top_srcdir}/support/codelet_prelude.dft
PRELUDE_RDFT = ${top_srcdir}/support/codelet_prelude.rdft
ASMPRELUDE = ${top_srcdir}/support/codelet_asmprelude
ADD_DATE = sed -e s/@DATE@/"`date`"/

COPYRIGHT=${top_srcdir}/COPYRIGHT
CODELET_DEPS=$(COPYRIGHT) $(PRELUDE) $(ASMPRELUDE)
PRELUDE_COMMANDS_DFT=cat $(COPYRIGHT) $(PRELUDE_DFT)
PRELUDE_COMMANDS_RDFT=cat $(COPYRIGHT) $(PRELUDE_RDFT)
ASMPRELUDE_COMMANDS=cat $(COPYRIGHT) $(ASMPRELUDE)

FLAGS_COMMON = -compact -variables 4
DFT_FLAGS_COMMON = $(FLAGS_COMMON) -pipeline-latency 4
RDFT_FLAGS_COMMON = $(FLAGS_COMMON) -pipeline-latency 4

# cancel the hideous builtin rules that cause an infinite loop
%: %.o
%: %.s
%: %.c
%: %.S

endif # MAINTAINER_MODE
