Don't need the GMP library when building with integerSimple
[hadrian.git] / src / Settings / Builders / Ghc.hs
1 module Settings.Builders.Ghc (ghcBuilderArgs, ghcMBuilderArgs, haddockGhcArgs) where
2
3 import Flavour
4 import GHC
5 import Settings.Builders.Common
6
7 ghcBuilderArgs :: Args
8 ghcBuilderArgs = (builder (Ghc CompileHs) ||^ builder (Ghc LinkHs)) ? do
9 needTouchy
10 mconcat [ arg "-Wall"
11 , commonGhcArgs
12 , splitObjectsArgs
13 , ghcLinkArgs
14 , builder (Ghc CompileHs) ? arg "-c"
15 , append =<< getInputs
16 , arg "-o", arg =<< getOutput ]
17
18 ghcLinkArgs :: Args
19 ghcLinkArgs = builder (Ghc LinkHs) ? do
20 stage <- getStage
21 pkg <- getPackage
22 libs <- getPkgDataList DepExtraLibs
23 libDirs <- getPkgDataList DepLibDirs
24 gmpLibs <- if stage > Stage0 && integerLibrary flavour == integerGmp
25 then do -- TODO: get this data more gracefully
26 let strip = fromMaybe "" . stripPrefix "extra-libraries: "
27 buildInfo <- lift $ readFileLines gmpBuildInfoPath
28 return $ concatMap (words . strip) buildInfo
29 else return []
30 mconcat [ arg "-no-auto-link-packages"
31 , nonHsMainPackage pkg ? arg "-no-hs-main"
32 , append [ "-optl-l" ++ lib | lib <- libs ++ gmpLibs ]
33 , append [ "-optl-L" ++ unifyPath dir | dir <- libDirs ] ]
34
35 needTouchy :: ReaderT Target Action ()
36 needTouchy = notStage0 ? do
37 maybePath <- lift $ programPath (vanillaContext Stage0 touchy)
38 lift . whenJust maybePath $ \path -> need [path]
39
40 splitObjectsArgs :: Args
41 splitObjectsArgs = splitObjects flavour ? do
42 lift $ need [ghcSplit]
43 arg "-split-objs"
44
45 ghcMBuilderArgs :: Args
46 ghcMBuilderArgs = builder (Ghc FindHsDependencies) ? do
47 ways <- getLibraryWays
48 mconcat [ arg "-M"
49 , commonGhcArgs
50 , arg "-include-pkg-deps"
51 , arg "-dep-makefile", arg =<< getOutput
52 , append $ concat [ ["-dep-suffix", wayPrefix w] | w <- ways ]
53 , append =<< getInputs ]
54
55 haddockGhcArgs :: Args
56 haddockGhcArgs = mconcat [ commonGhcArgs, append =<< getPkgDataList HsArgs ]
57
58 -- This is included into ghcBuilderArgs, ghcMBuilderArgs and haddockGhcArgs.
59 commonGhcArgs :: Args
60 commonGhcArgs = do
61 way <- getWay
62 path <- getBuildPath
63 confCc <- getSettingList . ConfCcArgs =<< getStage
64 confCpp <- getSettingList . ConfCppArgs =<< getStage
65 cppArgs <- getPkgDataList CppArgs
66 mconcat [ arg "-hisuf", arg $ hisuf way
67 , arg "-osuf" , arg $ osuf way
68 , arg "-hcsuf", arg $ hcsuf way
69 , wayGhcArgs
70 , packageGhcArgs
71 , includeGhcArgs
72 , append $ map ("-optc" ++) confCc
73 , append $ map ("-optP" ++) confCpp
74 , append $ map ("-optP" ++) cppArgs
75 , arg "-odir" , arg path
76 , arg "-hidir" , arg path
77 , arg "-stubdir" , arg path
78 , (not . nonHsMainPackage) <$> getPackage ? arg "-rtsopts" ]
79
80 -- TODO: Do '-ticky' in all debug ways?
81 wayGhcArgs :: Args
82 wayGhcArgs = do
83 way <- getWay
84 mconcat [ if (Dynamic `wayUnit` way)
85 then append ["-fPIC", "-dynamic"]
86 else arg "-static"
87 , (Threaded `wayUnit` way) ? arg "-optc-DTHREADED_RTS"
88 , (Debug `wayUnit` way) ? arg "-optc-DDEBUG"
89 , (Profiling `wayUnit` way) ? arg "-prof"
90 , (Logging `wayUnit` way) ? arg "-eventlog"
91 , (way == debug || way == debugDynamic) ?
92 append ["-ticky", "-DTICKY_TICKY"] ]
93
94 packageGhcArgs :: Args
95 packageGhcArgs = do
96 pkg <- getPackage
97 compId <- getPkgData ComponentId
98 pkgDepIds <- getPkgDataList DepIds
99 -- FIXME: Get rid of to-be-deprecated -this-package-key.
100 thisArg <- do
101 not0 <- notStage0
102 unit <- getFlag SupportsThisUnitId
103 return $ if not0 || unit then "-this-unit-id " else "-this-package-key "
104 mconcat [ arg "-hide-all-packages"
105 , arg "-no-user-package-db"
106 , bootPackageDatabaseArgs
107 , isLibrary pkg ? arg (thisArg ++ compId)
108 , append $ map ("-package-id " ++) pkgDepIds ]
109
110 includeGhcArgs :: Args
111 includeGhcArgs = do
112 pkg <- getPackage
113 path <- getBuildPath
114 context <- getContext
115 srcDirs <- getPkgDataList SrcDirs
116 mconcat [ arg "-i"
117 , arg $ "-i" ++ path
118 , arg $ "-i" ++ autogenPath context
119 , append [ "-i" ++ pkgPath pkg -/- dir | dir <- srcDirs ]
120 , cIncludeArgs
121 , arg $ "-I" ++ generatedPath
122 , arg $ "-optc-I" ++ generatedPath
123 , (not $ nonCabalContext context) ?
124 append [ "-optP-include"
125 , "-optP" ++ autogenPath context -/- "cabal_macros.h" ] ]