From cdddeb0f1280b40cc194028bbaef36e127175c4c Mon Sep 17 00:00:00 2001 From: Rodrigo Mesquita <rodrigo.m.mesquita@gmail.com> Date: Fri, 19 Jan 2024 09:14:18 +0000 Subject: [PATCH] Work around autotools setting C11 standard in CC/CXX In autoconf >=2.70, C11 is set by default for $CC and $CXX via the -std=...11 flag. In this patch, we split the "-std" flag out of the $CC and $CXX variables, which we traditionally assume to be just the executable name/path, and move it to $CFLAGS/$CXXFLAGS instead. Fixes #24324 --- configure.ac | 3 +++ m4/fp_prog_move_to_flags.m4 | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 m4/fp_prog_move_to_flags.m4 diff --git a/configure.ac b/configure.ac index 495ddd0202ab..b7e1ae57a782 100644 --- a/configure.ac +++ b/configure.ac @@ -417,6 +417,9 @@ dnl detect compiler (prefer gcc over clang) and set $CC (unless CC already set), dnl later CC is copied to CC_STAGE{1,2,3} AC_PROG_CC([cc gcc clang]) AC_PROG_CXX([g++ clang++ c++]) +# Work around #24324 +MOVE_TO_FLAGS([CC],[CFLAGS]) +MOVE_TO_FLAGS([CXX],[CXXFLAGS]) MAYBE_OVERRIDE_STAGE0([ar],[AR_STAGE0]) diff --git a/m4/fp_prog_move_to_flags.m4 b/m4/fp_prog_move_to_flags.m4 new file mode 100644 index 000000000000..b5fcb005cd04 --- /dev/null +++ b/m4/fp_prog_move_to_flags.m4 @@ -0,0 +1,19 @@ +# MOVE_TO_FLAGS +# -------------------------------- +# Split off flags from $1 (the compiler) to $2 (the flags). +# This works around autoconf setting $CC and $CXX to be a program plus the C11 +# `-std=...11` flag (#24324), starting from autotools 2.70. +AC_DEFUN([MOVE_TO_FLAGS],[ + +dnl Use IFS=' ' to split off the command from the arguments in $1. +dnl By expanding $$1, set accounts for quoting correctly, such that splitting +dnl e.g. '"A B/C" D' results in "A B/C" and "D". +tmp_IFS="$IFS" +IFS=' ' +eval set -- $$1 +IFS="$tmp_IFS" + +$1="[$]1" +shift +$2="[$]@ $$2" +]) -- GitLab