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