From 6c593ff0ce9277a8ddc98eaa1980b3e6f0832fa5 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 17 Apr 2020 18:23:02 -0700 Subject: configure: improve shell search-and-re-execute logic. * configure: If we determine we are running on Bash, then do not re-execute. If re-executing, then look for CONFIG_SHELL first, which is an Autoconf convention that some distros rely on. Include dash in the fallback shell list because dash works fine. Include more places in which to look for bash and dash. Uses of txr_shell must be quoted now because it could take on the value of CONFIG_SHELL which we don't control. Print a trace message about re-executing. Print the message about which shell we are running on earlier, before parsing the variables and printing the baner. Since we might not re-execute any more, we might not know the exact name of the shell we are running on. That is difficult and hacky to obtain, so instead we print an alternative message that we are running on the original shell. (gen_config_make): Only generate the SHELL Makefile variable if txr_shell is set. If whatever shell we were run with is good enough for the configure script, it's good enough for Makefile recipes. Likely, the configure script was executed directly, so that /bin/sh is that default shell and that is what GNU Make will use by default. --- configure | 62 ++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 16 deletions(-) (limited to 'configure') diff --git a/configure b/configure index be2b6097..2f78a8af 100755 --- a/configure +++ b/configure @@ -27,29 +27,61 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # -# The #!/bin/sh might be some legacy piece of crap, -# not even up to 1990 POSIX.2 spec. So the first step -# is to look for a better shell in some known places -# and re-execute ourselves with that interpreter. +# The #!/bin/sh might be some legacy piece of junk, not even up to 1990 POSIX.2 +# spec. So the first step is to look for a better shell in some known places +# and re-execute ourselves with that interpreter, unless there is evidence we +# are already running in a usable shell. # -if test x$txr_shell = x ; then - for shell in /bin/bash /usr/bin/bash /usr/xpg4/bin/sh ; do - if test -x $shell ; then +while true ; do + # we have already recursed into a desired shell + if test "x$txr_shell" != x ; then + break + fi + + # Evidence we are running on Bash in POSIX mode. + if test x$POSIXLY_CORRECT = y ; then + break + fi + + # Evidence we are running on Bash in regular mode. + if test x$BASH_VERSION != x ; then + break + fi + + # Slow path: find a suitable shell. + # First choice is $CONFIG_SHELL, a convention from GNU Autoconf. + for shell in "$CONFIG_SHELL" \ + /bin/bash /usr/bin/bash /usr/local/bin/bash \ + /bin/dash /usr/bin/dash /usr/local/bin/dash \ + /usr/xpg4/bin/sh + do + if test -x "$shell" ; then txr_shell=$shell break fi done - if test x$txr_shell = x ; then - echo "No known POSIX shell found: falling back on /bin/sh, which may not work" - txr_shell=/bin/sh + + if test "x$txr_shell" = x ; then + echo "No known modern shell found; sticking with this one." + break; fi + + # we export txr_shell because it acts as a flag indicating the recursed case export txr_shell - exec $txr_shell $0 ${@+"$@"} -fi + echo "Re-executing using $txr_shell" + exec "$txr_shell" $0 ${@+"$@"} + break +done set -u +if [ -n "${txr_shell+y}" ] ; then + printf "Now running in %s shell\n" $txr_shell +else + printf "Running in original shell.\n" +fi + # # Save command line in a way that can be re-run. # @@ -524,8 +556,6 @@ printf "+%s+\n|%s|\n+%s+\n" $banner_box "$banner_text" $banner_box set -e -printf "We are using this shell: %s\n" $txr_shell - # # Check for GNU make # @@ -740,10 +770,10 @@ gen_config_make() # Changes to this file are lost when the above is re-run. # -# Shell used by make for running recipes; this +${txr_shell:+# Shell used by make for running recipes; this # is the as the shell we chose for the configure script, # derived from the txr_shell variable. -SHELL := $txr_shell +SHELL := $txr_shell} txr_ver := $txr_ver -- cgit v1.2.3