meson: wire up support for AsciiDoctor

While our Makefile supports both Asciidoc and AsciiDoctor, our Meson build instructions only support the former. Wire up support for the latter, as well. Our Makefile always favors Asciidoc, but Meson will automatically figure out which of both to use based on whether they are installed or not. To keep compatibility with our Makefile it favors Asciidoc over Asciidoctor in case both are available. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Dec 27, 2024 at 14:59 UTC d838d821c9687a789673b2ac9dff707fdc599e1e
2 files changed +84 -28
Documentation/meson.build
+82 -28
@@ -204,29 +204,87 @@ manpages = {
204 'gitworkflows.txt' : 7,
205 }
206
207 -asciidoc = find_program('asciidoc')
208 -git = find_program('git', required: false)
209 -xmlto = find_program('xmlto')
207 +docs_backend = get_option('docs_backend')
208 +if docs_backend == 'auto'
209 + if find_program('asciidoc', required: false).found()
210 + docs_backend = 'asciidoc'
211 + elif find_program('asciidoctor', required: false).found()
212 + docs_backend = 'asciidoctor'
213 + else
214 + error('Neither asciidoc nor asciidoctor were found.')
215 + endif
216 +endif
217
211 -asciidoc_conf = custom_target(
212 - command: [
213 - shell,
214 - meson.project_source_root() / 'GIT-VERSION-GEN',
215 - meson.project_source_root(),
216 - '@INPUT@',
217 - '@OUTPUT@',
218 - ],
219 - input: meson.current_source_dir() / 'asciidoc.conf.in',
220 - output: 'asciidoc.conf',
221 - depends: [git_version_file],
222 - env: version_gen_environment,
223 -)
218 +if docs_backend == 'asciidoc'
219 + asciidoc = find_program('asciidoc', required: true)
220 + asciidoc_html = 'xhtml11'
221 + asciidoc_docbook = 'docbook'
222 + xmlto_extra = [ ]
223
225 -asciidoc_common_options = [
226 - asciidoc,
227 - '--conf-file=' + asciidoc_conf.full_path(),
228 - '--attribute=build_dir=' + meson.current_build_dir(),
229 -]
224 + asciidoc_conf = custom_target(
225 + command: [
226 + shell,
227 + meson.project_source_root() / 'GIT-VERSION-GEN',
228 + meson.project_source_root(),
229 + '@INPUT@',
230 + '@OUTPUT@',
231 + ],
232 + input: meson.current_source_dir() / 'asciidoc.conf.in',
233 + output: 'asciidoc.conf',
234 + depends: [git_version_file],
235 + env: version_gen_environment,
236 + )
237 +
238 + asciidoc_common_options = [
239 + asciidoc,
240 + '--conf-file=' + asciidoc_conf.full_path(),
241 + '--attribute=build_dir=' + meson.current_build_dir(),
242 + ]
243 +
244 + documentation_deps = [
245 + asciidoc_conf,
246 + ]
247 +elif docs_backend == 'asciidoctor'
248 + asciidoctor = find_program('asciidoctor', required: true)
249 + asciidoc_html = 'xhtml5'
250 + asciidoc_docbook = 'docbook5'
251 + xmlto_extra = [
252 + '--skip-validation',
253 + '-x', meson.current_source_dir() / 'manpage.xsl',
254 + ]
255 +
256 + asciidoctor_extensions = custom_target(
257 + command: [
258 + shell,
259 + meson.project_source_root() / 'GIT-VERSION-GEN',
260 + meson.project_source_root(),
261 + '@INPUT@',
262 + '@OUTPUT@',
263 + ],
264 + input: meson.current_source_dir() / 'asciidoctor-extensions.rb.in',
265 + output: 'asciidoctor-extensions.rb',
266 + depends: [git_version_file],
267 + env: version_gen_environment,
268 + )
269 +
270 + asciidoc_common_options = [
271 + asciidoctor,
272 + '--attribute', 'compat-mode',
273 + '--attribute', 'tabsize=8',
274 + '--attribute', 'litdd=&#x2d;&#x2d;',
275 + '--attribute', 'docinfo=shared',
276 + '--attribute', 'build_dir=' + meson.current_build_dir(),
277 + '--load-path', meson.current_build_dir(),
278 + '--require', 'asciidoctor-extensions',
279 + ]
280 +
281 + documentation_deps = [
282 + asciidoctor_extensions,
283 + ]
284 +endif
285 +
286 +git = find_program('git', required: false)
287 +xmlto = find_program('xmlto')
288
289 cmd_lists = [
290 'cmds-ancillaryinterrogators.txt',
@@ -243,10 +301,6 @@ cmd_lists = [
301 'cmds-foreignscminterface.txt',
302 ]
303
246 -documentation_deps = [
247 - asciidoc_conf,
248 -]
249 -
304 documentation_deps += custom_target(
305 command: [
306 perl,
@@ -278,7 +332,7 @@ foreach manpage, category : manpages
332 if get_option('docs').contains('man')
333 manpage_xml_target = custom_target(
334 command: asciidoc_common_options + [
281 - '--backend=docbook',
335 + '--backend=' + asciidoc_docbook,
336 '--doctype=manpage',
337 '--out-file=@OUTPUT@',
338 meson.current_source_dir() / manpage,
@@ -301,7 +355,7 @@ foreach manpage, category : manpages
355 manpage_xml_target,
356 '-o',
357 meson.current_build_dir(),
304 - ],
358 + ] + xmlto_extra,
359 output: manpage_path,
360 install: true,
361 install_dir: get_option('mandir') / 'man' + category.to_string(),
@@ -311,7 +365,7 @@ foreach manpage, category : manpages
365 if get_option('docs').contains('html') and category == 1
366 custom_target(
367 command: asciidoc_common_options + [
314 - '--backend=xhtml11',
368 + '--backend=' + asciidoc_html,
369 '--doctype=manpage',
370 '--out-file=@OUTPUT@',
371 meson.current_source_dir() / manpage,
meson_options.txt
+2
@@ -85,6 +85,8 @@ option('docs', type: 'array', choices: ['man', 'html'], value: [],
85 description: 'Which documenattion formats to build and install.')
86 option('default_help_format', type: 'combo', choices: ['man', 'html'], value: 'man',
87 description: 'Default format used when executing git-help(1).')
88 +option('docs_backend', type: 'combo', choices: ['asciidoc', 'asciidoctor', 'auto'], value: 'auto',
89 + description: 'Which backend to use to generate documentation.')
90
91 # Testing.
92 option('tests', type: 'boolean', value: true,