Autogenerate parts of the makefile rather then calling seperate shell scripts.
[ira/wip.git] / docs / Makefile
1 #################################################################
2 # Makefile for Samba Documentation
3 # Authors:      
4 #               James Moore <jmoore@php.net>
5 #               Gerald Carter <jerry@samba.org>
6 #               Jelmer Vernooij <jelmer@samba.org>
7 include Makefile.settings
8
9 # Docs to build
10 MAIN_DOCS = $(patsubst %/index.xml,%,$(wildcard */index.xml))
11 MANPAGES = $(wildcard $(MANPAGEDIR)/*.?.xml)
12
13 # Lists of files to process
14 LATEX_FIGURES = xslt/figures/caution.pdf xslt/figures/important.pdf xslt/figures/note.pdf xslt/figures/tip.pdf xslt/figures/warning.pdf
15 MANPAGES_PLUCKER = $(patsubst $(MANPAGEDIR)/%.xml,$(PLUCKERDIR)/%.pdb,$(MANPAGES))
16
17 DATETIME := $(shell date +%Y%m%d%H%M%S)
18
19 ifndef OUTPUTDIR
20 Makefile.settings: configure
21         @echo Makefile.settings not present, trying to run configure...
22         @./configure
23
24 configure: configure.in
25         @echo configure not present, trying to generate
26         @autoreconf
27 endif
28
29 help: 
30         @echo "Supported make targets:"
31         @echo " release - Build the docs needed for a Samba release"
32         @echo " all - Build all docs that can be build using the utilities found by configure"
33         @echo " everything - Build all of the above"
34         @echo " pdf,tex,dvi,ps,manpages,txt,pearson,fo,htmlhelp - Build specific output format"
35         @echo " html - Build multi-file HTML versions"
36         @echo " html-single - Build single-file HTML versions"
37         @echo " htmlman - Build HTML version of manpages"
38         @echo " undocumented - Output list of undocumented smb.conf options"
39         @echo " samples - Extract examples"
40         @echo " files - Extract other files"
41
42 Samba-Guide/index.xml: $(subst Samba-Guide/index.xml,,$(wildcard Samba-Guide/*.xml))
43 Samba-HOWTO-Collection/index.xml: $(subst Samba-HOWTO-Collection/index.xml,,$(wildcard Samba-HOWTO-Collection/*.xml)) Samba-HOWTO-Collection-attributions.xml
44 Samba-Developers-Guide/index.xml: $(subst Samba-Developers-Guide/index.xml,,$(wildcard Samba-Developers-Guide/*.xml)) Samba-Developers-Guide-attributions.xml
45
46 # Pseudo targets 
47 all: $(TARGETS)
48 everything: manpages pdf html-single html htmlman txt ps fo htmlhelp pearson 
49 release: manpages htmlman html pdf 
50
51 # Output format targets
52 pdf: $(patsubst %,$(PDFDIR)/%.pdf,$(MAIN_DOCS))
53 dvi: $(patsubst %,$(DVIDIR)/%.dvi,$(MAIN_DOCS))
54 ps: $(patsubst %,$(PSDIR)/%.ps,$(MAIN_DOCS))
55 txt: $(patsubst %,$(TXTDIR)/%.txt,$(MAIN_DOCS))
56 txt-chunks: $(addsuffix -txt-chunks,$(MAIN_DOCS))
57 fo: $(patsubst %,$(FODIR)/%.fo,$(MAIN_DOCS))
58 fo-pdf: $(patsubst %,$(FOPDFDIR)/%.pdf,$(MAIN_DOCS))
59 tex: $(addsuffix .tex,$(MAIN_DOCS))
60 texi: $(patsubst %,$(TEXINFODIR)/%.texi,$(MAIN_DOCS))
61 texiinfo: $(patsubst %,$(TEXINFODIR)/%.info,$(MAIN_DOCS))
62 manpages: $(patsubst $(MANPAGEDIR)/%.xml,$(MANDIR)/%,$(MANPAGES)) 
63 pearson: $(PEARSONDIR)/Samba-HOWTO-Collection.xml
64 pearson-verify: $(PEARSONDIR)/Samba-HOWTO-Collection.report.html
65 plucker: $(patsubst %,$(PLUCKERDIR)/%.pdb,$(MAIN_DOCS))
66 htmlman: $(patsubst $(MANPAGEDIR)/%.xml,$(HTMLDIR)/%.html,$(MANPAGES)) $(HTMLDIR)/manpages.html
67 html-single: $(patsubst %,$(HTMLDIR)/%.html,$(MAIN_DOCS))
68 html: $(patsubst %,$(HTMLDIR)/%/index.html,$(MAIN_DOCS)) $(HTMLDIR)/index.html
69 htmlhelp: $(addprefix $(HTMLHELPDIR)/,$(MAIN_DOCS))
70 validate: $(addsuffix -validate,$(MAIN_DOCS))
71
72 # Intermediate docbook docs
73
74 $(DOCBOOKDIR)/%.xml: %/index.xml xslt/expand-sambadoc.xsl
75         mkdir -p $(@D)
76         $(XSLTPROC) --stringparam latex.imagebasedir "$*/" --stringparam noreference 1 --xinclude --output $@ xslt/expand-sambadoc.xsl $<
77
78 $(DOCBOOKDIR)/%.xml: $(MANPAGEDIR)/%.xml xslt/expand-sambadoc.xsl
79         mkdir -p $(@D)
80         $(XSLTPROC) --xinclude --stringparam latex.imagebasedir "$*/" --stringparam noreference 1 --output $@ xslt/expand-sambadoc.xsl $<
81
82 $(DOCBOOKDIR)/manpages.xml: $(MANPAGES) xslt/manpage-summary.xsl
83         mkdir -p $(@D)
84         echo "<article><variablelist>" > $@
85         for I in $(MANPAGES); do $(XSLTPROC) xslt/manpage-summary.xsl $$I >> $@; done
86         echo "</variablelist></article>" >> $@
87
88 # HTML docs
89
90 $(HTMLDIR)/index.html: htmldocs.html
91         mkdir -p $(@D)
92         cp $< $@
93         
94 $(HTMLDIR)/%/index.html: $(DOCBOOKDIR)/%.xml $(HTMLDIR)/%/samba.css xslt/html-chunk.xsl %-images-html-chunks
95         mkdir -p $(@D)
96         $(XSLTPROC) --stringparam base.dir "$(HTMLDIR)/$*/" xslt/html-chunk.xsl $<
97
98 # Single large HTML files
99 $(OUTPUTDIR)/%/samba.css: xslt/html/samba.css
100         mkdir -p $(@D)
101         cp $< $@
102
103 $(patsubst %,$(HTMLDIR)/%.html,$(MAIN_DOCS)): $(HTMLDIR)/%.html: %-images-html-single
104
105 $(HTMLDIR)/%.html: $(DOCBOOKDIR)/%.xml $(HTMLDIR)/samba.css xslt/html.xsl 
106         $(XSLTPROC) --output $@ xslt/html.xsl $<
107
108 # Attributions
109 %-attributions.xml: 
110         $(XSLTPROC) --xinclude -o $@ xslt/generate-attributions.xsl $*/index.xml 
111
112 # Text files
113 $(TXTDIR)/%.txt: $(HTMLDIR)/%.html
114         mkdir -p $(@D)
115         $(HTML2TEXT) -nobs -style pretty -o $@ $<
116
117 # Tex files
118 %.tex: $(DOCBOOKDIR)/%.xml xslt/latex.xsl
119         mkdir -p $(@D)
120         $(XSLTPROC) --output $@ xslt/latex.xsl $<
121
122 latexfigures: $(LATEX_FIGURES)
123         touch $@
124
125 $(PDFDIR)/%.pdf: %.pdf
126         mkdir -p $(@D)
127         cp $< $@
128
129 %.idx: %.tex latexfigures
130         -$(PDFLATEX) $<
131
132 %.ind: %.idx
133         $(MAKEINDEX) $<
134
135 # Dependency files
136 %.d: $(DOCBOOKDIR)/%.xml xslt/generate-dependencies.xsl
137         $(XSLTPROC) \
138                 --novalid \
139                 --stringparam txtbasedir "$(TXTDIR)/$*/" \
140                 --stringparam target "$*" \
141                 -o $@ xslt/generate-dependencies.xsl $<
142         @echo "$*-images-latex-png: \$$(addsuffix .png, \$$($*-images-latex))" >> $@
143         @echo " touch \$$@" >> $@
144         @echo >> $@
145         @echo "$*-images-latex-eps: \$$(addsuffix .eps, \$$($*-images-latex))" >> $@
146         @echo " touch \$$@" >> $@
147         @echo >> $@
148         @echo "\$$(HTMLDIR)/%: $*/%" >> $@
149         @echo " mkdir -p \$$(@D)" >> $@
150         @echo " cp \$$< \$$@" >> $@
151         @echo >> $@
152         @echo "\$$(HTMLDIR)/$*/%: $*/%" >> $@
153         @echo " mkdir -p \$$(@D)" >> $@
154         @echo " cp \$$< \$$@" >> $@
155         @echo >> $@
156         @echo "\$$(HTMLHELPDIR)/$*/%: $*/%" >> $@
157         @echo " mkdir -p \$$(@D)" >> $@
158         @echo " cp \$$< \$$@" >> $@
159         @echo >> $@
160         @echo "$*-images-html-single: \$$(addprefix \$$(HTMLDIR)/, \$$($*-images-html))" >> $@
161         @echo " touch \$$@" >> $@
162         @echo "$*-images-html-chunks: \$$(addprefix \$$(HTMLDIR)/$*/, \$$($*-images-html))" >> $@
163         @echo " touch \$$@" >> $@
164         @echo "$*-images-htmlhelp: \$$(addprefix \$$(HTMLHELPDIR)/$*/, \$$($*-images-html))" >> $@
165         @echo " touch \$$@" >> $@
166
167 ifdef OUTPUTDIR
168 include $(addsuffix .d,$(MAIN_DOCS))
169 endif
170
171 # Adobe PDF files
172 %.pdf: %.tex %.ind latexfigures %-images-latex-png
173         -$(PDFLATEX) $<
174         $(THUMBPDF) --quiet $*.pdf
175         -$(PDFLATEX) $<
176
177 # DVI files
178 $(DVIDIR)/%.dvi: %.dvi
179         mkdir -p $(@D)
180         cp $< $@
181
182 %.dvi: %.tex %.idx %-images-latex-eps
183         -$(LATEX) $< 
184
185 %.png: %.dia
186         $(DIA) -e $@ $<
187
188 %.eps: %.png
189         $(PNGTOPNM) $< | $(PNMTOPS) > $@
190
191 # PostScript files
192 $(PSDIR)/%.ps: $(DVIDIR)/%.dvi
193         mkdir -p $(@D)
194         $(DVIPS) -o $@ $<
195
196 xslt/figures/%.pdf: xslt/figures/%.eps
197         $(EPSTOPDF) $<
198
199 # Fo
200 $(FODIR)/%.fo: $(DOCBOOKDIR)/%.xml
201         mkdir -p $(@D)
202         $(XSLTPROC) --output $@ http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl $<
203
204 # PDF thru Fo
205 $(FOPDFDIR)/%.pdf: $(FODIR)/%.fo
206         mkdir -p $(@D)
207         JAVA_OPTS=-Xmx250m $(FOP) -q -d $< -pdf $@
208
209 $(HTMLHELPDIR)/%: $(DOCBOOKDIR)/%.xml %-images-htmlhelp
210         $(XSLTPROC) --stringparam htmlhelp.chm $*.chm \
211                                 --stringparam manifest.in.base.dir "$@/" \
212                                 --stringparam base.dir "$@/" \
213         http://docbook.sourceforge.net/release/xsl/current/htmlhelp/htmlhelp.xsl $<
214
215 # Plucker docs
216 $(PLUCKERDIR)/%.pdb: $(HTMLDIR)/%.html 
217         mkdir -p $(@D)
218         $(PLUCKERBUILD) -v -V 2 --stayonhost --zlib-compression -f $* -p $(PLUCKERDIR) file:$< 
219
220 # Texinfo docs
221 $(TEXINFODIR)/%.texi: $(DOCBOOKDIR)/%.xml
222         mkdir -p $(@D)
223         cd $(@D) && $(DB2TEXI) $(shell pwd)/$<
224
225 $(TEXINFODIR)/%.info: $(TEXINFODIR)/%.texi
226         $(MAKEINFO) --no-validate --force -o $@ "$<"
227
228 # Manpages
229 $(MANPAGEDIR)/smb.conf.5.xml: $(SMBDOTCONFDOC)/parameters.all.xml $(SMBDOTCONFDOC)/parameters.service.xml $(SMBDOTCONFDOC)/parameters.global.xml
230
231 $(SMBDOTCONFDOC)/parameters.all.xml: $(shell find $(SMBDOTCONFDOC) -type f -name '*.xml' -mindepth 2 | sort -t/ -k3 | xargs) $(SMBDOTCONFDOC)/generate-file-list.sh
232         $(SMBDOTCONFDOC)/generate-file-list.sh $(SMBDOTCONFDOC) > $@
233
234 $(SMBDOTCONFDOC)/parameters.global.xml: $(SMBDOTCONFDOC)/parameters.all.xml $(SMBDOTCONFDOC)/generate-context.xsl
235         $(XSLTPROC) --xinclude --param smb.context "'G'" --output $(SMBDOTCONFDOC)/parameters.global.xml $(SMBDOTCONFDOC)/generate-context.xsl $<
236
237 $(SMBDOTCONFDOC)/parameters.service.xml: $(SMBDOTCONFDOC)/parameters.all.xml $(SMBDOTCONFDOC)/generate-context.xsl
238         $(XSLTPROC) --xinclude --param smb.context "'S'" --output $(SMBDOTCONFDOC)/parameters.service.xml $(SMBDOTCONFDOC)/generate-context.xsl $<
239
240 $(MANDIR)/%: $(DOCBOOKDIR)/%.xml xslt/man.xsl
241         mkdir -p $(@D)
242         $(XSLTPROC) --output $@ xslt/man.xsl $<
243
244 # Individual smb.conf parameters
245 smb.conf-chunks: $(patsubst $(SMBDOTCONFDOC)/%.xml,$(HTMLDIR)/smb.conf/%.html,$(wildcard $(SMBDOTCONFDOC)/*/*.xml))
246         
247 $(HTMLDIR)/smb.conf/%.html: $(SMBDOTCONFDOC)/%.xml
248         mkdir -p $(@D)
249         $(XSLTPROC) --output $@ xslt/smb.conf-html.xsl $<
250
251 # Pearson compatible XML
252 $(PEARSONDIR)/%.xml: %/index.xml xslt/pearson.xsl
253         mkdir -p $(@D)
254         $(XSLTPROC) --xinclude --output $@ xslt/sambadoc2pearson.xsl $<
255
256 $(PEARSONDIR)/%.report.html: $(PEARSONDIR)/%.xml
257         mkdir -p $(@D)
258         -$(XMLLINT) --valid --noout $< 2> $@
259
260 # Validation verification
261 %-validate: %/index.xml
262         cd $(<D) && $(XMLLINT) --xinclude --noent --postvalid --noout $(<F)
263
264 # Find undocumented parameters
265 undocumented: $(SMBDOTCONFDOC)/parameters.all.xml scripts/find_missing_doc.pl scripts/find_missing_manpages.pl
266         @$(PERL) scripts/find_missing_doc.pl $(SRCDIR)
267         @$(PERL) scripts/find_missing_manpages.pl $(SRCDIR)
268
269 # Examples and the like
270 files: Samba-HOWTO-Collection/index.xml xslt/extract-smbfiles.xsl
271         $(XSLTPROC) xslt/extract-smbfiles.xsl $< > /dev/null
272
273 samples: $(DOCBOOKDIR)/Samba-HOWTO-Collection.xml xslt/extract-examples.xsl scripts/indent-smb.conf.pl
274         mkdir -p $(EXAMPLESDIR)
275         $(XSLTPROC) --xinclude xslt/extract-examples.xsl $< > /dev/null 2> examples/README
276         for I in examples/*.conf; do { ./scripts/indent-smb.conf.pl < $$I > $$I.tmp; mv $$I.tmp $$I; } done
277
278 # Archiving
279 archive: pdf
280         mkdir -p $(ARCHIVEDIR)
281         cp $(PDFDIR)/Samba-HOWTO-Collection.pdf $(ARCHIVEDIR)/TOSHARG-$(DATETIME).pdf
282         cp $(PDFDIR)/Samba-Guide.pdf $(ARCHIVEDIR)/S3bE-$(DATETIME).pdf
283
284 # XSL scripts
285 xslt/html.xsl: xslt/html-common.xsl settings.xsl
286 xslt/html-chunk.xsl: xslt/html-common.xsl settings.xsl
287 xslt/latex.xsl: settings.xsl
288 xslt/expand-sambadoc.xsl: settings.xsl
289 xslt/generate-attributions.xsl: 
290 xslt/man.xsl:
291 xslt/pearson.xsl:
292
293 clobber: clean
294         rm Makefile.settings settings.xsl config.status config.log configure
295
296 clean: 
297         rm -rf $(OUTPUTDIR)/* $(DOCBOOKDIR)
298         rm -f *.xml *.d
299         rm -f xslt/figures/*pdf
300         rm -f $(SMBDOTCONFDOC)/parameters.*.xml
301         rm -f $(addsuffix .*,$(MAIN_DOCS))
302
303 # Always keep intermediate files if we can
304 .SECONDARY:
305 .PHONY: clean clobber archive release everything all