config-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Modernize more C programs in config.guess.


From: Jacob Bachmeyer
Subject: Re: [PATCH] Modernize more C programs in config.guess.
Date: Thu, 04 Apr 2024 17:25:28 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.22) Gecko/20090807 MultiZilla/1.8.3.4e SeaMonkey/1.1.17 Mnenhy/0.7.6.0

Zack Weinberg wrote:
From: Zack Weinberg <zack@owlfolio.org>

Specifically, on top of Petr Vorel’s patch, eliminate all use of
old-style function definitions and implicit function declarations.

Many of the C programs embedded in config.guess are only used on very
old systems that may never have had an ISO C compiler (other than gcc,
which we cannot assume has been installed) so we have to do this
carefully.  I assume that stdio.h exists unconditionally, and that
either it declares puts and printf, or the compiler is so old that
implicit function declarations are the order of the day.  I also
assume it is safe to declare main as ‘int main (void)’; that may need
to get reverted.  All uses of ‘exit’ are replaced with returning from
main, so that we do not need to worry about whether stdlib.h exists.

The only C program that took command line arguments, and therefore
needed to declare main with arguments, is replaced with a
preprocessor-only check and string manipulation from shell.

Wherever possible, uses of printf are demoted to puts.
---
 config.guess | 111 ++++++++++++++++++++++++---------------------------
 1 file changed, 52 insertions(+), 59 deletions(-)

diff --git a/config.guess b/config.guess
index ff5146b..1059f76 100755
--- a/config.guess
+++ b/config.guess
@@ -4,7 +4,7 @@
# shellcheck disable=SC2006,SC2268 # see below for rationale -timestamp='2024-01-03'
+timestamp='2024-04-04'
# This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -534,29 +534,22 @@ case 
$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in
     mips:*:*:UMIPS | mips:*:*:RISCos)
        set_cc_for_build
        sed 's/^        //' << EOF > "$dummy.c"
[...]
 EOF
-       $CC_FOR_BUILD -o "$dummy" "$dummy.c" &&
-         dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` &&
-         SYSTEM_NAME=`"$dummy" "$dummyarg"` &&
+       SYSTEM_TYPE="`$CC_FOR_BUILD -E - < "$dummy.c" |
+           sed -n 's/^ *SYSTYPE *= *//p'`" &&
+       SYSTEM_REL="`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'`" &&
+       SYSTEM_NAME="mips-mips-riscos${SYSTEM_REL}${SYSTEM_TYPE}" &&

You have tripped up on a known portability issue here: due to bugs in various shells, there is no portable way to use double quotes inside double-quoted backticks. Since word-splitting is not done on variable assignments, the simplest solution is to remove the outermost double quotes, like so:

SYSTEM_TYPE=`$CC_FOR_BUILD -E - < "$dummy.c" | sed -n 's/^ *SYSTYPE *= *//p'` &&
SYSTEM_REL=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` &&
SYSTEM_NAME=mips-mips-riscos${SYSTEM_REL}${SYSTEM_TYPE} && There are reasons that variable assignments in config.guess usually omit unnecessary quotes, mostly due to bugs in ancient shells under which config.guess still needs to be able to run.
[...]
@@ -793,20 +782,25 @@ EOF
[...]
-       $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` &&
-               { echo "$SYSTEM_NAME"; exit; }
+       if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_CPU=`"$dummy"`; then
+           if [ "$SYSTEM_CPU" != "unknown" ]; then
+               SYSTEM_NAME="${SYSTEM_CPU}-hitachi-hiuxwe2"
Once again, this should be:

SYSTEM_NAME=${SYSTEM_CPU}-hitachi-hiuxwe2

We could argue style all day long, but this script has to run under ancient shells (because it is supposed to identify archaic systems) and all other assignments avoid unneeded quotes.


-- Jacob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]