From a7693c88566dd84df325402742210865448d7cf2 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Tue, 7 Feb 2023 18:29:44 +0100 Subject: [PATCH] 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 --- configure | 16 ++++++++++++++-- configure.ac | 13 +++++++++++-- util/Makefile.in | 4 ++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/configure b/configure index 33aa03e1..423bccba 100755 --- a/configure +++ b/configure @@ -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" diff --git a/configure.ac b/configure.ac index c941465a..27f3f5b7 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/util/Makefile.in b/util/Makefile.in index 552cedda..1afa0e51 100644 --- a/util/Makefile.in +++ b/util/Makefile.in @@ -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 $@