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