chiark / gitweb /
Prep v236: Adapt elogind parts in the build system to upstream changes.
[elogind.git] / man / meson.build
1 # SPDX-License-Identifier: LGPL-2.1+
2 #
3 # Copyright 2017 Zbigniew JÄ™drzejewski-Szmek
4 #
5 # elogind is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation; either version 2.1 of the License, or
8 # (at your option) any later version.
9 #
10 # elogind is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with elogind; If not, see <http://www.gnu.org/licenses/>.
17
18 # This is lame, I know, but meson has no other include mechanism
19 subdir('rules')
20
21 want_man = get_option('man')
22 want_html = get_option('html')
23 xsltproc = find_program('xsltproc',
24                         required : want_man == 'true' or want_html == 'true')
25 want_man = want_man != 'false' and xsltproc.found()
26 want_html = want_html != 'false' and xsltproc.found()
27
28 xsltproc_flags = [
29         '--nonet',
30         '--xinclude',
31         '--maxdepth', '9000',
32         '--stringparam', 'man.output.quietly', '1',
33         '--stringparam', 'funcsynopsis.style', 'ansi',
34         '--stringparam', 'man.authors.section.enabled', '0',
35         '--stringparam', 'man.copyright.section.enabled', '0',
36         '--stringparam', 'elogind.version', '@0@'.format(meson.project_version()),
37         '--path',
38         '@0@:@1@'.format(meson.current_build_dir(), meson.current_source_dir())]
39
40 custom_man_xsl = files('custom-man.xsl')
41 custom_html_xsl = files('custom-html.xsl')
42 xslt_cmd = [xsltproc, '-o', '@OUTPUT0@'] + xsltproc_flags
43
44 #if 0 /// UNNEEDED by elogind
45 # custom_entities_ent = configure_file(
46 #         input : 'custom-entities.ent.in',
47 #         output : 'custom-entities.ent',
48 #         configuration : conf)
49 #endif // 0
50
51 man_pages = []
52 html_pages = []
53 source_xml_files = []
54 foreach tuple : xsltproc.found() ? manpages : []
55         stem = tuple[0]
56         section = tuple[1]
57         aliases = tuple[2]
58         condition = tuple[3]
59
60         xml = stem + '.xml'
61         html = stem + '.html'
62         man = stem + '.' + section
63
64         manaliases = []
65         htmlaliases = []
66         foreach alias : aliases
67                 manaliases += [alias + '.' + section]
68                 htmlaliases += [alias + '.html']
69         endforeach
70
71         mandirn = join_paths(get_option('mandir'), 'man' + section)
72
73         if condition == '' or conf.get(condition) == 1
74                 p1 = custom_target(
75                         man,
76                         input : xml,
77                         output : [man] + manaliases,
78                         command : xslt_cmd + [custom_man_xsl, '@INPUT@'],
79 #if 0 /// UNNEEDED by elogind
80 #                         depend_files : custom_entities_ent,
81 #endif // 0
82                         install : want_man,
83                         install_dir : mandirn)
84                 man_pages += [p1]
85
86                 p2 = []
87                 foreach htmlalias : htmlaliases
88                         link = custom_target(
89                                 htmlalias,
90                                 input : p2,
91                                 output : htmlalias,
92                                 command : ['ln', '-fs', html, '@OUTPUT@'])
93                         if want_html
94 #if 0 /// This must be configurable in elogind
95 #                                 dst = join_paths(docdir, 'html', htmlalias)
96 #else
97                                   dst = get_option('htmldir')
98                                   dst = dst != '' ? dst: join_paths(docdir, 'html', htmlalias)
99 #endif // 0
100                                 cmd = 'ln -fs @0@ $DESTDIR@1@'.format(html, dst)
101                                 meson.add_install_script('sh', '-c', cmd)
102                                 p2 += [link]
103                         endif
104                         html_pages += [link]
105                 endforeach
106
107                 p3 = custom_target(
108                         html,
109                         input : xml,
110                         output : html,
111                         command : xslt_cmd + [custom_html_xsl, '@INPUT@'],
112 #if 0 /// UNNEEDED by elogind
113 #                         depend_files : custom_entities_ent,
114 #endif // 0
115                         depends : p2,
116                         install : want_html,
117                         install_dir : join_paths(docdir, 'html'))
118                 html_pages += [p3]
119
120                 source_xml_files += files(tuple[0] + '.xml')
121         else
122                 message('Skipping @0@.@1@ because @2@ is false'.format(stem, section, condition))
123         endif
124 endforeach
125
126 ############################################################
127
128 have_lxml = run_command(xml_helper_py).returncode() == 0
129 if not have_lxml
130         message('python-lxml not available, not making man page indices')
131 endif
132
133 elogind_directives_xml = custom_target(
134         'elogind.directives.xml',
135         input : source_xml_files,
136         output : 'elogind.directives.xml',
137         command : [make_directive_index_py, '@OUTPUT@'] + source_xml_files)
138
139 nonindex_xml_files = source_xml_files + [elogind_directives_xml]
140 elogind_index_xml = custom_target(
141         'elogind.index.xml',
142         input : nonindex_xml_files,
143         output : 'elogind.index.xml',
144         command : [make_man_index_py, '@OUTPUT@'] + nonindex_xml_files)
145
146 foreach tuple : want_man or want_html ? [['elogind.directives', '7', elogind_directives_xml],
147                                          ['elogind.index',      '7', elogind_index_xml]] : []
148         stem = tuple[0]
149         section = tuple[1]
150         xml = tuple[2]
151
152         html = stem + '.html'
153         man = stem + '.' + section
154
155         mandirn = join_paths(get_option('mandir'), 'man' + section)
156
157         p1 = custom_target(
158                 man,
159                 input : xml,
160                 output : man,
161                 command : xslt_cmd + [custom_man_xsl, '@INPUT@'],
162                 install : want_man and have_lxml,
163                 install_dir : mandirn)
164         man_pages += [p1]
165
166         p2 = []
167         if html == 'elogind.index.html'
168                 htmlalias = 'index.html'
169                 link = custom_target(
170                         htmlalias,
171                         input : p2,
172                         output : htmlalias,
173                         command : ['ln', '-fs', html, '@OUTPUT@'])
174                 if want_html
175                         dst = join_paths(docdir, 'html', htmlalias)
176                         cmd = 'ln -fs @0@ $DESTDIR@1@'.format(html, dst)
177                         meson.add_install_script('sh', '-c', cmd)
178                         p2 += [link]
179                 endif
180                 html_pages += [link]
181         endif
182
183         p3 = custom_target(
184                 html,
185                 input : xml,
186                 output : html,
187                 command : xslt_cmd + [custom_html_xsl, '@INPUT@'],
188 #if 0 /// UNNEEDED by elogind
189 #                 depend_files : custom_entities_ent,
190 #endif // 0
191                 depends : p2,
192                 install : want_html and have_lxml,
193                 install_dir : join_paths(docdir, 'html'))
194         html_pages += [p3]
195 endforeach
196
197 # cannot use run_target until https://github.com/mesonbuild/meson/issues/1644 is resolved
198 man = custom_target(
199         'man',
200         output : 'man',
201         depends : man_pages,
202         command : ['echo'])
203
204 html = custom_target(
205         'html',
206         output : 'html',
207         depends : html_pages,
208         command : ['echo'])
209
210 #if 0 /// UNNEEDED in elogind
211 # run_target(
212 #         'doc-sync',
213 #         depends : man_pages + html_pages,
214 #         command : ['rsync', '-rlv',
215 #                    '--delete-excluded',
216 #                    '--include=man',
217 #                    '--include=*.html',
218 #                    '--exclude=*',
219 #                    '--omit-dir-times',
220 #                    meson.current_build_dir(),
221 #                    get_option('www-target')])
222 #endif // 0
223
224 ############################################################
225
226 if git.found()
227         custom_target(
228                 'update-man-rules',
229                 output : 'update-man-rules',
230                 # slightly strange syntax because of
231                 # https://github.com/mesonbuild/meson/issues/1643
232                 # and https://github.com/mesonbuild/meson/issues/1512
233                 command : ['sh', '-c',
234                            'cd @0@ && '.format(meson.build_root()) +
235                            'python3 @0@/tools/make-man-rules.py `git ls-files ":/man/*.xml"` >t && '.format(meson.source_root()) +
236                            'mv t @0@/rules/meson.build'.format(meson.current_source_dir())],
237 #if 0 /// UNNEEDED by elogind
238 #                 depend_files : custom_entities_ent)
239 #else
240                 )
241 #endif // 0
242 endif