162306a36Sopenharmony_ci# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
262306a36Sopenharmony_ci# Most of this file is copied from tools/perf/Documentation/Makefile
362306a36Sopenharmony_ci
462306a36Sopenharmony_ciinclude ../../../scripts/Makefile.include
562306a36Sopenharmony_ciinclude ../../../scripts/utilities.mak
662306a36Sopenharmony_ci
762306a36Sopenharmony_ciMAN3_TXT  = libperf.txt
862306a36Sopenharmony_ciMAN7_TXT  = libperf-counting.txt libperf-sampling.txt
962306a36Sopenharmony_ciMAN_EX    = examples/*.c
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ciMAN_TXT   = $(MAN3_TXT) $(MAN7_TXT)
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci_MAN_XML  = $(patsubst %.txt,%.xml,$(MAN_TXT))
1462306a36Sopenharmony_ci_MAN_HTML = $(patsubst %.txt,%.html,$(MAN_TXT))
1562306a36Sopenharmony_ci_MAN_3    = $(patsubst %.txt,%.3,$(MAN3_TXT))
1662306a36Sopenharmony_ci_MAN_7    = $(patsubst %.txt,%.7,$(MAN7_TXT))
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ciMAN_XML   = $(addprefix $(OUTPUT),$(_MAN_XML))
1962306a36Sopenharmony_ciMAN_HTML  = $(addprefix $(OUTPUT),$(_MAN_HTML))
2062306a36Sopenharmony_ciMAN_3     = $(addprefix $(OUTPUT),$(_MAN_3))
2162306a36Sopenharmony_ciMAN_7     = $(addprefix $(OUTPUT),$(_MAN_7))
2262306a36Sopenharmony_ciMAN_X     = $(MAN_3) $(MAN_7)
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci# Make the path relative to DESTDIR, not prefix
2562306a36Sopenharmony_ciifndef DESTDIR
2662306a36Sopenharmony_ci  prefix ?=$(HOME)
2762306a36Sopenharmony_ciendif
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_cimandir  ?= $(prefix)/share/man
3062306a36Sopenharmony_ciman3dir  = $(mandir)/man3
3162306a36Sopenharmony_ciman7dir  = $(mandir)/man7
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_cidocdir  ?= $(prefix)/share/doc/libperf
3462306a36Sopenharmony_cihtmldir  = $(docdir)/html
3562306a36Sopenharmony_ciexdir    = $(docdir)/examples
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ciASCIIDOC        = asciidoc
3862306a36Sopenharmony_ciASCIIDOC_EXTRA  = --unsafe -f asciidoc.conf
3962306a36Sopenharmony_ciASCIIDOC_HTML   = xhtml11
4062306a36Sopenharmony_ciMANPAGE_XSL     = manpage-normal.xsl
4162306a36Sopenharmony_ciXMLTO_EXTRA     =
4262306a36Sopenharmony_ciXMLTO           =xmlto
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ciINSTALL ?= install
4562306a36Sopenharmony_ciRM      ?= rm -f
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci# For asciidoc ...
4862306a36Sopenharmony_ci#	-7.1.2,	no extra settings are needed.
4962306a36Sopenharmony_ci#	8.0-,	set ASCIIDOC8.
5062306a36Sopenharmony_ci#
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci# For docbook-xsl ...
5362306a36Sopenharmony_ci#	-1.68.1,	set ASCIIDOC_NO_ROFF? (based on changelog from 1.73.0)
5462306a36Sopenharmony_ci#	1.69.0,		no extra settings are needed?
5562306a36Sopenharmony_ci#	1.69.1-1.71.0,	set DOCBOOK_SUPPRESS_SP?
5662306a36Sopenharmony_ci#	1.71.1,		no extra settings are needed?
5762306a36Sopenharmony_ci#	1.72.0,		set DOCBOOK_XSL_172.
5862306a36Sopenharmony_ci#	1.73.0-,	set ASCIIDOC_NO_ROFF
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci# If you had been using DOCBOOK_XSL_172 in an attempt to get rid
6162306a36Sopenharmony_ci# of 'the ".ft C" problem' in your generated manpages, and you
6262306a36Sopenharmony_ci# instead ended up with weird characters around callouts, try
6362306a36Sopenharmony_ci# using ASCIIDOC_NO_ROFF instead (it works fine with ASCIIDOC8).
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ciifdef ASCIIDOC8
6662306a36Sopenharmony_ci  ASCIIDOC_EXTRA += -a asciidoc7compatible
6762306a36Sopenharmony_ciendif
6862306a36Sopenharmony_ciifdef DOCBOOK_XSL_172
6962306a36Sopenharmony_ci  ASCIIDOC_EXTRA += -a libperf-asciidoc-no-roff
7062306a36Sopenharmony_ci  MANPAGE_XSL = manpage-1.72.xsl
7162306a36Sopenharmony_cielse
7262306a36Sopenharmony_ci  ifdef ASCIIDOC_NO_ROFF
7362306a36Sopenharmony_ci    # docbook-xsl after 1.72 needs the regular XSL, but will not
7462306a36Sopenharmony_ci    # pass-thru raw roff codes from asciidoc.conf, so turn them off.
7562306a36Sopenharmony_ci    ASCIIDOC_EXTRA += -a libperf-asciidoc-no-roff
7662306a36Sopenharmony_ci  endif
7762306a36Sopenharmony_ciendif
7862306a36Sopenharmony_ciifdef MAN_BOLD_LITERAL
7962306a36Sopenharmony_ci  XMLTO_EXTRA += -m manpage-bold-literal.xsl
8062306a36Sopenharmony_ciendif
8162306a36Sopenharmony_ciifdef DOCBOOK_SUPPRESS_SP
8262306a36Sopenharmony_ci  XMLTO_EXTRA += -m manpage-suppress-sp.xsl
8362306a36Sopenharmony_ciendif
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ciDESTDIR ?=
8662306a36Sopenharmony_ciDESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ciexport DESTDIR DESTDIR_SQ
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci# Please note that there is a minor bug in asciidoc.
9162306a36Sopenharmony_ci# The version after 6.0.3 _will_ include the patch found here:
9262306a36Sopenharmony_ci#   http://marc.theaimsgroup.com/?l=libtraceevent&m=111558757202243&w=2
9362306a36Sopenharmony_ci#
9462306a36Sopenharmony_ci# Until that version is released you may have to apply the patch
9562306a36Sopenharmony_ci# yourself - yes, all 6 characters of it!
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ciQUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
9862306a36Sopenharmony_ciQUIET_SUBDIR1  =
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ciifneq ($(findstring $(MAKEFLAGS),w),w)
10162306a36Sopenharmony_ci  PRINT_DIR = --no-print-directory
10262306a36Sopenharmony_cielse # "make -w"
10362306a36Sopenharmony_ci  NO_SUBDIR = :
10462306a36Sopenharmony_ciendif
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ciifneq ($(findstring $(MAKEFLAGS),s),s)
10762306a36Sopenharmony_ci  ifneq ($(V),1)
10862306a36Sopenharmony_ci    QUIET_ASCIIDOC = @echo '  ASCIIDOC '$@;
10962306a36Sopenharmony_ci    QUIET_XMLTO    = @echo '  XMLTO    '$@;
11062306a36Sopenharmony_ci  endif
11162306a36Sopenharmony_ciendif
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ciall: $(MAN_X) $(MAN_HTML)
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci$(MAN_HTML) $(MAN_X): asciidoc.conf
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ciinstall-man: all
11862306a36Sopenharmony_ci	$(call QUIET_INSTALL, man) \
11962306a36Sopenharmony_ci		$(INSTALL) -d -m 755 $(DESTDIR)$(man3dir); \
12062306a36Sopenharmony_ci		$(INSTALL) -m 644 $(MAN_3) $(DESTDIR)$(man3dir); \
12162306a36Sopenharmony_ci		$(INSTALL) -d -m 755 $(DESTDIR)$(man7dir); \
12262306a36Sopenharmony_ci		$(INSTALL) -m 644 $(MAN_7) $(DESTDIR)$(man7dir);
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ciinstall-html:
12562306a36Sopenharmony_ci	$(call QUIET_INSTALL, html) \
12662306a36Sopenharmony_ci		$(INSTALL) -d -m 755 $(DESTDIR)$(htmldir); \
12762306a36Sopenharmony_ci		$(INSTALL) -m 644 $(MAN_HTML) $(DESTDIR)$(htmldir); \
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ciinstall-examples:
13062306a36Sopenharmony_ci	$(call QUIET_INSTALL, examples) \
13162306a36Sopenharmony_ci		$(INSTALL) -d -m 755 $(DESTDIR)$(exdir); \
13262306a36Sopenharmony_ci		$(INSTALL) -m 644 $(MAN_EX) $(DESTDIR)$(exdir); \
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ciCLEAN_FILES =					\
13562306a36Sopenharmony_ci	$(MAN_XML) $(addsuffix +,$(MAN_XML))	\
13662306a36Sopenharmony_ci	$(MAN_HTML) $(addsuffix +,$(MAN_HTML))	\
13762306a36Sopenharmony_ci	$(MAN_X)
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ciclean:
14062306a36Sopenharmony_ci	$(call QUIET_CLEAN, Documentation) $(RM) $(CLEAN_FILES)
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci$(MAN_3): $(OUTPUT)%.3: %.xml
14362306a36Sopenharmony_ci	$(QUIET_XMLTO)$(XMLTO) -o $(OUTPUT). -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $<
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci$(MAN_7): $(OUTPUT)%.7: %.xml
14662306a36Sopenharmony_ci	$(QUIET_XMLTO)$(XMLTO) -o $(OUTPUT). -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $<
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci$(MAN_XML): $(OUTPUT)%.xml: %.txt
14962306a36Sopenharmony_ci	$(QUIET_ASCIIDOC)$(ASCIIDOC) -b docbook -d manpage \
15062306a36Sopenharmony_ci		$(ASCIIDOC_EXTRA) -alibperf_version=$(EVENT_PARSE_VERSION) -o $@+ $< && \
15162306a36Sopenharmony_ci	mv $@+ $@
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci$(MAN_HTML): $(OUTPUT)%.html: %.txt
15462306a36Sopenharmony_ci	$(QUIET_ASCIIDOC)$(ASCIIDOC) -b $(ASCIIDOC_HTML) -d manpage \
15562306a36Sopenharmony_ci	$(ASCIIDOC_EXTRA) -aperf_version=$(EVENT_PARSE_VERSION) -o $@+ $< && \
15662306a36Sopenharmony_ci	mv $@+ $@
157