configure.ac: find include path to libxml2 using xml2-config tool

This patch replaces the hard-coded `-I /usr/include/libxml2` used when
building clixon_util_regexp with the output from `xml2-config --cflags`.

To support cross-compiling, and preserve backwards compatibility with
the `--with-libxml2` option, we allow the user to pass the path to the
xml2-config tool as an optional argument.  Similar to what python-lxml,
and other packages, that rely on libxml2 do.  The argument is optional
to ensure that we default to use the hard-coded path from before.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg 2023-02-07 18:29:44 +01:00
parent fcb6e5cb03
commit a7693c8856
3 changed files with 27 additions and 6 deletions

16
configure vendored
View file

@ -638,6 +638,7 @@ YANG_STANDARD_DIR
YANG_INSTALLDIR
CLIXON_YANG_SCHEMA_MOUNT
CLIXON_YANG_PATCH
LIBXML2_CFLAGS
with_libxml2
HAVE_HTTP1
HAVE_LIBNGHTTP2
@ -1398,7 +1399,8 @@ Optional Packages:
Directory of generated YANG specs (default:
$prefix/share/mib-yangs)
--with-configfile=FILE Set default path to config file
--with-libxml2 Use gnome/libxml2 regex engine
--with-libxml2[=/path/to/xml2-config]
Use libxml2 regex engine
--without-sigaction Don't use sigaction
--with-yang-installdir=DIR
Install Clixon yang files here (default:
@ -5657,6 +5659,16 @@ fi
if test "${with_libxml2}"; then
# Find libxml2 lib
if test -x "${with_libxml2}" 2>/dev/null; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libxml2 header files and libs" >&5
$as_echo_n "checking for libxml2 header files and libs... " >&6; }
LIBXML2_CFLAGS="`${with_libxml2} --cflags`"
LIBS="$LIBS `${with_libxml2} --libs`"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBXML2_CFLAGS" >&5
$as_echo "$LIBXML2_CFLAGS" >&6; }
else
LIBXML2_CFLAGS="-I/usr/include/libxml2"
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for xmlRegexpCompile in -lxml2" >&5
$as_echo_n "checking for xmlRegexpCompile in -lxml2... " >&6; }
if ${ac_cv_lib_xml2_xmlRegexpCompile+:} false; then :
@ -5731,7 +5743,7 @@ else
fi
if test "x${with_sigaction}" == "xyes"; then
if test "x${with_sigaction}" = "xyes"; then
for ac_func in sigaction
do :
ac_fn_c_check_func "$LINENO" "sigaction" "ac_cv_func_sigaction"

View file

@ -118,7 +118,8 @@ AC_SUBST(with_restconf) # Set to native or fcgi -> compile apps/restconf
AC_SUBST(enable_netsnmp) # Enable build of apps/snmp
AC_SUBST(HAVE_LIBNGHTTP2,false) # consider using neutral constant such as with-http2
AC_SUBST(HAVE_HTTP1,false)
AC_SUBST(with_libxml2)
AC_SUBST(with_libxml2)
AC_SUBST(LIBXML2_CFLAGS)
AC_SUBST(CLIXON_YANG_PATCH)
AC_SUBST(CLIXON_YANG_SCHEMA_MOUNT)
# Where Clixon installs its YANG specs
@ -344,9 +345,17 @@ AC_CHECK_LIB(dl, dlopen)
# Note this only enables the compiling of the code. In order to actually
# use it you need to set Clixon config option CLICON_YANG_REGEXP to libxml2
AC_ARG_WITH([libxml2],
[AS_HELP_STRING([--with-libxml2],[Use gnome/libxml2 regex engine])])
[AS_HELP_STRING([--with-libxml2[[=/path/to/xml2-config]]],[Use libxml2 regex engine])])
if test "${with_libxml2}"; then
# Find libxml2 lib
if test -x "${with_libxml2}" 2>/dev/null; then
AC_MSG_CHECKING([for libxml2 header files and libs])
LIBXML2_CFLAGS="`${with_libxml2} --cflags`"
LIBS="$LIBS `${with_libxml2} --libs`"
AC_MSG_RESULT([$LIBXML2_CFLAGS])
else
LIBXML2_CFLAGS="-I/usr/include/libxml2"
fi
AC_CHECK_LIB(xml2, xmlRegexpCompile,[], AC_MSG_ERROR([libxml2 not found]))
fi

View file

@ -46,7 +46,7 @@ localstatedir = @localstatedir@
sysconfdir = @sysconfdir@
HOST_VENDOR = @host_vendor@
with_restconf = @with_restconf@
HAVE_LIBXML2 = @HAVE_LIBXML2@
LIBXML2_CFLAGS = @LIBXML2_CFLAGS@
SH_SUFFIX = @SH_SUFFIX@
@ -150,7 +150,7 @@ clixon_util_xml_mod: clixon_util_xml_mod.c $(LIBDEPS)
$(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -D__PROGRAM__=\"$@\" $(LDFLAGS) $^ $(LIBS) -o $@
clixon_util_regexp: clixon_util_regexp.c $(LIBDEPS)
$(CC) $(INCLUDES) -I /usr/include/libxml2 $(CPPFLAGS) -D__PROGRAM__=\"$@\" $(CFLAGS) $(LDFLAGS) $^ $(LIBS) -o $@
$(CC) $(INCLUDES) $(LIBXML2_CFLAGS) $(CPPFLAGS) -D__PROGRAM__=\"$@\" $(CFLAGS) $(LDFLAGS) $^ $(LIBS) -o $@
clixon_util_socket: clixon_util_socket.c $(LIBDEPS)
$(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -D__PROGRAM__=\"$@\" $(LDFLAGS) $^ $(LIBS) -o $@