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