d1404a0f9fc830b7feab3ac8ee10066460575f97
[hadrian.git] / src / Settings / Builders / Ghc.hs
1 module Settings.Builders.Ghc (ghcArgs, ghcMArgs, commonGhcArgs) where
2
3 import Expression
4 import Predicates (stagedBuilder, splitObjects, stage0)
5 import Oracles
6 import Settings
7
8 -- TODO: add support for -dyno
9 -- $1/$2/build/%.$$($3_o-bootsuf) : $1/$4/%.hs-boot
10 -- $$(call cmd,$1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -c $$< -o $$@
11 -- $$(if $$(findstring YES,$$($1_$2_DYNAMIC_TOO)),-dyno
12 -- $$(addsuffix .$$(dyn_osuf)-boot,$$(basename $$@)))
13 ghcArgs :: Args
14 ghcArgs = stagedBuilder Ghc ? do
15 file <- getFile
16 srcs <- getSources
17 mconcat [ commonGhcArgs
18 , arg "-c", append srcs
19 , arg "-o", arg file ]
20
21 ghcMArgs :: Args
22 ghcMArgs = stagedBuilder GhcM ? do
23 ways <- getWays
24 file <- getFile
25 srcs <- getSources
26 mconcat [ arg "-M"
27 , commonGhcArgs
28 , arg "-dep-makefile", arg file
29 , append $ concat [ ["-dep-suffix", wayPrefix w] | w <- ways ]
30 , append srcs ]
31
32 -- This is included into ghcArgs, ghcMArgs and haddockArgs.
33 commonGhcArgs :: Args
34 commonGhcArgs = do
35 way <- getWay
36 hsArgs <- getPkgDataList HsArgs
37 cppArgs <- getPkgDataList CppArgs
38 path <- getTargetPath
39 let buildPath = path -/- "build"
40 mconcat [ arg "-hisuf", arg $ hisuf way
41 , arg "-osuf" , arg $ osuf way
42 , arg "-hcsuf", arg $ hcsuf way
43 , wayGhcArgs
44 , packageGhcArgs
45 , includeGhcArgs
46 , append hsArgs
47 , append $ map ("-optP" ++) cppArgs
48 , arg "-odir" , arg buildPath
49 , arg "-stubdir" , arg buildPath
50 , arg "-hidir" , arg buildPath
51 , splitObjects ? arg "-split-objs"
52 , arg "-rtsopts" ] -- TODO: is this needed?
53
54 -- TODO: do '-ticky' in all debug ways?
55 wayGhcArgs :: Args
56 wayGhcArgs = do
57 way <- getWay
58 mconcat [ if (Dynamic `wayUnit` way)
59 then append ["-fPIC", "-dynamic"]
60 else arg "-static"
61 , (Threaded `wayUnit` way) ? arg "-optc-DTHREADED_RTS"
62 , (Debug `wayUnit` way) ? arg "-optc-DDEBUG"
63 , (Profiling `wayUnit` way) ? arg "-prof"
64 , (Logging `wayUnit` way) ? arg "-eventlog"
65 , (Parallel `wayUnit` way) ? arg "-parallel"
66 , (GranSim `wayUnit` way) ? arg "-gransim"
67 , (way == debug || way == debugDynamic) ?
68 append ["-ticky", "-DTICKY_TICKY"] ]
69
70 packageGhcArgs :: Args
71 packageGhcArgs = do
72 stage <- getStage
73 supportsPackageKey <- getFlag SupportsPackageKey
74 pkgKey <- getPkgData PackageKey
75 pkgDepIds <- getPkgDataList DepIds
76 mconcat
77 [ arg "-hide-all-packages"
78 , arg "-no-user-package-db"
79 , arg "-include-pkg-deps"
80 , stage0 ? arg "-package-db libraries/bootstrapping.conf"
81 , if supportsPackageKey || stage /= Stage0
82 then arg $ "-this-package-key " ++ pkgKey
83 else arg $ "-package-name " ++ pkgKey
84 , append $ map ("-package-id " ++) pkgDepIds ]
85
86 includeGhcArgs :: Args
87 includeGhcArgs = do
88 pkg <- getPackage
89 path <- getTargetPath
90 srcDirs <- getPkgDataList SrcDirs
91 incDirs <- getPkgDataList IncludeDirs
92 cppArgs <- getPkgDataList CppArgs
93 let buildPath = path -/- "build"
94 autogenPath = buildPath -/- "autogen"
95 mconcat
96 [ arg "-i"
97 , arg $ "-i" ++ buildPath
98 , arg $ "-i" ++ autogenPath
99 , arg $ "-I" ++ buildPath
100 , arg $ "-I" ++ autogenPath
101 , append [ "-i" ++ pkgPath pkg -/- dir | dir <- srcDirs ]
102 , append [ "-I" ++ pkgPath pkg -/- dir | dir <- incDirs ]
103 , arg "-optP-include", arg $ "-optP" ++ autogenPath -/- "cabal_macros.h"
104 , append $ map ("-optP" ++) cppArgs ]
105
106 -- TODO: see ghc.mk
107 -- # And then we strip it out again before building the package:
108 -- define libraries/ghc-prim_PACKAGE_MAGIC
109 -- libraries/ghc-prim_dist-install_MODULES := $$(filter-out GHC.Prim,$$(libraries/ghc-prim_dist-install_MODULES))
110 -- endef