# CLISP Implementation Notes generation
# (c) 2000-2004 Sam Steingold

DTDVER=4.2
IMPNOTES=cl-ent.xml clhs-ent.xml impbody.xml impent.xml			\
	impext.xml impissue.xml impbyte.xml unix-ent.xml		\
	../modules/dirkey/dirkey.xml ../modules/syscalls/syscalls.xml	\
	../modules/regexp/regexp.xml ../modules/netica/netica.xml \
	../modules/berkeley-db/berkeley-db.xml ../modules/pcre/pcre.xml \
	../modules/oracle/oracle.xml ../modules/fastcgi/fastcgi.xml
OLINK=tdb-man.xml tdb-pile.xml tdb-chunk.xml olink-pile.xml olink-chunk.xml
RM=/bin/rm -f
# DOC=$(shell pwd)

ifneq (,$(filter Windows%,$(OS)))
XMLHOME=c:/doc/xml
NSGMLS=d:/gnu/sp/bin/nsgmls.exe
XMLSOC=d:/gnu/sp/pubtext/xml.soc
JAVAXML=c:/java
JAVA=/cygdrive/c/java/jdk1.3/bin/java.exe
SEP=;
DTD=$(XMLHOME)/db4xml/docbookx.dtd
else
XMLHOME=/usr/local/src/xml
NSGMLS=nsgmls
# XMLSOC=/usr/local/src/sp/pubtext/xml.soc
XMLSOC=/usr/share/sgml/xml.soc
JAVAXML=/usr/local/src/xml
JAVA=java
SEP=:
DTD=/usr/share/sgml/docbook/xml-dtd-$(DTDVER)/docbookx.dtd
endif

XALAN=$(JAVAXML)/xalan-j_2_0_0
SAXON=$(JAVAXML)/saxon
CLASSPATH=$(XALAN)/bin/xerces.jar$(SEP)$(XALAN)/bin/xalan.jar$(SEP)$(SAXON)/saxon.jar

# chose one:
#TEXI2HTML=texi2html -monolithic -verbose $< -out_file $@
TEXI2HTML=makeinfo --verbose --no-split --no-headers --html $< -o $@

#DIST=cvs2.cons.org:/home/ftp/pub/lisp/clisp/snapshots

# this is the original DTD
# when processing with a tool which can get the DTD from the net,
# e.g., (open)jade, you can use this definition,
# otherwise you have to stick with the local DTDs
DTD=http://www.oasis-open.org/docbook/xml/$(DTDVER)/docbookx.dtd

# to generate HTML, you will need:
# http://xml.apache.org/xalan-j
# http://nwalsh.com/docbook/xsl/dbx129.zip
#  or
# http://users.iclway.co.uk/mhkay/saxon/
#  or
# http://openjade.sourceforge.net/
# http://www.jclark.com/jade/

FILLIN=sed -e 's,@DTD@,$(DTD),' \
	    -e 's,@DTDVER@,$(DTDVER),' \
	    -e 's,@VERSION@,'`cat ../src/VERSION`',' \
	    -e 's,@TODAY@,'`date +"%Y-%m-%d"`','

SGML_UNCOMMENT=-e 's/^ *<!-- *//' -e 's/ *--> *$$//' \
		-e 's/ *--> *<!-- */\n/g' \
		-e 's/ *<!-- */\n/g' -e 's/ *--> */\n/g'

all: check impnotes.html regexp.html wildcard.html _clisp.html _clisp.1

MAKE_TDB=xsltproc --stringparam collect.xref.targets "only" \
	--stringparam targets.filename

# the tail+2 hack removes DOCTYPE from the database
# it should be removed as soon as the XHTML stylesheets are fixed
tdb-man.xml: clisp.xml
	$(MAKE_TDB) "$@" pile.xsl $<
	tail +2 $@ > tmp; mv -f tmp $@

tdb-pile.xml: impnotes.xml $(IMPNOTES)
	$(MAKE_TDB) "$@" pile.xsl $<
	tail +2 $@ > tmp; mv -f tmp $@

tdb-chunk.xml: impnotes.xml $(IMPNOTES)
	$(MAKE_TDB) "$@" chunk.xsl $<
	tail +2 $@ > tmp; mv -f tmp $@

clisp.xml: clisp.xml.in ../src/VERSION Makefile
	$(RM) $@
	$(FILLIN) $< > $@

XMLOUT=xsltproc --timing --stringparam target.database.document

clisp.html: clisp.xml common.xsl pile.xsl tdb-pile.xml olink-pile.xml
	$(XMLOUT) "olink-pile.xml" --stringparam current.docid "man" \
		-o $@ pile.xsl $<

_clisp.html: clisp.html
	sed $(SGML_UNCOMMENT) $< > $@

clisp.1: clisp.xml common.xsl man.xsl tdb-pile.xml olink-pile.xml
	$(XMLOUT) "olink-pile.xml" --stringparam current.docid "man" \
		-o $@ man.xsl $<

_clisp.1: clisp.1
	sed $(SGML_UNCOMMENT) $< > $@

impnotes.xml: impnotes.xml.in $(IMPNOTES) ../src/VERSION Makefile
	$(RM) $@
	$(FILLIN) $< > $@

check: impnotes.xml $(IMPNOTES) clisp.xml
	$(NSGMLS) -s -wxml -c$(XMLSOC) impnotes.xml
	$(NSGMLS) -s -wxml -c$(XMLSOC) clisp.xml
	xmllint --noout --valid --postvalid --timing --noent clisp.xml
	xmllint --noout --valid --postvalid --timing --noent impnotes.xml

impnotes.texi: impnotes.xml $(IMPNOTES)
	time docbook2texi $<

impnotes.html: impnotes.xml $(IMPNOTES) common.xsl pile.xsl $(OLINK)
	$(XMLOUT) "olink-pile.xml" --stringparam current.docid "impnotes" \
		-o $@ pile.xsl $<
#	cp impnotes.html impnotes-saved.html
#	tidy -config tidy.conf -f tidy.err impnotes.html || true
#	egrep -Hn 'NAME="[A-Z0-9]*"' $@ || true
	(test -n "$(DIST)" && scp -p impnotes.html $(DIST)/impnotes/ && \
	 test -d "../build/" && cd ../build && make clisp.html && \
	 make clisp.1 && scp -p clisp.1 clisp.html $(DIST)) || true

impnotes.pdf: impnotes.xml $(IMPNOTES)
	time docbook2pdf $<
	$(RM) impnotes.out

html: impnotes.xml $(IMPNOTES) common.xsl chunk.xsl pile.xsl clisp.xml $(OLINK)
	if [ ! -h $@ ]; then $(RM) -r $@; ln -s ../../sf/www/impnotes $@; fi
	cd html && sed 's/^/ln -vfs /' .symlinks | sh -
	$(XMLOUT) "olink-chunk.xml" --stringparam current.docid "impnotes" \
		-o $@/ chunk.xsl $<
	$(XMLOUT) "olink-chunk.xml" --stringparam current.docid "man" \
		-o $@/clisp.html pile.xsl clisp.xml
	sed $(SGML_UNCOMMENT) $@/clisp.html > _clisp-1.html
	cd ../build; make clisp-1.html;
	mv -f ../build/clisp-1.html $@/clisp.html
	rm -f _clisp-1.html
#	time xmlto xhtml -o $@/ -m chunk.xsl $<
#	time docbook2html --dsl impnotes.dsl -o $@ $<
#	egrep -Hnr 'NAME="[A-Z0-9]*"' $@ || true
	(test -n "$(DIST)" && scp -p html/*.html $(DIST)/impnotes/;) || true

up: impnotes.html html
	scp impnotes.html sf:/home/groups/c/cl/clisp/www/impnotes-new.html
	scp -r html/* sf:/home/groups/c/cl/clisp/www/impnotes-new/

regexp.html: ../modules/regexp/regexp.texinfo
	$(TEXI2HTML)

wildcard.html: ../modules/wildcard/wildcard.texinfo
	$(TEXI2HTML)

clean: force
	$(RM) impnotes.xml impnotes.texi impnotes.html impnotes.pdf html \
		clisp.html clisp.1

count: $(IMPNOTES)
	wc $^

force:
