]>
Commit | Line | Data |
---|---|---|
1 | # SPDX-License-Identifier: LGPL-2.1+ | |
2 | ||
3 | # This is lame, I know, but meson has no other include mechanism | |
4 | subdir('rules') | |
5 | ||
6 | want_man = get_option('man') | |
7 | want_html = get_option('html') | |
8 | xsltproc = find_program('xsltproc', | |
9 | required : want_man == 'true' or want_html == 'true') | |
10 | want_man = want_man != 'false' and xsltproc.found() | |
11 | want_html = want_html != 'false' and xsltproc.found() | |
12 | ||
13 | xsltproc_flags = [ | |
14 | '--nonet', | |
15 | '--xinclude', | |
16 | '--maxdepth', '9000', | |
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', | |
23 | '@0@:@1@'.format(meson.current_build_dir(), meson.current_source_dir())] | |
24 | ||
25 | custom_man_xsl = files('custom-man.xsl') | |
26 | custom_html_xsl = files('custom-html.xsl') | |
27 | xslt_cmd = [xsltproc, '-o', '@OUTPUT0@'] + xsltproc_flags | |
28 | ||
29 | custom_entities_ent = configure_file( | |
30 | input : 'custom-entities.ent.in', | |
31 | output : 'custom-entities.ent', | |
32 | configuration : conf) | |
33 | ||
34 | man_pages = [] | |
35 | html_pages = [] | |
36 | source_xml_files = [] | |
37 | dbus_docs = [] | |
38 | foreach tuple : xsltproc.found() ? manpages : [] | |
39 | stem = tuple[0] | |
40 | section = tuple[1] | |
41 | aliases = tuple[2] | |
42 | condition = tuple[3] | |
43 | ||
44 | xml = stem + '.xml' | |
45 | html = stem + '.html' | |
46 | man = stem + '.' + section | |
47 | ||
48 | manaliases = [] | |
49 | htmlaliases = [] | |
50 | foreach alias : aliases | |
51 | manaliases += alias + '.' + section | |
52 | htmlaliases += alias + '.html' | |
53 | endforeach | |
54 | ||
55 | mandirn = join_paths(get_option('mandir'), 'man' + section) | |
56 | ||
57 | if condition == '' or conf.get(condition) == 1 | |
58 | p1 = custom_target( | |
59 | man, | |
60 | input : xml, | |
61 | output : [man] + manaliases, | |
62 | command : xslt_cmd + [custom_man_xsl, '@INPUT@'], | |
63 | depend_files : custom_entities_ent, | |
64 | install : want_man, | |
65 | install_dir : mandirn) | |
66 | man_pages += p1 | |
67 | ||
68 | p2 = [] | |
69 | foreach htmlalias : htmlaliases | |
70 | link = custom_target( | |
71 | htmlalias, | |
72 | output : htmlalias, | |
73 | command : ['ln', '-fs', html, '@OUTPUT@']) | |
74 | if want_html | |
75 | dst = join_paths(docdir, 'html', htmlalias) | |
76 | cmd = 'ln -fs @0@ $DESTDIR@1@'.format(html, dst) | |
77 | meson.add_install_script('sh', '-c', cmd) | |
78 | p2 += link | |
79 | endif | |
80 | html_pages += link | |
81 | endforeach | |
82 | ||
83 | p3 = custom_target( | |
84 | html, | |
85 | input : xml, | |
86 | output : html, | |
87 | command : xslt_cmd + [custom_html_xsl, '@INPUT@'], | |
88 | depend_files : custom_entities_ent, | |
89 | depends : p2, | |
90 | install : want_html, | |
91 | install_dir : join_paths(docdir, 'html')) | |
92 | html_pages += p3 | |
93 | ||
94 | file = files(tuple[0] + '.xml') | |
95 | source_xml_files += file | |
96 | if tuple[0].startswith('org.freedesktop.') | |
97 | dbus_docs += file | |
98 | endif | |
99 | else | |
100 | message('Skipping @0@.@1@ because @2@ is false'.format(stem, section, condition)) | |
101 | endif | |
102 | endforeach | |
103 | ||
104 | ############################################################ | |
105 | ||
106 | have_lxml = run_command(xml_helper_py).returncode() == 0 | |
107 | if not have_lxml | |
108 | message('python-lxml not available, not making man page indices') | |
109 | endif | |
110 | ||
111 | systemd_directives_xml = custom_target( | |
112 | 'systemd.directives.xml', | |
113 | input : ['directives-template.xml', source_xml_files], | |
114 | output : 'systemd.directives.xml', | |
115 | command : [make_directive_index_py, '@OUTPUT@', '@INPUT@']) | |
116 | ||
117 | nonindex_xml_files = source_xml_files + [systemd_directives_xml] | |
118 | systemd_index_xml = custom_target( | |
119 | 'systemd.index.xml', | |
120 | input : nonindex_xml_files, | |
121 | output : 'systemd.index.xml', | |
122 | command : [make_man_index_py, '@OUTPUT@'] + nonindex_xml_files) | |
123 | ||
124 | foreach tuple : xsltproc.found() ? [['systemd.directives', '7', systemd_directives_xml], | |
125 | ['systemd.index', '7', systemd_index_xml]] : [] | |
126 | stem = tuple[0] | |
127 | section = tuple[1] | |
128 | xml = tuple[2] | |
129 | ||
130 | html = stem + '.html' | |
131 | man = stem + '.' + section | |
132 | ||
133 | mandirn = join_paths(get_option('mandir'), 'man' + section) | |
134 | ||
135 | p1 = custom_target( | |
136 | man, | |
137 | input : xml, | |
138 | output : man, | |
139 | command : xslt_cmd + [custom_man_xsl, '@INPUT@'], | |
140 | install : want_man and have_lxml, | |
141 | install_dir : mandirn) | |
142 | man_pages += p1 | |
143 | ||
144 | p2 = [] | |
145 | if html == 'systemd.index.html' | |
146 | htmlalias = 'index.html' | |
147 | link = custom_target( | |
148 | htmlalias, | |
149 | input : p2, | |
150 | output : htmlalias, | |
151 | command : ['ln', '-fs', html, '@OUTPUT@']) | |
152 | if want_html | |
153 | dst = join_paths(docdir, 'html', htmlalias) | |
154 | cmd = 'ln -fs @0@ $DESTDIR@1@'.format(html, dst) | |
155 | meson.add_install_script('sh', '-c', cmd) | |
156 | p2 += link | |
157 | endif | |
158 | html_pages += link | |
159 | endif | |
160 | ||
161 | p3 = custom_target( | |
162 | html, | |
163 | input : xml, | |
164 | output : html, | |
165 | command : xslt_cmd + [custom_html_xsl, '@INPUT@'], | |
166 | depend_files : custom_entities_ent, | |
167 | depends : p2, | |
168 | install : want_html and have_lxml, | |
169 | install_dir : join_paths(docdir, 'html')) | |
170 | html_pages += p3 | |
171 | endforeach | |
172 | ||
173 | # Cannot use run_target because those targets are used in depends | |
174 | # Also see https://github.com/mesonbuild/meson/issues/368. | |
175 | man = custom_target( | |
176 | 'man', | |
177 | output : 'man', | |
178 | depends : man_pages, | |
179 | command : ['echo']) | |
180 | ||
181 | html = custom_target( | |
182 | 'html', | |
183 | output : 'html', | |
184 | depends : html_pages, | |
185 | command : ['echo']) | |
186 | ||
187 | run_target( | |
188 | 'doc-sync', | |
189 | depends : man_pages + html_pages, | |
190 | command : ['rsync', '-rlv', | |
191 | '--delete-excluded', | |
192 | '--include=man', | |
193 | '--include=*.html', | |
194 | '--exclude=*', | |
195 | '--omit-dir-times', | |
196 | meson.current_build_dir(), | |
197 | get_option('www-target')]) | |
198 | ||
199 | ############################################################ | |
200 | ||
201 | if dbus_docs.length() > 0 | |
202 | custom_target( | |
203 | 'update-dbus-docs', | |
204 | output : 'update-dbus-docs', | |
205 | command : ['python3', | |
206 | '@0@/tools/update-dbus-docs.py'.format(project_source_root), | |
207 | '--build-dir=@0@'.format(project_build_root), | |
208 | '@INPUT@'], | |
209 | input : dbus_docs) | |
210 | endif | |
211 | ||
212 | ############################################################ | |
213 | ||
214 | if git.found() | |
215 | custom_target( | |
216 | 'update-man-rules', | |
217 | output : 'update-man-rules', | |
218 | command : ['sh', '-c', | |
219 | 'cd @0@ && '.format(meson.build_root()) + | |
220 | 'python3 @0@/tools/update-man-rules.py $(git ls-files ":/man/*.xml") >t && '.format(project_source_root) + | |
221 | 'mv t @0@/rules/meson.build'.format(meson.current_source_dir())], | |
222 | depend_files : custom_entities_ent) | |
223 | endif | |
224 | ||
225 | ############################################################ | |
226 | ||
227 | configure_file( | |
228 | input : 'man.in', | |
229 | output : 'man', | |
230 | configuration : substs) | |
231 | ||
232 | configure_file( | |
233 | input : 'html.in', | |
234 | output : 'html', | |
235 | configuration : substs) |