]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/meson.build
final v236 update (#7649)
[thirdparty/systemd.git] / man / meson.build
CommitLineData
3a726fcd
ZJS
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
5c23128d
ZJS
18# This is lame, I know, but meson has no other include mechanism
19subdir('rules')
20
527d43d7
ZJS
21want_man = get_option('man')
22want_html = get_option('html')
23xsltproc = find_program('xsltproc',
4390be30
ZJS
24 required : want_man == 'true' or want_html == 'true')
25want_man = want_man != 'false' and xsltproc.found()
26want_html = want_html != 'false' and xsltproc.found()
527d43d7 27
5c23128d 28xsltproc_flags = [
37efbbd8
ZJS
29 '--nonet',
30 '--xinclude',
f2adcd22 31 '--maxdepth', '9000',
37efbbd8
ZJS
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())]
5c23128d
ZJS
39
40custom_man_xsl = files('custom-man.xsl')
527d43d7 41custom_html_xsl = files('custom-html.xsl')
37efbbd8 42xslt_cmd = [xsltproc, '-o', '@OUTPUT0@'] + xsltproc_flags
04e3eb46
ZJS
43
44custom_entities_ent = configure_file(
37efbbd8
ZJS
45 input : 'custom-entities.ent.in',
46 output : 'custom-entities.ent',
47 configuration : conf)
5c23128d 48
527d43d7
ZJS
49man_pages = []
50html_pages = []
51source_xml_files = []
559d215b 52foreach tuple : xsltproc.found() ? manpages : []
37efbbd8
ZJS
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
349cc4a5 71 if condition == '' or conf.get(condition) == 1
37efbbd8
ZJS
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
38acf8a7 82 p2 = []
488477d1 83 foreach htmlalias : htmlaliases
38acf8a7 84 link = custom_target(
488477d1
ZJS
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)
38acf8a7 93 p2 += [link]
488477d1 94 endif
38acf8a7 95 html_pages += [link]
488477d1
ZJS
96 endforeach
97
38acf8a7
ZJS
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
37efbbd8
ZJS
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
5c23128d
ZJS
113endforeach
114
115############################################################
116
b184e8fe
ZJS
117have_lxml = run_command(xml_helper_py).returncode() == 0
118if not have_lxml
37efbbd8 119 message('python-lxml not available, not making man page indices')
b184e8fe
ZJS
120endif
121
5c23128d 122systemd_directives_xml = custom_target(
37efbbd8
ZJS
123 'systemd.directives.xml',
124 input : source_xml_files,
125 output : 'systemd.directives.xml',
126 command : [make_directive_index_py, '@OUTPUT@'] + source_xml_files)
5c23128d
ZJS
127
128nonindex_xml_files = source_xml_files + [systemd_directives_xml]
129systemd_index_xml = custom_target(
37efbbd8
ZJS
130 'systemd.index.xml',
131 input : nonindex_xml_files,
132 output : 'systemd.index.xml',
133 command : [make_man_index_py, '@OUTPUT@'] + nonindex_xml_files)
5c23128d 134
5b316b9e
YW
135foreach tuple : want_man or want_html ? [['systemd.directives', '7', systemd_directives_xml],
136 ['systemd.index', '7', systemd_index_xml]] : []
37efbbd8
ZJS
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
38acf8a7 155 p2 = []
064d9ef0
MB
156 if html == 'systemd.index.html'
157 htmlalias = 'index.html'
38acf8a7 158 link = custom_target(
064d9ef0
MB
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)
38acf8a7 167 p2 += [link]
064d9ef0 168 endif
38acf8a7 169 html_pages += [link]
064d9ef0 170 endif
38acf8a7
ZJS
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]
5c23128d 182endforeach
527d43d7 183
9c84bb78
ZJS
184# cannot use run_target until https://github.com/mesonbuild/meson/issues/1644 is resolved
185man = custom_target(
a923e085 186 'man',
9c84bb78 187 output : 'man',
a923e085
ZJS
188 depends : man_pages,
189 command : ['echo'])
190
e85a690b 191html = custom_target(
a923e085 192 'html',
a923e085 193 output : 'html',
e85a690b 194 depends : html_pages,
a923e085
ZJS
195 command : ['echo'])
196
197run_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')])
18af8932
ZJS
208
209############################################################
210
211if git.found()
e85a690b 212 custom_target(
18af8932 213 'update-man-rules',
e85a690b 214 output : 'update-man-rules',
18af8932
ZJS
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()) +
0689f766 220 'python3 @0@/tools/make-man-rules.py `git ls-files ":/man/*.xml"` >t && '.format(meson.source_root()) +
18af8932
ZJS
221 'mv t @0@/rules/meson.build'.format(meson.current_source_dir())],
222 depend_files : custom_entities_ent)
223endif