Allow CONFIG_SHELL to override build-time shell in mkheaders
authorAlexandre Oliva <oliva@adacore.com>
Fri, 21 Feb 2020 01:09:03 +0000 (22:09 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Fri, 21 Feb 2020 01:09:03 +0000 (22:09 -0300)
mkheaders.in uses substitutions of @SHELL@ to run fixinc.sh and
mkinstalldirs.  Problem is, SHELL comes from CONFIG_SHELL for the
build system, and it needs not match whatever is available at an
unrelated host system after installation, when mkheaders is supposed
to be run.

I considered ditching the hardcoding altogether, but decided to retain
it, but allowing CONFIG_SHELL and SHELL to override it, if any of them
can successfully run mkinstalldirs, and if those and the substituted
@SHELL@ fail, fallback to /bin/sh and to plain execution of the
script, which appears to enable at least one shell on a system that
doesn't typicall have a shell to recognize a script by #!/bin/sh and
reinvoke itself to run it.

If all of these fail, we fail, but only after telling the user to
retry after setting CONFIG_SHELL, that fixincl itself also uses.

for  fixincludes/ChangeLog

* mkheaders.in: Don't require build-time shell on host.

fixincludes/ChangeLog
fixincludes/mkheaders.in

index 5b3d9ae1055aa7ecf780013efadbdb5f35b51352..3f93053e121a5d268b338ca4ed677fe73ace41cc 100644 (file)
@@ -1,3 +1,7 @@
+2020-02-20  Alexandre Oliva <oliva@adacore.com>
+
+       * mkheaders.in: Don't require build-time shell on host.
+
 2020-02-13  Matheus Castanho  <msc@linux.ibm.com>
 
        * fixinc.in: Skip machine_name fix on powerpc*-*-linux*.
index a293a57a73b4c06f56ffa686b2334ef8c236e657..4109dc633dde5a03d541c9bd6d9eb619d6186c5f 100644 (file)
@@ -77,11 +77,29 @@ libexecsubdir=${libexecdir}/gcc/${target_noncanonical}/${version}
 itoolsdir=${libexecsubdir}/install-tools
 itoolsdatadir=${libsubdir}/install-tools
 incdir=${libsubdir}/include-fixed
-mkinstalldirs="@SHELL@ ${itoolsdir}/mkinstalldirs"
+mkinstalldirs="${itoolsdir}/mkinstalldirs"
 
 cd ${itoolsdir}
 rm -rf ${incdir}/*
 
+for shell in $CONFIG_SHELL $SHELL @SHELL@ /bin/sh ""; do
+  if { test -x $shell || test -x $shell.exe; } \
+  && $shell $mkinstalldirs > /dev/null 2>&1; then
+    mkinstalldirs="$shell $mkinstalldirs"
+    break
+  elif test x$shell = x; then
+    if $mkinstalldirs > /dev/null 2>&1; then
+      break
+    elif test ! -f $mkinstalldirs; then
+      echo mkheaders: could not find $mkinstalldirs >&2
+      exit 1
+    else
+      echo mkheaders: please rerun with CONFIG_SHELL set to a working Bourne shell >&2
+      exit 1
+    fi
+  fi
+done
+
 for ml in `cat ${itoolsdatadir}/fixinc_list`; do
   sysroot_headers_suffix=`echo ${ml} | sed -e 's/;.*$//'`
   multi_dir=`echo ${ml} | sed -e 's/^[^;]*;//'`
@@ -91,7 +109,7 @@ for ml in `cat ${itoolsdatadir}/fixinc_list`; do
   if [ x${STMP_FIXINC} != x ] ; then
        TARGET_MACHINE="${target}" target_canonical="${target}" \
            MACRO_LIST="${itoolsdatadir}/macro_list" \
-           @SHELL@ ./fixinc.sh ${subincdir} \
+           $shell ./fixinc.sh ${subincdir} \
            ${isysroot}${SYSTEM_HEADER_DIR} ${OTHER_FIXINCLUDES_DIRS}
        rm -f ${subincdir}/syslimits.h
        if [ -f ${subincdir}/limits.h ]; then