libxml.m4 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. # Configure paths for LIBXML2
  2. # Simon Josefsson 2020-02-12
  3. # Fix autoconf 2.70+ warnings
  4. # Mike Hommey 2004-06-19
  5. # use CPPFLAGS instead of CFLAGS
  6. # Toshio Kuratomi 2001-04-21
  7. # Adapted from:
  8. # Configure paths for GLIB
  9. # Owen Taylor 97-11-3
  10. dnl AM_PATH_XML2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
  11. dnl Test for XML, and define XML_CPPFLAGS and XML_LIBS
  12. dnl
  13. AC_DEFUN([AM_PATH_XML2],[
  14. AC_ARG_WITH(xml-prefix,
  15. [ --with-xml-prefix=PFX Prefix where libxml is installed (optional)],
  16. xml_config_prefix="$withval", xml_config_prefix="")
  17. AC_ARG_WITH(xml-exec-prefix,
  18. [ --with-xml-exec-prefix=PFX Exec prefix where libxml is installed (optional)],
  19. xml_config_exec_prefix="$withval", xml_config_exec_prefix="")
  20. AC_ARG_ENABLE(xmltest,
  21. [ --disable-xmltest Do not try to compile and run a test LIBXML program],,
  22. enable_xmltest=yes)
  23. if test x$xml_config_exec_prefix != x ; then
  24. xml_config_args="$xml_config_args"
  25. if test x${XML2_CONFIG+set} != xset ; then
  26. XML2_CONFIG=$xml_config_exec_prefix/bin/xml2-config
  27. fi
  28. fi
  29. if test x$xml_config_prefix != x ; then
  30. xml_config_args="$xml_config_args --prefix=$xml_config_prefix"
  31. if test x${XML2_CONFIG+set} != xset ; then
  32. XML2_CONFIG=$xml_config_prefix/bin/xml2-config
  33. fi
  34. fi
  35. AC_PATH_PROG(XML2_CONFIG, xml2-config, no)
  36. min_xml_version=ifelse([$1], ,2.0.0,[$1])
  37. AC_MSG_CHECKING(for libxml - version >= $min_xml_version)
  38. no_xml=""
  39. if test "$XML2_CONFIG" = "no" ; then
  40. no_xml=yes
  41. else
  42. XML_CPPFLAGS=`$XML2_CONFIG $xml_config_args --cflags`
  43. XML_LIBS=`$XML2_CONFIG $xml_config_args --libs`
  44. xml_config_major_version=`$XML2_CONFIG $xml_config_args --version | \
  45. sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
  46. xml_config_minor_version=`$XML2_CONFIG $xml_config_args --version | \
  47. sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
  48. xml_config_micro_version=`$XML2_CONFIG $xml_config_args --version | \
  49. sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
  50. if test "x$enable_xmltest" = "xyes" ; then
  51. ac_save_CPPFLAGS="$CPPFLAGS"
  52. ac_save_LIBS="$LIBS"
  53. CPPFLAGS="$CPPFLAGS $XML_CPPFLAGS"
  54. LIBS="$XML_LIBS $LIBS"
  55. dnl
  56. dnl Now check if the installed libxml is sufficiently new.
  57. dnl (Also sanity checks the results of xml2-config to some extent)
  58. dnl
  59. rm -f conf.xmltest
  60. AC_RUN_IFELSE(
  61. [AC_LANG_SOURCE([[
  62. #include <stdlib.h>
  63. #include <stdio.h>
  64. #include <string.h>
  65. #include <libxml/xmlversion.h>
  66. int
  67. main()
  68. {
  69. int xml_major_version, xml_minor_version, xml_micro_version;
  70. int major, minor, micro;
  71. char *tmp_version;
  72. system("touch conf.xmltest");
  73. /* Capture xml2-config output via autoconf/configure variables */
  74. /* HP/UX 9 (%@#!) writes to sscanf strings */
  75. tmp_version = (char *)strdup("$min_xml_version");
  76. if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
  77. printf("%s, bad version string from xml2-config\n", "$min_xml_version");
  78. exit(1);
  79. }
  80. free(tmp_version);
  81. /* Capture the version information from the header files */
  82. tmp_version = (char *)strdup(LIBXML_DOTTED_VERSION);
  83. if (sscanf(tmp_version, "%d.%d.%d", &xml_major_version, &xml_minor_version, &xml_micro_version) != 3) {
  84. printf("%s, bad version string from libxml includes\n", "LIBXML_DOTTED_VERSION");
  85. exit(1);
  86. }
  87. free(tmp_version);
  88. /* Compare xml2-config output to the libxml headers */
  89. if ((xml_major_version != $xml_config_major_version) ||
  90. (xml_minor_version != $xml_config_minor_version) ||
  91. (xml_micro_version != $xml_config_micro_version))
  92. {
  93. printf("*** libxml header files (version %d.%d.%d) do not match\n",
  94. xml_major_version, xml_minor_version, xml_micro_version);
  95. printf("*** xml2-config (version %d.%d.%d)\n",
  96. $xml_config_major_version, $xml_config_minor_version, $xml_config_micro_version);
  97. return 1;
  98. }
  99. /* Compare the headers to the library to make sure we match */
  100. /* Less than ideal -- doesn't provide us with return value feedback,
  101. * only exits if there's a serious mismatch between header and library.
  102. */
  103. LIBXML_TEST_VERSION;
  104. /* Test that the library is greater than our minimum version */
  105. if ((xml_major_version > major) ||
  106. ((xml_major_version == major) && (xml_minor_version > minor)) ||
  107. ((xml_major_version == major) && (xml_minor_version == minor) &&
  108. (xml_micro_version >= micro)))
  109. {
  110. return 0;
  111. }
  112. else
  113. {
  114. printf("\n*** An old version of libxml (%d.%d.%d) was found.\n",
  115. xml_major_version, xml_minor_version, xml_micro_version);
  116. printf("*** You need a version of libxml newer than %d.%d.%d.\n",
  117. major, minor, micro);
  118. printf("***\n");
  119. printf("*** If you have already installed a sufficiently new version, this error\n");
  120. printf("*** probably means that the wrong copy of the xml2-config shell script is\n");
  121. printf("*** being found. The easiest way to fix this is to remove the old version\n");
  122. printf("*** of LIBXML, but you can also set the XML2_CONFIG environment to point to the\n");
  123. printf("*** correct copy of xml2-config. (In this case, you will have to\n");
  124. printf("*** modify your LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf\n");
  125. printf("*** so that the correct libraries are found at run-time))\n");
  126. }
  127. return 1;
  128. }
  129. ]])],, no_xml=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
  130. CPPFLAGS="$ac_save_CPPFLAGS"
  131. LIBS="$ac_save_LIBS"
  132. fi
  133. fi
  134. if test "x$no_xml" = x ; then
  135. AC_MSG_RESULT(yes (version $xml_config_major_version.$xml_config_minor_version.$xml_config_micro_version))
  136. ifelse([$2], , :, [$2])
  137. else
  138. AC_MSG_RESULT(no)
  139. if test "$XML2_CONFIG" = "no" ; then
  140. echo "*** The xml2-config script installed by LIBXML could not be found"
  141. echo "*** If libxml was installed in PREFIX, make sure PREFIX/bin is in"
  142. echo "*** your path, or set the XML2_CONFIG environment variable to the"
  143. echo "*** full path to xml2-config."
  144. else
  145. if test -f conf.xmltest ; then
  146. :
  147. else
  148. echo "*** Could not run libxml test program, checking why..."
  149. CPPFLAGS="$CPPFLAGS $XML_CPPFLAGS"
  150. LIBS="$LIBS $XML_LIBS"
  151. AC_LINK_IFELSE(
  152. [AC_LANG_PROGRAM([[
  153. #include <libxml/xmlversion.h>
  154. #include <stdio.h>
  155. ]], [[ LIBXML_TEST_VERSION; return 0;]])],
  156. [ echo "*** The test program compiled, but did not run. This usually means"
  157. echo "*** that the run-time linker is not finding LIBXML or finding the wrong"
  158. echo "*** version of LIBXML. If it is not finding LIBXML, you'll need to set your"
  159. echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
  160. echo "*** to the installed location Also, make sure you have run ldconfig if that"
  161. echo "*** is required on your system"
  162. echo "***"
  163. echo "*** If you have an old version installed, it is best to remove it, although"
  164. echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH" ],
  165. [ echo "*** The test program failed to compile or link. See the file config.log for the"
  166. echo "*** exact error that occurred. This usually means LIBXML was incorrectly installed"
  167. echo "*** or that you have moved LIBXML since it was installed. In the latter case, you"
  168. echo "*** may want to edit the xml2-config script: $XML2_CONFIG" ])
  169. CPPFLAGS="$ac_save_CPPFLAGS"
  170. LIBS="$ac_save_LIBS"
  171. fi
  172. fi
  173. XML_CPPFLAGS=""
  174. XML_LIBS=""
  175. ifelse([$3], , :, [$3])
  176. fi
  177. AC_SUBST(XML_CPPFLAGS)
  178. AC_SUBST(XML_LIBS)
  179. rm -f conf.xmltest
  180. ])