#
# this is a GNUmakefile.  It must be processed with GNU make.
#

TARGET_ARCH=
TOP=../..

# you should define the make variables LOBJS and HEADERS before the
# include directive.  LOBJS is a list of Library OBJects that belong
# in libiac++.a.  HEADERS is a list of public header files that belong
# in iac++/include.

#IDIIMPL=IntDI
IDIIMPL=IntDiscreteImage

# comment out for quick instantiation
#OTHERI=UcharDiscreteImage.o
OTHERI= FloatDiscreteImage.o UcharDiscreteImage.o

LOBJS = ${IDIIMPL}.o ${OTHERI} FloatCI.o\
	IntDDTempl.o UcharDDTempl.o FloatDDTempl.o

HEADERS= BaseDI.h DiscreteImage.h OtherDI.h \
	BaseCI.h ContinuousImage.h OtherCI.h \
	DIVIter.h DIPIter.h BaseDIIter.h \
	${IDIIMPL}.h IntImageOps.h \
	UcharDiscreteImage.h UcharImageOps.h \
	FloatDiscreteImage.h FloatImageOps.h \
    BaseDT.h DDTempl.h OtherDT.h \
	IntDDTempl.h IntConvolutions.h \
	UcharDDTempl.h UcharConvolutions.h \
	FloatDDTempl.h FloatConvolutions.h \
	PPComp.h

SRCS= BaseDI.c ConstDI.c VectorDI.c FunctionRefDI.c OtherDI.c \
	DiscreteImage.c ContinuousImage.c \
	DIPIter.c DIVIter.c \
	BaseDIIter.c ConstDIVIter.c ConstDIPIter.c \
		VectorDIVIter.c VectorDIPIter.c \
		OtherDIIter.c \
		FunctionDT.c

SIMPLETESTS=test000
TESTS=

OTHER_CFLAGS= -O

XTRACCFLAGS=

CLOSUREARGS = #-ptr./ptrepository -ptr../valueset/ptrepository
CLOSUREOBJS= closure.o
BLASTABLE_PTFILES = ___ad__FRC14IA_IntPointSetT1 \
	___ls__FR7ostreamRC8IA_IntPoint \
	*IA_ValueSet* *IA_Array* \
	*IA_BasePS* *IA_PSPred*

include ${TOP}/src/gnumake.templ

lib: closure

depend: # ${GENERATED_CFILES}

closure: ${SRCS} # ${GENERATED_CFILES} ${GENERATED_HFILES}
closure: DDTempl.h DDTempl.c InvariantDT.h InvariantDT.c OtherDT.h
closure: ConstDI.h VectorDI.h FunctionRefDI.h
closure: ConstDIVIter.h ConstDIPIter.h \
		VectorDIVIter.h VectorDIPIter.h \
		FunctionDT.h

GENBOPMETA = ./generate-bo.perl
BOPMETAFILES = $(foreach pw,pw sr,$(foreach comm,c nc,$(foreach arity,II Is sI,$(foreach isop,op fn,opgen-templs/b${pw}_${comm}_${arity}_${isop}))))
UOPMETAFILES = opgen-templs/upw opgen-templs/conversion
REDMETAFILES = $(foreach op,op fn,opgen-templs/reduce_${op}_nz)
ALLMETAFILES = ${BOPMETAFILES} ${UOPMETAFILES} ${REDMETAFILES}

${BOPMETAFILES}: ${GENBOPMETA}
	- mkdir opgen-templs
	for pw in pw sr; do for comm in c nc; do for arity in II Is sI; do for optype in op fn; do \
	${GENBOPMETA} -$$pw -$$comm -$$arity -$$optype > opgen-templs/b$${pw}_$${comm}_$${arity}_$${optype}; \
	done; done; done; done

opgen-templs/upw: unary-op.templ
	- mkdir opgen-templs
	- ln -s ../unary-op.templ $@

opgen-templs/conversion: conversion.templ
	- mkdir opgen-templs
	- ln -s ../conversion.templ $@

${REDMETAFILES}: #reduce_op_nz reduce_fn_nz
	- mkdir opgen-templs
	rm -f $@
	- for op in op fn; do \
		(ln -s ../reduce_$${op}_nz opgen-templs/reduce_$${op}_nz); \
	done

GENCOPS = ./generate-ops-c.perl
GENHOPS = ./generate-ops-h.perl

IntImageOps.c: int-operations.desc ${ALLMETAFILES} ${GENCOPS}
	rm -f $@
	${GENCOPS} < int-operations.desc | \
		sed -e 's/DiscreteImage<int>/IntDiscreteImage/g' > $@
	chmod a-w $@

IntImageOps.h: int-operations.desc ${GENHOPS}
	rm -f $@
	${GENHOPS} < int-operations.desc | \
		sed -e 's/DiscreteImage<int>/IntDiscreteImage/g' > $@
	chmod a-w $@

UcharImageOps.c: uchar-operations.desc ${ALLMETAFILES} ${GENCOPS}
	rm -f $@
	${GENCOPS} < uchar-operations.desc | \
		sed -e 's/DiscreteImage<u_char>/UcharDiscreteImage/g' > $@
	chmod a-w $@

UcharImageOps.h: uchar-operations.desc ${GENHOPS}
	rm -f $@
	${GENHOPS} < uchar-operations.desc | \
		sed -e 's/DiscreteImage<u_char>/UcharDiscreteImage/g' > $@
	chmod a-w $@

FloatImageOps.c: float-operations.desc ${ALLMETAFILES} ${GENCOPS}
	rm -f $@
	${GENCOPS} < float-operations.desc | \
		sed -e 's/DiscreteImage<float>/FloatDiscreteImage/g' > $@
	chmod a-w $@

FloatImageOps.h: float-operations.desc ${GENHOPS}
	rm -f $@
	${GENHOPS} < float-operations.desc | \
		sed -e 's/DiscreteImage<float>/FloatDiscreteImage/g' > $@
	chmod a-w $@

#
#
#

IntConvolutions.c: gen-conv-c.perl absorber int-convolutions.desc
	rm -f $@
	./gen-conv-c.perl < int-convolutions.desc  | \
	 sed -e 's/IA_DiscreteImage *< *int *>/IA_IntDiscreteImage/g'| \
	 sed -e 's/IA_DDTemplate *< *IA_IntDiscreteImage *>/IA_IntDDTemplate/g' > $@
	chmod a-w $@

IntConvolutions.h: gen-conv-h.perl int-convolutions.desc
	rm -f $@
	./gen-conv-h.perl < int-convolutions.desc | \
	 sed -e 's/IA_DiscreteImage *< *int *>/IA_IntDiscreteImage/g' | \
	 sed -e 's/IA_DDTemplate *< *IA_IntDiscreteImage *>/IA_IntDDTemplate/g' > $@
	chmod a-w $@

UcharConvolutions.c: gen-conv-c.perl absorber uchar-convolutions.desc
	rm -f $@
	./gen-conv-c.perl < uchar-convolutions.desc  | \
	 sed -e 's/IA_DiscreteImage *< *u_char *>/IA_UcharDiscreteImage/g'| \
	 sed -e 's/IA_DDTemplate *< *IA_UcharDiscreteImage *>/IA_UcharDDTemplate/g' > $@
	chmod a-w $@

UcharConvolutions.h: gen-conv-h.perl uchar-convolutions.desc
	rm -f $@
	./gen-conv-h.perl < uchar-convolutions.desc | \
	 sed -e 's/IA_DiscreteImage *< *u_char *>/IA_UcharDiscreteImage/g' | \
	 sed -e 's/IA_DDTemplate *< *IA_UcharDiscreteImage *>/IA_UcharDDTemplate/g' > $@
	chmod a-w $@

FloatConvolutions.c: gen-conv-c.perl absorber float-convolutions.desc
	rm -f $@
	./gen-conv-c.perl < float-convolutions.desc  | \
	 sed -e 's/IA_DiscreteImage *< *float *>/IA_FloatDiscreteImage/g'| \
	 sed -e 's/IA_DDTemplate *< *IA_FloatDiscreteImage *>/IA_FloatDDTemplate/g' > $@
	chmod a-w $@

FloatConvolutions.h: gen-conv-h.perl float-convolutions.desc
	rm -f $@
	./gen-conv-h.perl < float-convolutions.desc | \
	 sed -e 's/IA_DiscreteImage *< *float *>/IA_FloatDiscreteImage/g' | \
	 sed -e 's/IA_DDTemplate *< *IA_FloatDiscreteImage *>/IA_FloatDDTemplate/g' > $@
	chmod a-w $@


print:
	enscript -2rGPps335 ${HEADERS} ${SRCS}

spotless:
	/bin/rm -rf ptrepository
	rm -f ${BOPMETAFILES}
	rm -f IntConvolutions.[ch] UcharConvolutions.[ch] FloatConvolutions.[ch]
	rm -f IntImageOps.[ch] UcharImageOps.[ch] FloatImageOps.[ch]

spotless:

checkin:
	ci $(SRCS) $(HEADRS)

# weird ObjectCenter support

LSRCS = ${patsubst %.o,%.c,${LOBJS}}
oclib_src:
	!load ${CCFLAGS} ${LSRCS}

oclib_obj:
	!load ${CCFLAGS} ${LOBJS}

OCSRCS = ${patsubst %.o,%_src,${LOBJS}}
OCOBJS = ${patsubst %.o,%_obj,${LOBJS}}

${OCSRCS}: %_src: %.c
	!load ${CCFLAGS} $<

${OCOBJS}: %_obj: %.o
	!load ${CCFLAGS} $<

# dependencies
BaseDI.o : BaseDI.c ../../include/IPSIter.h ../../include/BaseIPSIter.h ../../include/IntPoint.h \
  ../../include/ia.h ../../include/IntPointSet.h ../../include/BasePS.h ../../include/SetStructure.h \
  ../../include/Array.h BaseDI.h ../../include/ValueSet.h OtherDIIter.h BaseDIIter.h \
  VectorDI.h 
BaseDIIter.o : BaseDIIter.c BaseDIIter.h ../../include/IntPoint.h ../../include/ia.h \
  BaseDI.h ../../include/IntPointSet.h ../../include/BasePS.h ../../include/SetStructure.h \
  ../../include/Array.h ../../include/ValueSet.h 
ConstDI.o : ConstDI.c VectorDI.h BaseDI.h ../../include/ia.h ../../include/IntPoint.h \
  ../../include/IntPointSet.h ../../include/BasePS.h ../../include/SetStructure.h \
  ../../include/Array.h ../../include/ValueSet.h ConstDI.h ConstDIVIter.h ../../include/IPSIter.h \
  ../../include/BaseIPSIter.h BaseDIIter.h ConstDIPIter.h 
ConstDIPIter.o : ConstDIPIter.c ConstDIPIter.h ../../include/IPSIter.h ../../include/BaseIPSIter.h \
  ../../include/IntPoint.h ../../include/ia.h ../../include/IntPointSet.h ../../include/BasePS.h \
  ../../include/SetStructure.h ../../include/Array.h BaseDIIter.h ConstDI.h BaseDI.h \
  ../../include/ValueSet.h 
ConstDIVIter.o : ConstDIVIter.c ConstDIVIter.h ../../include/IPSIter.h ../../include/BaseIPSIter.h \
  ../../include/IntPoint.h ../../include/ia.h ../../include/IntPointSet.h ../../include/BasePS.h \
  ../../include/SetStructure.h ../../include/Array.h BaseDIIter.h ConstDI.h BaseDI.h \
  ../../include/ValueSet.h 
ContinuousImage.o : ContinuousImage.c ContinuousImage.h ../../include/ia.h BaseCI.h \
  ../../include/FloatPoint.h ../../include/IntPoint.h ../../include/FloatPointSet.h \
  ../../include/BasePS.h ../../include/ValueSet.h DiscreteImage.h ../../include/IntPointSet.h \
  ../../include/SetStructure.h ../../include/Array.h BaseDI.h PPComp.h OtherCI.h \
  ../../include/IPSIter.h ../../include/BaseIPSIter.h ../../include/PredicatePS.h 
DDTempl.o : DDTempl.c DDTempl.h BaseDT.h ../../include/ia.h ../../include/IntPoint.h \
  ../../include/IntPointSet.h ../../include/BasePS.h ../../include/SetStructure.h \
  ../../include/Array.h ../../include/ValueSet.h InvariantDT.h FunctionDT.h OtherDT.h 
DIPIter.o : DIPIter.c DIPIter.h BaseDIIter.h ../../include/IntPoint.h ../../include/ia.h \
  DiscreteImage.h ../../include/IntPointSet.h ../../include/BasePS.h ../../include/SetStructure.h \
  ../../include/Array.h BaseDI.h ../../include/ValueSet.h PPComp.h ConstDIPIter.h \
  ../../include/IPSIter.h ../../include/BaseIPSIter.h ConstDI.h VectorDIPIter.h \
  VectorDI.h OtherDIIter.h 
DIVIter.o : DIVIter.c DIVIter.h BaseDIIter.h ../../include/IntPoint.h ../../include/ia.h \
  DiscreteImage.h ../../include/IntPointSet.h ../../include/BasePS.h ../../include/SetStructure.h \
  ../../include/Array.h BaseDI.h ../../include/ValueSet.h PPComp.h ConstDIVIter.h \
  ../../include/IPSIter.h ../../include/BaseIPSIter.h ConstDI.h VectorDIVIter.h \
  VectorDI.h OtherDIIter.h 
DiscreteImage.o : DiscreteImage.c ../../include/SetStructure.h ../../include/Array.h \
  DiscreteImage.h ../../include/ia.h ../../include/IntPoint.h ../../include/IntPointSet.h \
  ../../include/BasePS.h BaseDI.h ../../include/ValueSet.h PPComp.h DIVIter.h \
  BaseDIIter.h DIPIter.h ErrorDI.h ConstDI.h VectorDI.h OtherDI.h FunctionRefDI.h \
  ../../include/PredicatePS.h 
FloatCI.o : FloatCI.c FloatCI.h ContinuousImage.h ../../include/ia.h BaseCI.h \
  ../../include/FloatPoint.h ../../include/IntPoint.h ../../include/FloatPointSet.h \
  ../../include/BasePS.h ../../include/ValueSet.h DiscreteImage.h ../../include/IntPointSet.h \
  ../../include/SetStructure.h ../../include/Array.h BaseDI.h PPComp.h OtherCI.h 
FloatConvolutions.o : FloatConvolutions.c 
FloatDDTempl.o : FloatDDTempl.c ../../include/IPSIter.h ../../include/BaseIPSIter.h \
  ../../include/IntPoint.h ../../include/ia.h ../../include/IntPointSet.h ../../include/BasePS.h \
  ../../include/SetStructure.h ../../include/Array.h DIVIter.h BaseDIIter.h DiscreteImage.h \
  BaseDI.h ../../include/ValueSet.h PPComp.h DIPIter.h InvariantDT.h BaseDT.h \
  OtherDT.h FloatDDTempl.h DDTempl.h FloatDiscreteImage.h FloatImageOps.h FloatConvolutions.h \
  VectorDI.h FloatConvolutions.c 
FloatDiscreteImage.o : FloatDiscreteImage.c FloatDiscreteImage.h DiscreteImage.h \
  ../../include/ia.h ../../include/IntPoint.h ../../include/IntPointSet.h ../../include/BasePS.h \
  ../../include/SetStructure.h ../../include/Array.h BaseDI.h ../../include/ValueSet.h \
  PPComp.h FloatImageOps.h VectorDI.h ConstDI.h OtherDI.h ErrorDI.h DIVIter.h \
  BaseDIIter.h DIPIter.h ../../include/IPSIter.h ../../include/BaseIPSIter.h FloatImageOps.c 
FloatImageOps.o : FloatImageOps.c 
FunctionDT.o : FunctionDT.c FunctionDT.h ../../include/ia.h BaseDT.h ../../include/IntPoint.h \
  ../../include/IntPointSet.h ../../include/BasePS.h ../../include/SetStructure.h \
  ../../include/Array.h ../../include/ValueSet.h ../../include/IPSIter.h ../../include/BaseIPSIter.h 
FunctionRefDI.o : FunctionRefDI.c FunctionRefDI.h ../../include/ia.h BaseDI.h \
  ../../include/IntPoint.h ../../include/IntPointSet.h ../../include/BasePS.h \
  ../../include/SetStructure.h ../../include/Array.h ../../include/ValueSet.h \
  VectorDI.h ../../include/IPSIter.h ../../include/BaseIPSIter.h 
IntConvolutions.o : IntConvolutions.c 
IntDDTempl.o : IntDDTempl.c ../../include/IPSIter.h ../../include/BaseIPSIter.h \
  ../../include/IntPoint.h ../../include/ia.h ../../include/IntPointSet.h ../../include/BasePS.h \
  ../../include/SetStructure.h ../../include/Array.h DIVIter.h BaseDIIter.h DiscreteImage.h \
  BaseDI.h ../../include/ValueSet.h PPComp.h DIPIter.h InvariantDT.h BaseDT.h \
  OtherDT.h IntDDTempl.h DDTempl.h IntDiscreteImage.h IntImageOps.h IntConvolutions.h \
  VectorDI.h IntConvolutions.c 
IntDiscreteImage.o : IntDiscreteImage.c IntDiscreteImage.h DiscreteImage.h ../../include/ia.h \
  ../../include/IntPoint.h ../../include/IntPointSet.h ../../include/BasePS.h \
  ../../include/SetStructure.h ../../include/Array.h BaseDI.h ../../include/ValueSet.h \
  PPComp.h IntImageOps.h VectorDI.h ConstDI.h OtherDI.h ErrorDI.h DIVIter.h BaseDIIter.h \
  DIPIter.h ../../include/IPSIter.h ../../include/BaseIPSIter.h IntImageOps.c 
IntImageOps.o : IntImageOps.c 
InvariantDT.o : InvariantDT.c InvariantDT.h BaseDT.h ../../include/ia.h ../../include/IntPoint.h \
  ../../include/IntPointSet.h ../../include/BasePS.h ../../include/SetStructure.h \
  ../../include/Array.h ../../include/ValueSet.h 
OtherDI.o : OtherDI.c DIPIter.h BaseDIIter.h ../../include/IntPoint.h ../../include/ia.h \
  DiscreteImage.h ../../include/IntPointSet.h ../../include/BasePS.h ../../include/SetStructure.h \
  ../../include/Array.h BaseDI.h ../../include/ValueSet.h PPComp.h OtherDI.h 
OtherDIIter.o : OtherDIIter.c OtherDIIter.h ../../include/IPSIter.h ../../include/BaseIPSIter.h \
  ../../include/IntPoint.h ../../include/ia.h ../../include/IntPointSet.h ../../include/BasePS.h \
  ../../include/SetStructure.h ../../include/Array.h BaseDIIter.h BaseDI.h ../../include/ValueSet.h 
UcharConvolutions.o : UcharConvolutions.c 
UcharDDTempl.o : UcharDDTempl.c ../../include/IPSIter.h ../../include/BaseIPSIter.h \
  ../../include/IntPoint.h ../../include/ia.h ../../include/IntPointSet.h ../../include/BasePS.h \
  ../../include/SetStructure.h ../../include/Array.h DIVIter.h BaseDIIter.h DiscreteImage.h \
  BaseDI.h ../../include/ValueSet.h PPComp.h DIPIter.h InvariantDT.h BaseDT.h \
  OtherDT.h UcharDDTempl.h DDTempl.h UcharDiscreteImage.h ../../include/ImageDisplayProtocol.h \
  UcharImageOps.h UcharConvolutions.h VectorDI.h UcharConvolutions.c 
UcharDiscreteImage.o : UcharDiscreteImage.c UcharDiscreteImage.h DiscreteImage.h \
  ../../include/ia.h ../../include/IntPoint.h ../../include/IntPointSet.h ../../include/BasePS.h \
  ../../include/SetStructure.h ../../include/Array.h BaseDI.h ../../include/ValueSet.h \
  PPComp.h ../../include/ImageDisplayProtocol.h UcharImageOps.h VectorDI.h ConstDI.h \
  OtherDI.h ErrorDI.h DIVIter.h BaseDIIter.h DIPIter.h ../../include/IPSIter.h \
  ../../include/BaseIPSIter.h UcharImageOps.c 
UcharImageOps.o : UcharImageOps.c 
VectorDI.o : VectorDI.c VectorDI.h BaseDI.h ../../include/ia.h ../../include/IntPoint.h \
  ../../include/IntPointSet.h ../../include/BasePS.h ../../include/SetStructure.h \
  ../../include/Array.h ../../include/ValueSet.h ../../include/IPSIter.h ../../include/BaseIPSIter.h \
  VectorDIVIter.h BaseDIIter.h VectorDIPIter.h 
VectorDIPIter.o : VectorDIPIter.c VectorDIPIter.h ../../include/IPSIter.h ../../include/BaseIPSIter.h \
  ../../include/IntPoint.h ../../include/ia.h ../../include/IntPointSet.h ../../include/BasePS.h \
  ../../include/SetStructure.h ../../include/Array.h BaseDIIter.h VectorDI.h BaseDI.h \
  ../../include/ValueSet.h 
VectorDIVIter.o : VectorDIVIter.c VectorDIVIter.h ../../include/IPSIter.h ../../include/BaseIPSIter.h \
  ../../include/IntPoint.h ../../include/ia.h ../../include/IntPointSet.h ../../include/BasePS.h \
  ../../include/SetStructure.h ../../include/Array.h BaseDIIter.h VectorDI.h BaseDI.h \
  ../../include/ValueSet.h 
closure.o : closure.c ../../include/Array.h ../../include/ValueSet.h ../../include/ia.h \
  ../../include/BasePS.h ../../include/PredicatePS.h ../../include/IntPoint.h \
  ../../include/FloatPoint.h 
