configure.ac: add proper check for libcurl + curl/curl.h

Both util/clixon_util_stream.c and lib/src/clixon_stream.c depend on
libcurl.  The latter has `#ifdef CLIXON_PUBLISH_STREAMS` but the former
does not.  So `make util` fails without `--enable-publish` if libcurl
is not installed.

To preserve the original behavior (libcurl is an implicit dependency),
this patch adds a `--without-libcurl` option to indicate this default.
The check for libcurl and curl/curl.h is factored out as a separate
check before checking for `--enable-publish`.  If the two build options
are in conflict we exit with a clear error code.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg 2023-02-07 18:30:33 +01:00
parent a7693c8856
commit e84d43c8e3
4 changed files with 60 additions and 29 deletions

57
configure vendored
View file

@ -644,6 +644,7 @@ HAVE_HTTP1
HAVE_LIBNGHTTP2 HAVE_LIBNGHTTP2
enable_netsnmp enable_netsnmp
with_restconf with_restconf
with_libcurl
LINKAGE LINKAGE
LIBSTATIC_SUFFIX LIBSTATIC_SUFFIX
SH_SUFFIX SH_SUFFIX
@ -724,6 +725,7 @@ enable_debug
with_cligen with_cligen
enable_yang_patch enable_yang_patch
enable_yang_schema_mount enable_yang_schema_mount
with_libcurl
enable_publish enable_publish
with_restconf with_restconf
enable_http1 enable_http1
@ -1391,6 +1393,8 @@ Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-cligen=dir Use CLIGEN installation in this dir --with-cligen=dir Use CLIGEN installation in this dir
--without-libcurl Disable use of libcurl, affects publish
notification, including clixon_util_stream
--with-restconf=native Integration with embedded web server (DEFAULT) --with-restconf=native Integration with embedded web server (DEFAULT)
--with-restconf=fcgi FCGI interface for stand-alone web rev-proxy eg --with-restconf=fcgi FCGI interface for stand-alone web rev-proxy eg
nginx nginx
@ -4699,25 +4703,16 @@ $as_echo "#define CLIXON_YANG_SCHEMA_MOUNT 1" >>confdefs.h
fi fi
# Experimental: Curl publish notification stream to eg Nginx nchan. # publish streams uses libcurl
# Check whether --enable-publish was given.
if test "${enable_publish+set}" = set; then :
enableval=$enable_publish;
if test "$enableval" = no; then
ac_enable_publish=no
else
ac_enable_publish=yes
fi
# Check whether --with-libcurl was given.
if test "${with_libcurl+set}" = set; then :
withval=$with_libcurl; with_libcurl=$withval
else else
ac_enable_publish=no with_libcurl=yes
fi fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: publish is $ac_enable_publish" >&5 if test "x${with_libcurl}" != "xno"; then
$as_echo "publish is $ac_enable_publish" >&6; }
if test "$ac_enable_publish" = "yes"; then
# publish streams uses libcurl
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
$as_echo_n "checking for grep that handles long lines and -e... " >&6; } $as_echo_n "checking for grep that handles long lines and -e... " >&6; }
@ -4978,16 +4973,16 @@ fi
done done
for ac_header in curl.h for ac_header in curl/curl.h
do : do :
ac_fn_c_check_header_mongrel "$LINENO" "curl.h" "ac_cv_header_curl_h" "$ac_includes_default" ac_fn_c_check_header_mongrel "$LINENO" "curl/curl.h" "ac_cv_header_curl_curl_h" "$ac_includes_default"
if test "x$ac_cv_header_curl_h" = xyes; then : if test "x$ac_cv_header_curl_curl_h" = xyes; then :
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define HAVE_CURL_H 1 #define HAVE_CURL_CURL_H 1
_ACEOF _ACEOF
else else
as_fn_error $? "curl missing" "$LINENO" 5 as_fn_error $? "curl header(s) missing" "$LINENO" 5
fi fi
done done
@ -5039,10 +5034,32 @@ else
as_fn_error $? "libcurl missing" "$LINENO" 5 as_fn_error $? "libcurl missing" "$LINENO" 5
fi fi
fi
# Experimental: Curl publish notification stream to eg Nginx nchan.
# Check whether --enable-publish was given.
if test "${enable_publish+set}" = set; then :
enableval=$enable_publish;
if test "$enableval" = no; then
ac_enable_publish=no
else
ac_enable_publish=yes
fi
else
ac_enable_publish=no
fi
if test "$ac_enable_publish" = "yes"; then
if test "x${with_libcurl}" = "xno"; then
as_fn_error $? "--enable-publish conflicts with --without-libcurl" "$LINENO" 5
fi
$as_echo "#define CLIXON_PUBLISH_STREAMS 1" >>confdefs.h $as_echo "#define CLIXON_PUBLISH_STREAMS 1" >>confdefs.h
fi fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: publish is $ac_enable_publish" >&5
$as_echo "publish is $ac_enable_publish" >&6; }
for ac_header in cligen/cligen.h for ac_header in cligen/cligen.h
do : do :

View file

@ -114,6 +114,7 @@ AC_SUBST(LIBS)
AC_SUBST(SH_SUFFIX) AC_SUBST(SH_SUFFIX)
AC_SUBST(LIBSTATIC_SUFFIX) AC_SUBST(LIBSTATIC_SUFFIX)
AC_SUBST(LINKAGE) AC_SUBST(LINKAGE)
AC_SUBST(with_libcurl)
AC_SUBST(with_restconf) # Set to native or fcgi -> compile apps/restconf AC_SUBST(with_restconf) # Set to native or fcgi -> compile apps/restconf
AC_SUBST(enable_netsnmp) # Enable build of apps/snmp 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_LIBNGHTTP2,false) # consider using neutral constant such as with-http2
@ -213,8 +214,19 @@ if test "${enable_yang_schema_mount}" = "yes"; then
AC_DEFINE(CLIXON_YANG_SCHEMA_MOUNT, 1, [Enable YANG schema mount, RFC 8528]) AC_DEFINE(CLIXON_YANG_SCHEMA_MOUNT, 1, [Enable YANG schema mount, RFC 8528])
fi fi
# publish streams uses libcurl
AC_ARG_WITH([libcurl],
[AS_HELP_STRING([--without-libcurl],
[Disable use of libcurl, affects publish notification, including clixon_util_stream])],
[with_libcurl=$withval],[with_libcurl=yes])
if test "x${with_libcurl}" != "xno"; then
AC_CHECK_HEADERS(curl/curl.h,[], AC_MSG_ERROR([curl header(s) missing]))
AC_CHECK_LIB(curl, curl_global_init,, AC_MSG_ERROR([libcurl missing]))
fi
# Experimental: Curl publish notification stream to eg Nginx nchan. # Experimental: Curl publish notification stream to eg Nginx nchan.
AC_ARG_ENABLE(publish, AS_HELP_STRING([--enable-publish],[Enable publish of notification streams using SSE and curl]),[ AC_ARG_ENABLE(publish, AS_HELP_STRING([--enable-publish],
[Enable publish of notification streams using SSE and curl]),[
if test "$enableval" = no; then if test "$enableval" = no; then
ac_enable_publish=no ac_enable_publish=no
else else
@ -222,14 +234,13 @@ AC_ARG_ENABLE(publish, AS_HELP_STRING([--enable-publish],[Enable publish of noti
fi fi
], ],
[ ac_enable_publish=no]) [ ac_enable_publish=no])
AC_MSG_RESULT(publish is $ac_enable_publish)
if test "$ac_enable_publish" = "yes"; then if test "$ac_enable_publish" = "yes"; then
# publish streams uses libcurl if test "x${with_libcurl}" = "xno"; then
AC_CHECK_HEADERS(curl.h,[], AC_MSG_ERROR([curl missing])) AC_MSG_ERROR([--enable-publish conflicts with --without-libcurl])
AC_CHECK_LIB(curl, curl_global_init,, AC_MSG_ERROR([libcurl missing])) fi
AC_DEFINE(CLIXON_PUBLISH_STREAMS, 1, [Enable publish of notification streams using SSE and curl]) AC_DEFINE(CLIXON_PUBLISH_STREAMS, 1, [Enable publish of notification streams using SSE and curl])
fi fi
AC_MSG_RESULT(publish is $ac_enable_publish)
AC_CHECK_HEADERS(cligen/cligen.h,, AC_MSG_ERROR([CLIgen missing. Try: git clone https://github.com/clicon/cligen.git])) AC_CHECK_HEADERS(cligen/cligen.h,, AC_MSG_ERROR([CLIgen missing. Try: git clone https://github.com/clicon/cligen.git]))

View file

@ -30,8 +30,8 @@
/* Define to 1 if you have the <cligen/cligen.h> header file. */ /* Define to 1 if you have the <cligen/cligen.h> header file. */
#undef HAVE_CLIGEN_CLIGEN_H #undef HAVE_CLIGEN_CLIGEN_H
/* Define to 1 if you have the <curl.h> header file. */ /* Define to 1 if you have the <curl/curl.h> header file. */
#undef HAVE_CURL_H #undef HAVE_CURL_CURL_H
/* Define to 1 if you have the `getpeereid' function. */ /* Define to 1 if you have the `getpeereid' function. */
#undef HAVE_GETPEEREID #undef HAVE_GETPEEREID

View file

@ -46,6 +46,7 @@ localstatedir = @localstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@
HOST_VENDOR = @host_vendor@ HOST_VENDOR = @host_vendor@
with_restconf = @with_restconf@ with_restconf = @with_restconf@
with_libcurl = @with_libcurl@
LIBXML2_CFLAGS = @LIBXML2_CFLAGS@ LIBXML2_CFLAGS = @LIBXML2_CFLAGS@
SH_SUFFIX = @SH_SUFFIX@ SH_SUFFIX = @SH_SUFFIX@
@ -102,7 +103,9 @@ APPSRC += clixon_util_dispatcher.c
APPSRC += clixon_netconf_ssh_callhome.c APPSRC += clixon_netconf_ssh_callhome.c
APPSRC += clixon_netconf_ssh_callhome_client.c APPSRC += clixon_netconf_ssh_callhome_client.c
ifdef with_restconf ifdef with_restconf
APPSRC += clixon_util_stream.c # Needs curl ifdef with_libcurl
APPSRC += clixon_util_stream.c
endif
ifeq ($(with_restconf), native) ifeq ($(with_restconf), native)
APPSRC += clixon_restconf_callhome_client.c APPSRC += clixon_restconf_callhome_client.c
endif endif