1include ../../scripts/Makefile.include
2include ../../scripts/utilities.mak
3
4MAN1_TXT= \
5	$(filter-out $(addsuffix .txt, $(ARTICLES) $(SP_ARTICLES)), \
6		$(wildcard perf-*.txt)) \
7	perf.txt
8MAN5_TXT=
9MAN7_TXT=
10
11MAN_TXT = $(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT)
12_MAN_XML=$(patsubst %.txt,%.xml,$(MAN_TXT))
13_MAN_HTML=$(patsubst %.txt,%.html,$(MAN_TXT))
14
15MAN_XML=$(addprefix $(OUTPUT),$(_MAN_XML))
16MAN_HTML=$(addprefix $(OUTPUT),$(_MAN_HTML))
17
18ARTICLES =
19# with their own formatting rules.
20SP_ARTICLES =
21API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technical/api-index.txt, $(wildcard technical/api-*.txt)))
22SP_ARTICLES += $(API_DOCS)
23SP_ARTICLES += technical/api-index
24
25_DOC_HTML = $(_MAN_HTML)
26_DOC_HTML+=$(patsubst %,%.html,$(ARTICLES) $(SP_ARTICLES))
27DOC_HTML=$(addprefix $(OUTPUT),$(_DOC_HTML))
28
29_DOC_MAN1=$(patsubst %.txt,%.1,$(MAN1_TXT))
30_DOC_MAN5=$(patsubst %.txt,%.5,$(MAN5_TXT))
31_DOC_MAN7=$(patsubst %.txt,%.7,$(MAN7_TXT))
32
33DOC_MAN1=$(addprefix $(OUTPUT),$(_DOC_MAN1))
34DOC_MAN5=$(addprefix $(OUTPUT),$(_DOC_MAN5))
35DOC_MAN7=$(addprefix $(OUTPUT),$(_DOC_MAN7))
36
37# Make the path relative to DESTDIR, not prefix
38ifndef DESTDIR
39prefix?=$(HOME)
40endif
41bindir?=$(prefix)/bin
42htmldir?=$(prefix)/share/doc/perf-doc
43pdfdir?=$(prefix)/share/doc/perf-doc
44mandir?=$(prefix)/share/man
45man1dir=$(mandir)/man1
46man5dir=$(mandir)/man5
47man7dir=$(mandir)/man7
48
49ASCIIDOC=asciidoc
50ASCIIDOC_EXTRA = --unsafe -f asciidoc.conf
51ASCIIDOC_HTML = xhtml11
52MANPAGE_XSL = manpage-normal.xsl
53XMLTO_EXTRA =
54INSTALL?=install
55RM ?= rm -f
56DOC_REF = origin/man
57HTML_REF = origin/html
58
59ifdef USE_ASCIIDOCTOR
60ASCIIDOC = asciidoctor
61ASCIIDOC_EXTRA = -a compat-mode
62ASCIIDOC_EXTRA += -I. -rasciidoctor-extensions
63ASCIIDOC_EXTRA += -a mansource="perf" -a manmanual="perf Manual"
64ASCIIDOC_HTML = xhtml5
65endif
66
67infodir?=$(prefix)/share/info
68MAKEINFO=makeinfo
69INSTALL_INFO=install-info
70DOCBOOK2X_TEXI=docbook2x-texi
71DBLATEX=dblatex
72XMLTO=xmlto
73ifndef PERL_PATH
74	PERL_PATH = /usr/bin/perl
75endif
76
77-include ../config.mak.autogen
78-include ../config.mak
79
80_tmp_tool_path := $(call get-executable,$(ASCIIDOC))
81ifeq ($(_tmp_tool_path),)
82	missing_tools = $(ASCIIDOC)
83endif
84
85ifndef USE_ASCIIDOCTOR
86_tmp_tool_path := $(call get-executable,$(XMLTO))
87ifeq ($(_tmp_tool_path),)
88	missing_tools += $(XMLTO)
89endif
90endif
91
92#
93# For asciidoc ...
94#	-7.1.2,	no extra settings are needed.
95#	8.0-,	set ASCIIDOC8.
96#
97
98#
99# For docbook-xsl ...
100#	-1.68.1,	set ASCIIDOC_NO_ROFF? (based on changelog from 1.73.0)
101#	1.69.0,		no extra settings are needed?
102#	1.69.1-1.71.0,	set DOCBOOK_SUPPRESS_SP?
103#	1.71.1,		no extra settings are needed?
104#	1.72.0,		set DOCBOOK_XSL_172.
105#	1.73.0-,	set ASCIIDOC_NO_ROFF
106#
107
108#
109# If you had been using DOCBOOK_XSL_172 in an attempt to get rid
110# of 'the ".ft C" problem' in your generated manpages, and you
111# instead ended up with weird characters around callouts, try
112# using ASCIIDOC_NO_ROFF instead (it works fine with ASCIIDOC8).
113#
114
115ifdef ASCIIDOC8
116ASCIIDOC_EXTRA += -a asciidoc7compatible
117endif
118ifdef DOCBOOK_XSL_172
119ASCIIDOC_EXTRA += -a perf-asciidoc-no-roff
120MANPAGE_XSL = manpage-1.72.xsl
121else
122	ifdef ASCIIDOC_NO_ROFF
123	# docbook-xsl after 1.72 needs the regular XSL, but will not
124	# pass-thru raw roff codes from asciidoc.conf, so turn them off.
125	ASCIIDOC_EXTRA += -a perf-asciidoc-no-roff
126	endif
127endif
128ifdef MAN_BOLD_LITERAL
129XMLTO_EXTRA += -m manpage-bold-literal.xsl
130endif
131ifdef DOCBOOK_SUPPRESS_SP
132XMLTO_EXTRA += -m manpage-suppress-sp.xsl
133endif
134
135SHELL_PATH ?= $(SHELL)
136# Shell quote;
137SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
138
139#
140# Please note that there is a minor bug in asciidoc.
141# The version after 6.0.3 _will_ include the patch found here:
142#   http://marc.theaimsgroup.com/?l=perf&m=111558757202243&w=2
143#
144# Until that version is released you may have to apply the patch
145# yourself - yes, all 6 characters of it!
146#
147
148QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
149QUIET_SUBDIR1  =
150
151ifneq ($(findstring $(MAKEFLAGS),w),w)
152PRINT_DIR = --no-print-directory
153else # "make -w"
154NO_SUBDIR = :
155endif
156
157ifneq ($(findstring $(MAKEFLAGS),s),s)
158ifneq ($(V),1)
159	QUIET_ASCIIDOC	= @echo '  ASCIIDOC '$@;
160	QUIET_XMLTO	= @echo '  XMLTO    '$@;
161	QUIET_DB2TEXI	= @echo '  DB2TEXI  '$@;
162	QUIET_MAKEINFO	= @echo '  MAKEINFO '$@;
163	QUIET_DBLATEX	= @echo '  DBLATEX  '$@;
164	QUIET_XSLTPROC	= @echo '  XSLTPROC '$@;
165	QUIET_GEN	= @echo '  GEN      '$@;
166	QUIET_STDERR	= 2> /dev/null
167	QUIET_SUBDIR0	= +@subdir=
168	QUIET_SUBDIR1	= ;$(NO_SUBDIR) \
169			   echo '  SUBDIR   ' $$subdir; \
170			  $(MAKE) $(PRINT_DIR) -C $$subdir
171	export V
172endif
173endif
174
175all: html man
176
177html: $(DOC_HTML)
178
179$(DOC_HTML) $(DOC_MAN1) $(DOC_MAN5) $(DOC_MAN7): asciidoc.conf
180
181man: man1 man5 man7
182man1: $(DOC_MAN1)
183man5: $(DOC_MAN5)
184man7: $(DOC_MAN7)
185
186info: $(OUTPUT)perf.info $(OUTPUT)perfman.info
187
188pdf: $(OUTPUT)user-manual.pdf
189
190install: install-man
191
192check-man-tools:
193ifdef missing_tools
194	$(error "You need to install $(missing_tools) for man pages")
195endif
196
197do-install-man: man
198	$(call QUIET_INSTALL, Documentation-man) \
199		$(INSTALL) -d -m 755 $(DESTDIR)$(man1dir); \
200#		$(INSTALL) -d -m 755 $(DESTDIR)$(man5dir); \
201#		$(INSTALL) -d -m 755 $(DESTDIR)$(man7dir); \
202		$(INSTALL) -m 644 $(DOC_MAN1) $(DESTDIR)$(man1dir); \
203#		$(INSTALL) -m 644 $(DOC_MAN5) $(DESTDIR)$(man5dir); \
204#		$(INSTALL) -m 644 $(DOC_MAN7) $(DESTDIR)$(man7dir)
205
206install-man: check-man-tools man do-install-man
207
208ifdef missing_tools
209  DO_INSTALL_MAN = $(warning Please install $(missing_tools) to have the man pages installed)
210else
211  DO_INSTALL_MAN = do-install-man
212endif
213
214try-install-man: $(DO_INSTALL_MAN)
215
216install-info: info
217	$(call QUIET_INSTALL, Documentation-info) \
218		$(INSTALL) -d -m 755 $(DESTDIR)$(infodir); \
219		$(INSTALL) -m 644 $(OUTPUT)perf.info $(OUTPUT)perfman.info $(DESTDIR)$(infodir); \
220	if test -r $(DESTDIR)$(infodir)/dir; then \
221		$(INSTALL_INFO) --info-dir=$(DESTDIR)$(infodir) perf.info ;\
222		$(INSTALL_INFO) --info-dir=$(DESTDIR)$(infodir) perfman.info ;\
223	else \
224	  echo "No directory found in $(DESTDIR)$(infodir)" >&2 ; \
225	fi
226
227install-pdf: pdf
228	$(call QUIET_INSTALL, Documentation-pdf) \
229		$(INSTALL) -d -m 755 $(DESTDIR)$(pdfdir); \
230		$(INSTALL) -m 644 $(OUTPUT)user-manual.pdf $(DESTDIR)$(pdfdir)
231
232#install-html: html
233#	'$(SHELL_PATH_SQ)' ./install-webdoc.sh $(DESTDIR)$(htmldir)
234
235
236#
237# Determine "include::" file references in asciidoc files.
238#
239$(OUTPUT)doc.dep : $(wildcard *.txt) build-docdep.perl
240	$(QUIET_GEN)$(RM) $@+ $@ && \
241	$(PERL_PATH) ./build-docdep.perl >$@+ $(QUIET_STDERR) && \
242	mv $@+ $@
243
244-include $(OUPTUT)doc.dep
245
246_cmds_txt = cmds-ancillaryinterrogators.txt \
247	cmds-ancillarymanipulators.txt \
248	cmds-mainporcelain.txt \
249	cmds-plumbinginterrogators.txt \
250	cmds-plumbingmanipulators.txt \
251	cmds-synchingrepositories.txt \
252	cmds-synchelpers.txt \
253	cmds-purehelpers.txt \
254	cmds-foreignscminterface.txt
255cmds_txt=$(addprefix $(OUTPUT),$(_cmds_txt))
256
257$(cmds_txt): $(OUTPUT)cmd-list.made
258
259$(OUTPUT)cmd-list.made: cmd-list.perl ../command-list.txt $(MAN1_TXT)
260	$(QUIET_GEN)$(RM) $@ && \
261	$(PERL_PATH) ./cmd-list.perl ../command-list.txt $(QUIET_STDERR) && \
262	date >$@
263
264CLEAN_FILES =									\
265	$(MAN_XML) $(addsuffix +,$(MAN_XML))					\
266	$(MAN_HTML) $(addsuffix +,$(MAN_HTML))					\
267	$(DOC_HTML) $(DOC_MAN1) $(DOC_MAN5) $(DOC_MAN7)				\
268	$(OUTPUT)*.texi $(OUTPUT)*.texi+ $(OUTPUT)*.texi++			\
269	$(OUTPUT)perf.info $(OUTPUT)perfman.info				\
270	$(OUTPUT)howto-index.txt $(OUTPUT)howto/*.html $(OUTPUT)doc.dep		\
271	$(OUTPUT)technical/api-*.html $(OUTPUT)technical/api-index.txt		\
272	$(cmds_txt) $(OUTPUT)*.made
273clean:
274	$(call QUIET_CLEAN, Documentation) $(RM) $(CLEAN_FILES)
275
276$(MAN_HTML): $(OUTPUT)%.html : %.txt
277	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
278	$(ASCIIDOC) -b $(ASCIIDOC_HTML) -d manpage \
279		$(ASCIIDOC_EXTRA) -aperf_version=$(PERF_VERSION) -o $@+ $< && \
280	mv $@+ $@
281
282ifdef USE_ASCIIDOCTOR
283$(OUTPUT)%.1 $(OUTPUT)%.5 $(OUTPUT)%.7 : %.txt
284	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
285	$(ASCIIDOC) -b manpage -d manpage \
286		$(ASCIIDOC_EXTRA) -aperf_version=$(PERF_VERSION) -o $@+ $< && \
287	mv $@+ $@
288endif
289
290$(OUTPUT)%.1 $(OUTPUT)%.5 $(OUTPUT)%.7 : $(OUTPUT)%.xml
291	$(QUIET_XMLTO)$(RM) $@ && \
292	$(XMLTO) -o $(OUTPUT). -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $<
293
294$(OUTPUT)%.xml : %.txt
295	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
296	$(ASCIIDOC) -b docbook -d manpage \
297		$(ASCIIDOC_EXTRA) -aperf_version=$(PERF_VERSION) -o $@+ $< && \
298	mv $@+ $@
299
300XSLT = docbook.xsl
301XSLTOPTS = --xinclude --stringparam html.stylesheet docbook-xsl.css
302
303$(OUTPUT)user-manual.html: $(OUTPUT)user-manual.xml
304	$(QUIET_XSLTPROC)xsltproc $(XSLTOPTS) -o $@ $(XSLT) $<
305
306$(OUTPUT)perf.info: $(OUTPUT)user-manual.texi
307	$(QUIET_MAKEINFO)$(MAKEINFO) --no-split -o $@ $(OUTPUT)user-manual.texi
308
309$(OUTPUT)user-manual.texi: $(OUTPUT)user-manual.xml
310	$(QUIET_DB2TEXI)$(RM) $@+ $@ && \
311	$(DOCBOOK2X_TEXI) $(OUTPUT)user-manual.xml --encoding=UTF-8 --to-stdout >$@++ && \
312	$(PERL_PATH) fix-texi.perl <$@++ >$@+ && \
313	rm $@++ && \
314	mv $@+ $@
315
316$(OUTPUT)user-manual.pdf: $(OUTPUT)user-manual.xml
317	$(QUIET_DBLATEX)$(RM) $@+ $@ && \
318	$(DBLATEX) -o $@+ -p /etc/asciidoc/dblatex/asciidoc-dblatex.xsl -s /etc/asciidoc/dblatex/asciidoc-dblatex.sty $< && \
319	mv $@+ $@
320
321$(OUTPUT)perfman.texi: $(MAN_XML) cat-texi.perl
322	$(QUIET_DB2TEXI)$(RM) $@+ $@ && \
323	($(foreach xml,$(MAN_XML),$(DOCBOOK2X_TEXI) --encoding=UTF-8 \
324		--to-stdout $(xml) &&) true) > $@++ && \
325	$(PERL_PATH) cat-texi.perl $@ <$@++ >$@+ && \
326	rm $@++ && \
327	mv $@+ $@
328
329$(OUTPUT)perfman.info: $(OUTPUT)perfman.texi
330	$(QUIET_MAKEINFO)$(MAKEINFO) --no-split --no-validate $*.texi
331
332$(patsubst %.txt,%.texi,$(MAN_TXT)): %.texi : %.xml
333	$(QUIET_DB2TEXI)$(RM) $@+ $@ && \
334	$(DOCBOOK2X_TEXI) --to-stdout $*.xml >$@+ && \
335	mv $@+ $@
336
337howto-index.txt: howto-index.sh $(wildcard howto/*.txt)
338	$(QUIET_GEN)$(RM) $@+ $@ && \
339	'$(SHELL_PATH_SQ)' ./howto-index.sh $(wildcard howto/*.txt) >$@+ && \
340	mv $@+ $@
341
342$(patsubst %,%.html,$(ARTICLES)) : %.html : %.txt
343	$(QUIET_ASCIIDOC)$(ASCIIDOC) -b $(ASCIIDOC_HTML) $*.txt
344
345WEBDOC_DEST = /pub/software/tools/perf/docs
346
347$(patsubst %.txt,%.html,$(wildcard howto/*.txt)): %.html : %.txt
348	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
349	sed -e '1,/^$$/d' $< | $(ASCIIDOC) -b $(ASCIIDOC_HTML) - >$@+ && \
350	mv $@+ $@
351
352# UNIMPLEMENTED
353#install-webdoc : html
354#	'$(SHELL_PATH_SQ)' ./install-webdoc.sh $(WEBDOC_DEST)
355
356# quick-install: quick-install-man
357
358# quick-install-man:
359#	'$(SHELL_PATH_SQ)' ./install-doc-quick.sh $(DOC_REF) $(DESTDIR)$(mandir)
360
361#quick-install-html:
362#	'$(SHELL_PATH_SQ)' ./install-doc-quick.sh $(HTML_REF) $(DESTDIR)$(htmldir)
363