include Makefile.defs

CPPFLAGS = -Wall -g

VERSION=0.3.2

DISTFILES = \
   AUTHORS \
   COPYING \
   ChangeLog \
   Makefile \
   Makefile.defs.tmpl \
   NEWS \
   README \
   README.tmpl \
   TODO \
   BUGS \
   gracetmpl.h \
   gracetmpl.cpp \
   gracetmpl.dox \
   gracetmpl-config.in \
   gracetmpldemo.cpp \
   doxygen.conf \
   doc/ \
   python/Makefile \
   python/README \
   python/setup.py \
   python/prereq.py \
   python/example/Makefile \
   python/example/example.agr \
   python/example/example.py \
   python/lib/Makefile \
   python/lib/version.py \
   python/src/Makefile \
   python/src/pygracetmpl.cc \
   tests/Makefile \
   tests/*.tmpl \
   tests/*.py \
   tests/*.dat


all: gracetmpl.a gracetmpldemo gracetmpl-config

Makefile.defs: Makefile.defs.tmpl
	@echo
	@echo "  Copy Makefile.defs.tmpl to Makefile.defs and change the latter"
	@echo "  to reflect your preferred installation settings."
	@echo
	@exit 1

gracetmpl.a: gracetmpl.o
	$(AR) -r gracetmpl.a gracetmpl.o

gracetmpldemo: gracetmpldemo.o gracetmpl.o
	$(CPP) -o gracetmpldemo gracetmpldemo.o gracetmpl.o

envtest: envtest.o gracetmpl.o
	$(CPP) -o envtest envtest.o gracetmpl.o

install: all
	${BSD_INSTALL_DATA} gracetmpl.h $(INC_PREFIX)/gracetmpl.h
	${BSD_INSTALL_DATA} gracetmpl.a $(LIB_PREFIX)/libgracetmpl.a
	${BSD_INSTALL_PROGRAM} gracetmpldemo $(BIN_PREFIX)/gracetmpldemo
	${BSD_INSTALL_SCRIPT} gracetmpl-config $(BIN_PREFIX)/gracetmpl-config

gracetmpl-config: gracetmpl-config.in Makefile.defs
	sed -e 's!__PREFIX__!$(PREFIX)!g' \
	    -e 's!__INC_PREFIX__!$(INC_PREFIX)!g' \
	    -e 's!__LIB_PREFIX__!$(LIB_PREFIX)!g' \
	    -e 's!__BIN_PREFIX__!$(BIN_PREFIX)!g' \
		< gracetmpl-config.in > gracetmpl-config \
	    || rm -f gracetmpl-config

doc: docclean testpics
	doxygen doxygen.conf

clean: 
	rm -f *~ \#*\#

pythonwrap:
	@if python python/prereq.py 2>/dev/null; then \
	  (cd python; $(MAKE)); \
	else \
	  echo missing python numarray extension.; \
	  echo not building python stuff; \
	fi

pythonwrap_install:
	@if python python/prereq.py 2>/dev/null; then \
	  (cd python; $(MAKE) install); \
	else \
	  echo not installing python stuff; \
	fi


versioncheck:
	@wrongversion() { (echo; echo "*** Error: $$*"; echo) >&2; exit 1; } ;\
	[ -s gracetmpl-$(VERSION) ] \
		&& wrongversion "remove gracetmpl-$(VERSION), first!"; \
	grep -q PROJECT_NUMBER.*=.*$(VERSION) doxygen.conf \
		|| wrongversion "wrong doxygen version"; \
	grep -q "version='$(VERSION)'" python/lib/version.py \
		|| wrongversion "wrong python version";


distclean: clean
	rm -f Makefile.bak $(OBJ) $(EXEC) *.o *.a gracetmpldemo envtest
	rm -f example*-*.agr
	rm -fr python/build
	rm -f tests/*.agr tests/*.jpg tests/graceTMPL.so
	rm -fr doc/[a-z]*
	for i in $$(find . -name "*~"); do rm $$i; done
	rm -f gracetmpl-$(VERSION).tar.bz2

dist: versioncheck distclean doc
	ln -s . gracetmpl-$(VERSION) || exit 1
	tar chvjf gracetmpl-$(VERSION).tar.bz2 `find $(addprefix gracetmpl-$(VERSION)/, $(DISTFILES)) -type f|grep -v CVS|grep -v .cvsignore|grep -v ~$$`
	rm -f gracetmpl-$(VERSION)

docclean:
	rm -fr doc/html

test: gracetmpldemo pythonwrap
	@cd tests; $(MAKE)

testpics: gracetmpldemo pythonwrap
	@cd tests; $(MAKE) pics

web: doc
	(cd doc/html; tar cvhzf ../../web-`date +%s`.tgz .)

ChangeLog.cvs: * 
	cvs log | perl ./mkchlog > ChangeLog.cvs


# DO NOT DELETE
#
# g++ -MM *.cpp
# 

gracetmpl.o: gracetmpl.cpp gracetmpl.h
gracetmpldemo.o: gracetmpldemo.cpp gracetmpl.h
envtest.o: envtest.cpp gracetmpl.cpp gracetmpl.h


syntax highlighted by Code2HTML, v. 0.9.1