]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/meson.build
man: generate link mode list dynamically
[thirdparty/systemd.git] / man / meson.build
1 # SPDX-License-Identifier: LGPL-2.1-or-later
2
3 # This is lame, I know, but meson has no other include mechanism
4 subdir('rules')
5
6 want_man = get_option('man')
7 want_html = get_option('html')
8 xsltproc = find_program('xsltproc',
9 required : want_man == 'true' or want_html == 'true')
10 want_man = want_man != 'false' and xsltproc.found()
11 want_html = want_html != 'false' and xsltproc.found()
12
13 xsltproc_flags = [
14 '--nonet',
15 '--xinclude',
16 '--maxdepth', '9000',
17 '--stringparam', 'man.output.quietly', '1',
18 '--stringparam', 'funcsynopsis.style', 'ansi',
19 '--stringparam', 'man.authors.section.enabled', '0',
20 '--stringparam', 'man.copyright.section.enabled', '0',
21 '--stringparam', 'systemd.version', '@0@'.format(meson.project_version()),
22 '--path',
23 '@0@:@1@:@2@'.format(meson.current_build_dir(),
24 meson.current_source_dir(),
25 libshared_build_dir)]
26
27 custom_man_xsl = files('custom-man.xsl')
28 custom_html_xsl = files('custom-html.xsl')
29 xslt_cmd = [xsltproc, '-o', '@OUTPUT0@'] + xsltproc_flags
30
31 custom_entities_ent = custom_target(
32 'custom-entities.ent',
33 input : 'custom-entities.ent.in',
34 output : 'custom-entities.ent',
35 command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'])
36
37 man_page_depends += custom_entities_ent
38
39 man_pages = []
40 html_pages = []
41 source_xml_files = []
42 dbus_docs = []
43 foreach tuple : manpages
44 stem = tuple[0]
45 section = tuple[1]
46 aliases = tuple[2]
47 condition = tuple[3]
48
49 xml = stem + '.xml'
50 html = stem + '.html'
51 man = stem + '.' + section
52
53 manaliases = []
54 htmlaliases = []
55 foreach alias : aliases
56 manaliases += alias + '.' + section
57 htmlaliases += alias + '.html'
58 endforeach
59
60 mandirn = get_option('mandir') / ('man' + section)
61
62 if condition == '' or conf.get(condition) == 1
63 file = files(tuple[0] + '.xml')
64 source_xml_files += file
65 if tuple[0].startswith('org.freedesktop.')
66 dbus_docs += file
67 endif
68
69 if xsltproc.found()
70 p1 = custom_target(
71 man,
72 input : xml,
73 output : [man] + manaliases,
74 command : xslt_cmd + [custom_man_xsl, '@INPUT@'],
75 depends : man_page_depends,
76 install : want_man,
77 install_dir : mandirn)
78 man_pages += p1
79
80 p2 = []
81 foreach htmlalias : htmlaliases
82 link = custom_target(
83 htmlalias,
84 output : htmlalias,
85 command : [ln, '-fs', html, '@OUTPUT@'])
86 if want_html
87 dst = docdir / 'html' / htmlalias
88 cmd = 'ln -fs @0@ $DESTDIR@1@'.format(html, dst)
89 meson.add_install_script('sh', '-c', cmd)
90 p2 += link
91 endif
92 html_pages += link
93 endforeach
94
95 p3 = custom_target(
96 html,
97 input : xml,
98 output : html,
99 command : xslt_cmd + [custom_html_xsl, '@INPUT@'],
100 depends : [man_page_depends, p2],
101 install : want_html,
102 install_dir : docdir / 'html')
103 html_pages += p3
104 endif
105 else
106 message('Skipping @0@.@1@ because @2@ is false'.format(stem, section, condition))
107 endif
108 endforeach
109
110 ############################################################
111
112 have_lxml = run_command(xml_helper_py, check: false).returncode() == 0
113 if not have_lxml
114 message('python-lxml not available, not making man page indices')
115 endif
116
117 systemd_directives_xml = custom_target(
118 'systemd.directives.xml',
119 input : ['directives-template.xml', source_xml_files],
120 output : 'systemd.directives.xml',
121 depends : man_page_depends,
122 command : [make_directive_index_py, '@OUTPUT@', '@INPUT@'])
123
124 nonindex_xml_files = source_xml_files + [systemd_directives_xml]
125 systemd_index_xml = custom_target(
126 'systemd.index.xml',
127 input : nonindex_xml_files,
128 output : 'systemd.index.xml',
129 command : [make_man_index_py, '@OUTPUT@'] + nonindex_xml_files)
130
131 foreach tuple : xsltproc.found() ? [['systemd.directives', '7', systemd_directives_xml],
132 ['systemd.index', '7', systemd_index_xml]] : []
133 stem = tuple[0]
134 section = tuple[1]
135 xml = tuple[2]
136
137 html = stem + '.html'
138 man = stem + '.' + section
139
140 mandirn = get_option('mandir') / ('man' + section)
141
142 p1 = custom_target(
143 man,
144 input : xml,
145 output : man,
146 command : xslt_cmd + [custom_man_xsl, '@INPUT@'],
147 install : want_man and have_lxml,
148 install_dir : mandirn)
149 man_pages += p1
150
151 p2 = []
152 if html == 'systemd.index.html'
153 htmlalias = 'index.html'
154 link = custom_target(
155 htmlalias,
156 input : p2,
157 output : htmlalias,
158 command : [ln, '-fs', html, '@OUTPUT@'])
159 if want_html
160 dst = docdir / 'html' / htmlalias
161 cmd = 'ln -fs @0@ $DESTDIR@1@'.format(html, dst)
162 meson.add_install_script('sh', '-c', cmd)
163 p2 += link
164 endif
165 html_pages += link
166 endif
167
168 p3 = custom_target(
169 html,
170 input : xml,
171 output : html,
172 command : xslt_cmd + [custom_html_xsl, '@INPUT@'],
173 depends : [man_page_depends, p2],
174 install : want_html and have_lxml,
175 install_dir : docdir / 'html')
176 html_pages += p3
177 endforeach
178
179 # Cannot use run_target because those targets are used in depends
180 # Also see https://github.com/mesonbuild/meson/issues/368.
181 man = custom_target(
182 'man',
183 output : 'man',
184 depends : man_pages,
185 command : [echo])
186
187 html = custom_target(
188 'html',
189 output : 'html',
190 depends : html_pages,
191 command : [echo])
192
193 if rsync.found()
194 run_target(
195 'doc-sync',
196 depends : man_pages + html_pages,
197 command : [rsync, '-rlv',
198 '--delete-excluded',
199 '--include=man',
200 '--include=*.html',
201 '--exclude=*',
202 '--omit-dir-times',
203 meson.current_build_dir(),
204 get_option('www-target')])
205 endif
206
207 ############################################################
208
209 buildroot_substs = configuration_data()
210 buildroot_substs.set_quoted('BUILD_ROOT', project_build_root)
211
212 configure_file(
213 input : 'man.in',
214 output : 'man',
215 configuration : buildroot_substs)
216
217 configure_file(
218 input : 'html.in',
219 output : 'html',
220 configuration : buildroot_substs)
221
222 ############################################################
223
224 update_dbus_docs = custom_target(
225 'update-dbus-docs-impl',
226 output : 'update-dbus-docs',
227 command : [update_dbus_docs_py, '--build-dir', project_build_root, '@INPUT@'],
228 input : dbus_docs)
229
230 if conf.get('BUILD_MODE_DEVELOPER') == 1
231 test('dbus-docs-fresh',
232 update_dbus_docs_py,
233 suite : 'dist',
234 args : ['--build-dir', project_build_root, '--test', dbus_docs],
235 depends : dbus_programs)
236 endif
237
238 update_man_rules = custom_target(
239 'update-man-rules-impl',
240 output : 'update-man-rules',
241 command : [update_man_rules_py,
242 '@0@/man/*.xml'.format(project_source_root),
243 '@0@/rules/meson.build'.format(meson.current_source_dir())],
244 depends : man_page_depends)