xref: /aosp_15_r20/external/libtraceevent/Documentation/meson.build (revision 436bf2bcd5202612ffffe471bbcc1f277cc8d28e)
1# SPDX-License-Identifier: LGPL-2.1
2#
3# Copyright (c) 2023 Daniel Wagner, SUSE LLC
4
5# input text file: man page section
6sources = {
7    'libtraceevent.txt': '3',
8    'libtraceevent-func_apis.txt': '3',
9    'libtraceevent-commands.txt': '3',
10    'libtraceevent-cpus.txt': '3',
11    'libtraceevent-debug.txt': '3',
12    'libtraceevent-endian_read.txt': '3',
13    'libtraceevent-event_find.txt': '3',
14    'libtraceevent-event_get.txt': '3',
15    'libtraceevent-event_list.txt': '3',
16    'libtraceevent-event_print.txt': '3',
17    'libtraceevent-field_find.txt': '3',
18    'libtraceevent-field_get_val.txt': '3',
19    'libtraceevent-field_print.txt': '3',
20    'libtraceevent-field_read.txt': '3',
21    'libtraceevent-fields.txt': '3',
22    'libtraceevent-file_endian.txt': '3',
23    'libtraceevent-filter.txt': '3',
24    'libtraceevent-func_find.txt': '3',
25    'libtraceevent-handle.txt': '3',
26    'libtraceevent-header_page.txt': '3',
27    'libtraceevent-host_endian.txt': '3',
28    'libtraceevent-kbuffer-create.txt': '3',
29    'libtraceevent-kbuffer-read.txt': '3',
30    'libtraceevent-kbuffer-timestamp.txt': '3',
31    'libtraceevent-kvm-plugin.txt': '3',
32    'libtraceevent-log.txt': '3',
33    'libtraceevent-long_size.txt': '3',
34    'libtraceevent-page_size.txt': '3',
35    'libtraceevent-parse_event.txt': '3',
36    'libtraceevent-parse-files.txt': '3',
37    'libtraceevent-parse_head.txt': '3',
38    'libtraceevent-plugins.txt': '3',
39    'libtraceevent-record_parse.txt': '3',
40    'libtraceevent-reg_event_handler.txt': '3',
41    'libtraceevent-reg_print_func.txt': '3',
42    'libtraceevent-set_flag.txt': '3',
43    'libtraceevent-strerror.txt': '3',
44    'libtraceevent-tseq.txt': '3',
45}
46
47conf_dir = meson.current_source_dir() + '/'
48top_source_dir = meson.current_source_dir() + '/../'
49
50#
51# For asciidoc ...
52#   -7.1.2,     no extra settings are needed.
53#    8.0-,      set ASCIIDOC8.
54#
55
56#
57# For docbook-xsl ...
58#   -1.68.1,         set ASCIIDOC_NO_ROFF? (based on changelog from 1.73.0)
59#    1.69.0,         no extra settings are needed?
60#    1.69.1-1.71.0,  set DOCBOOK_SUPPRESS_SP?
61#    1.71.1,         no extra settings are needed?
62#    1.72.0,         set DOCBOOK_XSL_172.
63#    1.73.0-,        set ASCIIDOC_NO_ROFF
64#
65
66#
67# If you had been using DOCBOOK_XSL_172 in an attempt to get rid
68# of 'the ".ft C" problem' in your generated manpages, and you
69# instead ended up with weird characters around callouts, try
70# using ASCIIDOC_NO_ROFF instead (it works fine with ASCIIDOC8).
71#
72
73if get_option('asciidoctor')
74    asciidoc = find_program('asciidoctor')
75    asciidoc_extra  = ['-a', 'compat-mode']
76    asciidoc_extra += ['-I.']
77    asciidoc_extra += ['-r', 'asciidoctor-extensions']
78    asciidoc_extra += ['-a', 'mansource=libtraceevent']
79    asciidoc_extra += ['-a', 'manmanual="libtraceevent Manual"']
80    asciidoc_html = 'xhtml5'
81else
82    asciidoc = find_program('asciidoc')
83    asciidoc_extra  = ['--unsafe']
84    asciidoc_extra += ['-f', conf_dir + 'asciidoc.conf']
85    asciidoc_html = 'xhtml11'
86
87    r = run_command(asciidoc, '--version', check: true)
88    v = r.stdout().strip()
89    if v.version_compare('>=8.0')
90        asciidoc_extra += ['-a', 'asciidoc7compatible']
91    endif
92endif
93
94manpage_xsl = conf_dir + 'manpage-normal.xsl'
95
96if get_option('docbook-xls-172')
97    asciidoc_extra += ['-a', 'libtraceevent-asciidoc-no-roff']
98    manpage_xsl = conf_dir + 'manpage-1.72.xsl'
99elif get_option('asciidoc-no-roff')
100    # docbook-xsl after 1.72 needs the regular XSL, but will not
101    # pass-thru raw roff codes from asciidoc.conf, so turn them off.
102    asciidoc_extra += ['-a', 'libtraceevent-asciidoc-no-roff']
103endif
104
105xmlto = find_program('xmlto')
106xmlto_extra = []
107
108if get_option('man-bold-literal')
109    xmlto_extra += ['-m ', conf_dir + 'manpage-bold-literal.xsl']
110endif
111
112if get_option('docbook-suppress-sp')
113    xmlto_extra += ['-m ',  conf_dir + 'manpage-suppress-sp.xsl']
114endif
115
116check_doc = custom_target(
117    'check-doc',
118    output: 'dummy',
119    command : [
120        top_source_dir + 'check-manpages.sh',
121        meson.current_source_dir()])
122
123gen = generator(
124    asciidoc,
125    output: '@[email protected]',
126    arguments: [
127        '-b', 'docbook',
128        '-d', 'manpage',
129        '-a', 'libtraceevent_version=' + meson.project_version(),
130        '-o', '@OUTPUT@']
131        + asciidoc_extra
132        +  ['@INPUT@'])
133
134man = []
135html = []
136foreach txt, section : sources
137    # build man page(s)
138    xml = gen.process(txt)
139    man += custom_target(
140        txt.underscorify() + '_man',
141        input: xml,
142        output: '@BASENAME@.' + section,
143        depends: check_doc,
144        command: [
145            xmlto,
146            '-m', manpage_xsl,
147            'man',
148            '-o', '@OUTPUT@']
149            + xmlto_extra
150            + ['@INPUT@'])
151
152    # build html pages
153    html += custom_target(
154        txt.underscorify() + '_html',
155        input: txt,
156        output: '@[email protected]',
157        depends: check_doc,
158        command: [
159            asciidoc,
160            '-b', asciidoc_html,
161            '-d', 'manpage',
162            '-a', 'libtraceevent_version=' + meson.project_version(),
163            '-o', '@OUTPUT@']
164            + asciidoc_extra
165            + ['@INPUT@'])
166endforeach
167
168# Install path workaround because:
169#
170# - xmlto might generate more than one file and we would to tell meson
171#   about those output files. We could figure out which files are generated
172#   (see sed match in check-manpages.sh).
173#
174# - The man page generation puts all the generated files under sub dirs
175#   and it's not obvious how to tell Meson it should not do this without
176#   causing the install step to fail (confusion where the generated files
177#   are stored)
178#
179# - The documentation build is not part of the 'build' target. The user
180#   has explicitly to trigger the doc build. Hence the documentation is
181#   not added to the 'install' target.
182#
183# Thus just use a plain old shell script to move the generated files to the
184# right location.
185
186conf = configuration_data()
187conf.set('SRCDIR', meson.current_build_dir())
188conf.set('MANDIR', mandir)
189conf.set('HTMLDIR', htmldir)
190configure_file(
191    input: 'install-docs.sh.in',
192    output: 'install-docs.sh',
193    configuration: conf)
194
195meson.add_install_script(
196    join_paths(meson.current_build_dir(), 'install-docs.sh'))
197