From 305913a6b182dd57d185420b7eb4a71185dcf6ae Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Sun, 19 Aug 2012 07:36:36 -0700 Subject: [PATCH] Handle POSIX shell for tests in configure and Makefile Although the trick of finding a POSIX shell in the system PATH works fine most of the time, it has some drawbacks. * The commands must be copied into every test script. * The scripts are always forced to re-execute themselves. * There's no guarantee the sh found in `getconf PATH` is a POSIX shell and there's no way to override it. Move the handling of this shell to configure where we can detect it once. This gives preference to bash and ksh since they're typically POSIX compatible. It also uses the current PATH with the getconf PATH at the end which should allow things to work on platforms where getconf might not be available like mingw/msys. By specifying the shell in TESTS_ENVIRONMENT, automake will run each script with this shell and we can drop the re-exec dance. --- check/Makefile.am | 2 ++ check/check-cflags | 5 ----- check/check-cmd-options | 5 ----- check/check-conflicts | 5 ----- check/check-define-variable | 5 ----- check/check-idirafter | 5 ----- check/check-includedir | 5 ----- check/check-libs | 5 ----- check/check-libs-private | 5 ----- check/check-missing | 5 ----- check/check-requires-private | 4 ---- check/check-version | 5 ----- check/check-whitespace | 5 ----- configure.ac | 7 +++++++ 14 files changed, 9 insertions(+), 59 deletions(-) diff --git a/check/Makefile.am b/check/Makefile.am index fd9cd98..4aa9a62 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -1,3 +1,5 @@ +TESTS_ENVIRONMENT = $(TESTS_SHELL) + TESTS = \ check-cflags \ check-libs \ diff --git a/check/check-cflags b/check/check-cflags index eb2d6bc..f662687 100755 --- a/check/check-cflags +++ b/check/check-cflags @@ -1,10 +1,5 @@ #! /bin/sh -# Make sure we're POSIX -if [ "$PKG_CONFIG_SHELL_IS_POSIX" != "1" ]; then - PKG_CONFIG_SHELL_IS_POSIX=1 PATH=`getconf PATH` exec sh $0 "$@" -fi - set -e . ${srcdir}/common diff --git a/check/check-cmd-options b/check/check-cmd-options index cd22f17..8b5ef4c 100755 --- a/check/check-cmd-options +++ b/check/check-cmd-options @@ -1,10 +1,5 @@ #! /bin/sh -# Make sure we're POSIX -if [ "$PKG_CONFIG_SHELL_IS_POSIX" != "1" ]; then - PKG_CONFIG_SHELL_IS_POSIX=1 PATH=`getconf PATH` exec sh $0 "$@" -fi - set -e . ${srcdir}/common diff --git a/check/check-conflicts b/check/check-conflicts index 8092ba9..7f160db 100755 --- a/check/check-conflicts +++ b/check/check-conflicts @@ -1,10 +1,5 @@ #! /bin/sh -# Make sure we're POSIX -if [ "$PKG_CONFIG_SHELL_IS_POSIX" != "1" ]; then - PKG_CONFIG_SHELL_IS_POSIX=1 PATH=`getconf PATH` exec sh $0 "$@" -fi - set -e . ${srcdir}/common diff --git a/check/check-define-variable b/check/check-define-variable index d35e445..b0aaabd 100755 --- a/check/check-define-variable +++ b/check/check-define-variable @@ -1,10 +1,5 @@ #! /bin/sh -# Make sure we're POSIX -if [ "$PKG_CONFIG_SHELL_IS_POSIX" != "1" ]; then - PKG_CONFIG_SHELL_IS_POSIX=1 PATH=`getconf PATH` exec sh $0 "$@" -fi - set -e . ${srcdir}/common diff --git a/check/check-idirafter b/check/check-idirafter index 7abd2dc..439d799 100755 --- a/check/check-idirafter +++ b/check/check-idirafter @@ -1,10 +1,5 @@ #! /bin/sh -# Make sure we're POSIX -if [ "$PKG_CONFIG_SHELL_IS_POSIX" != "1" ]; then - PKG_CONFIG_SHELL_IS_POSIX=1 PATH=`getconf PATH` exec sh $0 "$@" -fi - set -e . ${srcdir}/common diff --git a/check/check-includedir b/check/check-includedir index d78ec24..26d8ab5 100755 --- a/check/check-includedir +++ b/check/check-includedir @@ -1,10 +1,5 @@ #! /bin/sh -# Make sure we're POSIX -if [ "$PKG_CONFIG_SHELL_IS_POSIX" != "1" ]; then - PKG_CONFIG_SHELL_IS_POSIX=1 PATH=`getconf PATH` exec sh $0 "$@" -fi - set -e . ${srcdir}/common diff --git a/check/check-libs b/check/check-libs index 9b1b495..372314d 100755 --- a/check/check-libs +++ b/check/check-libs @@ -1,10 +1,5 @@ #! /bin/sh -# Make sure we're POSIX -if [ "$PKG_CONFIG_SHELL_IS_POSIX" != "1" ]; then - PKG_CONFIG_SHELL_IS_POSIX=1 PATH=`getconf PATH` exec sh $0 "$@" -fi - set -e . ${srcdir}/common diff --git a/check/check-libs-private b/check/check-libs-private index 961962b..0678fd7 100755 --- a/check/check-libs-private +++ b/check/check-libs-private @@ -1,10 +1,5 @@ #! /bin/sh -# Make sure we're POSIX -if [ "$PKG_CONFIG_SHELL_IS_POSIX" != "1" ]; then - PKG_CONFIG_SHELL_IS_POSIX=1 PATH=`getconf PATH` exec sh $0 "$@" -fi - set -e . ${srcdir}/common diff --git a/check/check-missing b/check/check-missing index 93c2267..5616945 100755 --- a/check/check-missing +++ b/check/check-missing @@ -1,10 +1,5 @@ #! /bin/sh -# Make sure we're POSIX -if [ "$PKG_CONFIG_SHELL_IS_POSIX" != "1" ]; then - PKG_CONFIG_SHELL_IS_POSIX=1 PATH=`getconf PATH` exec sh $0 "$@" -fi - set -e . ${srcdir}/common diff --git a/check/check-requires-private b/check/check-requires-private index 45115ee..e9ef2f2 100755 --- a/check/check-requires-private +++ b/check/check-requires-private @@ -1,9 +1,5 @@ #! /bin/sh -# Make sure we're POSIX -if [ "$PKG_CONFIG_SHELL_IS_POSIX" != "1" ]; then - PKG_CONFIG_SHELL_IS_POSIX=1 PATH=`getconf PATH` exec sh $0 "$@" -fi set -e . ${srcdir}/common diff --git a/check/check-version b/check/check-version index 6e92077..4254d65 100755 --- a/check/check-version +++ b/check/check-version @@ -1,10 +1,5 @@ #! /bin/sh -# Make sure we're POSIX -if [ "$PKG_CONFIG_SHELL_IS_POSIX" != "1" ]; then - PKG_CONFIG_SHELL_IS_POSIX=1 PATH=`getconf PATH` exec sh $0 "$@" -fi - set -e . ${srcdir}/common diff --git a/check/check-whitespace b/check/check-whitespace index c328f74..b26ec3d 100755 --- a/check/check-whitespace +++ b/check/check-whitespace @@ -1,10 +1,5 @@ #! /bin/sh -# Make sure we're POSIX -if [ "$PKG_CONFIG_SHELL_IS_POSIX" != "1" ]; then - PKG_CONFIG_SHELL_IS_POSIX=1 PATH=`getconf PATH` exec sh $0 "$@" -fi - set -e . ${srcdir}/common diff --git a/configure.ac b/configure.ac index 4788ee5..37fe831 100644 --- a/configure.ac +++ b/configure.ac @@ -23,6 +23,13 @@ AC_PROG_CC dnl Check for headers AC_CHECK_HEADERS([dirent.h unistd.h sys/wait.h malloc.h]) +dnl A POSIX shell is required for the tests. If TEST_SHELL hasn't been +dnl set on the command line then we try to find bash or ksh or sh from +dnl the path. If none of those are available, we just use whatever +dnl autoconf detected for configure. +AC_ARG_VAR([TESTS_SHELL], [Path to a POSIX shell to be used for testing]) +conf_path="$PATH:`getconf PATH 2>/dev/null`" +AC_PATH_PROGS([TESTS_SHELL], [bash ksh sh], [$CONFIG_SHELL], [$conf_path]) dnl dnl Default pkg-config search path