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