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