X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=m4%2Fsigrok.m4;h=e9052585c2339e302130e865d102b9cbc4745902;hb=e662d9e8e5c6a5d677194fc217da3a88040387a3;hp=5c311ed473f644ac3f547f51ec7e65cad959aaf9;hpb=4cf2f34f430be5d38a7973c31f811fdb15a58329;p=libsigrok.git
diff --git a/m4/sigrok.m4 b/m4/sigrok.m4
index 5c311ed4..e9052585 100644
--- a/m4/sigrok.m4
+++ b/m4/sigrok.m4
@@ -16,7 +16,7 @@
## You should have received a copy of the GNU General Public License
## along with sigrok. If not, see .
-#serial 20150823
+#serial 20150824
## SR_APPEND(var-name, [list-sep,] element)
##
@@ -31,6 +31,19 @@ m4_assert([$# >= 2])[]dnl
$1=[$]{$1[}]m4_if([$#], [2], [[$]{$1:+' '}$2], [[$]{$1:+$2}$3])[]dnl
])
+## SR_PREPEND(var-name, [list-sep,] element)
+##
+## Prepend the shell word to the shell variable named ,
+## suffixed by unless the list was empty before prepending. If
+## only two arguments are supplied, defaults to a single space
+## character.
+##
+AC_DEFUN([SR_PREPEND],
+[dnl
+m4_assert([$# >= 2])[]dnl
+$1=m4_if([$#], [2], [$2[$]{$1:+' '}], [$3[$]{$1:+$2}])[$]$1[]dnl
+])
+
## _SR_PKG_VERSION_SET(var-prefix, pkg-name, tag-prefix, base-version, major, minor, [micro])
##
m4_define([_SR_PKG_VERSION_SET],
@@ -115,6 +128,172 @@ _SR_LIB_VERSION_SET([$1],
[$2], m4_unquote(m4_split([$2], [:])))
])
+## SR_SEARCH_LIBS(libs-var, function, search-libs,
+## [action-if-found], [action-if-not-found], [other-libs])
+##
+## Same as AC_SEARCH_LIBS, except that the result is prepended
+## to instead of LIBS. Calls AC_SUBST on .
+##
+AC_DEFUN([SR_SEARCH_LIBS],
+[dnl
+m4_assert([$# >= 3])[]dnl
+sr_sl_save_LIBS=$LIBS
+AC_SEARCH_LIBS([$2], [$3],,, m4_join([$6], [[$]$1]))
+LIBS=$sr_sl_save_LIBS
+AS_CASE([$ac_cv_search_$2], [no*],,
+ [SR_PREPEND([$1], [$ac_cv_search_$2])])
+m4_ifvaln([$4$5], [AS_IF([test "x$ac_cv_search_$2" = xno], [$5], [$4])])[]dnl
+AC_SUBST([$1])[]dnl
+])
+
+## _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_CHECK_COMPILE_FLAGS(flags-var, description, flags)
+##
+## Find a compiler flag for . For each flag in , check
+## if the compiler for the current language accepts it. On success, stop the
+## search and append the last tested flag to . Calls AC_SUBST
+## on .
+##
+AC_DEFUN([SR_CHECK_COMPILE_FLAGS],
+[dnl
+m4_assert([$# >= 3])[]dnl
+AC_MSG_CHECKING([compiler flag for $2])
+sr_ccf_result=no
+sr_ccf_save_CPPFLAGS=$CPPFLAGS
+for sr_flag in $3
+do
+ CPPFLAGS="$sr_ccf_save_CPPFLAGS $sr_flag"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [sr_ccf_result=$sr_flag])
+ test "x$sr_ccf_result" = xno || break
+done
+CPPFLAGS=$sr_ccf_save_CPPFLAGS
+AS_IF([test "x$sr_ccf_result" != xno],
+ [SR_APPEND([$1], [$sr_ccf_result])])
+AC_MSG_RESULT([$sr_ccf_result])
+AC_SUBST([$1])
+])
+
## _SR_ARG_ENABLE_WARNINGS_ONCE
##
## Implementation helper macro of SR_ARG_ENABLE_WARNINGS. Pulled in