Refactor package-specific settings (#622)
[hadrian.git] / src / Rules / Configure.hs
1 module Rules.Configure (configureRules) where
2
3 import qualified System.Info.Extra as System
4
5 import Base
6 import Builder
7 import CommandLine
8 import Context
9 import GHC
10 import Target
11 import Utilities
12
13 -- TODO: Make this list complete.
14 -- | Files generated by running the @configure@ script.
15 configureResults :: [FilePath]
16 configureResults =
17 [ configFile, "settings", configH, "compiler/ghc.cabal", "rts/rts.cabal"]
18
19 configureRules :: Rules ()
20 configureRules = do
21 configureResults &%> \outs -> do
22 skip <- not <$> cmdConfigure
23 if skip
24 then unlessM (doesFileExist configFile) $
25 error $ "Configuration file " ++ configFile ++ " is missing.\n"
26 ++ "Run the configure script manually or let Hadrian run it "
27 ++ "automatically by passing the flag --configure."
28 else do
29 -- We cannot use windowsHost here due to a cyclic dependency.
30 when System.isWindows $ do
31 putBuild "| Checking for Windows tarballs..."
32 quietly $ cmd ["bash", "mk/get-win32-tarballs.sh", "download", System.arch]
33 let srcs = map (<.> "in") outs
34 context = vanillaContext Stage0 compiler
35 need srcs
36 build $ target context (Configure ".") srcs outs
37 -- We need to copy the directory with unpacked Windows tarball to
38 -- the build directory, so that the built GHC has access to it.
39 -- See https://github.com/snowleopard/hadrian/issues/564.
40 when System.isWindows $ do
41 root <- buildRoot
42 copyDirectory "inplace/mingw" (root -/- "mingw")
43
44 ["configure", configH <.> "in"] &%> \_ -> do
45 skip <- not <$> cmdConfigure
46 if skip
47 then unlessM (doesFileExist "configure") $
48 error $ "The configure script is missing.\nRun the boot script "
49 ++ "manually let Hadrian run it automatically by passing the "
50 ++ "flag --configure."
51 else do
52 need ["configure.ac"]
53 putBuild "| Running boot..."
54 verbosity <- getVerbosity
55 quietly $ cmd [EchoStdout (verbosity >= Loud)] "python3 boot --hadrian"