1#----------------------------------------------------------------------------
2#
3# PostgreSQL documentation makefile
4#
5# doc/src/sgml/Makefile
6#
7#----------------------------------------------------------------------------
8
9# This makefile is for building and installing the documentation.
10# When a release tarball is created, the documentation files are
11# prepared using the distprep target.  In Git-based trees these files
12# don't exist, unless explicitly built, so we skip the installation in
13# that case.
14
15
16# Make "html" the default target, since that is what most people tend
17# to want to use.
18man:
19
20# We don't need the tree-wide headers or install support here.
21NO_GENERATED_HEADERS=yes
22NO_TEMP_INSTALL=yes
23
24subdir = doc/src/sgml
25top_builddir = ../../..
26include $(top_builddir)/src/Makefile.global
27
28
29all: man
30
31distprep: html distprep-man
32
33
34ifndef DBTOEPUB
35DBTOEPUB = $(missing) dbtoepub
36endif
37
38ifndef FOP
39FOP = $(missing) fop
40endif
41
42XMLINCLUDE = --path .
43
44ifndef XMLLINT
45XMLLINT = $(missing) xmllint
46endif
47
48ifndef XSLTPROC
49XSLTPROC = $(missing) xsltproc
50endif
51
52override XSLTPROCFLAGS += --stringparam pg.version '$(VERSION)'
53
54
55GENERATED_SGML = version.sgml \
56	features-supported.sgml features-unsupported.sgml errcodes-table.sgml
57
58ALLSGML := $(wildcard $(srcdir)/*.sgml $(srcdir)/ref/*.sgml) $(GENERATED_SGML)
59
60
61##
62## Man pages
63##
64
65
66man-stamp: stylesheet-man.xsl postgres.sgml $(ALLSGML)
67	$(XMLLINT) $(XMLINCLUDE) --noout --valid $(word 2,$^)
68	$(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) $(XSLTPROC_MAN_FLAGS) $(wordlist 1,2,$^)
69	touch $@
70
71
72##
73## common files
74##
75
76# Technically, this should depend on Makefile.global, but then
77# version.sgml would need to be rebuilt after every configure run,
78# even in distribution tarballs.  So this is cheating a bit, but it
79# will achieve the goal of updating the version number when it
80# changes.
81version.sgml: $(top_srcdir)/configure
82	{ \
83	  echo "<!ENTITY version \"$(VERSION)\">"; \
84	  echo "<!ENTITY majorversion \"$(MAJORVERSION)\">"; \
85	} > $@
86
87features-supported.sgml: $(top_srcdir)/src/backend/catalog/sql_feature_packages.txt $(top_srcdir)/src/backend/catalog/sql_features.txt
88	$(PERL) $(srcdir)/mk_feature_tables.pl YES $^ > $@
89
90features-unsupported.sgml: $(top_srcdir)/src/backend/catalog/sql_feature_packages.txt $(top_srcdir)/src/backend/catalog/sql_features.txt
91	$(PERL) $(srcdir)/mk_feature_tables.pl NO $^ > $@
92
93errcodes-table.sgml: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes-table.pl
94	$(PERL) $(srcdir)/generate-errcodes-table.pl $< > $@
95
96
97##
98## Generation of some text files.
99##
100
101ICONV = iconv
102LYNX = lynx
103
104# The documentation may contain non-ASCII characters (mostly for
105# contributor names), which lynx converts to the encoding determined
106# by the current locale.  To get text output that is deterministic and
107# easily readable by everyone, we make lynx produce LATIN1 and then
108# convert that to ASCII with transliteration for the non-ASCII characters.
109# Official releases were historically built on FreeBSD, which has limited
110# locale support and is very picky about locale name spelling.  The
111# below has been finely tuned to run on FreeBSD and Linux/glibc.
112INSTALL: % : %.html
113	$(PERL) -p -e 's,<h(1|2) class="title",<h\1 align=center,g' $< | LC_ALL=en_US.ISO8859-1 $(LYNX) -force_html -dump -nolist -stdin | $(ICONV) -f latin1 -t us-ascii//TRANSLIT > $@
114
115INSTALL.html: %.html : stylesheet-text.xsl %.xml
116	$(XMLLINT) --noout --valid $*.xml
117	$(XSLTPROC) $(XSLTPROCFLAGS) $(XSLTPROC_HTML_FLAGS) $^ >$@
118
119INSTALL.xml: standalone-profile.xsl standalone-install.xml postgres.sgml $(ALLSGML)
120	$(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) --xinclude $(wordlist 1,2,$^) >$@
121
122
123##
124## HTML
125##
126
127ifeq ($(STYLE),website)
128XSLTPROC_HTML_FLAGS += --param website.stylesheet 1
129endif
130
131html: html-stamp
132
133html-stamp: stylesheet.xsl postgres.sgml $(ALLSGML)
134	$(XMLLINT) $(XMLINCLUDE) --noout --valid $(word 2,$^)
135	$(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) $(XSLTPROC_HTML_FLAGS) $(wordlist 1,2,$^)
136	cp $(srcdir)/stylesheet.css html/
137	touch $@
138
139htmlhelp: stylesheet-hh.xsl postgres.sgml $(ALLSGML)
140	$(XMLLINT) $(XMLINCLUDE) --noout --valid $(word 2,$^)
141	$(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) $(wordlist 1,2,$^)
142
143# single-page HTML
144postgres.html: stylesheet-html-nochunk.xsl postgres.sgml $(ALLSGML)
145	$(XMLLINT) $(XMLINCLUDE) --noout --valid $(word 2,$^)
146	$(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) $(XSLTPROC_HTML_FLAGS) -o $@ $(wordlist 1,2,$^)
147
148# single-page text
149postgres.txt: postgres.html
150	$(LYNX) -force_html -dump -nolist $< > $@
151
152
153##
154## Print
155##
156
157postgres.pdf:
158	$(error Invalid target;  use postgres-A4.pdf or postgres-US.pdf as targets)
159
160%-A4.fo: stylesheet-fo.xsl %.sgml $(ALLSGML)
161	$(XMLLINT) $(XMLINCLUDE) --noout --valid $(word 2,$^)
162	$(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) --stringparam paper.type A4 -o $@ $(wordlist 1,2,$^)
163
164%-US.fo: stylesheet-fo.xsl %.sgml $(ALLSGML)
165	$(XMLLINT) $(XMLINCLUDE) --noout --valid $(word 2,$^)
166	$(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) --stringparam paper.type USletter -o $@ $(wordlist 1,2,$^)
167
168%.pdf: %.fo
169	$(FOP) -fo $< -pdf $@
170
171
172##
173## EPUB
174##
175
176epub: postgres.epub
177postgres.epub: postgres.sgml $(ALLSGML)
178	$(XMLLINT) --noout --valid $<
179	$(DBTOEPUB) -o $@ $<
180
181
182##
183## Experimental Texinfo targets
184##
185
186DB2X_TEXIXML = db2x_texixml
187DB2X_XSLTPROC = db2x_xsltproc
188MAKEINFO = makeinfo
189
190%.texixml: %.sgml $(ALLSGML)
191	$(XMLLINT) --noout --valid $<
192	$(DB2X_XSLTPROC) -s texi -g output-file=$(basename $@) $< -o $@
193
194%.texi: %.texixml
195	$(DB2X_TEXIXML) --encoding=iso-8859-1//TRANSLIT $< --to-stdout > $@
196
197%.info: %.texi
198	$(MAKEINFO) --enable-encoding --no-split --no-validate $< -o $@
199
200
201##
202## Check
203##
204
205# Quick syntax check without style processing
206check: postgres.sgml $(ALLSGML) check-tabs
207	$(XMLLINT) $(XMLINCLUDE) --noout --valid $<
208
209
210##
211## Install
212##
213
214install: install-man
215
216installdirs:
217	$(MKDIR_P) $(addprefix '$(DESTDIR)$(mandir)'/man, 1 3 $(sqlmansectnum))
218
219# If the install used a man directory shared with other applications, this will remove all files.
220uninstall:
221	rm -f '$(DESTDIR)$(htmldir)/html/'* $(addprefix  '$(DESTDIR)$(mandir)'/man, 1/* 3/* $(sqlmansectnum)/*)
222
223
224## Install html
225
226install-html: html installdirs
227	cp -R $(call vpathsearch,html) '$(DESTDIR)$(htmldir)'
228
229
230## Install man
231
232install-man: man installdirs
233
234sqlmansect ?= 7
235sqlmansectnum = $(shell expr X'$(sqlmansect)' : X'\([0-9]\)')
236
237# Before we install the man pages, we massage the section numbers to
238# follow the local conventions.
239#
240ifeq ($(sqlmansectnum),7)
241install-man:
242	cp -R $(foreach dir,man1 man3 man7,$(call vpathsearch,$(dir))) '$(DESTDIR)$(mandir)'
243
244else # sqlmansectnum != 7
245fix_sqlmansectnum = sed -e '/^\.TH/s/"7"/"$(sqlmansect)"/' \
246			-e 's/\\fR(7)/\\fR($(sqlmansectnum))/g' \
247			-e '1s/^\.so man7/.so man$(sqlmansectnum)/g;1s/^\(\.so.*\)\.7$$/\1.$(sqlmansect)/g'
248
249man: fixed-man-stamp
250
251fixed-man-stamp: man-stamp
252	@$(MKDIR_P) $(addprefix fixedman/,man1 man3 man$(sqlmansectnum))
253	for file in $(call vpathsearch,man1)/*.1; do $(fix_sqlmansectnum) $$file >fixedman/man1/`basename $$file` || exit; done
254	for file in $(call vpathsearch,man3)/*.3; do $(fix_sqlmansectnum) $$file >fixedman/man3/`basename $$file` || exit; done
255	for file in $(call vpathsearch,man7)/*.7; do $(fix_sqlmansectnum) $$file >fixedman/man$(sqlmansectnum)/`basename $$file | sed s/\.7$$/.$(sqlmansect)/` || exit; done
256
257install-man:
258	cp -R $(foreach dir,man1 man3 man$(sqlmansectnum),fixedman/$(dir)) '$(DESTDIR)$(mandir)'
259
260clean: clean-man
261.PHONY: clean-man
262clean-man:
263	rm -rf fixedman/ fixed-man-stamp
264
265endif # sqlmansectnum != 7
266
267# tabs are harmless, but it is best to avoid them in SGML files
268check-tabs:
269	@( ! grep '	' $(wildcard $(srcdir)/*.sgml $(srcdir)/ref/*.sgml $(srcdir)/*.xsl) ) || (echo "Tabs appear in SGML/XML files" 1>&2;  exit 1)
270
271##
272## Clean
273##
274
275# This allows removing some files from the distribution tarballs while
276# keeping the dependencies satisfied.
277.SECONDARY: $(GENERATED_SGML)
278.SECONDARY: INSTALL.html INSTALL.xml
279.SECONDARY: postgres-A4.fo postgres-US.fo
280
281clean:
282# text --- these are shipped, but not in this directory
283	rm -f INSTALL
284	rm -f INSTALL.html INSTALL.xml
285# single-page output
286	rm -f postgres.html postgres.txt
287# print
288	rm -f *.fo *.pdf
289# generated SGML files
290	rm -f $(GENERATED_SGML)
291# HTML Help
292	rm -f htmlhelp.hhp toc.hhc index.hhk
293# EPUB
294	rm -f postgres.epub
295# Texinfo
296	rm -f *.texixml *.texi *.info db2texi.refs
297
298distclean: clean
299
300maintainer-clean: distclean
301# HTML
302	rm -fr html/ html-stamp
303# man
304	rm -rf man1/ man3/ man7/ man-stamp
305