]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/meson.build
Merge pull request #8575 from keszybz/non-absolute-paths
[thirdparty/systemd.git] / man / meson.build
1 # SPDX-License-Identifier: LGPL-2.1+
2 #
3 # Copyright 2017 Zbigniew Jędrzejewski-Szmek
4
5 # This is lame, I know, but meson has no other include mechanism
6 subdir('rules')
7
8 want_man = get_option('man')
9 want_html = get_option('html')
10 xsltproc = find_program('xsltproc',
11 required : want_man == 'true' or want_html == 'true')
12 want_man = want_man != 'false' and xsltproc.found()
13 want_html = want_html != 'false' and xsltproc.found()
14
15 xsltproc_flags = [
16 '--nonet',
17 '--xinclude',
18 '--maxdepth', '9000',
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())]
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 = configure_file(
32 input : 'custom-entities.ent.in',
33 output : 'custom-entities.ent',
34 configuration : conf)
35
36 man_pages = []
37 html_pages = []
38 source_xml_files = []
39 foreach tuple : xsltproc.found() ? manpages : []
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
58 if condition == '' or conf.get(condition) == 1
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
69 p2 = []
70 foreach htmlalias : htmlaliases
71 link = custom_target(
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)
80 p2 += [link]
81 endif
82 html_pages += [link]
83 endforeach
84
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
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
100 endforeach
101
102 ############################################################
103
104 have_lxml = run_command(xml_helper_py).returncode() == 0
105 if not have_lxml
106 message('python-lxml not available, not making man page indices')
107 endif
108
109 systemd_directives_xml = custom_target(
110 'systemd.directives.xml',
111 input : source_xml_files,
112 output : 'systemd.directives.xml',
113 command : [make_directive_index_py, '@OUTPUT@'] + source_xml_files)
114
115 nonindex_xml_files = source_xml_files + [systemd_directives_xml]
116 systemd_index_xml = custom_target(
117 'systemd.index.xml',
118 input : nonindex_xml_files,
119 output : 'systemd.index.xml',
120 command : [make_man_index_py, '@OUTPUT@'] + nonindex_xml_files)
121
122 foreach tuple : want_man or want_html ? [['systemd.directives', '7', systemd_directives_xml],
123 ['systemd.index', '7', systemd_index_xml]] : []
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
142 p2 = []
143 if html == 'systemd.index.html'
144 htmlalias = 'index.html'
145 link = custom_target(
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)
154 p2 += [link]
155 endif
156 html_pages += [link]
157 endif
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]
169 endforeach
170
171 # cannot use run_target until https://github.com/mesonbuild/meson/issues/1644 is resolved
172 man = custom_target(
173 'man',
174 output : 'man',
175 depends : man_pages,
176 command : ['echo'])
177
178 html = custom_target(
179 'html',
180 output : 'html',
181 depends : html_pages,
182 command : ['echo'])
183
184 run_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')])
195
196 ############################################################
197
198 if git.found()
199 custom_target(
200 'update-man-rules',
201 output : 'update-man-rules',
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()) +
207 'python3 @0@/tools/make-man-rules.py `git ls-files ":/man/*.xml"` >t && '.format(meson.source_root()) +
208 'mv t @0@/rules/meson.build'.format(meson.current_source_dir())],
209 depend_files : custom_entities_ent)
210 endif