xref: /aosp_15_r20/external/ltp/m4/ltp-docparse.m4 (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1dnl SPDX-License-Identifier: GPL-2.0-or-later
2dnl Copyright (c) 2020 Petr Vorel <[email protected]>
3
4AC_DEFUN([LTP_CHECK_METADATA_GENERATOR_ASCIIDOCTOR], [
5	AC_MSG_NOTICE(checking asciidoctor as metadata generator)
6	AC_PATH_TOOL(asciidoctor, "asciidoctor")
7	metadata_generator_html=$asciidoctor
8	# pdf requires both asciidoctor and asciidoctor-pdf
9	if test "x$metadata_generator_html" != x; then
10		AC_PATH_TOOL(asciidoctor_pdf, "asciidoctor-pdf")
11		metadata_generator_pdf=$asciidoctor_pdf
12	fi
13])
14
15AC_DEFUN([LTP_CHECK_METADATA_GENERATOR_ASCIIDOC], [
16	AC_MSG_NOTICE(checking asciidoc as metadata generator)
17	AC_PATH_TOOL(a2x, "a2x")
18	if test "x$a2x" != x; then
19		version="`$a2x --version | cut -d ' ' -f2 `"
20		AX_COMPARE_VERSION([$version], lt, 9, [
21		AC_MSG_WARN([a2x unsupported version: $version. Use a2x >= 9])
22		a2x=
23		])
24	fi
25	metadata_generator_html=$a2x
26	# pdf requires both asciidoc and dblatex
27	if test "x$metadata_generator_html" != x; then
28		AC_PATH_TOOL(dblatex, "dblatex")
29		metadata_generator_pdf=$dblatex
30	fi
31])
32
33AC_DEFUN([LTP_DOCPARSE], [
34with_metadata=no
35with_metadata_html=no
36with_metadata_pdf=no
37
38if test "x$enable_metadata" != xyes; then
39	enable_metadata_html=no
40	enable_metadata_pdf=no
41	with_metadata_generator=none
42fi
43
44if test "x$enable_metadata_html" = xyes -o "x$enable_metadata_pdf" = xyes; then
45	AX_PROG_PERL_MODULES(Cwd File::Basename JSON LWP::Simple)
46fi
47
48if test "x$ax_perl_modules_failed" = x0; then
49	if test "x$with_metadata_generator" = xasciidoctor -o "x$with_metadata_generator" = xdetect; then
50		LTP_CHECK_METADATA_GENERATOR_ASCIIDOCTOR
51	elif test "x$with_metadata_generator" = xasciidoc; then
52		LTP_CHECK_METADATA_GENERATOR_ASCIIDOC
53	else
54		AC_MSG_ERROR([invalid metadata generator '$with_metadata_generator', use --with-metadata-generator=asciidoc|asciidoctor])
55	fi
56
57	# autodetection: check also Asciidoc
58	if test "x$with_metadata_generator" = xdetect; then
59		with_metadata_generator='asciidoctor'
60		# problems with Asciidoctor: (html enabled && not found) || (pdf enabled && not found) => try Asciidoc
61		if test "x$enable_metadata_html" = xyes -a "x$metadata_generator_html" = x ||
62			test "x$enable_metadata_pdf" = xyes -a "x$metadata_generator_pdf" = x; then
63			backup_html="$metadata_generator_html"
64			backup_pdf="$metadata_generator_pdf"
65			AC_MSG_NOTICE(missing some dependencies for Asciidoctor => trying Asciidoc)
66			with_metadata_generator='asciidoc'
67			LTP_CHECK_METADATA_GENERATOR_ASCIIDOC
68			# prefer Asciidoctor if it's not worse than Asciidoc
69			# (html not enabled || asciidoctor html found || asciidoc html not found) && (pdf ...)
70			if test "x$enable_metadata_html" != xyes -o "x$backup_html" != x -o "x$metadata_generator_html" = x &&
71				test "x$enable_metadata_pdf" != xyes -o "x$backup_pdf" != x -o "x$metadata_generator_pdf" = x; then
72				with_metadata_generator='asciidoctor'
73				metadata_generator_html="$backup_html"
74				metadata_generator_pdf="$backup_pdf"
75			fi
76		fi
77		if test "x$metadata_generator_html" != x -o "x$metadata_generator_pdf" != x; then
78			AC_MSG_NOTICE(choosing $with_metadata_generator for metadata generation)
79		fi
80	fi
81
82	if test "x$enable_metadata_html" = xno; then
83		AC_MSG_NOTICE(HTML metadata generation disabled)
84	elif test "x$metadata_generator_html" != x; then
85		with_metadata_html=yes
86	fi
87
88	if test "x$enable_metadata_pdf" = xno; then
89		AC_MSG_NOTICE(PDF metadata generation disabled)
90	elif test "x$metadata_generator_pdf" != x; then
91		with_metadata_pdf=yes
92	fi
93fi
94
95reason="metadata generation skipped due missing suitable generator"
96hint="specify correct generator with --with-metadata-generator=asciidoc|asciidoctor or use --disable-metadata|--disable-metadata-html|--disable-metadata-pdf"
97
98if test -z "$ax_perl_modules_failed"; then
99	AC_MSG_NOTICE(metadata generation disabled)
100elif test "x$ax_perl_modules_failed" = x1; then
101	AC_MSG_WARN(metadata generation skipped due missing required Perl modules)
102elif test "x$with_metadata_html" = xno -a "x$with_metadata_pdf" = xno; then
103	AC_MSG_WARN([$reason, $hint])
104else
105	with_metadata=yes
106	AC_SUBST(METADATA_GENERATOR, $with_metadata_generator)
107	if test "x$with_metadata_html" = xno -a "x$enable_metadata_html" = xyes; then
108		AC_MSG_WARN([HTML $reason, $hint])
109	fi
110	if test "x$with_metadata_pdf" = xno -a "x$enable_metadata_pdf" = xyes; then
111		AC_MSG_WARN([PDF $reason, $hint])
112	fi
113fi
114
115AC_SUBST(WITH_METADATA, $with_metadata)
116AC_SUBST(WITH_METADATA_HTML, $with_metadata_html)
117AC_SUBST(WITH_METADATA_PDF, $with_metadata_pdf)
118])
119