BRENNERMD_VERSION:=0.1.1
export BRENNERMD_VERSION

# FIXME -- we should automatically edit the source so it knows about
# SPLINEHOME.  Right now you have to go edit by hand, in open.inc
SPLINEHOME:=/usr/share/brennermd

EXEHOME:=/usr/bin

# Where to put the tar files.
TARHOME:=/home/tim
export TARHOME

# Where sources for source RPM's typically reside.  The maximum RPM
# document says /usr/src/redhat, but on my system it's /usr/src/RPM.
# The trend seems to be for Red Hat to take their name off of RPM
# (presumably to make it a widely-accepted standard), so I'm guessing
# that /usr/src/RPM is right in the long term.
RPMHOME:=/usr/src/RPM

# Omit sih.f because it is unused, likewise sili_germ.f.
# Omit mainFixed.f because it is a generated file and is redundant
# with everything else.
TAGS:
	etags `find . -name "*.inc" -o -name "*.f" | grep -v mainFixed.f | grep -v sih.f | grep -v sili_germ.f`

# Delete all files generated by Makefile's.
.PHONY: clean
clean:
	-rm TAGS 
	$(MAKE) -C Subroutines/General clean
	$(MAKE) -C Execute clean

# Rebuild from scratch.  Don't need to be root.
.PHONY: rebuild
rebuild:
	$(MAKE) clean
	$(MAKE) fullbuild

# Incrementally build for release.
.PHONY: fullbuild
fullbuild:
	$(MAKE) -C Subroutines/General


# Install the data files from the Spline directory and the executable.
# Must be root.
.PHONY: install
install:
	install -d $(SPLINEHOME)
	install -m ugo+r Spline/*.d Spline/README $(SPLINEHOME)
	install Subroutines/General/brennermd $(EXEHOME)

# Uninstall.  Must be root.
uninstall:
	-rm -rf $(SPLINEHOME)
	-rm -f $(EXEHOME)/brennermd

# Create ../brennermd-$(BRENNERMD_VERSION).tar.gz.
.PHONY: tar
tar:
	$(MAKE) clean
	find . -type f '!' -name '*.tar*' '!' -name '*.tar.gz' \
	   '!' -path '*/CVS/*' '!' -name '*~' > /tmp/brennermdfiles.txt
	@# Contort ourselves so that the file names in the archive
	@# start with brennermd-$(BRENNERMD_VERSION)/
	tar cTf /tmp/brennermdfiles.txt /tmp/brennermd-$(BRENNERMD_VERSION).tar
	rm /tmp/brennermdfiles.txt
	rm -rf brennermd-$(BRENNERMD_VERSION)
	mkdir brennermd-$(BRENNERMD_VERSION)
	(cd brennermd-$(BRENNERMD_VERSION); tar xf /tmp/brennermd-$(BRENNERMD_VERSION).tar)
	rm /tmp/brennermd-$(BRENNERMD_VERSION).tar
	tar czf $(TARHOME)/brennermd-$(BRENNERMD_VERSION).tar.gz brennermd-$(BRENNERMD_VERSION)
	rm -rf brennermd-$(BRENNERMD_VERSION)

# Make a source rpm.  Should be done as root.
# Do a "make tar" before "make srpm".
.PHONY: srpm
srpm: 
	mkdir -p $(RPMHOME)/SOURCES $(RPMHOME)/SPECS
	cp $(TARHOME)/brennermd-$(BRENNERMD_VERSION).tar.gz $(RPMHOME)/SOURCES
	perl -w spec.pl $(BRENNERMD_VERSION) $(EXEHOME) $(SPLINEHOME) > $(RPMHOME)/SPECS/brennermd.spec
	(cd $(RPMHOME)/SPECS; rpm --target i386-pc-linux-gnu -ba brennermd.spec)

# Update my local copy of the global web pages.  Nobody but Tim
# Freeman should be doing this target.
# Do "make tar", then "make srpm" as root, then "make htmlupdate" as me.
HTMLHOME:=/home/tim/public_html/fungimol
.PHONY: htmlupdate
htmlupdate:
	mkdir -p $(HTMLHOME)
	cp $(TARHOME)/brennermd-$(BRENNERMD_VERSION).tar.gz \
	   $(RPMHOME)/RPMS/i386/brennermd-$(BRENNERMD_VERSION)-0.i386.rpm \
	   $(RPMHOME)/SRPMS/brennermd-$(BRENNERMD_VERSION)-0.src.rpm \
	   $(HTMLHOME)
