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