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