diff options
author | Erlend E. Aasland <erlend@python.org> | 2024-11-07 09:49:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-07 09:49:58 (GMT) |
commit | a5b94d066016be63d632cccee0ec2a2eb24536dc (patch) | |
tree | 4ab0273b796bdcd7e83375e5ed116409fcb71969 /configure.ac | |
parent | 75f7cf91ec5afc6091a0fd442a1f0435c19300b2 (diff) | |
download | cpython-a5b94d066016be63d632cccee0ec2a2eb24536dc.zip cpython-a5b94d066016be63d632cccee0ec2a2eb24536dc.tar.gz cpython-a5b94d066016be63d632cccee0ec2a2eb24536dc.tar.bz2 |
gh-96398: Improve accuracy of compiler checks in configure.ac (#117815)
The following variables are now used in compiler checks:
- $ac_cv_gcc_compat is set to 'yes' for GCC compatible compilers
(the C preprocessor defines the __GNUC__ macro)
- for compiler basename checks, use $CC_BASENAME
(may contain platform triplets)
- for the rest, use $ac_cv_cc_name
(does not contain platform triplets)
Diffstat (limited to 'configure.ac')
-rw-r--r-- | configure.ac | 163 |
1 files changed, 59 insertions, 104 deletions
diff --git a/configure.ac b/configure.ac index da7d1ef..ce5a5eb 100644 --- a/configure.ac +++ b/configure.ac @@ -1048,6 +1048,9 @@ AC_PROG_GREP AC_PROG_SED AC_PROG_EGREP +dnl GNU Autoconf recommends the use of expr instead of basename. +AS_VAR_SET([CC_BASENAME], [$(expr "//$CC" : '.*/\(.*\)')]) + dnl detect compiler name dnl check for xlc before clang, newer xlc's can use clang as frontend. dnl check for GCC last, other compilers set __GNUC__, too. @@ -1073,9 +1076,7 @@ EOF if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then ac_cv_cc_name=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '` - if test $(expr "//$CC" : '.*/\(.*\)') = "mpicc"; then - ac_cv_cc_name="mpicc" - fi + AS_VAR_IF([CC_BASENAME], [mpicc], [ac_cv_cc_name=mpicc]) else ac_cv_cc_name="unknown" fi @@ -1104,11 +1105,11 @@ AC_SUBST([CXX]) preset_cxx="$CXX" if test -z "$CXX" then - case "$CC" in + case "$ac_cv_cc_name" in gcc) AC_PATH_TOOL([CXX], [g++], [g++], [notfound]) ;; cc) AC_PATH_TOOL([CXX], [c++], [c++], [notfound]) ;; - clang|*/clang) AC_PATH_TOOL([CXX], [clang++], [clang++], [notfound]) ;; - icc|*/icc) AC_PATH_TOOL([CXX], [icpc], [icpc], [notfound]) ;; + clang) AC_PATH_TOOL([CXX], [clang++], [clang++], [notfound]) ;; + icc) AC_PATH_TOOL([CXX], [icpc], [icpc], [notfound]) ;; esac if test "$CXX" = "notfound" then @@ -1381,7 +1382,7 @@ rmdir CaseSensitiveTestDir case $ac_sys_system in hp*|HP*) - case $CC in + case $ac_cv_cc_name in cc|*/cc) CC="$CC -Ae";; esac;; esac @@ -1467,7 +1468,7 @@ AC_MSG_RESULT([$EXPORTSYMS]) AC_SUBST([GNULD]) AC_MSG_CHECKING([for GNU ld]) ac_prog=ld -if test "$GCC" = yes; then +if test "$ac_cv_cc_name" = "gcc"; then ac_prog=`$CC -print-prog-name=ld` fi case `"$ac_prog" -V 2>&1 < /dev/null` in @@ -1874,14 +1875,12 @@ if test "$Py_OPT" = 'true' ; then DEF_MAKE_ALL_RULE="profile-opt" REQUIRE_PGO="yes" DEF_MAKE_RULE="build_all" - case $CC in - *gcc*) + AS_VAR_IF([ac_cv_gcc_compat], [yes], [ AX_CHECK_COMPILE_FLAG([-fno-semantic-interposition],[ CFLAGS_NODIST="$CFLAGS_NODIST -fno-semantic-interposition" LDFLAGS_NODIST="$LDFLAGS_NODIST -fno-semantic-interposition" ], [], [-Werror]) - ;; - esac + ]) elif test "$ac_sys_system" = "Emscripten" -o "$ac_sys_system" = "WASI"; then dnl Emscripten does not support shared extensions yet. Build dnl "python.[js,wasm]", "pybuilddir.txt", and "platform" files. @@ -1908,7 +1907,7 @@ AC_MSG_RESULT([$PROFILE_TASK]) llvm_bin_dir='' llvm_path="${PATH}" -if test "${CC}" = "clang" +if test "${ac_cv_cc_name}" = "clang" then clang_bin=`which clang` # Some systems install clang elsewhere as a symlink to the real path @@ -1955,8 +1954,8 @@ esac ], [AC_MSG_RESULT([no])]) if test "$Py_LTO" = 'true' ; then - case $CC in - *clang*) + case $ac_cv_cc_name in + clang) LDFLAGS_NOLTO="-fno-lto" dnl Clang linker requires -flto in order to link objects with LTO information. dnl Thin LTO is faster and works for object files with full LTO information, too. @@ -2019,14 +2018,14 @@ if test "$Py_LTO" = 'true' ; then ;; esac ;; - *emcc*) + emcc) if test "$Py_LTO_POLICY" != "default"; then AC_MSG_ERROR([emcc supports only default lto.]) fi LTOFLAGS="-flto" LTOCFLAGS="-flto" ;; - *gcc*) + gcc) if test $Py_LTO_POLICY = thin then AC_MSG_ERROR([thin lto is not supported under gcc compiler.]) @@ -2085,10 +2084,8 @@ then fi LLVM_PROF_ERR=no -# GNU Autoconf recommends the use of expr instead of basename. -AS_VAR_SET([CC_BASENAME], [$(expr "//$CC" : '.*/\(.*\)')]) -case "$CC_BASENAME" in - *clang*) +case "$ac_cv_cc_name" in + clang) # Any changes made here should be reflected in the GCC+Darwin case below PGO_PROF_GEN_FLAG="-fprofile-instr-generate" PGO_PROF_USE_FLAG="-fprofile-instr-use=\"\$(shell pwd)/code.profclangd\"" @@ -2107,35 +2104,13 @@ case "$CC_BASENAME" in fi fi ;; - *gcc*) - case $ac_sys_system in - Darwin*) - PGO_PROF_GEN_FLAG="-fprofile-instr-generate" - PGO_PROF_USE_FLAG="-fprofile-instr-use=\"\$(shell pwd)/code.profclangd\"" - LLVM_PROF_MERGER=m4_normalize(" - ${LLVM_PROFDATA} merge - -output=\"\$(shell pwd)/code.profclangd\" - \"\$(shell pwd)\"/*.profclangr - ") - LLVM_PROF_FILE="LLVM_PROFILE_FILE=\"\$(shell pwd)/code-%p.profclangr\"" - if test "${LLVM_PROF_FOUND}" = "not-found" - then - LLVM_PROF_ERR=yes - if test "${REQUIRE_PGO}" = "yes" - then - AC_MSG_ERROR([llvm-profdata is required for a --enable-optimizations build but could not be found.]) - fi - fi - ;; - *) - PGO_PROF_GEN_FLAG="-fprofile-generate" - PGO_PROF_USE_FLAG="-fprofile-use -fprofile-correction" - LLVM_PROF_MERGER="true" - LLVM_PROF_FILE="" - ;; - esac + gcc) + PGO_PROF_GEN_FLAG="-fprofile-generate" + PGO_PROF_USE_FLAG="-fprofile-use -fprofile-correction" + LLVM_PROF_MERGER="true" + LLVM_PROF_FILE="" ;; - *icc*) + icc) PGO_PROF_GEN_FLAG="-prof-gen" PGO_PROF_USE_FLAG="-prof-use" LLVM_PROF_MERGER="true" @@ -2259,19 +2234,6 @@ AC_MSG_RESULT([$BOLT_APPLY_FLAGS]) # compiler and platform. BASECFLAGS tweaks need to be made even if the # user set OPT. -case $CC in - *clang*) - cc_is_clang=1 - ;; - *) - if $CC --version 2>&1 | grep -q clang - then - cc_is_clang=1 - else - cc_is_clang= - fi -esac - dnl Historically, some of our code assumed that signed integer overflow dnl is defined behaviour via twos-complement. dnl Set STRICT_OVERFLOW_CFLAGS and NO_STRICT_OVERFLOW_CFLAGS depending on compiler support. @@ -2346,7 +2308,7 @@ if test "${OPT-unset}" = "unset" then case $GCC in yes) - if test -n "${cc_is_clang}" + if test "${ac_cv_cc_name}" != "clang" then # bpo-30104: disable strict aliasing to compile correctly dtoa.c, # see Makefile.pre.in for more information @@ -2526,8 +2488,7 @@ then AX_CHECK_COMPILE_FLAG([-D_FORTIFY_SOURCE=3], [CFLAGS_NODIST="$CFLAGS_NODIST -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"], [AC_MSG_WARN([-D_FORTIFY_SOURCE=3 not supported])], [-Werror]) fi -case $GCC in -yes) +AS_VAR_IF([ac_cv_gcc_compat], [yes], [ CFLAGS_NODIST="$CFLAGS_NODIST -std=c11" PY_CHECK_CC_WARNING([enable], [extra], [if we can add -Wextra]) @@ -2568,8 +2529,8 @@ yes) # ICC doesn't recognize the option, but only emits a warning ## XXX does it emit an unused result warning and can it be disabled? - AS_CASE(["$CC_BASENAME"], - [*icc*], [ac_cv_disable_unused_result_warning=no] + AS_CASE(["$ac_cv_cc_name"], + [icc], [ac_cv_disable_unused_result_warning=no] [PY_CHECK_CC_WARNING([disable], [unused-result])]) AS_VAR_IF([ac_cv_disable_unused_result_warning], [yes], [BASECFLAGS="$BASECFLAGS -Wno-unused-result" @@ -2662,20 +2623,17 @@ yes) Darwin*) # -Wno-long-double, -no-cpp-precomp, and -mno-fused-madd # used to be here, but non-Apple gcc doesn't accept them. - if test "${CC}" = gcc - then - AC_MSG_CHECKING([which compiler should be used]) - case "${UNIVERSALSDK}" in - */MacOSX10.4u.sdk) - # Build using 10.4 SDK, force usage of gcc when the - # compiler is gcc, otherwise the user will get very - # confusing error messages when building on OSX 10.6 - CC=gcc-4.0 - CPP=cpp-4.0 - ;; - esac - AC_MSG_RESULT([$CC]) - fi + AC_MSG_CHECKING([which compiler should be used]) + case "${UNIVERSALSDK}" in + */MacOSX10.4u.sdk) + # Build using 10.4 SDK, force usage of gcc when the + # compiler is gcc, otherwise the user will get very + # confusing error messages when building on OSX 10.6 + CC=gcc-4.0 + CPP=cpp-4.0 + ;; + esac + AC_MSG_RESULT([$CC]) LIPO_INTEL64_FLAGS="" if test "${enable_universalsdk}" @@ -2800,9 +2758,7 @@ yes) # end of Darwin* tests ;; esac - ;; - -*) +], [ case $ac_sys_system in OpenUNIX*|UnixWare*) BASECFLAGS="$BASECFLAGS -K pentium,host,inline,loop_unroll,alloca " @@ -2811,18 +2767,17 @@ yes) BASECFLAGS="$BASECFLAGS -belf -Ki486 -DSCO5" ;; esac - ;; -esac +]) -case "$CC_BASENAME" in -*mpicc*) +case "$ac_cv_cc_name" in +mpicc) CFLAGS_NODIST="$CFLAGS_NODIST" ;; -*icc*) +icc) # ICC needs -fp-model strict or floats behave badly CFLAGS_NODIST="$CFLAGS_NODIST -fp-model strict" ;; -*xlc*) +xlc) CFLAGS_NODIST="$CFLAGS_NODIST -qalias=noansi -qmaxmem=-1" ;; esac @@ -3430,7 +3385,7 @@ then LDSHARED="\$(LIBPL)/ld_so_aix \$(CC) -bI:\$(LIBPL)/python.exp" ;; SunOS/5*) - if test "$GCC" = "yes" ; then + if test "$ac_cv_gcc_compat" = "yes" ; then LDSHARED='$(CC) -shared' LDCXXSHARED='$(CXX) -shared' else @@ -3438,7 +3393,7 @@ then LDCXXSHARED='$(CXX) -G' fi ;; hp*|HP*) - if test "$GCC" = "yes" ; then + if test "$ac_cv_gcc_compat" = "yes" ; then LDSHARED='$(CC) -shared' LDCXXSHARED='$(CXX) -shared' else @@ -3531,7 +3486,7 @@ then LDSHARED='$(CC) -shared' LDCXXSHARED='$(CXX) -shared';; OpenUNIX*|UnixWare*) - if test "$GCC" = "yes" ; then + if test "$ac_cv_gcc_compat" = "yes" ; then LDSHARED='$(CC) -shared' LDCXXSHARED='$(CXX) -shared' else @@ -3571,13 +3526,13 @@ AC_MSG_CHECKING([CCSHARED]) if test -z "$CCSHARED" then case $ac_sys_system/$ac_sys_release in - SunOS*) if test "$GCC" = yes; + SunOS*) if test "$ac_cv_gcc_compat" = "yes"; then CCSHARED="-fPIC"; elif test `uname -p` = sparc; then CCSHARED="-xcode=pic32"; else CCSHARED="-Kpic"; fi;; - hp*|HP*) if test "$GCC" = yes; + hp*|HP*) if test "$ac_cv_gcc_compat" = "yes"; then CCSHARED="-fPIC"; else CCSHARED="+z"; fi;; @@ -3589,12 +3544,12 @@ then FreeBSD*|NetBSD*|OpenBSD*|DragonFly*) CCSHARED="-fPIC";; Haiku*) CCSHARED="-fPIC";; OpenUNIX*|UnixWare*) - if test "$GCC" = "yes" + if test "$ac_cv_gcc_compat" = "yes" then CCSHARED="-fPIC" else CCSHARED="-KPIC" fi;; SCO_SV*) - if test "$GCC" = "yes" + if test "$ac_cv_gcc_compat" = "yes" then CCSHARED="-fPIC" else CCSHARED="-Kpic -belf" fi;; @@ -3652,13 +3607,13 @@ then then LINKFORSHARED="-Wl,--export-dynamic" fi;; - SunOS/5*) case $CC in - *gcc*) + SunOS/5*) if test "$ac_cv_gcc_compat" = "yes"; then if $CC -Xlinker --help 2>&1 | grep export-dynamic >/dev/null then LINKFORSHARED="-Xlinker --export-dynamic" - fi;; - esac;; + fi + fi + ;; CYGWIN*) if test $enable_shared = "no" then @@ -4228,7 +4183,7 @@ AS_VAR_IF( fi elif test $ac_cv_sizeof_size_t -eq 4; then if test "$ac_cv_gcc_asm_for_x87" = yes -a "$libmpdec_system" != sunos; then - AS_CASE([$CC], + AS_CASE([$ac_cv_cc_name], [*gcc*], [libmpdec_machine=ppro], [*clang*], [libmpdec_machine=ppro], [libmpdec_machine=ansi32] @@ -7150,8 +7105,8 @@ if test "$ac_cv_gcc_asm_for_x87" = yes; then # Some versions of gcc miscompile inline asm: # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html - case $CC in - *gcc*) + case $ac_cv_cc_name in + gcc) AC_MSG_CHECKING([for gcc ipa-pure-const bug]) saved_cflags="$CFLAGS" CFLAGS="-O2" |