VERSION=0.3.2
MZSCHEME=/f/Program Files/PLT/mzscheme
LAML=f:/Program Files/laml/
TOPDIR=$(PWD)
HD=doc/html
HD_R=../..
TMP=/tmp

EGG=dist/rgraph.egg
DIST=dist/rgraph-$(VERSION).tar
SRC=dist/rgraph-$(VERSION)-src.tar

GENBASE= \
	rgraph.setup \
	rgraph.scm \
	rgraph-test1.scm \

TARBASE= \
	rgraph-base.scm \
	rgraph-prop.scm \
	rgraph-vis.scm \
	rgraph-test2.scm \
	rgraph-test3.scm \

INSTALL=$(GENBASE) \
	$(TARBASE) \
	rgraph-al.scm \
	rgraph-vl-vector.scm \
	rgraph-vl-hash.scm \
	rgraph-el-slist.scm \
	rgraph-el-hash.scm \

EXTRAS= \
	COPYRIGHT AUTHORS NEWS README ChangeLog INSTALL TODO \

SRCEXTRAS=Makefile index.html expand.scm

LAMLS = rgraph.laml \
	rgraph-vis.laml \
	rgraph-prop.laml \
	rgraph-al.laml \
	rgraph-vl-vector.laml \
	rgraph-vl-hash.laml \
	rgraph-el-slist.laml \
	rgraph-el-hash.laml \
	rgraph-alg-dfs.laml \
	rgraph-alg-topsort.laml \
	rgraph-alg-part-fidmat.laml \

HTML=	$(HD)/index.html \
	$(HD)/rgraph.html \
	$(HD)/rgraph-vis.html \
	$(HD)/rgraph-prop.html \
	$(HD)/rgraph-al.html \
	$(HD)/rgraph-vl-vector.html \
	$(HD)/rgraph-vl-hash.html \
	$(HD)/rgraph-el-slist.html \
	$(HD)/rgraph-el-hash.html \
	$(HD)/rgraph-alg-dfs.html \
	$(HD)/rgraph-alg-topsort.html \
	$(HD)/rgraph-alg-part-fidmat.html \

all: doc
.PHONY: dist

$(HD)/rgraph.html: rgraph.scm
$(HD)/rgraph-prop.html: rgraph-prop.scm
$(HD)/rgraph-alg-dfs.html: rgraph-alg-dfs.scm
$(HD)/rgraph-alg-topsort.html: rgraph-alg-topsort.scm
$(HD)/rgraph-alg-part-fidmat.html: rgraph-alg-part-fidmat.scm

$(HD)/index.html: index.html
	@mkdir -p $(HD)
	sed "s/==VERSION==/$(VERSION)/" $< > $@

$(HD)/%.html: %.laml
	@mkdir -p $(HD)
	@echo SchemeDoc\'ing $< to $@
	@"$(MZSCHEME)" --mute-banner -v --eval \
		'(define laml-dir "$(LAML)")' \
		-f $< $(basename $<) ""
	@mv $(notdir $@) $(basename $(notdir $@)).css $(HD)
	@rm -f $(basename $<).manlsp

doc: $(HTML)

cvsdoc: $(HTML)
	cp -p $(HD)/*.html $(HD)/*.css www
	export CVS_RSH=ssh && \
	cd www && TOADD=`cvs status -l *.html *.css | grep File: | grep "Status: Unknown" | sed 's#File: \([A-Za-z0-9\._-]*\).*#\1#'` && \
	( test -z "$$TOADD" || cvs add -m "Initial import" $$TOADD ) && \
	cvs commit -l -m "Update for version $(VERSION).`date +%Y%m%d`" *.html *.css

dist: doc $(INSTALL) $(EXTRAS)
	@rm -f $(EGG) $(DIST).gz $(SRC).gz
	@mkdir -p dist
	tar cf $(EGG) $(TARBASE)
	@mkdir -p $(TMP)
	sed "s/==VERSION==/$(VERSION)/" rgraph.setup > $(TMP)/rgraph.setup
	csi -script expand.scm rgraph.scm > $(TMP)/rgraph.scm
	csi -script expand.scm rgraph-test1.scm > $(TMP)/rgraph-test1.scm

	cd $(TMP) && tar uf $(TOPDIR)/$(EGG) rgraph.setup rgraph.scm rgraph-test1.scm
	cp -p $(EGG) $(DIST)
	cp -p COPYRIGHT $(TMP)/rgraph-COPYRIGHT.txt && cd $(TMP) && tar uf $(TOPDIR)/$(EGG) rgraph-COPYRIGHT.txt
	gzip $(EGG)

	mv $(EGG).gz $(EGG)
	cp -p $(EGG) $(HD)/
	rm $(TMP)/rgraph.setup $(TMP)/rgraph*.scm
	tar uf $(DIST) $(EXTRAS) $(HTML)

	tar cf $(SRC) $(INSTALL) $(EXTRAS) $(SRCEXTRAS) $(LAMLS)

	gzip $(DIST)
	cp -p $(DIST).gz $(HD)/
	gzip $(SRC)
	cp -p $(SRC).gz $(HD)/

upload: dist	
	cd dist && rm -f rgraph*.sig && \
	gpg -b rgraph.egg && \
	gpg -b rgraph-$(VERSION).tar.gz && \
	gpg -b rgraph-$(VERSION)-src.tar.gz && \
	ncftpput savannah.nongnu.org /incoming/savannah/rgraph rgraph.egg rgraph-$(VERSION).tar.gz rgraph-$(VERSION)-src.tar.gz rgraph.egg.sig rgraph-$(VERSION).tar.gz.sig rgraph-$(VERSION)-src.tar.gz.sig

tilde:
	rm -f *~

install: dist
	@mkdir -p $(TMP)
	@rm -rf $(TMP)/rgraph/*
	mkdir -p $(TMP)/rgraph
	cd $(TMP)/rgraph && cp -p $(TOPDIR)/$(EGG) . && chicken-setup rgraph