From: Daniel Elstner Date: Sun, 23 Aug 2015 18:07:38 +0000 (+0200) Subject: Build: Move package check macros to m4/sigrok.m4 X-Git-Tag: libsigrok-0.4.0~410 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1bb196e4969b299d316bdcff2201a44dd517f240;p=libsigrok.git Build: Move package check macros to m4/sigrok.m4 Define generic macros for pkg-config dependency checks etc. in m4/sigrok.m4, so they can be easily reused by downstream modules. --- diff --git a/configure.ac b/configure.ac index 75e6dc6c..3aa73d48 100644 --- a/configure.ac +++ b/configure.ac @@ -73,54 +73,17 @@ SR_LIB_VERSION_SET([SR_LIB_VERSION], [2:0:0]) # We require at least 0.22, as "Requires.private" behaviour changed there. PKG_PROG_PKG_CONFIG([0.22]) -# This variable collects the pkg-config module names of all dependencies. +# Keep track of all checked modules so we can list them at the end. +SR_PKG_CHECK_SUMMARY([sr_pkglibs_summary]) + +# Collect the pkg-config module names of all dependencies in SR_PKGLIBS. # These are used to derive the compiler flags and for the "Requires.private" # field in the generated libsigrok.pc file. -SR_PKGLIBS= +SR_VAR_OPT_PKG([SR_PKGLIBS], [sr_deps_avail]) SR_PKGLIBS_CHECK= SR_PKGLIBS_CXX= SR_PKGLIBS_PYTHON= -# Keep track of all checked modules so we can list them at the end. -sr_pkglibs_summary= -sr_nl=' -' -## SR_PKG_CHECK(tag, [collect-var], module...) -m4_define([SR_PKG_CHECK], [ - sr_mod_leader=`printf '%.32s' "$3................................"` - PKG_CHECK_EXISTS([$3], [ - sr_have_$1=yes - m4_ifval([$2], [$2="[$]$2[$]{$2:+ }$3"]) - sr_$1_version=`$PKG_CONFIG --modversion "$3" 2>&AS_MESSAGE_LOG_FD` - AS_VAR_APPEND([sr_pkglibs_summary], [" - $sr_mod_leader $sr_$1_version$sr_nl"]) - ], [ - AS_VAR_APPEND([sr_pkglibs_summary], [" - $sr_mod_leader no$sr_nl"]) - m4_ifval([$4], - [SR_PKG_CHECK([$1], [$2], m4_shift3($@))], - [sr_have_$1=no sr_$1_version=]) - ]) -]) - -# List of detected features. -sr_deps_avail= - -## SR_ARG_OPT_PKG(opt-name, [cpp-name], [cond-name], module...) -m4_define([SR_ARG_OPT_PKG], [ - AC_ARG_WITH([$1], [AS_HELP_STRING([--without-$1], - [disable $1 support [default=detect]])]) - AS_IF([test "x$with_$1" = xno], [sr_have_$1=no], - [test "x$sr_have_$1" != xyes], - [SR_PKG_CHECK([$1], [SR_PKGLIBS], m4_shift3($@))]) - AS_IF([test "x$with_$1$sr_have_$1" = xyesno], - [AC_MSG_ERROR([$1 support requested, but it was not found.])]) - AS_IF([test "x$sr_have_$1" = xyes], - [sr_deps_avail="$sr_deps_avail $1"[]m4_ifval([$2], [ - AC_DEFINE([HAVE_$2], [1], [Whether $1 is available.]) - AC_DEFINE_UNQUOTED([CONF_$2_VERSION], ["$sr_$1_version"], [Build-time version of $1.]) - ])]) - m4_ifval([$3], [AM_CONDITIONAL([$3], [test "x$sr_have_$1" = xyes])]) -]) - SR_ARG_OPT_PKG([libserialport], [LIBSERIALPORT], [NEED_SERIAL], [libserialport >= 0.1.1]) @@ -154,9 +117,9 @@ SR_ARG_ENABLE_WARNINGS([SR_WFLAGS], [-Wall], [-Wall -Wextra -Wmissing-prototypes # Check host characteristics. AC_C_BIGENDIAN -AC_CHECK_HEADERS([sys/mman.h], [sr_deps_avail="$sr_deps_avail sys_mman_h"]) -AC_CHECK_HEADERS([sys/ioctl.h], [sr_deps_avail="$sr_deps_avail sys_ioctl_h"]) -AC_CHECK_HEADERS([sys/timerfd.h], [sr_deps_avail="$sr_deps_avail sys_timerfd_h"]) +AC_CHECK_HEADERS([sys/mman.h], [SR_APPEND([sr_deps_avail], [sys_mman_h])]) +AC_CHECK_HEADERS([sys/ioctl.h], [SR_APPEND([sr_deps_avail], [sys_ioctl_h])]) +AC_CHECK_HEADERS([sys/timerfd.h], [SR_APPEND([sr_deps_avail], [sys_timerfd_h])]) # RPC is only needed for VXI support. AC_CACHE_CHECK([for RPC support], [sr_cv_have_rpc], @@ -174,7 +137,7 @@ AM_CONDITIONAL([NEED_RPC], [test "x$sr_cv_have_rpc" = xyes]) ######################## # Keep track of all drivers so we can list them at the end. -sr_driver_summary= +SR_VAR_SUMMARY([sr_driver_summary]) # Check whether the sr_deps_avail list contains all of the arguments. # Unavailable dependencies are collected in sr_deps_missing. @@ -203,8 +166,7 @@ m4_define([_SR_DRIVER], [ AS_IF([test -n "$sr_deps_missing"], [$3=no sr_hw_info="no (missing:$sr_deps_missing)"]) ])], [sr_hw_info='no (disabled)']) - sr_hw_leader=`printf '%.32s' "$2................................"` - AS_VAR_APPEND([sr_driver_summary], [" - $sr_hw_leader $sr_hw_info$sr_nl"]) + sr_driver_summary_append "$2" "$sr_hw_info" AM_CONDITIONAL([$3], [test "x[$]$3" = xyes]) AM_COND_IF([$3], [AC_DEFINE([HAVE_$3], [1], [Whether to support $1 device.])]) @@ -476,10 +438,8 @@ Detected libraries (required): Detected libraries (optional): $sr_pkglibs_summary - Enabled hardware drivers: $sr_driver_summary - Enabled SCPI backends: - TCP............................. yes - RPC............................. $sr_cv_have_rpc diff --git a/m4/sigrok.m4 b/m4/sigrok.m4 index 5c311ed4..6bf00840 100644 --- a/m4/sigrok.m4 +++ b/m4/sigrok.m4 @@ -115,6 +115,128 @@ _SR_LIB_VERSION_SET([$1], [$2], m4_unquote(m4_split([$2], [:]))) ]) +## _SR_VAR_SUMMARY(tag, var-name, line-leader, align-columns, align-char) +## +m4_define([_SR_VAR_SUMMARY], [dnl +$2= +$1_append() { + sr_aligned=`printf '%.$4s' "[$][1]m4_for([i], [1], [$4],, [$5])"` + $2="[$]{$2}$3$sr_aligned [$]2"' +' +} +]) + +## SR_VAR_SUMMARY(tag, [var-name = ], +## [line-leader = [ - ]], [align-columns = 32], [align-char = .]) +## +## Define a shell function _append() to be used for aggregating +## a summary of test results in the shell variable . +## +AC_DEFUN([SR_VAR_SUMMARY], +[dnl +m4_assert([$# >= 1])[]dnl +_SR_VAR_SUMMARY([$1], + m4_default_quoted([$2], [$1]), + m4_default_quoted([$3], [ - ]), + m4_default_quoted([$4], [32]), + m4_default_quoted([$5], [.]))[]dnl +]) + +## SR_PKG_CHECK_SUMMARY([var-name = sr_pkg_check_summary], +## [line-leader = [ - ]], [align-columns = 32], [align-char = .]) +## +## Prepare for the aggregation of package check results +## in the shell variable . +## +AC_DEFUN([SR_PKG_CHECK_SUMMARY], + [SR_VAR_SUMMARY([sr_pkg_check_summary], $@)]) + +## SR_PKG_CHECK(tag, [collect-var], module...) +## +## Check for each pkg-config in the argument list. may +## include a version constraint. +## +## Output variables: sr_have_, sr__version +## +AC_DEFUN([SR_PKG_CHECK], +[dnl +m4_assert([$# >= 3])[]dnl +AC_REQUIRE([PKG_PROG_PKG_CONFIG])[]dnl +AC_REQUIRE([SR_PKG_CHECK_SUMMARY])[]dnl +dnl +PKG_CHECK_EXISTS([$3], [dnl + sr_have_$1=yes + m4_ifval([$2], [SR_APPEND([$2], ["$3"]) + ])sr_$1_version=`$PKG_CONFIG --modversion "$3" 2>&AS_MESSAGE_LOG_FD` + sr_pkg_check_summary_append "$3" "$sr_$1_version"[]dnl +], [dnl + sr_pkg_check_summary_append "$3" no + m4_ifval([$4], + [SR_PKG_CHECK([$1], [$2], m4_shift3($@))], + [sr_have_$1=no sr_$1_version=])[]dnl +]) +]) + +## SR_VAR_OPT_PKG([modules-var], [features-var]) +## +## Enable the collection of SR_ARG_OPT_PKG results into the shell variables +## and . +## +AC_DEFUN([SR_VAR_OPT_PKG], +[dnl +m4_define([_SR_VAR_OPT_PKG_MODULES], [$1])[]dnl +m4_define([_SR_VAR_OPT_PKG_FEATURES], [$2])[]dnl +m4_ifvaln([$1], [$1=])[]dnl +m4_ifvaln([$2], [$2=])[]dnl +]) + +## _SR_ARG_OPT_PKG(sh-name, [modules-var], [features-var], +## opt-name, [cpp-name], [cond-name], module...) +## +m4_define([_SR_ARG_OPT_PKG], +[dnl +AC_ARG_WITH([$4], [AS_HELP_STRING([--without-$4], + [disable $4 support [default=detect]])]) +AS_IF([test "x$with_$1" = xno], [sr_have_$1=no], + [test "x$sr_have_$1" != xyes], + [SR_PKG_CHECK([$1], [$2], m4_shiftn([6], $@))]) +AS_IF([test "x$with_$1$sr_have_$1" = xyesno], + [AC_MSG_ERROR([$4 support requested, but it was not found.])]) +AS_IF([test "x$sr_have_$1" = xyes], [m4_ifval([$3], [ + SR_APPEND([$3], ["$4"])])[]m4_ifval([$5], [ + AC_DEFINE([HAVE_$5], [1], [Whether $4 is available.]) + AC_DEFINE_UNQUOTED([CONF_$5_VERSION], ["$sr_$1_version"], + [Build-time version of $4.])])[]dnl +]) +m4_ifvaln([$6], [AM_CONDITIONAL([$6], [test "x$sr_have_$1" = xyes])])[]dnl +]) + +## SR_ARG_OPT_PKG(opt-name, [cpp-name], [cond-name], module...) +## +## Provide a --without- configure option for explicit disabling +## of an optional dependency. If not disabled, the availability of the +## optional dependency is auto-detected. +## +## Each pkg-config argument is checked in turn, and the first one +## found is selected. On success, the shell variable sr_have_ +## is set to "yes", otherwise to "no". Optionally, a preprocessor macro +## HAVE_ and an Automake conditional are generated. +## +## Use SR_VAR_OPT_PKG to generate lists of available modules and features. +## +AC_DEFUN([SR_ARG_OPT_PKG], +[dnl +m4_assert([$# >= 4])[]dnl +AC_REQUIRE([PKG_PROG_PKG_CONFIG])[]dnl +AC_REQUIRE([SR_PKG_CHECK_SUMMARY])[]dnl +AC_REQUIRE([SR_VAR_OPT_PKG])[]dnl +dnl +_SR_ARG_OPT_PKG(m4_expand([AS_TR_SH([$1])]), + m4_defn([_SR_VAR_OPT_PKG_MODULES]), + m4_defn([_SR_VAR_OPT_PKG_FEATURES]), + $@)[]dnl +]) + ## _SR_ARG_ENABLE_WARNINGS_ONCE ## ## Implementation helper macro of SR_ARG_ENABLE_WARNINGS. Pulled in