blob: 09de9fe2defaec1044442f1b7496a9e22e8c8376 [file] [log] [blame]
Daniel Veillard2913e4c2001-04-26 19:29:02 +00001# Configure paths for LIBXML2
Haibo Huang735158e2021-02-23 17:48:08 -08002# Simon Josefsson 2020-02-12
3# Fix autoconf 2.70+ warnings
Daniel Veillardb7cbbae2004-06-28 09:27:23 +00004# Mike Hommey 2004-06-19
5# use CPPFLAGS instead of CFLAGS
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +00006# Toshio Kuratomi 2001-04-21
7# Adapted from:
8# Configure paths for GLIB
9# Owen Taylor 97-11-3
10
Daniel Veillard2913e4c2001-04-26 19:29:02 +000011dnl AM_PATH_XML2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
Daniel Veillardb7cbbae2004-06-28 09:27:23 +000012dnl Test for XML, and define XML_CPPFLAGS and XML_LIBS
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000013dnl
Daniel Veillardcc199e02003-10-24 21:11:48 +000014AC_DEFUN([AM_PATH_XML2],[
Daniel Veillard2913e4c2001-04-26 19:29:02 +000015AC_ARG_WITH(xml-prefix,
16 [ --with-xml-prefix=PFX Prefix where libxml is installed (optional)],
17 xml_config_prefix="$withval", xml_config_prefix="")
18AC_ARG_WITH(xml-exec-prefix,
19 [ --with-xml-exec-prefix=PFX Exec prefix where libxml is installed (optional)],
20 xml_config_exec_prefix="$withval", xml_config_exec_prefix="")
21AC_ARG_ENABLE(xmltest,
22 [ --disable-xmltest Do not try to compile and run a test LIBXML program],,
23 enable_xmltest=yes)
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000024
Daniel Veillard2913e4c2001-04-26 19:29:02 +000025 if test x$xml_config_exec_prefix != x ; then
Daniel Veillard3df01182003-12-10 10:17:51 +000026 xml_config_args="$xml_config_args"
Daniel Veillard2913e4c2001-04-26 19:29:02 +000027 if test x${XML2_CONFIG+set} != xset ; then
28 XML2_CONFIG=$xml_config_exec_prefix/bin/xml2-config
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000029 fi
30 fi
Daniel Veillard2913e4c2001-04-26 19:29:02 +000031 if test x$xml_config_prefix != x ; then
32 xml_config_args="$xml_config_args --prefix=$xml_config_prefix"
33 if test x${XML2_CONFIG+set} != xset ; then
34 XML2_CONFIG=$xml_config_prefix/bin/xml2-config
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000035 fi
36 fi
37
Daniel Veillard2913e4c2001-04-26 19:29:02 +000038 AC_PATH_PROG(XML2_CONFIG, xml2-config, no)
39 min_xml_version=ifelse([$1], ,2.0.0,[$1])
40 AC_MSG_CHECKING(for libxml - version >= $min_xml_version)
41 no_xml=""
42 if test "$XML2_CONFIG" = "no" ; then
43 no_xml=yes
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000044 else
Daniel Veillardb7cbbae2004-06-28 09:27:23 +000045 XML_CPPFLAGS=`$XML2_CONFIG $xml_config_args --cflags`
Daniel Veillard2913e4c2001-04-26 19:29:02 +000046 XML_LIBS=`$XML2_CONFIG $xml_config_args --libs`
47 xml_config_major_version=`$XML2_CONFIG $xml_config_args --version | \
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000048 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
Daniel Veillard2913e4c2001-04-26 19:29:02 +000049 xml_config_minor_version=`$XML2_CONFIG $xml_config_args --version | \
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000050 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
Daniel Veillard2913e4c2001-04-26 19:29:02 +000051 xml_config_micro_version=`$XML2_CONFIG $xml_config_args --version | \
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000052 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
Daniel Veillard2913e4c2001-04-26 19:29:02 +000053 if test "x$enable_xmltest" = "xyes" ; then
Daniel Veillardb7cbbae2004-06-28 09:27:23 +000054 ac_save_CPPFLAGS="$CPPFLAGS"
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000055 ac_save_LIBS="$LIBS"
Daniel Veillardb7cbbae2004-06-28 09:27:23 +000056 CPPFLAGS="$CPPFLAGS $XML_CPPFLAGS"
Daniel Veillard2913e4c2001-04-26 19:29:02 +000057 LIBS="$XML_LIBS $LIBS"
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000058dnl
Daniel Veillard2913e4c2001-04-26 19:29:02 +000059dnl Now check if the installed libxml is sufficiently new.
60dnl (Also sanity checks the results of xml2-config to some extent)
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000061dnl
Daniel Veillard2913e4c2001-04-26 19:29:02 +000062 rm -f conf.xmltest
Haibo Huang735158e2021-02-23 17:48:08 -080063 AC_RUN_IFELSE(
64 [AC_LANG_SOURCE([[
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000065#include <stdlib.h>
Daniel Veillard2913e4c2001-04-26 19:29:02 +000066#include <stdio.h>
Daniel Veillard88e0ad42002-04-09 13:48:02 +000067#include <string.h>
Daniel Veillarde979e3b2002-03-29 22:43:00 +000068#include <libxml/xmlversion.h>
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000069
70int
Daniel Veillard2913e4c2001-04-26 19:29:02 +000071main()
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000072{
Daniel Veillard2913e4c2001-04-26 19:29:02 +000073 int xml_major_version, xml_minor_version, xml_micro_version;
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000074 int major, minor, micro;
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000075 char *tmp_version;
76
Daniel Veillard2913e4c2001-04-26 19:29:02 +000077 system("touch conf.xmltest");
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000078
79 /* Capture xml2-config output via autoconf/configure variables */
80 /* HP/UX 9 (%@#!) writes to sscanf strings */
Daniel Veillard2913e4c2001-04-26 19:29:02 +000081 tmp_version = (char *)strdup("$min_xml_version");
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000082 if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
Daniel Veillard2913e4c2001-04-26 19:29:02 +000083 printf("%s, bad version string from xml2-config\n", "$min_xml_version");
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000084 exit(1);
85 }
86 free(tmp_version);
87
88 /* Capture the version information from the header files */
Daniel Veillard2913e4c2001-04-26 19:29:02 +000089 tmp_version = (char *)strdup(LIBXML_DOTTED_VERSION);
90 if (sscanf(tmp_version, "%d.%d.%d", &xml_major_version, &xml_minor_version, &xml_micro_version) != 3) {
91 printf("%s, bad version string from libxml includes\n", "LIBXML_DOTTED_VERSION");
92 exit(1);
93 }
94 free(tmp_version);
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +000095
96 /* Compare xml2-config output to the libxml headers */
Daniel Veillard2913e4c2001-04-26 19:29:02 +000097 if ((xml_major_version != $xml_config_major_version) ||
98 (xml_minor_version != $xml_config_minor_version) ||
99 (xml_micro_version != $xml_config_micro_version))
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000100 {
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000101 printf("*** libxml header files (version %d.%d.%d) do not match\n",
102 xml_major_version, xml_minor_version, xml_micro_version);
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000103 printf("*** xml2-config (version %d.%d.%d)\n",
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000104 $xml_config_major_version, $xml_config_minor_version, $xml_config_micro_version);
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000105 return 1;
106 }
107/* Compare the headers to the library to make sure we match */
108 /* Less than ideal -- doesn't provide us with return value feedback,
109 * only exits if there's a serious mismatch between header and library.
110 */
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000111 LIBXML_TEST_VERSION;
112
113 /* Test that the library is greater than our minimum version */
114 if ((xml_major_version > major) ||
115 ((xml_major_version == major) && (xml_minor_version > minor)) ||
116 ((xml_major_version == major) && (xml_minor_version == minor) &&
117 (xml_micro_version >= micro)))
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000118 {
119 return 0;
120 }
121 else
122 {
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000123 printf("\n*** An old version of libxml (%d.%d.%d) was found.\n",
124 xml_major_version, xml_minor_version, xml_micro_version);
125 printf("*** You need a version of libxml newer than %d.%d.%d. The latest version of\n",
126 major, minor, micro);
127 printf("*** libxml is always available from ftp://ftp.xmlsoft.org.\n");
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000128 printf("***\n");
129 printf("*** If you have already installed a sufficiently new version, this error\n");
130 printf("*** probably means that the wrong copy of the xml2-config shell script is\n");
131 printf("*** being found. The easiest way to fix this is to remove the old version\n");
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000132 printf("*** of LIBXML, but you can also set the XML2_CONFIG environment to point to the\n");
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000133 printf("*** correct copy of xml2-config. (In this case, you will have to\n");
Haibo Huangcfd91dc2020-07-30 23:01:33 -0700134 printf("*** modify your LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf\n");
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000135 printf("*** so that the correct libraries are found at run-time))\n");
136 }
137 return 1;
138}
Haibo Huang735158e2021-02-23 17:48:08 -0800139]])],, no_xml=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
Daniel Veillardb7cbbae2004-06-28 09:27:23 +0000140 CPPFLAGS="$ac_save_CPPFLAGS"
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000141 LIBS="$ac_save_LIBS"
142 fi
143 fi
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000144
145 if test "x$no_xml" = x ; then
146 AC_MSG_RESULT(yes (version $xml_config_major_version.$xml_config_minor_version.$xml_config_micro_version))
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000147 ifelse([$2], , :, [$2])
148 else
149 AC_MSG_RESULT(no)
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000150 if test "$XML2_CONFIG" = "no" ; then
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000151 echo "*** The xml2-config script installed by LIBXML could not be found"
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000152 echo "*** If libxml was installed in PREFIX, make sure PREFIX/bin is in"
153 echo "*** your path, or set the XML2_CONFIG environment variable to the"
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000154 echo "*** full path to xml2-config."
155 else
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000156 if test -f conf.xmltest ; then
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000157 :
158 else
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000159 echo "*** Could not run libxml test program, checking why..."
Daniel Veillardb7cbbae2004-06-28 09:27:23 +0000160 CPPFLAGS="$CPPFLAGS $XML_CPPFLAGS"
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000161 LIBS="$LIBS $XML_LIBS"
Haibo Huang735158e2021-02-23 17:48:08 -0800162 AC_LINK_IFELSE(
163 [AC_LANG_PROGRAM([[
Daniel Veillarde979e3b2002-03-29 22:43:00 +0000164#include <libxml/xmlversion.h>
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000165#include <stdio.h>
Haibo Huang735158e2021-02-23 17:48:08 -0800166]], [[ LIBXML_TEST_VERSION; return 0;]])],
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000167 [ echo "*** The test program compiled, but did not run. This usually means"
168 echo "*** that the run-time linker is not finding LIBXML or finding the wrong"
169 echo "*** version of LIBXML. If it is not finding LIBXML, you'll need to set your"
170 echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
171 echo "*** to the installed location Also, make sure you have run ldconfig if that"
172 echo "*** is required on your system"
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000173 echo "***"
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000174 echo "*** If you have an old version installed, it is best to remove it, although"
175 echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH" ],
176 [ echo "*** The test program failed to compile or link. See the file config.log for the"
Nick Wellnhofer8bbe4502017-06-17 16:15:09 +0200177 echo "*** exact error that occurred. This usually means LIBXML was incorrectly installed"
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000178 echo "*** or that you have moved LIBXML since it was installed. In the latter case, you"
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000179 echo "*** may want to edit the xml2-config script: $XML2_CONFIG" ])
Daniel Veillardb7cbbae2004-06-28 09:27:23 +0000180 CPPFLAGS="$ac_save_CPPFLAGS"
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000181 LIBS="$ac_save_LIBS"
182 fi
183 fi
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000184
Daniel Veillardb7cbbae2004-06-28 09:27:23 +0000185 XML_CPPFLAGS=""
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000186 XML_LIBS=""
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000187 ifelse([$3], , :, [$3])
188 fi
Daniel Veillardb7cbbae2004-06-28 09:27:23 +0000189 AC_SUBST(XML_CPPFLAGS)
Daniel Veillard2913e4c2001-04-26 19:29:02 +0000190 AC_SUBST(XML_LIBS)
191 rm -f conf.xmltest
Daniel Veillard5c4ec4c2001-04-26 07:43:59 +0000192])