Squashed 'hadrian/' content from commit 438dc57
[ghc.git] / src / Settings / Builders / GhcCabal.hs
1 module Settings.Builders.GhcCabal (
2 ghcCabalBuilderArgs
3 ) where
4
5 import Hadrian.Haskell.Cabal
6
7 import Context
8 import Flavour
9 import Settings.Builders.Common
10
11 ghcCabalBuilderArgs :: Args
12 ghcCabalBuilderArgs = builder GhcCabal ? do
13 verbosity <- expr getVerbosity
14 top <- expr topDirectory
15 path <- getBuildPath
16 notStage0 ? expr (need inplaceLibCopyTargets)
17 mconcat [ arg "configure"
18 , arg =<< pkgPath <$> getPackage
19 , arg $ top -/- path
20 , withStaged $ Ghc CompileHs
21 , withStaged (GhcPkg Update)
22 , bootPackageDatabaseArgs
23 , libraryArgs
24 , configureArgs
25 , bootPackageConstraints
26 , withStaged $ Cc CompileC
27 , notStage0 ? with Ld
28 , withStaged (Ar Pack)
29 , with Alex
30 , with Happy
31 , verbosity < Chatty ? pure [ "-v0", "--configure-option=--quiet"
32 , "--configure-option=--disable-option-checking" ] ]
33
34 -- TODO: Isn't vanilla always built? If yes, some conditions are redundant.
35 -- TODO: Need compiler_stage1_CONFIGURE_OPTS += --disable-library-for-ghci?
36 libraryArgs :: Args
37 libraryArgs = do
38 ways <- getLibraryWays
39 withGhci <- expr ghcWithInterpreter
40 dynPrograms <- dynamicGhcPrograms <$> expr flavour
41 pure [ if vanilla `elem` ways
42 then "--enable-library-vanilla"
43 else "--disable-library-vanilla"
44 , if vanilla `elem` ways && withGhci && not dynPrograms
45 then "--enable-library-for-ghci"
46 else "--disable-library-for-ghci"
47 , if profiling `elem` ways
48 then "--enable-library-profiling"
49 else "--disable-library-profiling"
50 , if dynamic `elem` ways
51 then "--enable-shared"
52 else "--disable-shared" ]
53
54 -- TODO: LD_OPTS?
55 configureArgs :: Args
56 configureArgs = do
57 top <- expr topDirectory
58 root <- getBuildRoot
59 let conf key expr = do
60 values <- unwords <$> expr
61 not (null values) ?
62 arg ("--configure-option=" ++ key ++ "=" ++ values)
63 cFlags = mconcat [ remove ["-Werror"] cArgs
64 , getStagedSettingList ConfCcArgs
65 , arg $ "-I" ++ top -/- root -/- generatedDir ]
66 ldFlags = ldArgs <> (getStagedSettingList ConfGccLinkerArgs)
67 cppFlags = cppArgs <> (getStagedSettingList ConfCppArgs)
68 cldFlags <- unwords <$> (cFlags <> ldFlags)
69 mconcat
70 [ conf "CFLAGS" cFlags
71 , conf "LDFLAGS" ldFlags
72 , conf "CPPFLAGS" cppFlags
73 , not (null cldFlags) ? arg ("--gcc-options=" ++ cldFlags)
74 , conf "--with-iconv-includes" $ arg =<< getSetting IconvIncludeDir
75 , conf "--with-iconv-libraries" $ arg =<< getSetting IconvLibDir
76 , conf "--with-gmp-includes" $ arg =<< getSetting GmpIncludeDir
77 , conf "--with-gmp-libraries" $ arg =<< getSetting GmpLibDir
78 , conf "--with-curses-libraries" $ arg =<< getSetting CursesLibDir
79 , crossCompiling ? (conf "--host" $ arg =<< getSetting TargetPlatformFull)
80 , conf "--with-cc" $ arg =<< getBuilderPath . (Cc CompileC) =<< getStage ]
81
82 bootPackageConstraints :: Args
83 bootPackageConstraints = stage0 ? do
84 bootPkgs <- expr $ stagePackages Stage0
85 let pkgs = filter (\p -> p /= compiler && isLibrary p) bootPkgs
86 constraints <- expr $ fmap catMaybes $ forM (sort pkgs) $ \pkg -> do
87 version <- traverse pkgVersion (pkgCabalFile pkg)
88 return $ fmap ((pkgName pkg ++ " == ") ++) version
89 pure $ concat [ ["--constraint", c] | c <- constraints ]
90
91 cppArgs :: Args
92 cppArgs = do
93 root <- getBuildRoot
94 arg $ "-I" ++ root -/- generatedDir
95
96 withBuilderKey :: Builder -> String
97 withBuilderKey b = case b of
98 Ar _ _ -> "--with-ar="
99 Ld -> "--with-ld="
100 Cc _ _ -> "--with-gcc="
101 Ghc _ _ -> "--with-ghc="
102 Alex -> "--with-alex="
103 Happy -> "--with-happy="
104 GhcPkg _ _ -> "--with-ghc-pkg="
105 _ -> error $ "withBuilderKey: not supported builder " ++ show b
106
107 -- Expression 'with Alex' appends "--with-alex=/path/to/alex" and needs Alex.
108 with :: Builder -> Args
109 with b = do
110 path <- getBuilderPath b
111 if (null path) then mempty else do
112 top <- expr topDirectory
113 expr $ needBuilder b
114 arg $ withBuilderKey b ++ unifyPath (top </> path)
115
116 withStaged :: (Stage -> Builder) -> Args
117 withStaged sb = with . sb =<< getStage
118