1dnl SPDX-License-Identifier: GPL-2.0-or-later 2dnl Copyright (c) 2020 Petr Vorel <pvorel@suse.cz> 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 && test "x$enable_metadata_html" = xyes -o "x$enable_metadata_pdf" = xyes; then 39 AX_PROG_PERL_MODULES(Cwd File::Basename JSON LWP::Simple) 40fi 41 42if test "x$ax_perl_modules_failed" = x0; then 43 if test "x$with_metadata_generator" = xasciidoctor -o "x$with_metadata_generator" = xdetect; then 44 LTP_CHECK_METADATA_GENERATOR_ASCIIDOCTOR 45 elif test "x$with_metadata_generator" = xasciidoc; then 46 LTP_CHECK_METADATA_GENERATOR_ASCIIDOC 47 else 48 AC_MSG_ERROR([invalid metadata generator '$with_metadata_generator', use --with-metadata-generator=asciidoc|asciidoctor]) 49 fi 50 51 # autodetection: check also Asciidoc 52 if test "x$with_metadata_generator" = xdetect; then 53 with_metadata_generator='asciidoctor' 54 # problems with Asciidoctor: (html enabled && not found) || (pdf enabled && not found) => try Asciidoc 55 if test "x$enable_metadata_html" = xyes -a "x$metadata_generator_html" = x || 56 test "x$enable_metadata_pdf" = xyes -a "x$metadata_generator_pdf" = x; then 57 backup_html="$metadata_generator_html" 58 backup_pdf="$metadata_generator_pdf" 59 AC_MSG_NOTICE(missing some dependencies for Asciidoctor => trying Asciidoc) 60 with_metadata_generator='asciidoc' 61 LTP_CHECK_METADATA_GENERATOR_ASCIIDOC 62 # prefer Asciidoctor if it's not worse than Asciidoc 63 # (html not enabled || asciidoctor html found || asciidoc html not found) && (pdf ...) 64 if test "x$enable_metadata_html" != xyes -o "x$backup_html" != x -o "x$metadata_generator_html" = x && 65 test "x$enable_metadata_pdf" != xyes -o "x$backup_pdf" != x -o "x$metadata_generator_pdf" = x; then 66 with_metadata_generator='asciidoctor' 67 metadata_generator_html="$backup_html" 68 metadata_generator_pdf="$backup_pdf" 69 fi 70 fi 71 if test "x$metadata_generator_html" != x -o "x$metadata_generator_pdf" != x; then 72 AC_MSG_NOTICE(choosing $with_metadata_generator for metadata generation) 73 fi 74 fi 75 76 if test "x$enable_metadata_html" = xno; then 77 AC_MSG_NOTICE(HTML metadata generation disabled) 78 elif test "x$metadata_generator_html" != x; then 79 with_metadata_html=yes 80 fi 81 82 if test "x$enable_metadata_pdf" = xno; then 83 AC_MSG_NOTICE(PDF metadata generation disabled) 84 elif test "x$metadata_generator_pdf" != x; then 85 with_metadata_pdf=yes 86 fi 87fi 88 89reason="metadata generation skipped due missing suitable generator" 90hint="specify correct generator with --with-metadata-generator=asciidoc|asciidoctor or use --disable-metadata|--disable-metadata-html|--disable-metadata-pdf" 91 92if test -z "$ax_perl_modules_failed"; then 93 AC_MSG_NOTICE(metadata generation disabled) 94elif test "x$ax_perl_modules_failed" = x1; then 95 AC_MSG_WARN(metadata generation skipped due missing required Perl modules) 96elif test "x$with_metadata_html" = xno -a "x$with_metadata_pdf" = xno; then 97 AC_MSG_WARN([$reason, $hint]) 98else 99 with_metadata=yes 100 AC_SUBST(METADATA_GENERATOR, $with_metadata_generator) 101 if test "x$with_metadata_html" = xno -a "x$enable_metadata_html" = xyes; then 102 AC_MSG_WARN([HTML $reason, $hint]) 103 fi 104 if test "x$with_metadata_pdf" = xno -a "x$enable_metadata_pdf" = xyes; then 105 AC_MSG_WARN([PDF $reason, $hint]) 106 fi 107fi 108 109AC_SUBST(WITH_METADATA, $with_metadata) 110AC_SUBST(WITH_METADATA_HTML, $with_metadata_html) 111AC_SUBST(WITH_METADATA_PDF, $with_metadata_pdf) 112]) 113