diff options
-rw-r--r-- | utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs | 35 | ||||
-rw-r--r-- | utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs | 2 |
2 files changed, 21 insertions, 16 deletions
diff --git a/utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs b/utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs index a9fe18bd1d..4d0a3ddef5 100644 --- a/utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs +++ b/utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs @@ -3,9 +3,11 @@ module GHC.Toolchain.Tools.Cpp (Cpp(..), findCpp) where import Control.Monad +import System.FilePath import GHC.Toolchain.Prelude import GHC.Toolchain.Program +import GHC.Toolchain.Utils (withTempDir) import GHC.Toolchain.Tools.Cc @@ -30,19 +32,22 @@ findCpp progOpt cc = checking "for C preprocessor" $ do -- | Given a C preprocessor, figure out how it should be invoked to preprocess -- Haskell source. findHsCppArgs :: Program -> M [String] -findHsCppArgs cpp = - concat <$> sequence - [ ["-traditional"] <$ checkFlag "-traditional" - , tryFlag "-undef" - , tryFlag "-Wno-invalid-pp-token" - , tryFlag "-Wno-unicode" - , tryFlag "-Wno-trigraphs" - ] - where - -- Werror to ensure that unrecognized warnings result in an error - checkFlag flag = - checking ("for "++flag++" support") $ callProgram cpp ["-E", "-Werror", flag, "/dev/null"] - - tryFlag flag = - ([flag] <$ checkFlag flag) <|> return [] +findHsCppArgs cpp = withTempDir $ \dir -> do + let tmp_h = dir </> "tmp.h" + + -- Werror to ensure that unrecognized warnings result in an error + checkFlag flag = + checking ("for "++flag++" support") $ callProgram cpp ["-Werror", flag, tmp_h] + + tryFlag flag = + ([flag] <$ checkFlag flag) <|> return [] + + writeFile tmp_h "" + concat <$> sequence + [ ["-traditional"] <$ checkFlag "-traditional" + , tryFlag "-undef" + , tryFlag "-Wno-invalid-pp-token" + , tryFlag "-Wno-unicode" + , tryFlag "-Wno-trigraphs" + ] diff --git a/utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs b/utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs index ec0b051c09..71f53dba54 100644 --- a/utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs +++ b/utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs @@ -100,7 +100,7 @@ checkSupportsNoPie ccLink = checking "whether the cc linker supports -no-pie" $ checkSupportsCompactUnwind :: Cc -> Program -> M Bool checkSupportsCompactUnwind cc ccLink = checking "whether the cc linker understands -no_compact_unwind" $ withTempDir $ \dir -> do - let test_o = dir </> "o" + let test_o = dir </> "test.o" test2_o = dir </> "test2.o" compileC cc test_o "int foo() { return 0; }" |