]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
stty: support baud rate macro extraction on more compilers
authorH. Peter Anvin <hpa@zytor.com>
Mon, 23 Jun 2025 18:20:47 +0000 (11:20 -0700)
committerPádraig Brady <P@draigBrady.com>
Mon, 23 Jun 2025 21:13:51 +0000 (22:13 +0100)
For generating src/speedtest.h, try a sequence of command-line options
until (or unless) one of them works:

  -dM: gcc, clang and derived compilers, icc classic
  -xdumpmacros: Sun Studio (writes to stderr!)
  -qshowmacros: IBM XL classic
  -PD: MSVC (usable with a wrapper such as cccl from the SWIG project)

Because Sun Studio -xdumpmacros unconditionally writes to stderr,
capture stderr output instead of sending it to /dev/null. This is
perfectly safe, even in the presence of stray stderr output, because:

  1. speedgen ignores input that is not of the form #define B<number>
  2. even if a line of that format would somehow spuriously appear,
     the only outcome is that the generated C code will probe for a few
     more macros.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
src/local.mk

index d0cf00a7a5de542abf43f868fa1090bff3c52c6a..20094395480ddb00d46ae75a8e0a1829f64066d1 100644 (file)
@@ -695,15 +695,26 @@ src/version.h: Makefile
        $(AM_V_at)chmod a-w $@t
        $(AM_V_at)mv $@t $@
 
-# Target-specific termios baud rate file. This is opportunistic;
-# if cc -E doesn't support -dM, the speedgen script still includes
-# an extensive fallback list of common constants.
+# Target-specific termios baud rate file. This is opportunistic; if cc
+# -E doesn't support any of the macro extraction options, the speedgen
+# script still includes an extensive fallback list of common
+# constants.
+
+# List of options used by various compilers to extract macro definitions;
+# these are tried in the order listed until the compiler exits successfully.
+# -dM: gcc, clang and derived compilers, icc classic
+# -xdumpmacros: Sun Studio (writes to stderr!)
+# -qshowmacros: IBM XL classic
+# -PD: MSVC (usable with a wrapper such as cccl from the SWIG project)
+getmacopts = -dM -xdumpmacros -qshowmacros -PD
+
 CLEANFILES += src/speedlist.h
 src/speedlist.h: src/termios.c lib/config.h src/speedgen
        $(AM_V_GEN)rm -f $@
        $(AM_V_at)${MKDIR_P} src
-       $(AM_V_at)$(COMPILE) -E -dM $< 2>/dev/null |            \
-                 $(SHELL) $(srcdir)/src/speedgen $@t
+       $(AM_V_at)( for opt in $(getmacopts); do \
+                       $(COMPILE) -E $$opt $< 2>&1 && break; \
+                   done ) | $(SHELL) $(srcdir)/src/speedgen $@t
        $(AM_V_at)chmod a-w $@t
        $(AM_V_at)mv $@t $@