Skip to content
Snippets Groups Projects
Commit 662d351b authored by Matthew Pickering's avatar Matthew Pickering Committed by Marge Bot
Browse files

ghc-toolchain: Match CPP args with configure script

At the moment we need ghc-toolchain to precisely match the output as
provided by the normal configure script. The normal configure script
(FP_HSCPP_CMD_WITH_ARGS) branches on whether we are using clang or gcc
so we match that logic exactly in ghc-toolchain.

The old implementation (which checks if certain flags are supported) is
better but for now we have to match to catch any potential errors in the
configuration.

Ticket: #23720
parent bdab6898
No related branches found
No related tags found
No related merge requests found
......@@ -4,12 +4,13 @@ module GHC.Toolchain.Tools.Cpp (HsCpp(..), findHsCpp, Cpp(..), findCpp) where
import Control.Monad
import System.FilePath
import Data.List(isInfixOf)
import GHC.Toolchain.Prelude
import GHC.Toolchain.Program
import GHC.Toolchain.Utils (withTempDir)
import GHC.Toolchain.Tools.Cc
import GHC.Toolchain.Utils (withTempDir)
newtype Cpp = Cpp { cppProgram :: Program
}
......@@ -39,10 +40,31 @@ findHsCpp progOpt cc = checking "for Haskell C preprocessor" $ do
-- Haskell source.
findHsCppArgs :: Program -> M [String]
findHsCppArgs cpp = withTempDir $ \dir -> do
let tmp_c = dir </> "tmp.c"
writeFile tmp_c ""
(_, stdout0, stderr0) <- readProgram cpp ["-x", "c", tmp_c, "-dM", "-E"]
if "__clang__" `isInfixOf` stdout0 || "__clang__" `isInfixOf` stderr0
then return ["-undef", "-traditional", "-Wno-invalid-pp-token", "-Wno-unicode", "-Wno-trigraphs"]
else do
(_, stdout1, stderr1) <- readProgram cpp ["-v"]
if "gcc" `isInfixOf` stdout1 || "gcc" `isInfixOf` stderr1
then return ["-undef", "-traditional"]
else do
logDebug "Can't recognize your CPP program, you may need to set --with-hs-cpp-flags=FLAGS explicitly"
return []
{- TODO: We want to just check which flags are accepted rather than branching on which compiler
we are using but this does not match what ./configure does (#23720)
When we retire configure then this more precise logic can be reinstated.
withTmpDir $ \dir -> do
let tmp_h = dir </> "tmp.h"
-- Werror to ensure that unrecognized warnings result in an error
checkFlag flag =
let checkFlag flag =
checking ("for "++flag++" support") $ callProgram cpp ["-Werror", flag, tmp_h]
tryFlag flag =
......@@ -56,6 +78,7 @@ findHsCppArgs cpp = withTempDir $ \dir -> do
, tryFlag "-Wno-unicode"
, tryFlag "-Wno-trigraphs"
]
-}
----- C preprocessor -----
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment