chiark / gitweb /
Prep v239: Add man/custom-entities.ent.in, we now need it.
[elogind.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', 'elogind.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 #if 0 /// UNNEEDED by elogind
63 #                         depend_files : custom_entities_ent,
64 #endif // 0
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 #if 0 /// This must be configurable in elogind
78 #                                 dst = join_paths(docdir, 'html', htmlalias)
79 #else
80                                   dst = get_option('htmldir')
81                                   dst = dst != '' ? dst: join_paths(docdir, 'html', htmlalias)
82 #endif // 0
83                                 cmd = 'ln -fs @0@ $DESTDIR@1@'.format(html, dst)
84                                 meson.add_install_script('sh', '-c', cmd)
85                                 p2 += [link]
86                         endif
87                         html_pages += [link]
88                 endforeach
89
90                 p3 = custom_target(
91                         html,
92                         input : xml,
93                         output : html,
94                         command : xslt_cmd + [custom_html_xsl, '@INPUT@'],
95 #if 0 /// UNNEEDED by elogind
96 #                         depend_files : custom_entities_ent,
97 #endif // 0
98                         depends : p2,
99                         install : want_html,
100                         install_dir : join_paths(docdir, 'html'))
101                 html_pages += [p3]
102
103                 source_xml_files += files(tuple[0] + '.xml')
104         else
105                 message('Skipping @0@.@1@ because @2@ is false'.format(stem, section, condition))
106         endif
107 endforeach
108
109 ############################################################
110
111 have_lxml = run_command(xml_helper_py).returncode() == 0
112 if not have_lxml
113         message('python-lxml not available, not making man page indices')
114 endif
115
116 elogind_directives_xml = custom_target(
117         'elogind.directives.xml',
118         input : source_xml_files,
119         output : 'elogind.directives.xml',
120         command : [make_directive_index_py, '@OUTPUT@'] + source_xml_files)
121
122 nonindex_xml_files = source_xml_files + [elogind_directives_xml]
123 elogind_index_xml = custom_target(
124         'elogind.index.xml',
125         input : nonindex_xml_files,
126         output : 'elogind.index.xml',
127         command : [make_man_index_py, '@OUTPUT@'] + nonindex_xml_files)
128
129 foreach tuple : want_man or want_html ? [['elogind.directives', '7', elogind_directives_xml],
130                                          ['elogind.index',      '7', elogind_index_xml]] : []
131         stem = tuple[0]
132         section = tuple[1]
133         xml = tuple[2]
134
135         html = stem + '.html'
136         man = stem + '.' + section
137
138         mandirn = join_paths(get_option('mandir'), 'man' + section)
139
140         p1 = custom_target(
141                 man,
142                 input : xml,
143                 output : man,
144                 command : xslt_cmd + [custom_man_xsl, '@INPUT@'],
145                 install : want_man and have_lxml,
146                 install_dir : mandirn)
147         man_pages += [p1]
148
149         p2 = []
150         if html == 'elogind.index.html'
151                 htmlalias = 'index.html'
152                 link = custom_target(
153                         htmlalias,
154                         input : p2,
155                         output : htmlalias,
156                         command : ['ln', '-fs', html, '@OUTPUT@'])
157                 if want_html
158                         dst = join_paths(docdir, 'html', htmlalias)
159                         cmd = 'ln -fs @0@ $DESTDIR@1@'.format(html, dst)
160                         meson.add_install_script('sh', '-c', cmd)
161                         p2 += [link]
162                 endif
163                 html_pages += [link]
164         endif
165
166         p3 = custom_target(
167                 html,
168                 input : xml,
169                 output : html,
170                 command : xslt_cmd + [custom_html_xsl, '@INPUT@'],
171 #if 0 /// UNNEEDED by elogind
172 #                 depend_files : custom_entities_ent,
173 #endif // 0
174                 depends : p2,
175                 install : want_html and have_lxml,
176                 install_dir : join_paths(docdir, 'html'))
177         html_pages += [p3]
178 endforeach
179
180 # cannot use run_target until https://github.com/mesonbuild/meson/issues/1644 is resolved
181 man = custom_target(
182         'man',
183         output : 'man',
184         depends : man_pages,
185         command : ['echo'])
186
187 html = custom_target(
188         'html',
189         output : 'html',
190         depends : html_pages,
191         command : ['echo'])
192
193 #if 0 /// UNNEEDED in elogind
194 # run_target(
195 #         'doc-sync',
196 #         depends : man_pages + html_pages,
197 #         command : ['rsync', '-rlv',
198 #                    '--delete-excluded',
199 #                    '--include=man',
200 #                    '--include=*.html',
201 #                    '--exclude=*',
202 #                    '--omit-dir-times',
203 #                    meson.current_build_dir(),
204 #                    get_option('www-target')])
205 #endif // 0
206
207 ############################################################
208
209 if git.found()
210         custom_target(
211                 'update-man-rules',
212                 output : 'update-man-rules',
213                 # slightly strange syntax because of
214                 # https://github.com/mesonbuild/meson/issues/1643
215                 # and https://github.com/mesonbuild/meson/issues/1512
216                 command : ['sh', '-c',
217                            'cd @0@ && '.format(meson.build_root()) +
218                            'python3 @0@/tools/make-man-rules.py `git ls-files ":/man/*.xml"` >t && '.format(meson.source_root()) +
219                            'mv t @0@/rules/meson.build'.format(meson.current_source_dir())],
220 #if 0 /// UNNEEDED by elogind
221 #                 depend_files : custom_entities_ent)
222 #else
223                 )
224 #endif // 0
225 endif