@@ -654,11 +654,61 @@ dnl About the condition of version
654654dnl see https://mail.gnome.org/archives/xml/2010-February/msg00008.html
655655AS_IF ( [ test "x$enable_xml" != "xno"] , [
656656 PKG_CHECK_MODULES(LIBXML, [ libxml-2.0 >= 2.7.7] ,
657- [ have_libxml=yes
658- AC_DEFINE ( HAVE_LIBXML ) ] ,
659- [ AS_IF ( [ test "x$enable_xml" = "xyes"] , [
660- AC_MSG_ERROR ( [ libxml2 not found] ) ] ) ] )
657+ [ AC_MSG_CHECKING ( [ libxml-2.0 CRLF handling bug] )
658+ ORIGINAL_CFLAGS=$CFLAGS
659+ ORIGINAL_LIBS=$LIBS
660+ CFLAGS="$CFLAGS $LIBXML_CFLAGS"
661+ LIBS="$LIBS $LIBXML_LIBS"
662+ AC_RUN_IFELSE ( [ AC_LANG_SOURCE ( [ [
663+ #include <libxml/parser.h>
664+ #include <libxml/tree.h>
665+ #include <string.h>
666+
667+ #define CRLF "\r\n"
668+ #define __LF " \n"
669+
670+ const char * crlf = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><root><!---->"CRLF CRLF"<target/></root>";
671+ const char * __lf = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><root><!---->"__LF __LF"<target/></root>";
672+
673+ static int run(const char *input)
674+ {
675+ xmlDocPtr doc = xmlParseMemory(input, strlen(input));
676+ xmlNode *root = xmlDocGetRootElement(doc);
677+ xmlNode *node = root->children->next->next;
678+ return node->line;
679+ }
680+
681+ int main(void)
682+ {
683+ xmlLineNumbersDefault (1);
684+ return run(crlf) == run(__lf)? 0: 1;
685+ }] ] ) ] ,[ AC_MSG_RESULT ( [ good] )
686+ have_libxml=yes
687+ CFLAGS=$ORIGINAL_CFLAGS
688+ LIBS=$ORIGINAL_LIBS
689+ AC_DEFINE ( HAVE_LIBXML ) ] ,
690+ [ AC_MSG_RESULT ( [ bad] )
691+ AC_MSG_WARN ( [ Xpath feature is disabled because the way of handling CRLF in libxml2 is broken.
692+ See https://gitlab.gnome.org/GNOME/libxml2/-/commit/43b511fa714df875dc4f40d108061eede0d4d76b] ) ] ,
693+ dnl In a context of cross-compiling: We can not do try-run.
694+ dnl Instead, we check the version number only.
695+ [ PKG_CHECK_MODULES(LIBXML12d0, [ libxml-2.0 = 2.12.0] ,
696+ [ AC_MSG_WARN ( [ Xpath feature is disabled because the way of handling CRLF in libxml2 2.12.0 may be broken.
697+ See https://gitlab.gnome.org/GNOME/libxml2/-/commit/43b511fa714df875dc4f40d108061eede0d4d76b] )
698+ have_libxml=no] ,[
699+ PKG_CHECK_MODULES(LIBXML12d1, [ libxml-2.0 = 2.12.1] ,
700+ [ AC_MSG_WARN ( [ Xpath feature is disabled because the way of handling CRLF in libxml2 2.12.1 may be broken.
701+ See https://gitlab.gnome.org/GNOME/libxml2/-/commit/43b511fa714df875dc4f40d108061eede0d4d76b] )
702+ have_libxml=no] ,
703+ dnl The available libxml-2.0 is not 2.12.[ 01] .
704+ [ have_libxml=yes
705+ AC_DEFINE ( HAVE_LIBXML )
706+ ] )] )]
707+ ) ] ,
708+ [ AS_IF ( [ test "x$enable_xml" = "xyes"] , [
709+ AC_MSG_ERROR ( [ libxml2 not found] ) ] ) ] )
661710] )
711+
662712AM_CONDITIONAL(HAVE_LIBXML, test "x$have_libxml" = xyes)
663713
664714if test "${enable_static}" = "yes"; then
0 commit comments