summaryrefslogtreecommitdiff
path: root/hadrian/src/Settings/Builders/DeriveConstants.hs
blob: 6801dc05fbe1bc8076c2d15ae9192f1cebbd7530 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Settings.Builders.DeriveConstants (
    deriveConstantsBuilderArgs, deriveConstantsPairs
    ) where

import Builder
import Settings.Builders.Common

deriveConstantsPairs :: [(String, String)]
deriveConstantsPairs =
  [ ("DerivedConstants.h", "--gen-header")
  ]

deriveConstantsBuilderArgs :: Args
deriveConstantsBuilderArgs = builder DeriveConstants ? do
    cFlags <- includeCcArgs
    outs   <- getOutputs
    let (outputFile, mode, tempDir) = case outs of
            [ofile, mode, tmpdir] -> (ofile,mode,tmpdir)
            [ofile, tmpdir]
               | Just mode <- lookup (takeFileName ofile) deriveConstantsPairs
               -> (ofile, mode, tmpdir)
               | otherwise
               -> error $ "DeriveConstants: invalid output file, got " ++ show (takeFileName ofile)
            _  -> error $ "DeriveConstants: unexpected outputs, got " ++ show outs
    mconcat
        [ arg mode
        , arg "-o", arg outputFile
        , arg "--tmpdir", arg tempDir
        , arg "--gcc-program", arg =<< getBuilderPath (Cc CompileC Stage1)
        , pure $ concatMap (\a -> ["--gcc-flag", a]) cFlags
        , arg "--nm-program", arg =<< getBuilderPath Nm
        , isSpecified Objdump ? mconcat [ arg "--objdump-program"
                                        , arg =<< getBuilderPath Objdump ]
        , arg "--target-os", arg =<< getSetting TargetOs ]

includeCcArgs :: Args
includeCcArgs = do
    stage <- getStage
    libPath <- expr $ stageLibPath stage
    mconcat [ cArgs
            , cWarnings
            , getSettingList $ ConfCcArgs Stage1
            , flag GhcUnregisterised ? arg "-DUSE_MINIINTERPRETER"
            , arg "-Irts"
            , arg "-Irts/include"
            , arg $ "-I" ++ libPath
            , notM targetSupportsSMP ? arg "-DNOSMP"
            , arg "-fcommon" ]