summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRodrigo Mesquita <rodrigo.m.mesquita@gmail.com>2023-05-15 23:29:53 +0100
committerRodrigo Mesquita <rodrigo.m.mesquita@gmail.com>2023-05-15 23:29:53 +0100
commit2fff8d824663f128ca31420b1fdcbf50e9af1df4 (patch)
treed361e29cb2087a4c878adc8cd1828d3f253cd6d7
parent1e4e0543b518b047f253d3c68893ca1b63e23f05 (diff)
downloadhaskell-wip/toolchain-selection.tar.gz
-rw-r--r--utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs35
-rw-r--r--utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs2
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; }"