From 8c47af9be524405a961bb33200d5e187316191b1 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 23 Jun 2025 11:20:47 -0700 Subject: [PATCH] stty: support baud rate macro extraction on more compilers 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 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) --- src/local.mk | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/local.mk b/src/local.mk index d0cf00a7a5..2009439548 100644 --- a/src/local.mk +++ b/src/local.mk @@ -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 $@ -- 2.47.3