PYTHON_SRC=/home/gerhard/python2.2-2.2.2/

# This is the *documentation* release, and is used to construct the file
# names of the downloadable tarballs.
RELEASE = 0.11

MKHOWTO = $(PYTHON_SRC)/Doc/tools/mkhowto --split=4

# These must be declared phony since there
# are directories with matching names:
.PHONY: html

# This can be changed to a4
PAPER=		letter

MPFILES=	pysqlite.tex \
		copyright.tex \

# Main target
all:	html

dvi:	$(MPFILES)
	$(MKHOWTO) --dvi pysqlite.tex

pdf:	$(MPFILES)
	$(MKHOWTO) --pdf --$(PAPER) pysqlite.tex

ps:	$(MPFILES)
	$(MKHOWTO) --ps --$(PAPER) pysqlite.tex

html:	$(MPFILES)
	$(MKHOWTO) --html pysqlite.tex
	mkdir -p icons
	cp $(PYTHON_SRC)Doc/html/icons/* icons/
# the iconserver option of mkhowto is broken since it writes
# it to the end if the init_file where they aren't useful anymore,
# so we work around it:
	for f in `find sqlite`; do \
	  cat $$f | sed s/\.\.\\/icons/icons/g > $${f}2; \
	  mv $${f}2 $$f; \
	done

world:	ps pdf html tarballs

# Release packaging targets:

pdf-$(PAPER)-$(RELEASE).tgz: pdf
	tar cf - *.pdf | gzip -9 >$@

pdf-$(PAPER)-$(RELEASE).tar.bz2: pdf
	tar cf - *.pdf | bzip2 -9 >$@

pdf-$(PAPER)-$(RELEASE).zip: pdf
	rm -f $@
	zip -q -9 $@ *.pdf

postscript-$(PAPER)-$(RELEASE).tar.bz2: ps
	tar cf - *.ps | bzip2 -9 >$@

postscript-$(PAPER)-$(RELEASE).tgz: ps
	tar cf - *.ps | gzip -9 >$@

postscript-$(PAPER)-$(RELEASE).zip: ps
	rm -f $@
	zip -q -9 $@ *.ps

html-$(RELEASE).tgz:	html
	tar cf - pysqlite | gzip -9 >$@

html-$(RELEASE).tar.bz2:	html
	tar cf - pysqlite | bzip2 -9 >$@

html-$(RELEASE).zip:	html
	rm -f $@
	zip -q -9 $@ pysqlite

# convenience targets:

tarhtml:	html-$(RELEASE).tgz
tarps:		postscript-$(PAPER)-$(RELEASE).tgz
tarpdf:		pdf-$(PAPER)-$(RELEASE).tgz

tarballs:	tarpdf tarps tarhtml

ziphtml:	html-$(RELEASE).zip
zipps:		postscript-$(PAPER)-$(RELEASE).zip
zippdf:		pdf-$(PAPER)-$(RELEASE).zip

zips:		zippdf zipps ziphtml

bziphtml:	html-$(RELEASE).tar.bz2
bzipps:		postscript-$(PAPER)-$(RELEASE).tar.bz2
bzippdf:	pdf-$(PAPER)-$(RELEASE).tar.bz2

bzips:		bzippdf bzipps bziphtml


# Housekeeping targets

# Remove temporary files; all except the following:
# - sources: .tex, .bib, .sty, *.cls
# - useful results: .dvi, .pdf, .ps, .texi, .info
clean:
	rm -f *~ *.aux *.idx *.ilg *.ind *.log *.toc *.bkm *.syn *.pla api.tex

# Remove temporaries as well as final products
clobber:	clean
	rm -rf pysqlite
	rm -f html-$(RELEASE).tgz
	rm -f pdf-$(RELEASE).tgz postscript-$(RELEASE).tgz
	rm -f html-$(RELEASE).zip
	rm -f pdf-$(RELEASE).zip postscript-$(RELEASE).zip

realclean:  clobber
distclean:  clobber

# HTML in the doc directory
dist: version html
	rm -rf ../doc-html
	mv pysqlite ../doc-html

# Version substitution
version: ../src/include/mpversion.h
	DATE="`date +'%B %d, %Y'`"; \
	VERSION="`awk '/MPV_STRING/ {print $$3}' ../src/include/mpversion.h`"; \
	VERSION="`echo $$VERSION | sed s/\\"//g`"; \
	cat pysqlite.tex | sed s/\\release.*/\\release\{$$VERSION\}/ >pysqlite.tex2; \
	cat pysqlite.tex2 | sed s/\\date.*/\\date\{"$$DATE"\}/ >pysqlite.tex

upload:
	scp -r pysqlite/* owensmk@pysqlite.sourceforge.net:/home/groups/p/py/pysqlite/htdocs/documentation/pysqlite/
