config-patches
[Top][All Lists]
Advanced

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

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


From: Zack Weinberg
Subject: [PATCH] Modernize more C programs in config.guess.
Date: Thu, 4 Apr 2024 15:08:25 -0400

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"
-#ifdef __cplusplus
-#include <stdio.h>  /* for printf() prototype */
-       int main (int argc, char *argv[]) {
-#else
-       int main (argc, argv) int argc; char *argv[]; {
-#endif
+       #include <stdio.h>
        #if defined (host_mips) && defined (MIPSEB)
        #if defined (SYSTYPE_SYSV)
-         printf ("mips-mips-riscos%ssysv\\n", argv[1]); exit (0);
+       SYSTYPE=sysv
        #endif
        #if defined (SYSTYPE_SVR4)
-         printf ("mips-mips-riscos%ssvr4\\n", argv[1]); exit (0);
+       SYSTYPE=svr4
        #endif
        #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
-         printf ("mips-mips-riscos%sbsd\\n", argv[1]); exit (0);
+       SYSTYPE=bsd
        #endif
-       #endif
-         exit (-1);
-       }
 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}" &&
            { echo "$SYSTEM_NAME"; exit; }
        GUESS=mips-mips-riscos$UNAME_RELEASE
        ;;
@@ -633,19 +626,15 @@ EOF
                set_cc_for_build
                sed 's/^                //' << EOF > "$dummy.c"
                #include <sys/systemcfg.h>
-
                int
                main (void)
-                       {
-                       if (!__power_pc())
-                               exit(1);
-                       puts("powerpc-ibm-aix3.2.5");
-                       exit(0);
-                       }
+               {
+                       return !__power_pc();
+               }
 EOF
-               if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && 
SYSTEM_NAME=`"$dummy"`
+               if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && "$dummy"
                then
-                       GUESS=$SYSTEM_NAME
+                       GUESS=powerpc-ibm-aix3.2.5
                else
                        GUESS=rs6000-ibm-aix3.2.5
                fi
@@ -714,9 +703,8 @@ EOF
                if test "$HP_ARCH" = ""; then
                    set_cc_for_build
                    sed 's/^            //' << EOF > "$dummy.c"
-
                #define _HPUX_SOURCE
-               #include <stdlib.h>
+               #include <stdio.h>
                #include <unistd.h>
 
                int
@@ -744,7 +732,7 @@ EOF
                #endif
                        default: puts ("hppa1.0"); break;
                        }
-                   exit (0);
+                   return 0;
                }
 EOF
                    (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 
2>/dev/null) && HP_ARCH=`"$dummy"`
@@ -781,6 +769,7 @@ EOF
     3050*:HI-UX:*:*)
        set_cc_for_build
        sed 's/^        //' << EOF > "$dummy.c"
+       #include <stdio.h>
        #include <unistd.h>
        int
        main (void)
@@ -793,20 +782,25 @@ EOF
            {
              switch (cpu)
                {
-                 case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
-                 case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
-                 case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
-                 default: puts ("hppa-hitachi-hiuxwe2"); break;
+                 case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
+                 case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
+                 case CPU_PA_RISC2_0: puts ("hppa2.0"); break;
+                 default: puts ("hppa"); break;
                }
            }
          else if (CPU_IS_HP_MC68K (cpu))
-           puts ("m68k-hitachi-hiuxwe2");
-         else puts ("unknown-hitachi-hiuxwe2");
-         exit (0);
+           puts ("m68k");
+         else puts ("unknown");
+         return 0;
        }
 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"
+               echo "$SYSTEM_NAME"
+               exit
+           fi
+       fi
        GUESS=unknown-hitachi-hiuxwe2
        ;;
     9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*)
@@ -1611,6 +1605,7 @@ fi
 # No uname command or uname output not recognized.
 set_cc_for_build
 cat > "$dummy.c" <<EOF
+#include <stdio.h>
 #ifdef _SEQUENT_
 #include <sys/types.h>
 #include <sys/utsname.h>
@@ -1630,16 +1625,14 @@ main (void)
 #if defined (MIPSEB)
   /* BFD wants "bsd" instead of "newsos".  Perhaps BFD should be changed,
      I don't know....  */
-  printf ("mips-sony-bsd\n"); exit (0);
+  puts ("mips-sony-bsd"); return 0;
 #else
 #include <sys/param.h>
-  printf ("m68k-sony-newsos%s\n",
 #ifdef NEWSOS4
-  "4"
+  puts ("m68k-sony-newsos4"); return 0;
 #else
-  ""
+  puts ("m68k-sony-newsos"); return 0;
 #endif
-  ); exit (0);
 #endif
 #endif
 
@@ -1658,26 +1651,26 @@ main (void)
 
 #if defined (MULTIMAX) || defined (n16)
 #if defined (UMAXV)
-  printf ("ns32k-encore-sysv\n"); exit (0);
+  puts ("ns32k-encore-sysv"); return 0;
 #else
 #if defined (CMU)
-  printf ("ns32k-encore-mach\n"); exit (0);
+  puts ("ns32k-encore-mach"); return 0;
 #else
-  printf ("ns32k-encore-bsd\n"); exit (0);
+  puts ("ns32k-encore-bsd"); return 0;
 #endif
 #endif
 #endif
 
 #if defined (__386BSD__)
-  printf ("i386-pc-bsd\n"); exit (0);
+  puts ("i386-pc-bsd"); return 0;
 #endif
 
 #if defined (sequent)
 #if defined (i386)
-  printf ("i386-sequent-dynix\n"); exit (0);
+  puts ("i386-sequent-dynix"); return 0;
 #endif
 #if defined (ns32000)
-  printf ("ns32k-sequent-dynix\n"); exit (0);
+  puts ("ns32k-sequent-dynix"); return 0;
 #endif
 #endif
 
@@ -1686,12 +1679,12 @@ main (void)
 
   uname(&un);
   if (strncmp(un.version, "V2", 2) == 0) {
-    printf ("i386-sequent-ptx2\n"); exit (0);
+    puts ("i386-sequent-ptx2"); return 0;
   }
   if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
-    printf ("i386-sequent-ptx1\n"); exit (0);
+    puts ("i386-sequent-ptx1"); return 0;
   }
-  printf ("i386-sequent-ptx\n"); exit (0);
+  puts ("i386-sequent-ptx"); return 0;
 #endif
 
 #if defined (vax)
@@ -1699,16 +1692,16 @@ main (void)
 #include <sys/param.h>
 #if defined (BSD)
 #if BSD == 43
-  printf ("vax-dec-bsd4.3\n"); exit (0);
+  puts ("vax-dec-bsd4.3"); return 0;
 #else
 #if BSD == 199006
-  printf ("vax-dec-bsd4.3reno\n"); exit (0);
+  puts ("vax-dec-bsd4.3reno"); return 0;
 #else
-  printf ("vax-dec-bsd\n"); exit (0);
+  puts ("vax-dec-bsd"); return 0;
 #endif
 #endif
 #else
-  printf ("vax-dec-bsd\n"); exit (0);
+  puts ("vax-dec-bsd"); return 0;
 #endif
 #else
 #if defined(_SIZE_T_) || defined(SIGLOST)
@@ -1716,7 +1709,7 @@ main (void)
   uname (&un);
   printf ("vax-dec-ultrix%s\n", un.release); exit (0);
 #else
-  printf ("vax-dec-ultrix\n"); exit (0);
+  puts ("vax-dec-ultrix"); return 0;
 #endif
 #endif
 #endif
@@ -1727,16 +1720,16 @@ main (void)
   uname (&un);
   printf ("mips-dec-ultrix%s\n", un.release); exit (0);
 #else
-  printf ("mips-dec-ultrix\n"); exit (0);
+  puts ("mips-dec-ultrix"); return 0;
 #endif
 #endif
 #endif
 
 #if defined (alliant) && defined (i860)
-  printf ("i860-alliant-bsd\n"); exit (0);
+  puts ("i860-alliant-bsd"); return 0;
 #endif
 
-  exit (1);
+  return 1;
 }
 EOF
 
-- 
2.43.2




reply via email to

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