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