Minor revision of install stages
[hadrian.git] / src / Settings.hs
1 module Settings (
2 getArgs, getLibraryWays, getRtsWays, flavour, knownPackages,
3 findPackageByName, getPkgData, getPkgDataList, isLibrary, stagePackages,
4 programContext, integerLibraryName, getDestDir
5 ) where
6
7 import CommandLine
8 import Expression
9 import Flavour
10 import {-# SOURCE #-} Settings.Default
11 import Settings.Flavours.Development
12 import Settings.Flavours.Performance
13 import Settings.Flavours.Profiled
14 import Settings.Flavours.Quick
15 import Settings.Flavours.Quickest
16 import UserSettings
17
18 getArgs :: Args
19 getArgs = expr flavour >>= args
20
21 getLibraryWays :: Ways
22 getLibraryWays = expr flavour >>= libraryWays
23
24 getRtsWays :: Ways
25 getRtsWays = expr flavour >>= rtsWays
26
27 stagePackages :: Stage -> Action [Package]
28 stagePackages stage = do
29 f <- flavour
30 packages f stage
31
32 hadrianFlavours :: [Flavour]
33 hadrianFlavours =
34 [ defaultFlavour, developmentFlavour Stage1, developmentFlavour Stage2
35 , performanceFlavour, profiledFlavour, quickFlavour, quickestFlavour ]
36
37 flavour :: Action Flavour
38 flavour = do
39 flavourName <- fromMaybe "default" <$> cmdFlavour
40 let unknownFlavour = error $ "Unknown build flavour: " ++ flavourName
41 flavours = hadrianFlavours ++ userFlavours
42 return $ fromMaybe unknownFlavour $ find ((== flavourName) . name) flavours
43
44 integerLibraryName :: Action String
45 integerLibraryName = pkgName <$> (integerLibrary =<< flavour)
46
47 programContext :: Stage -> Package -> Action Context
48 programContext stage pkg = do
49 profiled <- ghcProfiled <$> flavour
50 return $ if pkg == ghc && profiled && stage > Stage0
51 then Context stage pkg profiling
52 else vanillaContext stage pkg
53
54 -- TODO: switch to Set Package as the order of packages should not matter?
55 -- Otherwise we have to keep remembering to sort packages from time to time.
56 knownPackages :: [Package]
57 knownPackages = sort $ ghcPackages ++ userPackages
58
59 -- TODO: Speed up? Switch to Set?
60 -- Note: this is slow but we keep it simple as there are just ~50 packages
61 findPackageByName :: PackageName -> Maybe Package
62 findPackageByName name = find (\pkg -> pkgName pkg == name) knownPackages
63
64 -- | Install's DESTDIR setting.
65 getDestDir :: Action FilePath
66 getDestDir = fromMaybe "" <$> cmdInstallDestDir