From: Gerhard Sittig Date: Wed, 22 Dec 2021 12:39:38 +0000 (+0100) Subject: configure: make zlib an optional dependency which input/stf depends on X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e4c9ea56d76cbcc0dbce1eb5386873f25759699f;p=libsigrok.git configure: make zlib an optional dependency which input/stf depends on The STF input module calls into the zlib's crc32() routine, although this dependency is not checked for and need not be satisfied. This went unnoticed because zlib is rather ubiquitous, most development machines provide it. Extend the configure script to check for the zlib presence. Absence is non-fatal (the library is truly optional). Reflect the version details in the libsigrok version output, update the README. Make the STF input module depend on the zlib presence, which makes the module optional. It's unfortunate that the MiniLZO library which the libsigrok source embeds does not provide the CRC32 calculation. Else we could have used it instead of introducing another external dependency. This implementation attempts to properly separate the autoconf/shell layer from the automake layer from the C language preprocessor, and separate the zlib library availability from the compression and CRC32 calculation availability from the STF input module applicability. This shall prepare more zlib use in future implementations. --- diff --git a/Makefile.am b/Makefile.am index 67b73b5d..280cf64d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -85,11 +85,14 @@ libsigrok_la_SOURCES += \ src/input/logicport.c \ src/input/raw_analog.c \ src/input/saleae.c \ - src/input/stf.c \ src/input/trace32_ad.c \ src/input/vcd.c \ src/input/wav.c \ src/input/null.c +if HAVE_INPUT_STF +libsigrok_la_SOURCES += \ + src/input/stf.c +endif # Output modules libsigrok_la_SOURCES += \ diff --git a/README b/README index d1f96566..768c8ca2 100644 --- a/README +++ b/README @@ -37,6 +37,7 @@ Requirements for the C library: - libtool (only needed when building from git) - pkg-config >= 0.22 - libglib >= 2.32.0 + - zlib (optional, used for CRC32 calculation in STF input) - libzip >= 0.10 - libtirpc (optional, used by VXI, fallback when glibc >= 2.26) - libserialport >= 0.1.1 (optional, used by some drivers) diff --git a/configure.ac b/configure.ac index 982f5430..27e79e4d 100644 --- a/configure.ac +++ b/configure.ac @@ -96,6 +96,18 @@ SR_PKGLIBS_RUBY= SR_EXTRA_LIBS= SR_EXTRA_CXX_LIBS= +SR_ARG_OPT_PKG([zlib], [ZLIB], , [zlib]) +AM_CONDITIONAL([HAVE_ZLIB], [test "x$sr_have_zlib" = xyes]) +AM_COND_IF([HAVE_ZLIB], [ + SR_APPEND([sr_deps_avail], [crc32 zlib]) + SR_PREPEND([SR_EXTRA_LIBS], [-lz]) +]) + +AM_CONDITIONAL([HAVE_INPUT_STF], [test "x$sr_have_zlib" = xyes]) +AM_COND_IF([HAVE_INPUT_STF], [ + AC_DEFINE([HAVE_INPUT_STF], [1], [Is the STF input module supported?]) +]) + SR_ARG_OPT_PKG([libserialport], [LIBSERIALPORT], , [libserialport >= 0.1.1]) @@ -621,9 +633,12 @@ AM_COND_IF([NEED_USB], [AS_CASE([$sr_have_libusb_os_handle:$host_os], [no:mingw* sr_glib_version=`$PKG_CONFIG --modversion glib-2.0 2>&AS_MESSAGE_LOG_FD` sr_libzip_version=`$PKG_CONFIG --modversion libzip 2>&AS_MESSAGE_LOG_FD` +sr_zlib_version=`$PKG_CONFIG --modversion zlib 2>&AS_MESSAGE_LOG_FD` AC_DEFINE_UNQUOTED([CONF_LIBZIP_VERSION], ["$sr_libzip_version"], [Build-time version of libzip.]) +AC_DEFINE_UNQUOTED([CONF_ZLIB_VERSION], ["$sr_zlib_version"], + [Build-time version of zlib.]) AC_DEFINE_UNQUOTED([CONF_HOST], ["$host"], [The canonical host libsigrok will run on.]) diff --git a/src/backend.c b/src/backend.c index 79340822..82ad42f7 100644 --- a/src/backend.c +++ b/src/backend.c @@ -137,6 +137,10 @@ SR_API GSList *sr_buildinfo_libs_get(void) glib_binary_age, glib_interface_age)); l = g_slist_append(l, m); + m = g_slist_append(NULL, g_strdup("zlib")); + m = g_slist_append(m, g_strdup_printf("%s", CONF_ZLIB_VERSION)); + l = g_slist_append(l, m); + m = g_slist_append(NULL, g_strdup("libzip")); m = g_slist_append(m, g_strdup_printf("%s", CONF_LIBZIP_VERSION)); l = g_slist_append(l, m); diff --git a/src/input/input.c b/src/input/input.c index 8708cc63..b5de532b 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -80,7 +80,9 @@ static const struct sr_input_module *input_module_list[] = { &input_binary, &input_chronovu_la8, &input_csv, +#if defined HAVE_INPUT_STF && HAVE_INPUT_STF &input_stf, +#endif &input_trace32_ad, &input_vcd, &input_wav,