From 76754e04fce5f6a7701bec57b057020585df2ae3 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 15 Apr 2015 16:31:34 -0600 Subject: lib: use shorter way to test if variable is set Based on an idea by Bernhard Reutner-Fischer. We frequently used the idiom of 'test "${var+set}" = set' to test if $var was set to a non-empty string, but this can portably be trimmed to a more compact 'test ${var+y}' for a smaller configure file. Testing that a variable is not set can be done with '${var+false} :' (although the value of $? is not reliably 1 when the variable is set). The code for AS_VAR_TEST_SET already used the form '${var+:} false', but it is slightly longer, and does not guarantee $? of 1. Tested on coreutils, where the resulting configure file is about 1k smaller. * doc/autoconf.texi (Shell Substitutions): Prefer shorter sequence for testing if a variable is set. (Limitations of Builtins) : Document it. * configure.ac: Use it. * lib/autoconf/c.m4 (_AC_PROG_CC_G, _AC_PROG_CXX_G) (_AC_PROG_OBJC_G, _AC_PROG_OBJCXX_G): Likewise. * lib/autoconf/fortran.m4 (_AC_PROG_FC_G): Likewise. * lib/autoconf/general.m4 (_AC_ENABLE_IF_ACTION, AC_CACHE_SAVE): Likewise. * lib/autoconf/lang.m4 (_AC_COMPILER_EXEEXT_DEFAULT): Likewise. * lib/autoconf/programs.m4 (AC_PROG_INSTALL, AC_PROG_MKDIR_P) (_AC_PROG_LEX_YYTEXT_DECL): Likewise. * lib/autoconf/status.m4 (_AC_OUTPUT_MAIN_LOOP): Likewise. * lib/autotest/general.m4 (AT_INIT): Likewise. * tests/base.at (AC_CACHE_CHECK): Likewise. * tests/m4sh.at (LINENO): Likewise. * lib/m4sugar/m4sh.m4 (_AS_BOURNE_COMPATIBLE) (_AS_DETECT_BETTER_SHELL, _AS_SHELL_SANITIZE) (_AS_PATH_SEPARATOR_PREPARE): Likewise. (AS_VAR_TEST_SET): Use shorter sequence. Signed-off-by: Eric Blake --- tests/base.at | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/base.at') diff --git a/tests/base.at b/tests/base.at index 63bd36e7..cbc5a598 100644 --- a/tests/base.at +++ b/tests/base.at @@ -342,7 +342,7 @@ my_cv_variable=true AC_MSG_RESULT([$my_cv_variable]) # Ensure that the result is available at this point. -if test ${my_cv_variable+set} != set; then +if ${my_cv_variable+false} :; then AC_MSG_ERROR([AC@&@&t@t@_CACHE_VAL did not ensure that the cache variable was set]) fi -- cgit v1.2.1