e40f20d16f9cab8eba3d556015d42e92118cfa94
[ghc.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 Settings.Flavours.QuickCross
17 import UserSettings
18
19 getArgs :: Args
20 getArgs = expr flavour >>= args
21
22 getLibraryWays :: Ways
23 getLibraryWays = expr flavour >>= libraryWays
24
25 getRtsWays :: Ways
26 getRtsWays = expr flavour >>= rtsWays
27
28 stagePackages :: Stage -> Action [Package]
29 stagePackages stage = do
30 f <- flavour
31 packages f stage
32
33 hadrianFlavours :: [Flavour]
34 hadrianFlavours =
35 [ defaultFlavour, developmentFlavour Stage1, developmentFlavour Stage2
36 , performanceFlavour, profiledFlavour, quickFlavour, quickestFlavour
37 , quickCrossFlavour ]
38
39 flavour :: Action Flavour
40 flavour = do
41 flavourName <- fromMaybe "default" <$> cmdFlavour
42 let unknownFlavour = error $ "Unknown build flavour: " ++ flavourName
43 flavours = hadrianFlavours ++ userFlavours
44 return $ fromMaybe unknownFlavour $ find ((== flavourName) . name) flavours
45
46 integerLibraryName :: Action String
47 integerLibraryName = pkgName <$> (integerLibrary =<< flavour)
48
49 programContext :: Stage -> Package -> Action Context
50 programContext stage pkg = do
51 profiled <- ghcProfiled <$> flavour
52 return $ if pkg == ghc && profiled && stage > Stage0
53 then Context stage pkg profiling
54 else vanillaContext stage pkg
55
56 -- TODO: switch to Set Package as the order of packages should not matter?
57 -- Otherwise we have to keep remembering to sort packages from time to time.
58 knownPackages :: [Package]
59 knownPackages = sort $ ghcPackages ++ userPackages
60
61 -- TODO: Speed up? Switch to Set?
62 -- Note: this is slow but we keep it simple as there are just ~50 packages
63 findPackageByName :: PackageName -> Maybe Package
64 findPackageByName name = find (\pkg -> pkgName pkg == name) knownPackages
65
66 -- | Install's DESTDIR setting.
67 getDestDir :: Action FilePath
68 getDestDir = fromMaybe "" <$> cmdInstallDestDir