1# libxml.m4 serial 9 2dnl Copyright (C) 2006, 2008, 2011, 2013, 2016, 2019 Free Software Foundation, Inc. 3dnl This file is free software; the Free Software Foundation 4dnl gives unlimited permission to copy and/or distribute it, 5dnl with or without modifications, as long as this notice is preserved. 6 7dnl From Bruno Haible. 8 9dnl gl_LIBXML 10dnl gives the user the option to decide whether to use the included or 11dnl an external libxml. 12dnl gl_LIBXML(FORCE-INCLUDED) 13dnl forces the use of the included or an external libxml. 14AC_DEFUN([gl_LIBXML], 15[ 16 AC_REQUIRE([AM_ICONV_LINK]) 17 18 ifelse([$1], , [ 19 AC_MSG_CHECKING([whether included libxml is requested]) 20 AC_ARG_WITH([included-libxml], 21 [ --with-included-libxml use the libxml2 included here], 22 [gl_cv_libxml_force_included=$withval], 23 [gl_cv_libxml_force_included=no]) 24 AC_MSG_RESULT([$gl_cv_libxml_force_included]) 25 ], [gl_cv_libxml_force_included=$1]) 26 27 gl_cv_libxml_use_included="$gl_cv_libxml_force_included" 28 LIBXML= 29 LTLIBXML= 30 INCXML= 31 ifelse([$1], [yes], , [ 32 if test "$gl_cv_libxml_use_included" != yes; then 33 dnl Figure out whether we can use a preinstalled libxml2, or have to use 34 dnl the included one. 35 AC_CACHE_VAL([gl_cv_libxml], [ 36 gl_cv_libxml=no 37 gl_cv_LIBXML= 38 gl_cv_LTLIBXML= 39 gl_cv_INCXML= 40 gl_save_LIBS="$LIBS" 41 LIBS="$LIBS $LIBICONV" 42 dnl Search for libxml2 and define LIBXML2, LTLIBXML2 and INCXML2 43 dnl accordingly. 44 dnl Don't use xml2-config nor pkg-config, since it doesn't work when 45 dnl cross-compiling or when the C compiler in use is different from the 46 dnl one that built the library. 47 dnl Use a test program that tries to invoke xmlFree. On Cygwin 1.7.x, 48 dnl libxml2 is built in such a way that uses of xmlFree work fine with 49 dnl -Wl,--enable-auto-import but lead to a link error with 50 dnl -Wl,--disable-auto-import. 51 AC_LIB_LINKFLAGS_BODY([xml2]) 52 LIBS="$gl_save_LIBS $LIBXML2 $LIBICONV" 53 AC_TRY_LINK([#include <libxml/xmlversion.h> 54 #include <libxml/xmlmemory.h> 55 #include <libxml/xpath.h> 56 ], 57 [xmlCheckVersion (0); 58 xmlFree ((void *) 0); 59 xmlXPathSetContextNode ((void *)0, (void *)0); 60 ], 61 [gl_cv_libxml=yes 62 gl_cv_LIBXML="$LIBXML2 $LIBICONV" 63 gl_cv_LTLIBXML="$LTLIBXML2 $LTLIBICONV" 64 ]) 65 if test "$gl_cv_libxml" != yes; then 66 gl_save_CPPFLAGS="$CPPFLAGS" 67 CPPFLAGS="$CPPFLAGS $INCXML2" 68 AC_TRY_LINK([#include <libxml/xmlversion.h> 69 #include <libxml/xmlmemory.h> 70 #include <libxml/xpath.h> 71 ], 72 [xmlCheckVersion (0); 73 xmlFree ((void *) 0); 74 xmlXPathSetContextNode ((void *)0, (void *)0); 75 ], 76 [gl_cv_libxml=yes 77 gl_cv_LIBXML="$LIBXML2 $LIBICONV" 78 gl_cv_LTLIBXML="$LTLIBXML2 $LTLIBICONV" 79 gl_cv_INCXML="$INCXML2" 80 ]) 81 if test "$gl_cv_libxml" != yes; then 82 dnl Often the include files are installed in /usr/include/libxml2. 83 dnl In libxml2-2.5, <libxml/xmlversion.h> is self-contained. 84 dnl In libxml2-2.6, it includes <libxml/xmlexports.h> which is 85 dnl self-contained. 86 libxml2_include_dir= 87 AC_TRY_CPP([#include <libxml2/libxml/xmlexports.h>], 88 [gl_ABSOLUTE_HEADER([libxml2/libxml/xmlexports.h]) 89 libxml2_include_dir=`echo "$gl_cv_absolute_libxml2_libxml_xmlexports_h" | sed -e 's,.libxml.xmlexports\.h$,,'` 90 ]) 91 if test -z "$libxml2_include_dir"; then 92 AC_TRY_CPP([#include <libxml2/libxml/xmlversion.h>], 93 [gl_ABSOLUTE_HEADER([libxml2/libxml/xmlversion.h]) 94 libxml2_include_dir=`echo "$gl_cv_absolute_libxml2_libxml_xmlversion_h" | sed -e 's,.libxml.xmlversion\.h$,,'` 95 ]) 96 fi 97 if test -n "$libxml2_include_dir" && test -d "$libxml2_include_dir"; then 98 CPPFLAGS="$gl_save_CPPFLAGS -I$libxml2_include_dir" 99 AC_TRY_LINK([#include <libxml/xmlversion.h> 100 #include <libxml/xmlmemory.h> 101 #include <libxml/xpath.h> 102 ], 103 [xmlCheckVersion (0); 104 xmlFree ((void *) 0); 105 xmlXPathSetContextNode ((void *)0, (void *)0); 106 ], 107 [gl_cv_libxml=yes 108 gl_cv_LIBXML="$LIBXML2 $LIBICONV" 109 gl_cv_LTLIBXML="$LTLIBXML2 $LTLIBICONV" 110 gl_cv_INCXML="-I$libxml2_include_dir" 111 ]) 112 fi 113 fi 114 CPPFLAGS="$gl_save_CPPFLAGS" 115 fi 116 LIBS="$gl_save_LIBS" 117 ]) 118 AC_MSG_CHECKING([for libxml]) 119 AC_MSG_RESULT([$gl_cv_libxml]) 120 if test $gl_cv_libxml = yes; then 121 LIBXML="$gl_cv_LIBXML" 122 LTLIBXML="$gl_cv_LTLIBXML" 123 INCXML="$gl_cv_INCXML" 124 else 125 gl_cv_libxml_use_included=yes 126 fi 127 fi 128 ]) 129 AC_SUBST([LIBXML]) 130 AC_SUBST([LTLIBXML]) 131 AC_SUBST([INCXML]) 132 AC_MSG_CHECKING([whether to use the included libxml]) 133 AC_MSG_RESULT([$gl_cv_libxml_use_included]) 134 135 if test "$gl_cv_libxml_use_included" = yes; then 136 LIBXML_H= 137 LIBXML_H="$LIBXML_H libxml/DOCBparser.h" 138 LIBXML_H="$LIBXML_H libxml/HTMLparser.h" 139 LIBXML_H="$LIBXML_H libxml/HTMLtree.h" 140 LIBXML_H="$LIBXML_H libxml/SAX2.h" 141 LIBXML_H="$LIBXML_H libxml/SAX.h" 142 LIBXML_H="$LIBXML_H libxml/c14n.h" 143 LIBXML_H="$LIBXML_H libxml/catalog.h" 144 LIBXML_H="$LIBXML_H libxml/chvalid.h" 145 LIBXML_H="$LIBXML_H libxml/debugXML.h" 146 LIBXML_H="$LIBXML_H libxml/dict.h" 147 LIBXML_H="$LIBXML_H libxml/encoding.h" 148 LIBXML_H="$LIBXML_H libxml/entities.h" 149 LIBXML_H="$LIBXML_H libxml/globals.h" 150 LIBXML_H="$LIBXML_H libxml/hash.h" 151 LIBXML_H="$LIBXML_H libxml/list.h" 152 LIBXML_H="$LIBXML_H libxml/nanoftp.h" 153 LIBXML_H="$LIBXML_H libxml/nanohttp.h" 154 LIBXML_H="$LIBXML_H libxml/parser.h" 155 LIBXML_H="$LIBXML_H libxml/parserInternals.h" 156 LIBXML_H="$LIBXML_H libxml/pattern.h" 157 LIBXML_H="$LIBXML_H libxml/relaxng.h" 158 LIBXML_H="$LIBXML_H libxml/schemasInternals.h" 159 LIBXML_H="$LIBXML_H libxml/schematron.h" 160 LIBXML_H="$LIBXML_H libxml/threads.h" 161 LIBXML_H="$LIBXML_H libxml/tree.h" 162 LIBXML_H="$LIBXML_H libxml/uri.h" 163 LIBXML_H="$LIBXML_H libxml/valid.h" 164 LIBXML_H="$LIBXML_H libxml/xinclude.h" 165 LIBXML_H="$LIBXML_H libxml/xlink.h" 166 LIBXML_H="$LIBXML_H libxml/xmlIO.h" 167 LIBXML_H="$LIBXML_H libxml/xmlautomata.h" 168 LIBXML_H="$LIBXML_H libxml/xmlerror.h" 169 LIBXML_H="$LIBXML_H libxml/xmlexports.h" 170 LIBXML_H="$LIBXML_H libxml/xmlmemory.h" 171 LIBXML_H="$LIBXML_H libxml/xmlmodule.h" 172 LIBXML_H="$LIBXML_H libxml/xmlreader.h" 173 LIBXML_H="$LIBXML_H libxml/xmlregexp.h" 174 LIBXML_H="$LIBXML_H libxml/xmlsave.h" 175 LIBXML_H="$LIBXML_H libxml/xmlschemas.h" 176 LIBXML_H="$LIBXML_H libxml/xmlschemastypes.h" 177 LIBXML_H="$LIBXML_H libxml/xmlstring.h" 178 LIBXML_H="$LIBXML_H libxml/xmlunicode.h" 179 LIBXML_H="$LIBXML_H libxml/xmlversion.h" 180 LIBXML_H="$LIBXML_H libxml/xmlwriter.h" 181 LIBXML_H="$LIBXML_H libxml/xpath.h" 182 LIBXML_H="$LIBXML_H libxml/xpathInternals.h" 183 LIBXML_H="$LIBXML_H libxml/xpointer.h" 184 AC_CHECK_HEADERS([arpa/inet.h ctype.h dlfcn.h dl.h errno.h \ 185 fcntl.h float.h limits.h malloc.h math.h netdb.h \ 186 netinet/in.h signal.h stdlib.h string.h \ 187 strings.h sys/select.h sys/socket.h sys/stat.h \ 188 sys/time.h sys/types.h time.h unistd.h]) 189 AC_CHECK_HEADERS([arpa/nameser.h], [], [], [ 190 #if HAVE_SYS_TYPES_H 191 # include <sys/types.h> 192 #endif 193 ]) 194 AC_CHECK_HEADERS([resolv.h], [], [], [ 195 #if HAVE_SYS_TYPES_H 196 # include <sys/types.h> 197 #endif 198 #if HAVE_NETINET_IN_H 199 # include <netinet/in.h> 200 #endif 201 #if HAVE_ARPA_NAMESER_H 202 # include <arpa/nameser.h> 203 #endif 204 ]) 205 AC_CHECK_FUNCS([getaddrinfo localtime stat strftime]) 206 dnl This relies on the va_copy replacement from the stdarg module. 207 AC_DEFINE([VA_COPY], [va_copy], 208 [Define to a working va_copy macro or replacement.]) 209 dnl Don't bother checking for pthread.h and other multithread facilities. 210 dnl Don't bother checking for zlib.h and how to link with libz. 211 else 212 LIBXML_H= 213 fi 214 AC_SUBST([LIBXML_H]) 215 216 AM_CONDITIONAL([INCLUDED_LIBXML], 217 [test "$gl_cv_libxml_use_included" = yes]) 218]) 219