Cheng Shao pushed to branch wip/rts-rm-c99-check at Glasgow Haskell Compiler / GHC
Commits:
-
3c9bcb37
by Cheng Shao at 2025-09-29T20:07:47+02:00
6 changed files:
- configure.ac
- distrib/configure.ac.in
- m4/fp_cmm_cpp_cmd_with_args.m4
- − m4/fp_set_cflags_c99.m4
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cc.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs
Changes:
| ... | ... | @@ -448,11 +448,6 @@ AC_SUBST([CmmCPPCmd]) |
| 448 | 448 | AC_SUBST([CmmCPPArgs])
|
| 449 | 449 | AC_SUBST([CmmCPPSupportsG0])
|
| 450 | 450 | |
| 451 | -FP_SET_CFLAGS_C99([CC],[CFLAGS],[CPPFLAGS])
|
|
| 452 | -FP_SET_CFLAGS_C99([CC_STAGE0],[CONF_CC_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])
|
|
| 453 | -FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1])
|
|
| 454 | -FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2])
|
|
| 455 | - |
|
| 456 | 451 | dnl ** Do we have a compatible emsdk version?
|
| 457 | 452 | dnl --------------------------------------------------------------
|
| 458 | 453 | EMSDK_VERSION("3.1.20", "", "")
|
| ... | ... | @@ -163,11 +163,6 @@ AC_SUBST([CmmCPPCmd]) |
| 163 | 163 | AC_SUBST([CmmCPPArgs])
|
| 164 | 164 | AC_SUBST([CmmCPPSupportsG0])
|
| 165 | 165 | |
| 166 | -FP_SET_CFLAGS_C99([CC],[CFLAGS],[CPPFLAGS])
|
|
| 167 | -dnl FP_SET_CFLAGS_C99([CC_STAGE0],[CONF_CC_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])
|
|
| 168 | -FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1])
|
|
| 169 | -FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2])
|
|
| 170 | - |
|
| 171 | 166 | dnl ** Which ld to use?
|
| 172 | 167 | dnl --------------------------------------------------------------
|
| 173 | 168 | FIND_LD([$target],[GccUseLdOpt])
|
| ... | ... | @@ -56,27 +56,6 @@ else |
| 56 | 56 | AC_MSG_RESULT([no])
|
| 57 | 57 | fi
|
| 58 | 58 | |
| 59 | -AC_MSG_CHECKING([the C-- preprocessor for C99 support])
|
|
| 60 | -cat > conftest.c <<EOF
|
|
| 61 | -#include <stdio.h>
|
|
| 62 | -#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
|
|
| 63 | -# error "Compiler does not advertise C99 conformance"
|
|
| 64 | -#endif
|
|
| 65 | -EOF
|
|
| 66 | -if "$CMM_CPP_CMD" $CMM_CPP_ARGS conftest.c -o conftest -g0 >/dev/null 2>&1; then
|
|
| 67 | - AC_MSG_RESULT([yes])
|
|
| 68 | -else
|
|
| 69 | - # Try -std=gnu99
|
|
| 70 | - if "$CMM_CPP_CMD" -std=gnu99 $CMM_CPP_ARGS conftest.c -o conftest -g0 >/dev/null 2>&1; then
|
|
| 71 | - $3="-std=gnu99 $$3"
|
|
| 72 | - AC_MSG_RESULT([needs -std=gnu99])
|
|
| 73 | - else
|
|
| 74 | - AC_MSG_ERROR([C99-compatible compiler needed])
|
|
| 75 | - fi
|
|
| 76 | -fi
|
|
| 77 | -rm -f conftest.c conftest.o conftest
|
|
| 78 | - |
|
| 79 | - |
|
| 80 | 59 | $2="$CMM_CPP_CMD"
|
| 81 | 60 | $3="$$3 $CMM_CPP_ARGS"
|
| 82 | 61 | |
| ... | ... | @@ -85,4 +64,3 @@ unset CMM_CPP_CMD |
| 85 | 64 | unset CMM_CPP_ARGS
|
| 86 | 65 | |
| 87 | 66 | ]) |
| 88 | - |
| 1 | -# FP_SET_CFLAGS_C99
|
|
| 2 | -# ----------------------------------
|
|
| 3 | -# figure out which CFLAGS are needed to place the compiler into C99 mode
|
|
| 4 | -# $1 is name of CC variable (unmodified)
|
|
| 5 | -# $2 is name of CC flags variable (augmented if needed)
|
|
| 6 | -# $3 is name of CPP flags variable (augmented if needed)
|
|
| 7 | -AC_DEFUN([FP_SET_CFLAGS_C99],
|
|
| 8 | -[
|
|
| 9 | - dnl save current state of AC_PROG_CC_C99
|
|
| 10 | - FP_COPY_SHELLVAR([CC],[fp_save_CC])
|
|
| 11 | - FP_COPY_SHELLVAR([CFLAGS],[fp_save_CFLAGS])
|
|
| 12 | - FP_COPY_SHELLVAR([CPPFLAGS],[fp_save_CPPFLAGS])
|
|
| 13 | - FP_COPY_SHELLVAR([ac_cv_prog_cc_c99],[fp_save_cc_c99])
|
|
| 14 | - dnl set local state
|
|
| 15 | - CC="$$1"
|
|
| 16 | - CFLAGS="$$2"
|
|
| 17 | - CPPFLAGS="$$3"
|
|
| 18 | - unset ac_cv_prog_cc_c99
|
|
| 19 | - dnl perform detection
|
|
| 20 | - AC_PROG_CC_C99
|
|
| 21 | - fp_cc_c99="$ac_cv_prog_cc_c99"
|
|
| 22 | - case "x$ac_cv_prog_cc_c99" in
|
|
| 23 | - x) ;; # noop
|
|
| 24 | - xno) AC_MSG_ERROR([C99-compatible compiler needed]) ;;
|
|
| 25 | - *) $2="$$2 $ac_cv_prog_cc_c99"
|
|
| 26 | - $3="$$3 $ac_cv_prog_cc_c99"
|
|
| 27 | - ;;
|
|
| 28 | - esac
|
|
| 29 | - dnl restore saved state
|
|
| 30 | - FP_COPY_SHELLVAR([fp_save_CC],[CC])
|
|
| 31 | - FP_COPY_SHELLVAR([fp_save_CFLAGS],[CFLAGS])
|
|
| 32 | - FP_COPY_SHELLVAR([fp_save_CPPFLAGS],[CPPFLAGS])
|
|
| 33 | - FP_COPY_SHELLVAR([fp_save_cc_c99],[ac_cv_prog_cc_c99])
|
|
| 34 | - dnl cleanup
|
|
| 35 | - unset fp_save_CC
|
|
| 36 | - unset fp_save_CFLAGS
|
|
| 37 | - unset fp_save_cc_c99
|
|
| 38 | -]) |
| ... | ... | @@ -11,7 +11,6 @@ module GHC.Toolchain.Tools.Cc |
| 11 | 11 | , compileC
|
| 12 | 12 | , compileAsm
|
| 13 | 13 | , addPlatformDepCcFlags
|
| 14 | - , checkC99Support
|
|
| 15 | 14 | ) where
|
| 16 | 15 | |
| 17 | 16 | import Control.Monad
|
| ... | ... | @@ -51,12 +50,8 @@ findCc archOs llvmTarget progOpt = do |
| 51 | 50 | cc1 <- ignoreUnusedArgs cc0
|
| 52 | 51 | cc2 <- ccSupportsTarget archOs llvmTarget cc1
|
| 53 | 52 | checking "whether Cc works" $ checkCcWorks cc2
|
| 54 | - cc3 <- oneOf "cc doesn't support C99" $ map checkC99Support
|
|
| 55 | - [ cc2
|
|
| 56 | - , cc2 & _ccFlags %++ "-std=gnu99"
|
|
| 57 | - ]
|
|
| 58 | - checkCcSupportsExtraViaCFlags cc3
|
|
| 59 | - return cc3
|
|
| 53 | + checkCcSupportsExtraViaCFlags cc2
|
|
| 54 | + return cc2
|
|
| 60 | 55 | |
| 61 | 56 | checkCcWorks :: Cc -> M ()
|
| 62 | 57 | checkCcWorks cc = withTempDir $ \dir -> do
|
| ... | ... | @@ -88,17 +83,6 @@ ccSupportsTarget archOs target cc = |
| 88 | 83 | checking "whether Cc supports --target" $
|
| 89 | 84 | supportsTarget archOs _ccProgram checkCcWorks target cc
|
| 90 | 85 | |
| 91 | -checkC99Support :: Cc -> M Cc
|
|
| 92 | -checkC99Support cc = checking "for C99 support" $ withTempDir $ \dir -> do
|
|
| 93 | - let test_o = dir </> "test.o"
|
|
| 94 | - compileC cc test_o $ unlines
|
|
| 95 | - [ "#include <stdio.h>"
|
|
| 96 | - , "#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L"
|
|
| 97 | - , "# error \"Compiler does not advertise C99 conformance\""
|
|
| 98 | - , "#endif"
|
|
| 99 | - ]
|
|
| 100 | - return cc
|
|
| 101 | - |
|
| 102 | 86 | checkCcSupportsExtraViaCFlags :: Cc -> M ()
|
| 103 | 87 | checkCcSupportsExtraViaCFlags cc = checking "whether cc supports extra via-c flags" $ withTempDir $ \dir -> do
|
| 104 | 88 | let test_o = dir </> "test.o"
|
| ... | ... | @@ -19,7 +19,7 @@ import GHC.Toolchain.Prelude |
| 19 | 19 | import GHC.Toolchain.Program
|
| 20 | 20 | |
| 21 | 21 | import GHC.Toolchain.Tools.Cc
|
| 22 | -import GHC.Toolchain.Utils (withTempDir, oneOf, expectFileExists)
|
|
| 22 | +import GHC.Toolchain.Utils (withTempDir, expectFileExists)
|
|
| 23 | 23 | |
| 24 | 24 | newtype Cpp = Cpp { cppProgram :: Program
|
| 25 | 25 | }
|
| ... | ... | @@ -160,13 +160,7 @@ findJsCpp progOpt cc = checking "for JavaScript C preprocessor" $ do |
| 160 | 160 | findCmmCpp :: ProgOpt -> Cc -> M CmmCpp
|
| 161 | 161 | findCmmCpp progOpt cc = checking "for a Cmm preprocessor" $ do
|
| 162 | 162 | -- Use the specified CPP or try to use the c compiler
|
| 163 | - foundCppProg <- findProgram "Cmm preprocessor" progOpt [] <|> pure (programFromOpt progOpt (prgPath $ ccProgram cc) [])
|
|
| 164 | - -- Check whether the C preprocessor needs -std=gnu99 (only very old toolchains need this)
|
|
| 165 | - Cc cpp <- oneOf "cc doesn't support C99" $ map checkC99Support
|
|
| 166 | - [ Cc foundCppProg
|
|
| 167 | - , Cc (foundCppProg & _prgFlags %++ "-std=gnu99")
|
|
| 168 | - ]
|
|
| 169 | - |
|
| 163 | + cpp <- findProgram "Cmm preprocessor" progOpt [] <|> pure (programFromOpt progOpt (prgPath $ ccProgram cc) [])
|
|
| 170 | 164 | cmmCppSupportsG0 <- withTempDir $ \dir -> do
|
| 171 | 165 | let conftest = dir </> "conftest.c"
|
| 172 | 166 | writeFile conftest "int main(void) {}"
|
| ... | ... | @@ -181,14 +175,9 @@ findCmmCpp progOpt cc = checking "for a Cmm preprocessor" $ do |
| 181 | 175 | findCpp :: ProgOpt -> Cc -> M Cpp
|
| 182 | 176 | findCpp progOpt cc = checking "for C preprocessor" $ do
|
| 183 | 177 | -- Use the specified CPP or try to use the c compiler
|
| 184 | - foundCppProg <- findProgram "C preprocessor" progOpt [] <|> pure (programFromOpt progOpt (prgPath $ ccProgram cc) [])
|
|
| 185 | - -- Check whether the C preprocessor needs -std=gnu99 (only very old toolchains need this)
|
|
| 186 | - Cc cpp2 <- oneOf "cc doesn't support C99" $ map checkC99Support
|
|
| 187 | - [ Cc foundCppProg
|
|
| 188 | - , Cc (foundCppProg & _prgFlags %++ "-std=gnu99")
|
|
| 189 | - ]
|
|
| 178 | + cpp <- findProgram "C preprocessor" progOpt [] <|> pure (programFromOpt progOpt (prgPath $ ccProgram cc) [])
|
|
| 190 | 179 | -- Always add the -E flag to the CPP, regardless of the user options
|
| 191 | - let cppProgram = addFlagIfNew "-E" cpp2
|
|
| 180 | + let cppProgram = addFlagIfNew "-E" cpp
|
|
| 192 | 181 | return Cpp{cppProgram}
|
| 193 | 182 | |
| 194 | 183 | --------------------------------------------------------------------------------
|