Use Cabal directly in place of ghc-cabal + make build root configurable (#531)
[hadrian.git] / src / Main.hs
1 module Main (main) where
2
3 import Development.Shake
4 import Hadrian.Expression
5 import Hadrian.Utilities
6
7 import qualified Base
8 import qualified CommandLine
9 import qualified Environment
10 import qualified Rules
11 import qualified Rules.Clean
12 import qualified Rules.Documentation
13 import qualified Rules.SourceDist
14 import qualified Rules.Selftest
15 import qualified Rules.Test
16 import qualified UserSettings
17
18 main :: IO ()
19 main = do
20 -- Provide access to command line arguments and some user settings through
21 -- Shake's type-indexed map 'shakeExtra'.
22 argsMap <- CommandLine.cmdLineArgsMap
23 let extra = insertExtra UserSettings.buildProgressColour
24 $ insertExtra UserSettings.successColour
25 $ insertExtra (VerboseCommand UserSettings.verboseCommand) argsMap
26
27 BuildRoot buildRoot = CommandLine.lookupBuildRoot argsMap
28
29 rebuild = [ (RebuildLater, buildRoot -/- "stage0//*")
30 | CommandLine.lookupFreeze1 argsMap ]
31
32 options :: ShakeOptions
33 options = shakeOptions
34 { shakeChange = ChangeModtimeAndDigest
35 , shakeFiles = buildRoot -/- Base.shakeFilesDir
36 , shakeProgress = progressSimple
37 , shakeRebuild = rebuild
38 , shakeTimings = True
39 , shakeExtra = extra }
40
41 rules :: Rules ()
42 rules = do
43 Rules.buildRules
44 Rules.Documentation.documentationRules
45 Rules.Clean.cleanRules
46 Rules.oracleRules
47 Rules.Selftest.selftestRules
48 Rules.SourceDist.sourceDistRules
49 Rules.Test.testRules
50 Rules.topLevelTargets
51
52 shakeArgsWith options CommandLine.optDescrs $ \_ targets -> do
53 Environment.setupEnvironment
54 return . Just $ if null targets
55 then rules
56 else want targets >> withoutActions rules