autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] m4sh: require a POSIX shell


From: Stefano Lattarini
Subject: [PATCH 2/2] m4sh: require a POSIX shell
Date: Wed, 7 Nov 2012 13:37:20 +0100

Since all the non-museum systems Autoconf strives to support should by
now have a POSIX shell somewhere [1][2], we can finally start to move
away from the need to support "classical" Bourne shells (which, remember,
do not support $(...) command substitution, $((..)) arithmetic expansion,
command negation with '!', the '-e' option for the 'test' builtin, XSI
${var#PATTERN} and ${var%PATTERN} parameter expansion, and so on; quite
a crippling for both readability and performances -- the latter because
the missing features must be emulated by spawning further processes).

 [1] For example, Solaris, while having a ludicrously brain-dead /bin/sh,
     also comes with a decent POSIX shell installed by default in
     /usr/bin/xpg4/sh.

 [2] The Git project strives to be portable to all POSIX-conforming shells,
     both in its testsuite and in its subcommands implemented as shell
     scripts, but it doesn't support non-POSIX Bourne shells.  So far
     it hasn't had any problem with such requirements AFAIK, although --
     at least according to its Makefile -- it targets all the following
     systems:
     GNU/Linux, GNU/kFreeBSD, Darwin, Solaris (back to SunOS 5.6), AIX,
     OSF1, Cygwin, MinGW, FreeBSD, OpenBSD, NetBSD, IRIX, HP-UX (11.0
     and 10.20), Interix, UnixWare and Minix.

For more reference and some discussion, see:
<http://lists.gnu.org/archive/html/bug-autoconf/2012-06/msg00009.html>
<http://lists.gnu.org/archive/html/automake/2012-08/msg00046.html>

note that updates to the NEWS file and the manual has not been written
yet.

* lib/m4sugar/m4sh.m4 (_AS_TEST_E_WORKS, _AS_CMD_NEGATION_WORKS,
_AS_VAR_CMD_WORKS, _AS_VAR_XSI_WORKS, _AS_POS_PARAM_WORKS,
_AS_SHIFT_WORKS): New.
(AS_INIT): Call '_AS_DETECT_REQUIRED' on them.

Signed-off-by: Stefano Lattarini <address@hidden>
---
 lib/m4sugar/m4sh.m4 | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index dc4207c..3e50bb6 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -1381,6 +1381,11 @@ esac[]])# AS_SET_CATFILE
 # These days, we require that `test -x' works.
 m4_define([_AS_TEST_X_WORKS], [test -x /])
 
+# _AS_TEST_E_WORKS
+# ----------------
+# These days, we require that `test -e' works.
+m4_define([_AS_TEST_E_WORKS], [test -e /])
+
 # _AS_TEST_PREPARE
 # ----------------
 # Provide back-compat to people that hooked into our undocumented
@@ -1965,6 +1970,48 @@ as_fn_arith ()
 m4_define([_AS_VAR_ARITH_WORKS],
 [test $(( 1 + 1 )) = 2])
 
+# _AS_VAR_XSI_WORKS
+# -----------------
+# Output a shell test to discover whether XSI parameter expansions work.
+m4_define([_AS_VAR_XSI_WORKS],
+[ac_v=a/b/c ac_0='' ac_1='x' ac_12=' foobar  baz' &&
+  test address@hidden:@ac_0} -eq 0 &&
+  test address@hidden:@ac_1} -eq 1 &&
+  test address@hidden:@ac_12} -eq 12 &&
+  test x"${ac_0:-ok}" = x"ok" &&
+  test x"${ac_0-ko}" = x &&
+  test "address@hidden:@*/}" = b/c &&
+  test "address@hidden:@@%:@*/}" = c &&
+  test "${ac_v%/*}" = a/b &&
+  test "${ac_v%%/*}" = a])
+
+# _AS_VAR_CMD_WORKS
+# -----------------
+# Output a shell test to discover whether $() command substitution works.
+m4_define([_AS_VAR_CMD_WORKS],
+[test "$(echo x)" = x])
+
+# _AS_CMD_NEGATION_WORKS
+# ----------------------
+# Output a shell test to discover whether command negation through '!'
+# works.
+m4_define([_AS_CMD_NEGATION_WORKS],
+[! true | false && ! { ! true; }])
+
+# _AS_POS_PARAM_WORKS
+# -------------------
+# Output a shell test to discover whether we can expand positional
+# parameters after the ninth.
+m4_define([_AS_POS_PARAM_WORKS],
+[(set 1 2 3 4 5 6 7 8 9 ok && test "${10}" = ok)])
+
+# _AS_SHIFT_WORKS
+# ---------------
+# Output a shell test to discover whether the 'shift' can accept an
+# argument (telling how many positional parameters to shift).
+m4_define([_AS_SHIFT_WORKS],
+[(set a b c && shift 2 && test $[]1 = c)])
+
 # AS_VAR_ARITH(VAR, EXPR)
 # -----------------------
 # Perform the arithmetic evaluation of the arguments in EXPR, and set
@@ -2161,6 +2208,12 @@ m4_divert([BODY])dnl
 m4_text_box([Main body of script.])
 _AS_DETECT_REQUIRED([_AS_SHELL_FN_WORK])dnl
 _AS_DETECT_REQUIRED([_AS_TEST_X_WORKS])dnl
+_AS_DETECT_REQUIRED([_AS_TEST_E_WORKS])dnl
 _AS_DETECT_REQUIRED([_AS_VAR_ARITH_WORKS])dnl
+_AS_DETECT_REQUIRED([_AS_VAR_XSI_WORKS])dnl
+_AS_DETECT_REQUIRED([_AS_VAR_CMD_WORKS])dnl
+_AS_DETECT_REQUIRED([_AS_CMD_NEGATION_WORKS])dnl
+_AS_DETECT_REQUIRED([_AS_POS_PARAM_WORKS])dnl
+_AS_DETECT_REQUIRED([_AS_SHIFT_WORKS])dnl
 AS_REQUIRE([_AS_UNSET_PREPARE], [], [M4SH-INIT-FN])dnl
 ])
-- 
1.8.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]