DOC=$(shell basename `pwd`)
MAIN=${DOC}.texi
SOURCES=$(shell ls [0-9][0-9]-*)

all: ${DOC}.txt ${DOC}.html ${DOC}.dvi ${DOC}.pdf ${DOC}.ps aux-clean

version.texi: ${SOURCES}
	echo -n "@set UPDATED " > version.texi
	grep '$$Date:' ${SOURCES} | cut --delimiter=' ' --fields=3 | sort | tail -1 >> version.texi
	echo -n "@set EDITION " >> version.texi
	(cd ../..; echo "import src; print src.VERSION" | gcvs) >> version.texi

${DOC}.txt: ${MAIN} ${SOURCES} version.texi
	LANG=C makeinfo --no-headers --output=${DOC}.txt ${MAIN}

${DOC}.html: ${MAIN} ${SOURCES} version.texi
	LANG=C makeinfo --html ${MAIN}
	echo "<html>" > ${DOC}.html
	echo "  <head>" >> ${DOC}.html
	echo "    <meta http-equiv=\"Refresh\" content=\"0; URL=${DOC}/index.html\">" >> ${DOC}.html
	echo "  </head>" >> ${DOC}.html
	echo "</html>" >> ${DOC}.html

${DOC}.dvi: ${MAIN} ${SOURCES} version.texi
	LANG=C texi2dvi ${MAIN}

${DOC}.pdf: ${MAIN} ${SOURCES} version.texi
	LANG=C texi2pdf ${MAIN}

${DOC}.ps: ${DOC}.dvi
	dvips ${DOC} -o ${DOC}.ps

aux-clean:
	rm -f *.aux *.cp *.fn *.ky *.log *.pg *.toc *.tp *.vr *.??s

clean: aux-clean
	rm -f version.texi *.dvi *.txt *.html *.pdf *.ps
	rm -rf ${DOC}
