]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/meson.build
verify: use manager_load_startable_unit_or_warn() to load units for verification
[thirdparty/systemd.git] / man / meson.build
1 # SPDX-License-Identifier: LGPL-2.1+
2 #
3 # Copyright 2017 Zbigniew Jędrzejewski-Szmek
4 #
5 # systemd is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation; either version 2.1 of the License, or
8 # (at your option) any later version.
9 #
10 # systemd is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
17
18 # This is lame, I know, but meson has no other include mechanism
19 subdir('rules')
20
21 want_man = get_option('man')
22 want_html = get_option('html')
23 xsltproc = find_program('xsltproc',
24 required : want_man == 'true' or want_html == 'true')
25 want_man = want_man != 'false' and xsltproc.found()
26 want_html = want_html != 'false' and xsltproc.found()
27
28 xsltproc_flags = [
29 '--nonet',
30 '--xinclude',
31 '--maxdepth', '9000',
32 '--stringparam', 'man.output.quietly', '1',
33 '--stringparam', 'funcsynopsis.style', 'ansi',
34 '--stringparam', 'man.authors.section.enabled', '0',
35 '--stringparam', 'man.copyright.section.enabled', '0',
36 '--stringparam', 'systemd.version', '@0@'.format(meson.project_version()),
37 '--path',
38 '@0@:@1@'.format(meson.current_build_dir(), meson.current_source_dir())]
39
40 custom_man_xsl = files('custom-man.xsl')
41 custom_html_xsl = files('custom-html.xsl')
42 xslt_cmd = [xsltproc, '-o', '@OUTPUT0@'] + xsltproc_flags
43
44 custom_entities_ent = configure_file(
45 input : 'custom-entities.ent.in',
46 output : 'custom-entities.ent',
47 configuration : conf)
48
49 man_pages = []
50 html_pages = []
51 source_xml_files = []
52 foreach tuple : xsltproc.found() ? manpages : []
53 stem = tuple[0]
54 section = tuple[1]
55 aliases = tuple[2]
56 condition = tuple[3]
57
58 xml = stem + '.xml'
59 html = stem + '.html'
60 man = stem + '.' + section
61
62 manaliases = []
63 htmlaliases = []
64 foreach alias : aliases
65 manaliases += [alias + '.' + section]
66 htmlaliases += [alias + '.html']
67 endforeach
68
69 mandirn = join_paths(get_option('mandir'), 'man' + section)
70
71 if condition == '' or conf.get(condition) == 1
72 p1 = custom_target(
73 man,
74 input : xml,
75 output : [man] + manaliases,
76 command : xslt_cmd + [custom_man_xsl, '@INPUT@'],
77 depend_files : custom_entities_ent,
78 install : want_man,
79 install_dir : mandirn)
80 man_pages += [p1]
81
82 p2 = []
83 foreach htmlalias : htmlaliases
84 link = custom_target(
85 htmlalias,
86 input : p2,
87 output : htmlalias,
88 command : ['ln', '-fs', html, '@OUTPUT@'])
89 if want_html
90 dst = join_paths(docdir, 'html', htmlalias)
91 cmd = 'ln -fs @0@ $DESTDIR@1@'.format(html, dst)
92 meson.add_install_script('sh', '-c', cmd)
93 p2 += [link]
94 endif
95 html_pages += [link]
96 endforeach
97
98 p3 = custom_target(
99 html,
100 input : xml,
101 output : html,
102 command : xslt_cmd + [custom_html_xsl, '@INPUT@'],
103 depend_files : custom_entities_ent,
104 depends : p2,
105 install : want_html,
106 install_dir : join_paths(docdir, 'html'))
107 html_pages += [p3]
108
109 source_xml_files += files(tuple[0] + '.xml')
110 else
111 message('Skipping @0@.@1@ because @2@ is false'.format(stem, section, condition))
112 endif
113 endforeach
114
115 ############################################################
116
117 have_lxml = run_command(xml_helper_py).returncode() == 0
118 if not have_lxml
119 message('python-lxml not available, not making man page indices')
120 endif
121
122 systemd_directives_xml = custom_target(
123 'systemd.directives.xml',
124 input : source_xml_files,
125 output : 'systemd.directives.xml',
126 command : [make_directive_index_py, '@OUTPUT@'] + source_xml_files)
127
128 nonindex_xml_files = source_xml_files + [systemd_directives_xml]
129 systemd_index_xml = custom_target(
130 'systemd.index.xml',
131 input : nonindex_xml_files,
132 output : 'systemd.index.xml',
133 command : [make_man_index_py, '@OUTPUT@'] + nonindex_xml_files)
134
135 foreach tuple : want_man or want_html ? [['systemd.directives', '7', systemd_directives_xml],
136 ['systemd.index', '7', systemd_index_xml]] : []
137 stem = tuple[0]
138 section = tuple[1]
139 xml = tuple[2]
140
141 html = stem + '.html'
142 man = stem + '.' + section
143
144 mandirn = join_paths(get_option('mandir'), 'man' + section)
145
146 p1 = custom_target(
147 man,
148 input : xml,
149 output : man,
150 command : xslt_cmd + [custom_man_xsl, '@INPUT@'],
151 install : want_man and have_lxml,
152 install_dir : mandirn)
153 man_pages += [p1]
154
155 p2 = []
156 if html == 'systemd.index.html'
157 htmlalias = 'index.html'
158 link = custom_target(
159 htmlalias,
160 input : p2,
161 output : htmlalias,
162 command : ['ln', '-fs', html, '@OUTPUT@'])
163 if want_html
164 dst = join_paths(docdir, 'html', htmlalias)
165 cmd = 'ln -fs @0@ $DESTDIR@1@'.format(html, dst)
166 meson.add_install_script('sh', '-c', cmd)
167 p2 += [link]
168 endif
169 html_pages += [link]
170 endif
171
172 p3 = custom_target(
173 html,
174 input : xml,
175 output : html,
176 command : xslt_cmd + [custom_html_xsl, '@INPUT@'],
177 depend_files : custom_entities_ent,
178 depends : p2,
179 install : want_html and have_lxml,
180 install_dir : join_paths(docdir, 'html'))
181 html_pages += [p3]
182 endforeach
183
184 # cannot use run_target until https://github.com/mesonbuild/meson/issues/1644 is resolved
185 man = custom_target(
186 'man',
187 output : 'man',
188 depends : man_pages,
189 command : ['echo'])
190
191 html = custom_target(
192 'html',
193 output : 'html',
194 depends : html_pages,
195 command : ['echo'])
196
197 run_target(
198 'doc-sync',
199 depends : man_pages + html_pages,
200 command : ['rsync', '-rlv',
201 '--delete-excluded',
202 '--include=man',
203 '--include=*.html',
204 '--exclude=*',
205 '--omit-dir-times',
206 meson.current_build_dir(),
207 get_option('www-target')])
208
209 ############################################################
210
211 if git.found()
212 custom_target(
213 'update-man-rules',
214 output : 'update-man-rules',
215 # slightly strange syntax because of
216 # https://github.com/mesonbuild/meson/issues/1643
217 # and https://github.com/mesonbuild/meson/issues/1512
218 command : ['sh', '-c',
219 'cd @0@ && '.format(meson.build_root()) +
220 'python3 @0@/tools/make-man-rules.py `git ls-files ":/man/*.xml"` >t && '.format(meson.source_root()) +
221 'mv t @0@/rules/meson.build'.format(meson.current_source_dir())],
222 depend_files : custom_entities_ent)
223 endif