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