X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=m4%2Fsigrok.m4;h=2ca2444dfddf813abe3d26b94ed3d4d64c5d412f;hb=1c50255506971b0bdb37fca88c80a8146abbb6e4;hp=6bf008401fb77ccb7279ee4b86e0dd849e862a2b;hpb=1bb196e4969b299d316bdcff2201a44dd517f240;p=libsigrok.git diff --git a/m4/sigrok.m4 b/m4/sigrok.m4 index 6bf00840..2ca2444d 100644 --- a/m4/sigrok.m4 +++ b/m4/sigrok.m4 @@ -1,22 +1,24 @@ -## Copyright (c) 2009 Openismus GmbH -## Copyright (c) 2015 Daniel Elstner ## ## This file is part of the sigrok project. ## -## sigrok is free software: you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by +## Copyright (C) 2009 Openismus GmbH +## Copyright (C) 2015 Daniel Elstner +## +## This program is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## -## sigrok is distributed in the hope that it will be useful, +## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with sigrok. If not, see . +## along with this program. If not, see . +## -#serial 20150823 +#serial 20150910 ## SR_APPEND(var-name, [list-sep,] element) ## @@ -31,6 +33,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 +130,24 @@ _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 @@ -190,25 +223,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([$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_]) +## +## Provide a --without- configure option for explicit disabling +## of an optional dependency. If not disabled, the availability of the +## optional dependency is auto-detected by running . +## +## The should set the shell variable sr_have_ +## to "yes" if the dependency is available, otherwise to "no". Optionally, +## the 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 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 ]) -m4_ifvaln([$6], [AM_CONDITIONAL([$6], [test "x$sr_have_$1" = xyes])])[]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...) @@ -231,10 +312,74 @@ 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 and store it in . +## +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) +## +## 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