New module posix-shell, for determining a POSIX shell
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 16 Nov 2007 00:28:05 +0000 (16:28 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 16 Nov 2007 00:28:05 +0000 (16:28 -0800)
or perhaps something that is close enough to a POSIX shell.
* m4/posix-shell.m4: New file.
* modules/posix-shell: New file.
* MODULES.html.sh: Mention new module.

ChangeLog
MODULES.html.sh
m4/posix-shell.m4 [new file with mode: 0644]
modules/posix-shell [new file with mode: 0644]

index 106df7a..6d9f663 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2007-11-15  Paul Eggert  <eggert@cs.ucla.edu>
 
+       New module posix-shell, for determining a POSIX shell
+       or perhaps something that is close enough to a POSIX shell.
+       * m4/posix-shell.m4: New file.
+       * modules/posix-shell: New file.
+       * MODULES.html.sh: Mention new module.
+
        New module gnu-make, for determining whether we're using GNU Make.
        * m4/gnu-make.m4: New file.
        * modules/gnu-make: New file.
index 43f4395..e825ce3 100755 (executable)
@@ -2731,6 +2731,7 @@ func_all_modules ()
   func_module gnu-make
   func_module host-os
   func_module perl
+  func_module posix-shell
   func_module uptime
   func_end_table
 }
diff --git a/m4/posix-shell.m4 b/m4/posix-shell.m4
new file mode 100644 (file)
index 0000000..ac526d5
--- /dev/null
@@ -0,0 +1,58 @@
+# Find a POSIX-conforming shell.
+
+# Copyright (C) 2007 Free Software Foundation, Inc.
+
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# Written by Paul Eggert.
+
+# If a POSIX-conforming shell can be found, set POSIX_SHELL and
+# PREFERABLY_POSIX_SHELL to it.  If not, set POSIX_SHELL to the
+# empty string and PREFERABLY_POSIX_SHELL to '/bin/sh'.
+
+AC_DEFUN([gl_POSIX_SHELL],
+[
+  AC_CACHE_CHECK([for a shell that conforms to POSIX], [gl_cv_posix_shell],
+    [gl_test_POSIX_SHELL='
+       func_return () {
+        (exit [$]1)
+       }
+       func_success () {
+        func_return 0
+       }
+       func_failure () {
+        func_return 1
+       }
+       func_ret_success () {
+        return 0
+       }
+       func_ret_failure () {
+        return 1
+       }
+       test "[$](echo foo)" = foo &&
+       func_success &&
+       ! func_failure &&
+       func_ret_success &&
+       ! func_ret_failure &&
+       (set x && func_ret_success y && test x = "[$]1")
+     '
+     for gl_cv_posix_shell in \
+        "$CONFIG_SHELL" "$SHELL" /bin/sh /bin/bash /bin/ksh /bin/sh5 no; do
+       case $gl_cv_posix_shell in
+         /*)
+          "$gl_cv_posix_shell" -c "$gl_test_POSIX_shell" 2>/dev/null && break;;
+       esac
+     done])
+
+  if test "$gl_cv_posix_shell" != no; then
+    POSIX_SHELL=$gl_cv_posix_shell
+    PREFERABLY_POSIX_SHELL=$POSIX_SHELL
+  else
+    POSIX_SHELL=
+    PREFERABLY_POSIX_SHELL=/bin/sh
+  fi
+  AC_SUBST([POSIX_SHELL])
+  AC_SUBST([PREFERABLY_POSIX_SHELL])
+])
diff --git a/modules/posix-shell b/modules/posix-shell
new file mode 100644 (file)
index 0000000..aafd5b7
--- /dev/null
@@ -0,0 +1,30 @@
+Description:
+Find a POSIX-conforming shell.
+
+Files:
+m4/posix-shell.m4
+
+Depends-on:
+
+configure.ac:
+gl_POSIX_SHELL
+
+Makefile.am:
+##Sample usage of posix-shell module:
+#script: script.in
+#      rm -f $@-t $@
+#      sed -e 's#@''PREFERABLY_POSIX_SHELL''@#$(PREFERABLY_POSIX_SHELL)#g' \
+#          -e 's#@''POSIX_SHELL''@#$(POSIX_SHELL)#g' \
+#          -e $(srcdir)/$@.in >$@-t
+#      chmod a+x $@-t
+#      mv $@-t $@
+#EXTRA_DIST += script.in
+#MOSTLYCLEANFILES += script script-t
+
+Include:
+
+License:
+GPL
+
+Maintainer:
+Paul Eggert