manywarnings: Fix for compilers that are named '$host-gcc'

Bruno Haible via Gnulib discussion list <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <9638323.CDJkKcVGEf@cagnes>
Building a current gettext on Cygwin 2.9.0, with CC=x86_64-pc-cygwin-gcc,
I see many warnings like

cc1: warning: command line option ‘-Wuseless-cast’ is valid for C++/ObjC++ but not for C
cc1: warning: command line option ‘-Wzero-as-null-pointer-constant’ is valid for C++/ObjC++ but not for C

$CC --version is

"x86_64-pc-cygwin-gcc (GCC) 6.4.0
Copyright ..."

The problem is that manywarnings.m4 understands only gcc binaries installed
under the name "gcc" or "gcc-<version>" or something like that. This patch
fixes it.


2026-06-25  Bruno Haible  <[email protected]>

	manywarnings: Fix for compilers that are named '$host-gcc'.
	* m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC(C)): Use only the first line
	of `$CC --version`. Allow $CC to be of the form '$host-gcc'.

diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4
index 1a50006245..6b323ba01d 100644
--- a/m4/manywarnings.m4
+++ b/m4/manywarnings.m4
@@ -1,5 +1,5 @@
 # manywarnings.m4
-# serial 35
+# serial 36
 dnl Copyright (C) 2008-2026 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -169,36 +169,39 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC(C
   AS_VAR_APPEND([$1], [' -Wvla-larger-than=4031'])
 
   # These depend on the GCC version.
-  if test -n "$GCC" && gl_gcc_version=`($CC --version) 2>/dev/null`; then
+  if test -n "$GCC" \
+     && gl_gcc_version=`($CC --version) 2>/dev/null | sed 1q`; then
     case $gl_gcc_version in
-      gcc*' ('*') '[[0-3]].* | \
-      gcc*' ('*') '4.[[0-7]].*)
+      *gcc*' ('*') '[[0-3]].* | \
+      *gcc*' ('*') '4.[[0-7]].*)
         AS_VAR_APPEND([$1], [' -fdiagnostics-show-option'])
         AS_VAR_APPEND([$1], [' -funit-at-a-time'])
-          ;;
+        ;;
     esac
     case $gl_gcc_version in
-      gcc*' ('*') '[[0-9]].*)
+      *gcc*' ('*') '[[0-9]].*)
+        # In GCC >= 10 this option is no longer needed, as it is
+        # enabled by default.
         AS_VAR_APPEND([$1], [' -fno-common'])
-          ;;
+        ;;
     esac
     case $gl_gcc_version in
-      gcc*' ('*') '?.* | gcc*' ('*') '1[[0-3]].*)
-          # In GCC < 14 the option either does not exist,
-          # or is accepted but always warns.
-          ;;
+      *gcc*' ('*') '?.* | gcc*' ('*') '1[[0-3]].*)
+        # In GCC < 14 the option either does not exist,
+        # or is accepted but always warns.
+        ;;
       *)
-          AS_VAR_APPEND([$1], [' -Wuseless-cast'])
-          ;;
+        AS_VAR_APPEND([$1], [' -Wuseless-cast'])
+        ;;
     esac
     case $gl_gcc_version in
-      gcc*' ('*') '?.* | gcc*' ('*') '1[[0-4]].*)
-          # In GCC < 15 the option either does not exist,
-          # or is accepted but always warns.
-          ;;
+      *gcc*' ('*') '?.* | gcc*' ('*') '1[[0-4]].*)
+        # In GCC < 15 the option either does not exist,
+        # or is accepted but always warns.
+        ;;
       *)
-          AS_VAR_APPEND([$1], [' -Wzero-as-null-pointer-constant'])
-          ;;
+        AS_VAR_APPEND([$1], [' -Wzero-as-null-pointer-constant'])
+        ;;
     esac
   fi
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.