# make template for src's subdirectories.  It contains definitions for
# standard targets.

all: headers lib

# we will not use Sun's target definitions
###   include make/default.mk
.SUFFIXES: ${SUFFIXES} .C .m4c .m4h
OUTPUT_OPTION=
COMPILE.cc=$(CCC) $(CCFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
LINK.cc=$(CCC) $(CCFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
.C:
	$(LINK.cc) -o $@ $< $(LDLIBS)
.C.o:
	$(COMPILE.cc) $(OUTPUT_OPTION) $<
.c:
	$(LINK.cc) -o $@ $< $(LDLIBS)
.c.o:
	$(COMPILE.cc) $(OUTPUT_OPTION) $<

M4=/local/gnu/m4
ifeq (1,0)
.m4h.h:
	rm -f $@
	${M4} defines.m4h $< | cat -s > $@
	chmod a-w $@

.m4c.c:
	rm -f $@
	${M4} defines.m4c $< | cat -s > $@
	chmod a-w $@
endif

VISIONDIR=/cis/vision/src/iac++

INCDIR=${TOP}/include

EXPDIR=/cis/lightning2/thoth.aux/gcc-bunker
#CCC=${EXPDIR}/g++ -B${EXPDIR}/ -Wall
#CCC=g++ -Wall
CCC=/local/bin/CC -pg
#CCC=/usr/lang/CC-3.0.2/CC

INCLUDEFLAGS= -I. -I${INCDIR} -I../../depot/include ${EXTRAINCLUDES}
CDEBUGFLAGS=-g
CCFLAGS= ${CDEBUGFLAGS} ${INCLUDEFLAGS} ${XTRAFLAGS} ${XTRACCFLAGS}

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

.PHONY: all clean spotless headers

##
##

# GURK = RCS/%,v
# # there's a bloody comma in the pattern :(
# RCSFILES = ${patsubst ${GURK},%,${wildcard RCS/*,v}}

# checkout: ${RCSFILES}
#
# ${RCSFILES}: %: RCS/%,v
#	co $@

##
##

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

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

headers: ${OTHERHEADERS}

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

##
##

WORKLIB = ${TOP}/lib/libiac++.a
ifneq (${LOBJS},)
lib: ${LOBJS}
	${AR} rv ${WORKLIB} ${LOBJS}
	${RANLIB} ${WORKLIB}
	touch $@
endif

LDLIBS = -L${TOP}/lib ${OTHERLIBS} -liac++ ../../depot/lib/libiac++.a -lm

##
##

closure: ${LOBJS} ${CLOSUREOBJS}
	if [ -d ptrepository ] ; then \
	( ${CCC} -ptk -ptmlinkmap -ptdclosure ${CLOSUREARGS} ${CCFLAGS} ${CLOSUREOBJS} ${LOBJS} ) ; \
	if [ ! -z "${BLASTABLE_PTFILES}" ] ; then \
		for i in ${BLASTABLE_PTFILES} nonexistent; do \
			rm -f ptrepository/$$i*.o; \
		done; \
	fi; \
	../../bin/add-templobj.perl ${WORKLIB} ptrepository/*.o ; \
	${RANLIB} ${WORKLIB} ; \
	fi
	touch closure

#	rm -f a.out ; \

##
##
##

ifneq (${SIMPLETESTS},)
${SIMPLETESTS}: test%: test%.o lib
	${LINK.cc} -o $@ $< ${LDLIBS}
endif

testprogs: ${TESTS}

clean::
	rm -f ${LOBJS} *.o *~

spotless:: clean
	rm -f ${TESTS} lib closure
	rm -rf ptrepository

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
