]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/meson.build
man: generate link mode list dynamically
[thirdparty/systemd.git] / man / meson.build
CommitLineData
db9ecf05 1# SPDX-License-Identifier: LGPL-2.1-or-later
3a726fcd 2
5c23128d
ZJS
3# This is lame, I know, but meson has no other include mechanism
4subdir('rules')
5
527d43d7
ZJS
6want_man = get_option('man')
7want_html = get_option('html')
8xsltproc = find_program('xsltproc',
4390be30
ZJS
9 required : want_man == 'true' or want_html == 'true')
10want_man = want_man != 'false' and xsltproc.found()
11want_html = want_html != 'false' and xsltproc.found()
527d43d7 12
5c23128d 13xsltproc_flags = [
37efbbd8
ZJS
14 '--nonet',
15 '--xinclude',
f2adcd22 16 '--maxdepth', '9000',
37efbbd8
ZJS
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',
c18dde32
ZJS
23 '@0@:@1@:@2@'.format(meson.current_build_dir(),
24 meson.current_source_dir(),
25 libshared_build_dir)]
5c23128d
ZJS
26
27custom_man_xsl = files('custom-man.xsl')
527d43d7 28custom_html_xsl = files('custom-html.xsl')
37efbbd8 29xslt_cmd = [xsltproc, '-o', '@OUTPUT0@'] + xsltproc_flags
04e3eb46 30
46c4f8dc
ZJS
31custom_entities_ent = custom_target(
32 'custom-entities.ent',
37efbbd8
ZJS
33 input : 'custom-entities.ent.in',
34 output : 'custom-entities.ent',
8f04a1ca 35 command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'])
5c23128d 36
c18dde32
ZJS
37man_page_depends += custom_entities_ent
38
527d43d7
ZJS
39man_pages = []
40html_pages = []
41source_xml_files = []
81e06775 42dbus_docs = []
f12c5d36 43foreach tuple : manpages
37efbbd8
ZJS
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
5a8b1640
ZJS
56 manaliases += alias + '.' + section
57 htmlaliases += alias + '.html'
37efbbd8
ZJS
58 endforeach
59
fce9abb2 60 mandirn = get_option('mandir') / ('man' + section)
37efbbd8 61
349cc4a5 62 if condition == '' or conf.get(condition) == 1
81e06775 63 file = files(tuple[0] + '.xml')
a7052c6e 64 source_xml_files += file
81e06775
ZJS
65 if tuple[0].startswith('org.freedesktop.')
66 dbus_docs += file
67 endif
f12c5d36
ZJS
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@'],
c18dde32 75 depends : man_page_depends,
f12c5d36
ZJS
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@'],
c18dde32 100 depends : [man_page_depends, p2],
f12c5d36
ZJS
101 install : want_html,
102 install_dir : docdir / 'html')
103 html_pages += p3
104 endif
37efbbd8
ZJS
105 else
106 message('Skipping @0@.@1@ because @2@ is false'.format(stem, section, condition))
107 endif
5c23128d
ZJS
108endforeach
109
110############################################################
111
68a06b3c 112have_lxml = run_command(xml_helper_py, check: false).returncode() == 0
b184e8fe 113if not have_lxml
37efbbd8 114 message('python-lxml not available, not making man page indices')
b184e8fe
ZJS
115endif
116
5c23128d 117systemd_directives_xml = custom_target(
37efbbd8 118 'systemd.directives.xml',
28223088 119 input : ['directives-template.xml', source_xml_files],
37efbbd8 120 output : 'systemd.directives.xml',
c18dde32 121 depends : man_page_depends,
28223088 122 command : [make_directive_index_py, '@OUTPUT@', '@INPUT@'])
5c23128d
ZJS
123
124nonindex_xml_files = source_xml_files + [systemd_directives_xml]
125systemd_index_xml = custom_target(
37efbbd8
ZJS
126 'systemd.index.xml',
127 input : nonindex_xml_files,
128 output : 'systemd.index.xml',
129 command : [make_man_index_py, '@OUTPUT@'] + nonindex_xml_files)
5c23128d 130
b7507787
ZJS
131foreach tuple : xsltproc.found() ? [['systemd.directives', '7', systemd_directives_xml],
132 ['systemd.index', '7', systemd_index_xml]] : []
37efbbd8
ZJS
133 stem = tuple[0]
134 section = tuple[1]
135 xml = tuple[2]
136
137 html = stem + '.html'
138 man = stem + '.' + section
139
fce9abb2 140 mandirn = get_option('mandir') / ('man' + section)
37efbbd8
ZJS
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)
5a8b1640 149 man_pages += p1
37efbbd8 150
38acf8a7 151 p2 = []
064d9ef0
MB
152 if html == 'systemd.index.html'
153 htmlalias = 'index.html'
38acf8a7 154 link = custom_target(
064d9ef0
MB
155 htmlalias,
156 input : p2,
157 output : htmlalias,
0f4c4f38 158 command : [ln, '-fs', html, '@OUTPUT@'])
064d9ef0 159 if want_html
fce9abb2 160 dst = docdir / 'html' / htmlalias
064d9ef0
MB
161 cmd = 'ln -fs @0@ $DESTDIR@1@'.format(html, dst)
162 meson.add_install_script('sh', '-c', cmd)
5a8b1640 163 p2 += link
064d9ef0 164 endif
5a8b1640 165 html_pages += link
064d9ef0 166 endif
38acf8a7
ZJS
167
168 p3 = custom_target(
169 html,
170 input : xml,
171 output : html,
172 command : xslt_cmd + [custom_html_xsl, '@INPUT@'],
c18dde32 173 depends : [man_page_depends, p2],
38acf8a7 174 install : want_html and have_lxml,
fce9abb2 175 install_dir : docdir / 'html')
5a8b1640 176 html_pages += p3
5c23128d 177endforeach
527d43d7 178
6939fb9e
ZJS
179# Cannot use run_target because those targets are used in depends
180# Also see https://github.com/mesonbuild/meson/issues/368.
9c84bb78 181man = custom_target(
a923e085 182 'man',
9c84bb78 183 output : 'man',
a923e085 184 depends : man_pages,
0f4c4f38 185 command : [echo])
a923e085 186
e85a690b 187html = custom_target(
a923e085 188 'html',
a923e085 189 output : 'html',
e85a690b 190 depends : html_pages,
0f4c4f38 191 command : [echo])
a923e085 192
7c5fd251
ZJS
193if 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')])
205endif
18af8932
ZJS
206
207############################################################
208
195a8a93
ZJS
209buildroot_substs = configuration_data()
210buildroot_substs.set_quoted('BUILD_ROOT', project_build_root)
211
e9bbff18
ZJS
212configure_file(
213 input : 'man.in',
214 output : 'man',
195a8a93 215 configuration : buildroot_substs)
e9bbff18
ZJS
216
217configure_file(
218 input : 'html.in',
219 output : 'html',
195a8a93 220 configuration : buildroot_substs)
f12c5d36
ZJS
221
222############################################################
223
224update_dbus_docs = custom_target(
d2ec38e2 225 'update-dbus-docs-impl',
f12c5d36
ZJS
226 output : 'update-dbus-docs',
227 command : [update_dbus_docs_py, '--build-dir', project_build_root, '@INPUT@'],
228 input : dbus_docs)
229
230if conf.get('BUILD_MODE_DEVELOPER') == 1
231 test('dbus-docs-fresh',
232 update_dbus_docs_py,
02e0f430 233 suite : 'dist',
e93ada98
DDM
234 args : ['--build-dir', project_build_root, '--test', dbus_docs],
235 depends : dbus_programs)
f12c5d36
ZJS
236endif
237
238update_man_rules = custom_target(
d2ec38e2 239 'update-man-rules-impl',
f12c5d36 240 output : 'update-man-rules',
77d45f1f
ZJS
241 command : [update_man_rules_py,
242 '@0@/man/*.xml'.format(project_source_root),
243 '@0@/rules/meson.build'.format(meson.current_source_dir())],
c18dde32 244 depends : man_page_depends)