xref: /aosp_15_r20/external/libtraceevent/Documentation/Makefile (revision 436bf2bcd5202612ffffe471bbcc1f277cc8d28e)
1include ../scripts/utilities.mak
2include ../scripts/utils.mk
3
4# This Makefile and manpage XSL files were taken from tools/perf/Documentation
5# and modified for libtraceevent.
6
7MAN3_TXT= \
8	$(wildcard libtraceevent-*.txt) \
9	libtraceevent.txt
10
11MAN_TXT = $(MAN3_TXT)
12_MAN_XML=$(patsubst %.txt,%.xml,$(MAN_TXT))
13_MAN_HTML=$(patsubst %.txt,%.html,$(MAN_TXT))
14_DOC_MAN3=$(patsubst %.txt,%.m,$(MAN3_TXT))
15
16OUTPUT		:= $(obj)/Documentation/
17
18MAN_XML=$(addprefix $(OUTPUT),$(_MAN_XML))
19MAN_HTML=$(addprefix $(OUTPUT),$(_MAN_HTML))
20DOC_MAN3=$(addprefix $(OUTPUT),$(_DOC_MAN3))
21
22# Make the path relative to DESTDIR, not prefix
23ifndef DESTDIR
24prefix?=$(HOME)
25endif
26bindir?=$(prefix)/bin
27htmldir?=$(prefix)/share/doc/libtraceevent-doc
28pdfdir?=$(prefix)/share/doc/libtraceevent-doc
29mandir?=$(prefix)/share/man
30man3dir=$(mandir)/man3
31
32ASCIIDOC=asciidoc
33ASCIIDOC_EXTRA = --unsafe -f asciidoc.conf
34ASCIIDOC_HTML = xhtml11
35MANPAGE_XSL = manpage-normal.xsl
36XMLTO_EXTRA =
37INSTALL?=install
38RM ?= rm -f
39
40ifdef USE_ASCIIDOCTOR
41ASCIIDOC = asciidoctor
42ASCIIDOC_EXTRA = -a compat-mode
43ASCIIDOC_EXTRA += -I. -rasciidoctor-extensions
44ASCIIDOC_EXTRA += -a mansource="libtraceevent" -a manmanual="libtraceevent Manual"
45ASCIIDOC_HTML = xhtml5
46endif
47
48XMLTO=xmlto
49
50_tmp_tool_path := $(call get-executable,$(ASCIIDOC))
51ifeq ($(_tmp_tool_path),)
52	missing_tools = $(ASCIIDOC)
53endif
54
55ifndef USE_ASCIIDOCTOR
56_tmp_tool_path := $(call get-executable,$(XMLTO))
57ifeq ($(_tmp_tool_path),)
58	missing_tools += $(XMLTO)
59endif
60endif
61
62#
63# For asciidoc ...
64#	-7.1.2,	no extra settings are needed.
65#	8.0-,	set ASCIIDOC8.
66#
67
68#
69# For docbook-xsl ...
70#	-1.68.1,	set ASCIIDOC_NO_ROFF? (based on changelog from 1.73.0)
71#	1.69.0,		no extra settings are needed?
72#	1.69.1-1.71.0,	set DOCBOOK_SUPPRESS_SP?
73#	1.71.1,		no extra settings are needed?
74#	1.72.0,		set DOCBOOK_XSL_172.
75#	1.73.0-,	set ASCIIDOC_NO_ROFF
76#
77
78#
79# If you had been using DOCBOOK_XSL_172 in an attempt to get rid
80# of 'the ".ft C" problem' in your generated manpages, and you
81# instead ended up with weird characters around callouts, try
82# using ASCIIDOC_NO_ROFF instead (it works fine with ASCIIDOC8).
83#
84
85ifdef ASCIIDOC8
86ASCIIDOC_EXTRA += -a asciidoc7compatible
87endif
88ifdef DOCBOOK_XSL_172
89ASCIIDOC_EXTRA += -a libtraceevent-asciidoc-no-roff
90MANPAGE_XSL = manpage-1.72.xsl
91else
92	ifdef ASCIIDOC_NO_ROFF
93	# docbook-xsl after 1.72 needs the regular XSL, but will not
94	# pass-thru raw roff codes from asciidoc.conf, so turn them off.
95	ASCIIDOC_EXTRA += -a libtraceevent-asciidoc-no-roff
96	endif
97endif
98ifdef MAN_BOLD_LITERAL
99XMLTO_EXTRA += -m manpage-bold-literal.xsl
100endif
101ifdef DOCBOOK_SUPPRESS_SP
102XMLTO_EXTRA += -m manpage-suppress-sp.xsl
103endif
104
105SHELL_PATH ?= $(SHELL)
106# Shell quote;
107SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
108
109DESTDIR ?=
110DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
111
112export DESTDIR DESTDIR_SQ
113
114#
115# Please note that there is a minor bug in asciidoc.
116# The version after 6.0.3 _will_ include the patch found here:
117#   http://marc.theaimsgroup.com/?l=libtraceevent&m=111558757202243&w=2
118#
119# Until that version is released you may have to apply the patch
120# yourself - yes, all 6 characters of it!
121#
122QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
123QUIET_SUBDIR1  =
124
125ifneq ($(findstring $(MAKEFLAGS),w),w)
126PRINT_DIR = --no-print-directory
127else # "make -w"
128NO_SUBDIR = :
129endif
130
131ifneq ($(findstring $(MAKEFLAGS),s),s)
132ifneq ($(V),1)
133	QUIET_ASCIIDOC	= @echo '  ASCIIDOC '$@;
134	QUIET_XMLTO	= @echo '  XMLTO    '$@;
135	QUIET_SUBDIR0	= +@subdir=
136	QUIET_SUBDIR1	= ;$(NO_SUBDIR) \
137			   echo '  SUBDIR   ' $$subdir; \
138			  $(MAKE) $(PRINT_DIR) -C $$subdir
139	export V
140endif
141endif
142
143all: html man
144
145man: man3
146man3: $(DOC_MAN3)
147
148html: $(MAN_HTML)
149
150$(MAN_HTML) $(DOC_MAN3): asciidoc.conf
151
152install: install-man install-html
153
154check-man-tools:
155ifdef missing_tools
156	$(error "You need to install $(missing_tools) for man pages")
157endif
158
159$(OUTPUT)install-%.3: $(OUTPUT)%.3
160	$(Q)$(call do_install,$<,$(man3dir),644)
161
162do-install-man: man $(patsubst $(OUTPUT)%,$(OUTPUT)install-%,$(wildcard $(OUTPUT)*.3))
163
164install-man: check-man-tools man
165	$(Q)$(MAKE) -C . do-install-man
166
167install-%.txt: $(OUTPUT)%.html
168	$(Q)$(call do_install,$<,$(htmldir),644)
169
170do-install-html: html $(addprefix install-,$(wildcard *.txt))
171
172install-html: check-man-tools html do-install-html
173
174uninstall: uninstall-man uninstall-html
175
176uninstall-man:
177	$(call QUIET_UNINST, Documentation-man) \
178		$(Q)$(RM) $(addprefix $(DESTDIR)$(man3dir)/,$(DOC_MAN3))
179
180uninstall-html:
181	$(call QUIET_UNINST, Documentation-html) \
182		$(Q)$(RM) $(addprefix $(DESTDIR)$(htmldir)/,$(MAN_HTML))
183
184ifdef missing_tools
185  DO_INSTALL_MAN = $(warning Please install $(missing_tools) to have the man pages installed)
186else
187  DO_INSTALL_MAN = do-install-man
188endif
189
190CLEAN_FILES =					\
191	$(MAN_XML) $(addsuffix +,$(MAN_XML))	\
192	$(MAN_HTML) $(addsuffix +,$(MAN_HTML))	\
193	$(DOC_MAN3) $(OUTPUT)*.3 $(OUTPUT)*.m
194
195clean:
196	$(call QUIET_CLEAN, Documentation) $(RM) $(CLEAN_FILES)
197
198ifdef USE_ASCIIDOCTOR
199$(OUTPUT)%.3 : $(OUTPUT)%.txt
200	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
201	$(ASCIIDOC) -b manpage -d manpage \
202		$(ASCIIDOC_EXTRA) -alibtraceevent_version=$(EVENT_PARSE_VERSION) -o $@+ $< && \
203	mv $@+ $@
204endif
205
206$(OUTPUT)%.m : $(OUTPUT)%.xml
207	$(QUIET_XMLTO)$(RM) $@ && \
208	$(XMLTO) -o $(OUTPUT). -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $<; \
209	touch $@
210
211$(OUTPUT)%.xml : %.txt
212	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
213	$(ASCIIDOC) -b docbook -d manpage \
214		$(ASCIIDOC_EXTRA) -alibtraceevent_version=$(EVENT_PARSE_VERSION) -o $@+ $< && \
215	mv $@+ $@
216
217$(MAN_HTML): $(OUTPUT)%.html : %.txt
218	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
219	$(ASCIIDOC) -b $(ASCIIDOC_HTML) -d manpage \
220		$(ASCIIDOC_EXTRA) -alibtraceevent_version=$(EVENT_PARSE_VERSION) -o $@+ $< && \
221	mv $@+ $@
222