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