]> sigrok.org Git - libsigrok.git/blobdiff - m4/sigrok.m4
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / m4 / sigrok.m4
index 2d0d70fc0af83da629ec5f21e3dc7a9a85e6dee6..5dc296090623b85c6ab1bbed484f8c448f582d53 100644 (file)
@@ -18,7 +18,7 @@
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ##
 
-#serial 20150825
+#serial 20150910
 
 ## SR_APPEND(var-name, [list-sep,] element)
 ##
@@ -52,34 +52,48 @@ m4_define([_SR_PKG_VERSION_SET],
 [dnl
 m4_assert([$# >= 6])[]dnl
 $1=$4
+dnl Check if we can get version control details. Re-configure when
+dnl branches change (when HEAD starts pointing somewhere else).
+dnl Track individual revisions at compile time, and only as a local
+dnl dependency of just a part of the library build. In other words:
+dnl Don't re-configure and re-build everything just because a commit
+dnl happened). Checks for tagged sources also happen at compile time.
 sr_git_deps=
-# Check if we can get revision information from git.
 sr_head=`git -C "$srcdir" rev-parse --verify --short HEAD 2>&AS_MESSAGE_LOG_FD`
-
-AS_IF([test "$?" = 0 && test "x$sr_head" != x], [dnl
-       test ! -f "$srcdir/.git/HEAD" \
-               || sr_git_deps="$sr_git_deps \$(top_srcdir)/.git/HEAD"
-
+AS_IF([test "$?" = 0 && test -n "$sr_head"], [dnl
+       test ! -f "$srcdir/.git/HEAD" || \
+               sr_git_deps="$sr_git_deps ${ac_abs_confdir}/.git/HEAD"
        sr_head_name=`git -C "$srcdir" rev-parse --symbolic-full-name HEAD 2>&AS_MESSAGE_LOG_FD`
-       AS_IF([test "$?" = 0 && test -f "$srcdir/.git/$sr_head_name"],
-               [sr_git_deps="$sr_git_deps \$(top_srcdir)/.git/$sr_head_name"])
-
-       # Append the revision hash unless we are exactly on a tagged release.
-       git -C "$srcdir" describe --match "$3$4" \
-               --exact-match >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD \
-               || $1="[$]$1-git-$sr_head"
+       AS_IF([test "$?" = 0 && test -f "$srcdir/.git/$sr_head_name"], [dnl
+               sr_head_file="${ac_abs_confdir}/.git/$sr_head_name"
+               AC_SUBST(VERSION_HEAD_FILE, [$sr_head_file])
+       ])
+       sr_hash=`git -C "$srcdir" describe --match "$3$4" --always --dirty`
+       sr_hash=`echo "$sr_hash" | sed 's/$3$4-//'` && \
+       $1_STRING_SUFFIX=`git -C "$srcdir" describe --match "$3$4" --exact-match > /dev/null 2> /dev/null || echo "-$sr_hash"`
+       AS_IF([test -n "$1_STRING_SUFFIX"], [$1="[$]$1-git"])
 ])
-# Use $(wildcard) so that things do not break if for whatever
-# reason these files do not exist anymore at make time.
+AM_CONDITIONAL([VCS_IS_GIT], [test -n "$sr_git_deps"])
+# Use $(wildcard) so that things do not break if for whatever reason
+# these files do not exist anymore at make time.
 AS_IF([test -n "$sr_git_deps"],
-       [SR_APPEND([CONFIG_STATUS_DEPENDENCIES], ["\$(wildcard$sr_git_deps)"])])
+       [SR_APPEND([CONFIG_STATUS_DEPENDENCIES], ["\$(wildcard $sr_git_deps)"])])
 AC_SUBST([CONFIG_STATUS_DEPENDENCIES])[]dnl
+AS_IF([test -n "$sr_git_deps$sr_head_file"],
+       [SR_APPEND([VERSION_GITVERSION_DEPS], ["\$(wildcard $sr_git_deps $sr_head_file)"])])
+AC_SUBST(VERSION_GITVERSION_DEPS)[]dnl
+AC_SUBST(VERSION_SOURCE_DIR, [${ac_abs_confdir}])
+AC_SUBST(VERSION_TAG_PREFIX, [$3])[]dnl
+AC_SUBST(VERSION_TAG_NUMBER, [$4])[]dnl
+AC_SUBST(VERSION_TAG_MATCH, [$3$4])[]dnl
+dnl End of git version control details gathering.
+dnl
 AC_SUBST([$1])[]dnl
 dnl
 AC_DEFINE([$1_MAJOR], [$5], [Major version number of $2.])[]dnl
 AC_DEFINE([$1_MINOR], [$6], [Minor version number of $2.])[]dnl
 m4_ifval([$7], [AC_DEFINE([$1_MICRO], [$7], [Micro version number of $2.])])[]dnl
-AC_DEFINE_UNQUOTED([$1_STRING], ["[$]$1"], [Version of $2.])[]dnl
+AC_DEFINE_UNQUOTED([$1_STRING_PREFIX], ["[$]$1"], [Version of $2.])[]dnl
 ])
 
 ## SR_PKG_VERSION_SET(var-prefix, version-triple)
@@ -223,25 +237,73 @@ 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...)
+## _SR_ARG_OPT_IMPL(sh-name, [features-var], opt-name,
+##                  [cpp-name], [cond-name], check-commands)
 ##
-m4_define([_SR_ARG_OPT_PKG],
+m4_define([_SR_ARG_OPT_IMPL],
 [dnl
-AC_ARG_WITH([$4], [AS_HELP_STRING([--without-$4],
-                       [disable $4 support [default=detect]])])
+AC_ARG_WITH([$3], [AS_HELP_STRING([--without-$3],
+                       [disable $3 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], $@))])
+       [test "x$sr_have_$1" != xyes], [dnl
+AC_MSG_CHECKING([for $3])
+$6
+AC_MSG_RESULT([$sr_have_$1])[]dnl
+])
 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
+       [AC_MSG_ERROR([$3 support requested, but it was not found.])])
+AS_IF([test "x$sr_have_$1" = xyes], [m4_ifval([$2], [
+       SR_APPEND([$2], ["$3"])])[]m4_ifval([$4], [
+       AC_DEFINE([HAVE_$4], [1], [Whether $3 is available.])])[]dnl
 ])
-m4_ifvaln([$6], [AM_CONDITIONAL([$6], [test "x$sr_have_$1" = xyes])])[]dnl
+m4_ifvaln([$5], [AM_CONDITIONAL([$5], [test "x$sr_have_$1" = xyes])])[]dnl
+])
+
+## _SR_ARG_OPT_CHECK(sh-name, [features-var], opt-name, [cpp-name],
+##                   [cond-name], check-commands, [summary-result])
+##
+m4_define([_SR_ARG_OPT_CHECK],
+[dnl
+_SR_ARG_OPT_IMPL($@)
+sr_pkg_check_summary_append "$3" m4_default([$7], ["$sr_have_$1"])
+])
+
+## SR_ARG_OPT_CHECK(opt-name, [cpp-name], [cond-name], check-commands,
+##                  [summary-result = $sr_have_<opt-name>])
+##
+## Provide a --without-<opt-name> configure option for explicit disabling
+## of an optional dependency. If not disabled, the availability of the
+## optional dependency is auto-detected by running <check-commands>.
+##
+## The <check-commands> should set the shell variable sr_have_<opt-name>
+## to "yes" if the dependency is available, otherwise to "no". Optionally,
+## the <summary-result> argument may be used to generate a line in the
+## configuration summary. If supplied, it should be a shell word which
+## expands to the result to be displayed for the <opt-name> dependency.
+##
+## Use SR_VAR_OPT_PKG to generate lists of available modules and features.
+##
+AC_DEFUN([SR_ARG_OPT_CHECK],
+[dnl
+m4_assert([$# >= 4])[]dnl
+AC_REQUIRE([SR_PKG_CHECK_SUMMARY])[]dnl
+AC_REQUIRE([SR_VAR_OPT_PKG])[]dnl
+dnl
+_SR_ARG_OPT_CHECK(m4_expand([AS_TR_SH([$1])]),
+       m4_defn([_SR_VAR_OPT_PKG_FEATURES]),
+       $@)[]dnl
+])
+
+## _SR_ARG_OPT_PKG([features-var], [cond-name], opt-name,
+##                 [cpp-name], sh-name, [modules-var], module...)
+##
+m4_define([_SR_ARG_OPT_PKG],
+[dnl
+_SR_ARG_OPT_IMPL([$5], [$1], [$3], [$4], [$2],
+       [SR_PKG_CHECK(m4_shiftn([4], $@))])
+m4_ifvaln([$4], [AS_IF([test "x$sr_have_$5" = xyes],
+       [AC_DEFINE_UNQUOTED([CONF_$4_VERSION], ["$sr_$5_version"],
+               [Build-time version of $3.])])])[]dnl
 ])
 
 ## SR_ARG_OPT_PKG(opt-name, [cpp-name], [cond-name], module...)
@@ -264,10 +326,48 @@ 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])]),
+_SR_ARG_OPT_PKG(m4_defn([_SR_VAR_OPT_PKG_FEATURES]),
+       [$3], [$1], [$2],
+       m4_expand([AS_TR_SH([$1])]),
        m4_defn([_SR_VAR_OPT_PKG_MODULES]),
-       m4_defn([_SR_VAR_OPT_PKG_FEATURES]),
-       $@)[]dnl
+       m4_shift3($@))[]dnl
+])
+
+## SR_PROG_VERSION(program, sh-var)
+##
+## Obtain the version of <program> and store it in <sh-var>.
+##
+AC_DEFUN([SR_PROG_VERSION],
+[dnl
+m4_assert([$# >= 2])[]dnl
+sr_prog_ver=`$1 --version 2>&AS_MESSAGE_LOG_FD | sed 1q 2>&AS_MESSAGE_LOG_FD`
+AS_CASE([[$]?:$sr_prog_ver],
+       [[0:*[0-9].[0-9]*]], [$2=$sr_prog_ver],
+       [$2=unknown])[]dnl
+])
+
+## SR_PROG_MAKE_ORDER_ONLY
+##
+## Check whether the make program supports order-only prerequisites.
+## If so, set the substitution variable ORDER to '|', or to the empty
+## string otherwise.
+##
+AC_DEFUN([SR_PROG_MAKE_ORDER_ONLY],
+[dnl
+AC_CACHE_CHECK([whether [$]{MAKE:-make} supports order-only prerequisites],
+       [sr_cv_prog_make_order_only], [
+cat >conftest.mk <<'_SREOF'
+a: b | c
+a b c: ; @:
+.PHONY: a b c
+_SREOF
+AS_IF([[$]{MAKE:-make} -f conftest.mk >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD],
+       [sr_cv_prog_make_order_only=yes], [sr_cv_prog_make_order_only=no])
+rm -f conftest.mk
+])
+AS_IF([test "x$sr_cv_prog_make_order_only" = xyes], [ORDER='|'], [ORDER=])
+AC_SUBST([ORDER])
+AM_SUBST_NOTMAKE([ORDER])[]dnl
 ])
 
 ## SR_CHECK_COMPILE_FLAGS(flags-var, description, flags)