# gnumake.iah          Section: include make file for all algorithms
#      Copyright 1994, Center for Computer Vision and Visualization,
#      University of Florida.  All rights reserved.
#
# gnumake template for iah-src's subdirectories.
#   It contains definitions for standard targets.
# This file is a modification of the gnumake.templ file for the iac++ code
#
# Primarily I want this file to support building of the libiah.a
#   library of IAH algorithms.
#
# Usage: Include in your GNUMakefile and
#        define the following symbols as appropriate
#
#   LOCALIACCVERSION	*only* define this symbol if you want to
#			override the default.  NOTE: you must
#			supply a complete path.
#   LOCALIAHDIR		*only* define this symbol if you want to
#			override the default iah directory.
#   BLASTABLE_PTFILES	are related to closure maintenance.
#			Treat these as prefix to files in the ptrepository/
#			that you DO NOT want added to the libiah.a ibrary.
#   CLOSUREOBJS	.o closure files to force generation of ptrepository/
#			.o files to go in the ${IAHLIBDIR}/libiah.a
#   HEADERS 	.h files to go in the ${IAHINCDIR}
#   LOBJS 	.o files to go in the ${IAHLIBDIR}/libiah.a library
#   SOURCES	source files for this group, may be used by target spotless
#   TESTS	source files to makes target testprogs
#   ARL		flag for temp file location
#   EXTRAINCLUDES	where other include files live
#   CPPFLAGS	additional cpp flags
#   STRIPPROGRAMS	if not empty, programs will be striped.
#   OTHERLIBS	additional libraries to be searched at link time
#   OUTPUT_OPTION	leave this one alone
#   TARGET_ARCH	leave this alone, it will default
#   XTRAFLAGS	
#   XTRACCFLAGS	


#######################################################################
# Environment
#######################################################################

AR		= /usr/bin/ar
PERL		= perl
RANLIB		= /usr/bin/ranlib


# This is where the iac++ development tree is rooted,
#  bin/ should exist under here.
IACCROOT	= /cis/research/iac++
IACCBINDIR	= ${IACCROOT}/bin

# This is the default iac++ library version.
# To override this, the user defines, LOCALIACCVERSION, in GNUmakefile
#
# It is expected that the developer of the iah library will modify
#   this value as appropriate.
# The  include/  and  lib/  directories should live here
IACCVERSION	= new

ifneq (${LOCALIACCVERSION},)
IACCDIR		= ${LOCALIACCVERSION}
else
IACCDIR		= ${IACCROOT}/${IACCVERSION}
endif
IACCINCLUDES	= ${IACCDIR}/include


#######################################################################
# This is where the IAH stuff lives
#######################################################################

IAHROOT		= /cis/research/iac++/handbook-src

# Eventually I want this to be based in the IAHROOT, but for
#   now, I'll keep in in my directory...
LOCALIAHDIR	= /cis/homes/rjj/iacc/iah-src

ifneq (${LOCALIAHDIR},)
IAHDIR		= ${LOCALIAHDIR}
else
IAHDIR		= ${IAHROOT}
endif

# Now define symbols specific to the IAHDIR
IAHLIBDIR	= ${IAHDIR}/lib
IAHLIBROOTNAME	= iah
IAHLIB		= ${IAHLIBDIR}/lib${IAHLIBROOTNAME}.a
IAHINCDIR	= ${IAHDIR}/include


#######################################################################
# Compilation and Linking related stuff
#######################################################################

CDEBUGFLAGS	= -g
INCLUDEFLAGS	=  -I. -I${IACCINCLUDES} -I${IAHINCDIR} ${EXTRAINCLUDES}

CCFLAGS		= ${CDEBUGFLAGS} ${INCLUDEFLAGS} ${XTRAFLAGS} ${XTRACCFLAGS}

LDLIBS		= -l${IAHLIBROOTNAME} -liac++ -lcomplex -lm ${OTHERLIBS}
LDDIRS		= -L${IAHLIBDIR} -L${IACCDIR}/lib
LDFLAGS		= ${LDDIRS}

CCC		= /local/bin/CC
COMPILE.cc	= $(CCC) $(CCFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
LINK.cc		= $(CCC) $(CCFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)

#######################################################################
# Closure and library maintenance related stuff
#######################################################################

CLOSUREFLAGS	= -I. -I${IACCINCLUDES} ${EXTRAINCLUDES}
LDCLOSURELIBS	= -liac++ -lcomplex -lm ${OTHERLIBS}
LDCLOSUREFLAGS	= -L${IACCDIR}/lib

CLOSURELIBS	= ${LDCLOSUREFLAGS} ${LDCLOSURELIBS}

CLOSURE.cc	= ${CCC} -ptk -ptmlinkmap -ptdclosure ${CLOSUREFLAGS}

REMANGLEFILENAME	= ar-remangling
IAHREMANGLEFILE		= ${IAHLIBDIR}/${REMANGLEFILENAME}
ARREMANGLEFILEFLAG	= -remangling ${IAHREMANGLEFILE}

ADDTEMPLOBJ_PERL	= ${IACCBINDIR}/add-templobj.perl

#######################################################################
# Rules
#######################################################################

ifneq (${STRIPPROGRAMS},)
.c:
	$(LINK.cc) -o $@ $< $(LDLIBS)
	strip $@
else
.c:
	$(LINK.cc) -o $@ $< $(LDLIBS)
endif
.o:
	$(LINK.cc) -o $@ $< $(LDLIBS)

.c.o:
	$(COMPILE.cc) $(OUTPUT_OPTION) $<


.PHONY: all clean spotless headers


#######################################################################
# Library  targets
#######################################################################

ifeq (${HEADERS},)
all:

else
ifneq (${CLOSUREOBJS},)
all: headers lib closure
else
all: headers lib
endif
endif

##
##

headers-force:: ${HEADERS}
	install -m0444 ${HEADERS} ${IAHINCDIR}/

OTHERHEADERS = ${patsubst %,${IAHINCDIR}/%,${HEADERS}}

headers: ${OTHERHEADERS}

ifneq (${OTHERHEADERS},)
${OTHERHEADERS}: ${IAHINCDIR}/%: %
	rm -f $@
	install -m0444 $< $@
endif

##
##

ifneq (${LOBJS},)
lib: ${LOBJS}
	${AR} rv${ARL} ${IAHLIB} ${LOBJS}
	${RANLIB} ${IAHLIB}
	touch $@
else
lib:
	echo Nothing to be done for lib in: `pwd`
endif


#######################################################################
# Tessting targets
#######################################################################

testprogs: ${TESTS}


#######################################################################
# Closure target - put ptrepository/*.o in library.
#######################################################################

closure: ${LOBJS} ${CLOSUREOBJS}
	if [ -d ptrepository ] ; then \
		( ${CLOSURE.cc}  ${LOBJS} ${CLOSUREOBJS} ${CLOSURELIBS} ) ; \
		rm -f a.out ; \
		if [ ! -z "${BLASTABLE_PTFILES}" ] ; then \
			for i in ${BLASTABLE_PTFILES} nonexistent; do \
				rm -f ptrepository/$$i*.o; \
			done; \
		fi; \
		find ptrepository -name \*.o -print | \
		${PERL} ${ADDTEMPLOBJ_PERL} \
				${ARREMANGLEFILEFLAG} -${ARL} ${IAHLIB} ;\
		${RANLIB} ${IAHLIB} ; \
	fi
	touch closure


#######################################################################
# Housekeeping targets
#######################################################################

tidy::
	/bin/rm -f *~

clean::
	/bin/rm -f ${LOBJS} ${CLOSUREOBJS} *.o *~ core

spotless:: clean
	/bin/rm -f ${TESTS} lib closure
	/bin/rm -rf ptrepository linkmap make.log

distfiles:


depend:
	awk '/^# dependencies/ { exit 0; } {print $0; } END{print "# dependencies";}' < GNUmakefile > GNUmakefile.new
	g++ -MM -I/local/include/CC/ ${INCLUDEFLAGS} *.c >> GNUmakefile.new
	mv GNUmakefile GNUmakefile.bak
	mv GNUmakefile.new GNUmakefile
