maint: Update HACKING
[automake.git] / t / ax / shell-no-trail-bslash.in
blobfc7b5410745c514d6962a62f728b1b6f5356d99f
1 #! @AM_TEST_RUNNER_SHELL@
2 # Copyright (C) 2012-2017 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 # A "shell" that chokes on '-c' commands and/or shell scripts having
18 # a trailing '\' character (possibly followed by whitespace only).
19 # This is to emulate problems seen in older bash versions (e.g., bash
20 # 2.05b). See also automake bug#10436.
22 set -u
24 am_SHELL=${AM_TESTSUITE_SHELL-'@SHELL@'}
27   set -e
28   shell_command=; unset shell_command
29   shell_script=; unset shell_script
30   while test $# -gt 0; do
31     case $1 in
32       # The shell might be invoked by make e.g. as "sh -ec" or "sh -ce".
33       # Be liberal (in the spirit of defensive programming) and accept
34       # both forms.
35       -*c*) shell_command=$2; shift;;
36        -?*) ;;
37          *) break;;
38     esac
39     shift
40   done
42   if test x${shell_command+"set"} != x"set"; then
43     if test $# -gt 0; then
44       shell_script=$1
45       shell_command=$(cat <"$shell_script")
46     else
47       # Some make implementations, like *BSD's, pass the recipes to the
48       # shell through its standard input.  Trying to run our extra checks
49       # in this case would be too tricky, so we just skip them.
50       exit 0
51     fi
52   fi
53   original_shell_command=$shell_command
55   tab=' '
56   nl='
58   case "$shell_command" in
59     *" "|*"$tab"|*"$nl")
60       shell_command=$(printf '%s\n' "$shell_command" | tr -d " $tab$nl");;
61   esac
63   case "$shell_command" in
64     *\\)
65       {
66         printf '%s\n' "$0: recipe/script ends with backslash character"
67         printf '%s\n' "=== BEGIN recipe/script"
68         if test x${shell_script+"set"} = x"set"; then
69           cat <"$shell_script"
70         else
71           printf '%s\n' "$original_shell_command"
72         fi
73         printf '%s\n' "=== END recipe/script"
74       } >&2
75       exit 1
76       ;;
77   esac
80 if test $? -gt 0; then
81   # Some of our scripts or makefile recipes had invalid contents.
82   exit 3
85 exec ${AM_TESTSUITE_SHELL-'@SHELL@'} ${1+"$@"}