1# CLISP Implementation Notes generation
2# (c) 2000-2011 Sam Steingold
3
4# To generate HTML, you will need xsltproc & xmllint from the libxml2
5# (http://xmlsoft.org/) package in addition to the DocBook DTDs and XSL
6# stylesheets (http://www.docbook.org/)
7# When writing docbook documentation, you need the "DocBook Definitive Guide"
8# http://docbook.org/tdg/en/html/docbook-x.html
9
10# which DTD to validate against
11DTDVER=4.5
12
13# all included XML files
14IMPNOTES=cl-ent.xml clhs-ent.xml impbody.xml impent.xml mop.xml gray.xml     \
15	impext.xml impissue.xml impbyte.xml unix-ent.xml mop-ent.xml faq.xml \
16	history.xml \
17	../modules/asdf/asdf.xml	        \
18	../modules/berkeley-db/berkeley-db.xml	\
19	../modules/berkeley-db/ent-bdb.xml	\
20	../modules/dbus/dbus.xml		\
21	../modules/dirkey/dirkey.xml		\
22	../modules/fastcgi/fastcgi.xml		\
23	../modules/gdbm/gdbm.xml		\
24	../modules/gtk2/gtk.xml			\
25	../modules/i18n/i18n.xml		\
26	../modules/libsvm/svm.xml		\
27	../modules/matlab/matlab.xml		\
28	../modules/netica/netica.xml		\
29	../modules/oracle/oracle.xml		\
30	../modules/pari/pari.xml		\
31	../modules/pcre/pcre.xml		\
32	../modules/postgresql/postgresql.xml	\
33	../modules/rawsock/rawsock.xml		\
34	../modules/readline/readline.xml	\
35	../modules/regexp/regexp.xml		\
36	../modules/syscalls/syscalls.xml	\
37	../modules/zlib/zlib.xml
38# all used stylesheets
39CLISP_XSL = chunk.xsl common.xsl fo.xsl id-href-map.xsl man.xsl pile.xsl
40CLISP_CSS = impnotes.css
41# targets for <olink> resolution
42OLINK = man.tdb clink.tdb pile.tdb chunk.tdb olink-pile.xml olink-chunk.xml
43
44RM=/bin/rm -f
45CURDIR=$(shell pwd)
46
47# what to do when there is no local system-wide DTD & XSL?
48DOWNLOAD=yes
49
50ifneq (,$(filter Windows%,$(OS)))
51DTD_PATH=$(firstword $(wildcard ./docbook-dtd*/docbookx.dtd \
52	/usr/share/docbook-xml$(DTDVER)/docbookx.dtd))
53# Make sure to use a trailing slash.
54XSL_PATH=$(firstword $(wildcard ./docbook-xsl*/ \
55	/usr/share/docbook-xsl*/))
56FOP=/cygdrive/c/java/fop-0.20.5/fop.bat
57else
58DTD_PATH=$(firstword $(wildcard ./docbook-dtd*/docbookx.dtd \
59	/usr/share/sgml/docbook/xml-dtd-$(DTDVER)*/docbookx.dtd \
60	/usr/share/xml/docbook/schema/dtd/$(DTDVER)*/docbookx.dtd))
61XSL_PATH=$(firstword $(wildcard ./docbook-xsl*/ \
62	/usr/share/sgml/docbook/xsl-stylesheets-1*/ \
63	/usr/share/xml/docbook/stylesheet/nwalsh*/))
64FOP=../../../fop/fop
65endif
66
67IN_FILES = impnotes.xml clisp.xml clisp-link.xml
68# common dependencies for all checkers
69CHECK_DEPS = $(IN_FILES)
70ifeq (,$(wildcard $(DTD_PATH))) # DTD does not exist
71ifeq (yes,$(DOWNLOAD))		# download once
72CHECK_DEPS += docbook-dtd
73DTD_PATH=./docbook-dtd/docbookx.dtd
74else # download on each check (you need network-aware tools to use it)
75# this is the original DTD
76DTD_PATH=http://www.oasis-open.org/docbook/xml/$(DTDVER)/docbookx.dtd
77#DTD_PATH=http://www.docbook.org/xml/$(DTDVER)/docbookx.dtd
78endif
79endif
80
81# common dependencies for all generators
82GEN_DEPS = common.xsl
83ifeq (,$(wildcard $(XSL_PATH))) # stylesheets do not exist
84ifeq (yes,$(DOWNLOAD))	        # download once
85GEN_DEPS += docbook-xsl
86XSL_PATH=./docbook-xsl/
87else # download on each build (you need network-aware tools to use it)
88XSL_PATH=http://docbook.xml-doc.org/snapshots/xsl/
89# XSL_PATH=http://docbook.sourceforge.net/release/xsl/snapshot/
90# XSL_PATH=http://docbook.sourceforge.net/release/xsl/current/
91endif
92endif
93
94# The xmlcatalog utility (from libxml2)
95XMLCATALOG=xmlcatalog
96
97# chose one:
98#TEXI2HTML=texi2html -monolithic -verbose $< -out_file $@
99TEXI2HTML=makeinfo --verbose --no-split --no-headers --force --html $< -o $@
100
101# NB: keep in sync with src/makemake.in:MYIMPROOT
102DIST_SFBETA = sds,clisp@web.sf.net:/home/groups/c/cl/clisp/htdocs/beta
103DIST =
104RSYNC = rsync -avC --copy-unsafe-links
105CHMOD = chmod -R a+rX
106
107##### nothing user-serviceable below #####
108
109# name of XML catalog file to create
110# (if not specified, no local catalog created or used)
111CATALOG_FILE=catalog.xml
112
113# Stylesheets URI used internally in the CLISP project *.xsl files.
114XSL_URI=http://docbook.sourceforge.net/release/xsl/current/
115
116FILLIN=. ../version.sh && sed -e 's,@DTD@,$(DTD_PATH),' \
117	    -e 's,@DTDVER@,$(DTDVER),' \
118	    -e 's,@VERSION@,'$${VERSION_NUMBER}',' \
119	    -e 's,@TODAY@,'`date +"%Y-%m-%d"`','
120
121# cannot use profiling <http://www.sagehill.net/docbookxsl/Profiling.html>
122# because that would require XSL tools to be installed on user machine
123SGML_UNCOMMENT=-e 's/^<!--\#\(.*\)-->$$/\#\1/'
124
125E=\ *<!--\(\#[^-]*\)--> *
126ROFF_UNCOMMENT=-e 's/^$E$$/\1/' -e 's/$E$$/\n\1/' -e 's/^$E/\1\n/' -e 's/$E/\n\1\n/g'
127
128.PHONY : all up count search clean
129
130all: check impnotes.html regexp.html man
131
132ifneq (,$(CATALOG_FILE))
133# depends on Makefile because of $(XSL_PATH)
134# gnu license xml files specify a bad dtd file
135GNU_DTD = http://www.oasis-open.org/docbook/xml/$(DTDVER)/docbookx.dtd
136$(CATALOG_FILE): Makefile
137	$(RM) $(CATALOG_FILE)
138	$(XMLCATALOG) --create > $(CATALOG_FILE)
139	$(XMLCATALOG) --noout --add "rewriteURI" \
140		$(XSL_URI) $(XSL_PATH) $(CATALOG_FILE)
141	$(XMLCATALOG) --noout --add "rewriteSystem" \
142		$(XSL_URI) $(XSL_PATH) $(CATALOG_FILE)
143	$(XMLCATALOG) --noout --add "rewriteURI" \
144		$(GNU_DTD) $(DTD_PATH) $(CATALOG_FILE)
145XSLTPROC=XML_CATALOG_FILES="$(CATALOG_FILE) ${XML_CATALOG_FILES}" xsltproc
146else
147XSLTPROC=xsltproc
148endif
149XMLS_COMMON = --timing --xinclude
150GOOGLEADS=0
151
152# target.database.document in this command is a workaround for bug
153#   warning: failed to load external entity \"olinkdb.xml\"
154#   Olink error: could not open target database \'olinkdb.xml\'.
155# https://sourceforge.net/p/docbook/bugs/1111/
156MAKE_TDB=$(XSLTPROC) $(XMLS_COMMON) --stringparam collect.xref.targets "only" \
157  --stringparam target.database.document "olink-pile.xml" \
158	--stringparam targets.filename
159
160man.tdb: clisp.xml pile.xsl $(GEN_DEPS) $(CATALOG_FILE)
161	$(MAKE_TDB) "$@" pile.xsl $<
162
163clink.tdb: clisp-link.xml pile.xsl $(GEN_DEPS) $(CATALOG_FILE)
164	$(MAKE_TDB) "$@" pile.xsl $<
165
166pile.tdb: impnotes.xml $(IMPNOTES) pile.xsl $(GEN_DEPS) $(CATALOG_FILE)
167	$(MAKE_TDB) "$@" pile.xsl $<
168
169chunk.tdb: impnotes.xml $(IMPNOTES) chunk.xsl $(GEN_DEPS) $(CATALOG_FILE)
170	$(MAKE_TDB) "$@" chunk.xsl $<
171
172ifneq (,$(wildcard ../version.sh))
173clisp.xml: clisp.xml.in ../version.sh Makefile
174	$(RM) $@
175	$(FILLIN) $< > $@
176
177clisp-link.xml: clisp-link.xml.in ../version.sh Makefile
178	$(RM) $@
179	$(FILLIN) $< > $@
180
181impnotes.xml: impnotes.xml.in $(IMPNOTES) ../version.sh Makefile
182	$(RM) $@
183	$(FILLIN) $< > $@
184endif
185
186XMLOUT=$(XSLTPROC) $(XMLS_COMMON) --param google.ads $(GOOGLEADS) \
187	--stringparam target.database.document
188DOC_MAN = --stringparam current.docid "man"
189DOC_CLK = --stringparam current.docid "clink"
190DOC_IMP = --stringparam current.docid "impnotes"
191
192CHECK_IDS = if egrep -Hnr 'id="id[0-9]*"' $@; then exit 1; else true; fi
193
194clisp.html: clisp.xml $(GEN_DEPS) pile.xsl $(OLINK)
195	$(XMLOUT) "olink-pile.xml" $(DOC_MAN) -o $@ pile.xsl $<
196	$(CHECK_IDS)
197
198clisp.1: clisp.xml $(GEN_DEPS) man.xsl $(OLINK)
199	$(XMLOUT) "olink-pile.xml" $(DOC_MAN) -o $@ man.xsl $<
200
201clisp-link.html: clisp-link.xml $(GEN_DEPS) pile.xsl $(OLINK)
202	$(XMLOUT) "olink-pile.xml" $(DOC_CLK) -o $@ pile.xsl $<
203	$(CHECK_IDS)
204
205clisp-link.1: clisp-link.xml $(GEN_DEPS) man.xsl $(OLINK)
206	$(XMLOUT) "olink-pile.xml" $(DOC_CLK) -o $@ man.xsl $<
207
208_%.html: %.html
209	sed $(SGML_UNCOMMENT) $< > $@
210
211_%.1: %.1
212	sed $(ROFF_UNCOMMENT) $< > $@
213
214check: $(IMPNOTES) $(CHECK_DEPS)
215	for f in $(IN_FILES); do \
216	  xmllint $(XMLS_COMMON) --noout --postvalid --noent $$f; done
217
218impnotes.texi: impnotes.xml $(IMPNOTES)
219	time docbook2texi $<
220
221impnotes.html: impnotes.xml $(IMPNOTES) $(GEN_DEPS) pile.xsl $(OLINK)
222	$(XMLOUT) "olink-pile.xml" $(DOC_IMP) -o $@ pile.xsl $<
223#	cp impnotes.html impnotes-saved.html
224#	tidy -config tidy.conf -f tidy.err impnotes.html || true
225	$(CHECK_IDS)
226	(test -n "$(DIST)" && $(CHMOD) impnotes.html impnotes.css && \
227	 $(RSYNC) impnotes.html impnotes.css $(DIST)/) || true
228
229man: _clisp.html _clisp.1 _clisp-link.html _clisp-link.1
230	(cd ../build && make clisp.html clisp.1 && \
231	 $(CHMOD) clisp.1 clisp.html && \
232	 test -n "$(DIST)" && $(RSYNC) clisp.1 clisp.html $(DIST)/) || true
233
234impnotes.fo: impnotes.xml $(IMPNOTES) fo.xsl $(XSL_TARGET)
235	$(XMLOUT) "olink-pile.xml" $(DOC_IMP) -o $@ fo.xsl $<
236
237# http://xmlgraphics.apache.org/fop/
238impnotes.pdf: impnotes.fo
239	${FOP} $< $@
240
241id-href.map : chunk.tdb
242	$(XSLTPROC) $(XMLS_COMMON) -o $@ id-href-map.xsl $<
243
244html: impnotes.xml $(IMPNOTES) $(GEN_DEPS) chunk.xsl pile.xsl clisp.xml $(OLINK) id-href.map
245	if [ ! -h $@ ]; then $(RM) -r $@; \
246	  if [ -d ../../sf/www/impnotes ]; then ln -s ../../sf/www/impnotes $@; \
247	  elif [ -d ../../www/impnotes ]; then ln -s ../../www/impnotes $@; \
248	  else echo 'no sf/www dir'; false; fi; fi
249	cd $@/ && grep -v -e "^#" .symlinks | sed 's/^/ln -vf /' | sh -
250	cp -pv impnotes.css id-href.map $@/
251	$(XMLOUT) "olink-chunk.xml" $(DOC_IMP) -o $@/ chunk.xsl $<
252	$(XMLOUT) "olink-chunk.xml" $(DOC_MAN) -o $@/clisp.html pile.xsl clisp.xml
253	$(XMLOUT) "olink-chunk.xml" $(DOC_CLK) -o $@/clisp-link.html pile.xsl clisp-link.xml
254	sed $(SGML_UNCOMMENT) $@/clisp.html > _clisp-1.html
255	sed $(SGML_UNCOMMENT) $@/clisp-link.html > _clisp-link-1.html
256	cd ../build; make clisp-1.html clisp-link-1.html;
257	mv -f ../build/clisp-1.html $@/clisp.html
258	mv -f ../build/clisp-link-1.html $@/clisp-link.html
259	rm -f _clisp-1.html _clisp-link-1.html
260	$(CHECK_IDS)
261	cd html; cd ..; $(CURDIR)/../utils/fix-perms.sh
262	(test -n "$(DIST)" && $(CHMOD) $@ impnotes.css && \
263	 $(RSYNC) $@/*.html $@/id-href.map impnotes.css $(DIST)/impnotes/) \
264	|| true
265
266# try to use http://www.graphviz.org/ instead of openoffice for MOP
267# class inheritance diagrams
268mop-classes.png : mop-classes.dot
269	dot -Tpng mop-classes.dot -o mop-classes.png
270
271up: impnotes.html html
272	mv html impnotes
273	$(CHMOD) impnotes.html impnotes
274	$(RSYNC) impnotes.html impnotes $(DIST_SFBETA)
275	mv impnotes html
276
277regexp.html: ../modules/regexp/regexp.texinfo
278	$(TEXI2HTML)
279
280clean: force
281	$(RM) impnotes.texi impnotes.html impnotes.pdf html \
282	  clisp.html clisp.1 *.tdb $(CATALOG_FILE) impnotes.fo \
283	  id-href.map clisp-link.html clisp-link.1
284	test -f impnotes.xml.in && $(RM) impnotes.xml
285	test -f clisp.xml.in && $(RM) clisp.xml
286	test -f clisp-link.xml.in && $(RM) clisp-link.xml
287
288count: $(IMPNOTES)
289	wc $^
290
291DTD_DOWNLOAD=http://www.docbook.org/xml/$(DTDVER)/docbook-xml-$(DTDVER).zip
292docbook-dtd :
293	mkdir docbook-dtd && cd docbook-dtd && \
294	  wget -O docbook-xml.zip $(DTD_DOWNLOAD) && \
295	  unzip docbook-xml.zip && $(RM) docbook-xml.zip
296
297#XSL_DOWNLOAD=https://sourceforge.net/projects/docbook/files/latest/download?source=files
298XSL_VERSION=1.79.1
299XSL_DOWNLOAD=https://downloads.sourceforge.net/project/docbook/docbook-xsl/$(XSL_VERSION)/docbook-xsl-$(XSL_VERSION).zip
300docbook-xsl :
301	wget $(XSL_DOWNLOAD) && unzip docbook-xsl-$(XSL_VERSION).zip && \
302	  mv -v docbook-xsl-$(XSL_VERSION) docbook-xsl && \
303	  $(RM) docbook-xsl-$(XSL_VERSION).zip
304	grep '<fm:Version>' docbook-xsl/VERSION
305
306IMPNOTES_SRC = impnotes-src
307$(IMPNOTES_SRC).zip : Makefile impnotes.xml clisp.xml clisp-link.xml \
308		$(IMPNOTES) $(CLISP_XSL) $(CLISP_CSS)
309	$(RM) -r $@ $(IMPNOTES_SRC)
310	mkdir $(IMPNOTES_SRC);
311	for f in $^; do sed 's,\.\./modules/[^/]*/,,' $$f > $(IMPNOTES_SRC)/`basename $$f`; done
312	zip -9mvr $@ $(IMPNOTES_SRC)
313	(test -n "$(DIST)" && $(CHMOD) $@ ../src/NEWS && \
314	 $(RSYNC) $@ ../src/NEWS $(DIST)/) || true
315
316SEARCH=
317search: force
318	@if test -z "$(SEARCH)"; then echo "usage: make search SEARCH=string"; \
319	else grep -n -- '$(SEARCH)' $(IMPNOTES) $(addsuffix .in, $(IN_FILES)); fi
320
321force:
322