]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/meson.build
core: introduce new Type=exec service type
[thirdparty/systemd.git] / man / meson.build
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 foreach tuple : xsltproc.found() ? manpages : []
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
50 manaliases += [alias + '.' + section]
51 htmlaliases += [alias + '.html']
52 endforeach
53
54 mandirn = join_paths(get_option('mandir'), 'man' + section)
55
56 if condition == '' or conf.get(condition) == 1
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)
65 man_pages += [p1]
66
67 p2 = []
68 foreach htmlalias : htmlaliases
69 link = custom_target(
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)
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 source_xml_files += files(tuple[0] + '.xml')
95 else
96 message('Skipping @0@.@1@ because @2@ is false'.format(stem, section, condition))
97 endif
98 endforeach
99
100 ############################################################
101
102 have_lxml = run_command(xml_helper_py).returncode() == 0
103 if not have_lxml
104 message('python-lxml not available, not making man page indices')
105 endif
106
107 systemd_directives_xml = custom_target(
108 'systemd.directives.xml',
109 input : source_xml_files,
110 output : 'systemd.directives.xml',
111 command : [make_directive_index_py, '@OUTPUT@'] + source_xml_files)
112
113 nonindex_xml_files = source_xml_files + [systemd_directives_xml]
114 systemd_index_xml = custom_target(
115 'systemd.index.xml',
116 input : nonindex_xml_files,
117 output : 'systemd.index.xml',
118 command : [make_man_index_py, '@OUTPUT@'] + nonindex_xml_files)
119
120 foreach tuple : xsltproc.found() ? [['systemd.directives', '7', systemd_directives_xml],
121 ['systemd.index', '7', systemd_index_xml]] : []
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)
138 man_pages += [p1]
139
140 p2 = []
141 if html == 'systemd.index.html'
142 htmlalias = 'index.html'
143 link = custom_target(
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)
152 p2 += [link]
153 endif
154 html_pages += [link]
155 endif
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'))
166 html_pages += [p3]
167 endforeach
168
169 # cannot use run_target until https://github.com/mesonbuild/meson/issues/1644 is resolved
170 man = custom_target(
171 'man',
172 output : 'man',
173 depends : man_pages,
174 command : ['echo'])
175
176 html = custom_target(
177 'html',
178 output : 'html',
179 depends : html_pages,
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')])
193
194 ############################################################
195
196 if git.found()
197 custom_target(
198 'update-man-rules',
199 output : 'update-man-rules',
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()) +
205 'python3 @0@/tools/make-man-rules.py `git ls-files ":/man/*.xml"` >t && '.format(meson.source_root()) +
206 'mv t @0@/rules/meson.build'.format(meson.current_source_dir())],
207 depend_files : custom_entities_ent)
208 endif