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