]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/meson.build
tree-wide: beautify remaining copyright statements
[thirdparty/systemd.git] / man / meson.build
CommitLineData
3a726fcd
ZJS
1# SPDX-License-Identifier: LGPL-2.1+
2#
96b2fb93 3# Copyright © 2017 Zbigniew Jędrzejewski-Szmek
3a726fcd 4
5c23128d
ZJS
5# This is lame, I know, but meson has no other include mechanism
6subdir('rules')
7
527d43d7
ZJS
8want_man = get_option('man')
9want_html = get_option('html')
10xsltproc = find_program('xsltproc',
4390be30
ZJS
11 required : want_man == 'true' or want_html == 'true')
12want_man = want_man != 'false' and xsltproc.found()
13want_html = want_html != 'false' and xsltproc.found()
527d43d7 14
5c23128d 15xsltproc_flags = [
37efbbd8
ZJS
16 '--nonet',
17 '--xinclude',
f2adcd22 18 '--maxdepth', '9000',
37efbbd8
ZJS
19 '--stringparam', 'man.output.quietly', '1',
20 '--stringparam', 'funcsynopsis.style', 'ansi',
21 '--stringparam', 'man.authors.section.enabled', '0',
22 '--stringparam', 'man.copyright.section.enabled', '0',
23 '--stringparam', 'systemd.version', '@0@'.format(meson.project_version()),
24 '--path',
25 '@0@:@1@'.format(meson.current_build_dir(), meson.current_source_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
ZJS
30
31custom_entities_ent = configure_file(
37efbbd8
ZJS
32 input : 'custom-entities.ent.in',
33 output : 'custom-entities.ent',
34 configuration : conf)
5c23128d 35
527d43d7
ZJS
36man_pages = []
37html_pages = []
38source_xml_files = []
559d215b 39foreach tuple : xsltproc.found() ? manpages : []
37efbbd8
ZJS
40 stem = tuple[0]
41 section = tuple[1]
42 aliases = tuple[2]
43 condition = tuple[3]
44
45 xml = stem + '.xml'
46 html = stem + '.html'
47 man = stem + '.' + section
48
49 manaliases = []
50 htmlaliases = []
51 foreach alias : aliases
52 manaliases += [alias + '.' + section]
53 htmlaliases += [alias + '.html']
54 endforeach
55
56 mandirn = join_paths(get_option('mandir'), 'man' + section)
57
349cc4a5 58 if condition == '' or conf.get(condition) == 1
37efbbd8
ZJS
59 p1 = custom_target(
60 man,
61 input : xml,
62 output : [man] + manaliases,
63 command : xslt_cmd + [custom_man_xsl, '@INPUT@'],
64 depend_files : custom_entities_ent,
65 install : want_man,
66 install_dir : mandirn)
67 man_pages += [p1]
68
38acf8a7 69 p2 = []
488477d1 70 foreach htmlalias : htmlaliases
38acf8a7 71 link = custom_target(
488477d1
ZJS
72 htmlalias,
73 input : p2,
74 output : htmlalias,
75 command : ['ln', '-fs', html, '@OUTPUT@'])
76 if want_html
77 dst = join_paths(docdir, 'html', htmlalias)
78 cmd = 'ln -fs @0@ $DESTDIR@1@'.format(html, dst)
79 meson.add_install_script('sh', '-c', cmd)
38acf8a7 80 p2 += [link]
488477d1 81 endif
38acf8a7 82 html_pages += [link]
488477d1
ZJS
83 endforeach
84
38acf8a7
ZJS
85 p3 = custom_target(
86 html,
87 input : xml,
88 output : html,
89 command : xslt_cmd + [custom_html_xsl, '@INPUT@'],
90 depend_files : custom_entities_ent,
91 depends : p2,
92 install : want_html,
93 install_dir : join_paths(docdir, 'html'))
94 html_pages += [p3]
95
37efbbd8
ZJS
96 source_xml_files += files(tuple[0] + '.xml')
97 else
98 message('Skipping @0@.@1@ because @2@ is false'.format(stem, section, condition))
99 endif
5c23128d
ZJS
100endforeach
101
102############################################################
103
b184e8fe
ZJS
104have_lxml = run_command(xml_helper_py).returncode() == 0
105if not have_lxml
37efbbd8 106 message('python-lxml not available, not making man page indices')
b184e8fe
ZJS
107endif
108
5c23128d 109systemd_directives_xml = custom_target(
37efbbd8
ZJS
110 'systemd.directives.xml',
111 input : source_xml_files,
112 output : 'systemd.directives.xml',
113 command : [make_directive_index_py, '@OUTPUT@'] + source_xml_files)
5c23128d
ZJS
114
115nonindex_xml_files = source_xml_files + [systemd_directives_xml]
116systemd_index_xml = custom_target(
37efbbd8
ZJS
117 'systemd.index.xml',
118 input : nonindex_xml_files,
119 output : 'systemd.index.xml',
120 command : [make_man_index_py, '@OUTPUT@'] + nonindex_xml_files)
5c23128d 121
5b316b9e
YW
122foreach tuple : want_man or want_html ? [['systemd.directives', '7', systemd_directives_xml],
123 ['systemd.index', '7', systemd_index_xml]] : []
37efbbd8
ZJS
124 stem = tuple[0]
125 section = tuple[1]
126 xml = tuple[2]
127
128 html = stem + '.html'
129 man = stem + '.' + section
130
131 mandirn = join_paths(get_option('mandir'), 'man' + section)
132
133 p1 = custom_target(
134 man,
135 input : xml,
136 output : man,
137 command : xslt_cmd + [custom_man_xsl, '@INPUT@'],
138 install : want_man and have_lxml,
139 install_dir : mandirn)
140 man_pages += [p1]
141
38acf8a7 142 p2 = []
064d9ef0
MB
143 if html == 'systemd.index.html'
144 htmlalias = 'index.html'
38acf8a7 145 link = custom_target(
064d9ef0
MB
146 htmlalias,
147 input : p2,
148 output : htmlalias,
149 command : ['ln', '-fs', html, '@OUTPUT@'])
150 if want_html
151 dst = join_paths(docdir, 'html', htmlalias)
152 cmd = 'ln -fs @0@ $DESTDIR@1@'.format(html, dst)
153 meson.add_install_script('sh', '-c', cmd)
38acf8a7 154 p2 += [link]
064d9ef0 155 endif
38acf8a7 156 html_pages += [link]
064d9ef0 157 endif
38acf8a7
ZJS
158
159 p3 = custom_target(
160 html,
161 input : xml,
162 output : html,
163 command : xslt_cmd + [custom_html_xsl, '@INPUT@'],
164 depend_files : custom_entities_ent,
165 depends : p2,
166 install : want_html and have_lxml,
167 install_dir : join_paths(docdir, 'html'))
168 html_pages += [p3]
5c23128d 169endforeach
527d43d7 170
9c84bb78
ZJS
171# cannot use run_target until https://github.com/mesonbuild/meson/issues/1644 is resolved
172man = custom_target(
a923e085 173 'man',
9c84bb78 174 output : 'man',
a923e085
ZJS
175 depends : man_pages,
176 command : ['echo'])
177
e85a690b 178html = custom_target(
a923e085 179 'html',
a923e085 180 output : 'html',
e85a690b 181 depends : html_pages,
a923e085
ZJS
182 command : ['echo'])
183
184run_target(
185 'doc-sync',
186 depends : man_pages + html_pages,
187 command : ['rsync', '-rlv',
188 '--delete-excluded',
189 '--include=man',
190 '--include=*.html',
191 '--exclude=*',
192 '--omit-dir-times',
193 meson.current_build_dir(),
194 get_option('www-target')])
18af8932
ZJS
195
196############################################################
197
198if git.found()
e85a690b 199 custom_target(
18af8932 200 'update-man-rules',
e85a690b 201 output : 'update-man-rules',
18af8932
ZJS
202 # slightly strange syntax because of
203 # https://github.com/mesonbuild/meson/issues/1643
204 # and https://github.com/mesonbuild/meson/issues/1512
205 command : ['sh', '-c',
206 'cd @0@ && '.format(meson.build_root()) +
0689f766 207 'python3 @0@/tools/make-man-rules.py `git ls-files ":/man/*.xml"` >t && '.format(meson.source_root()) +
18af8932
ZJS
208 'mv t @0@/rules/meson.build'.format(meson.current_source_dir())],
209 depend_files : custom_entities_ent)
210endif