summaryrefslogtreecommitdiff
path: root/hadrian/src/Rules/Configure.hs
blob: 10870b3e7cdade72e76c60a58528a79c9d95d417 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
module Rules.Configure (configureRules) where

import Base
import Builder
import CommandLine
import Context
import Packages
import Target
import Utilities

import qualified System.Info.Extra as System

-- | Files generated by running the @configure@ script.
configureResults :: [FilePath]
configureResults =
    [ configFile
    , configH
    , "compiler/ghc.cabal"
    , "rts/rts.cabal"
    , "ghc/ghc-bin.cabal"
    , "utils/iserv/iserv.cabal"
    , "utils/iserv-proxy/iserv-proxy.cabal"
    , "utils/remote-iserv/remote-iserv.cabal"
    , "utils/runghc/runghc.cabal"
    , "utils/gen-dll/gen-dll.cabal"
    , "libraries/ghc-boot/ghc-boot.cabal"
    , "libraries/ghc-boot-th/ghc-boot-th.cabal"
    , "libraries/ghci/ghci.cabal"
    , "libraries/ghc-heap/ghc-heap.cabal"
    , "libraries/libiserv/libiserv.cabal"
    , "libraries/template-haskell/template-haskell.cabal"
    , "docs/users_guide/ghc_config.py"
    , "docs/index.html"
    , "libraries/prologue.txt"
    , "distrib/configure.ac"
    ]

configureRules :: Rules ()
configureRules = do
    configureResults &%> \outs -> do
        -- Do not cache the results. The true dependencies of the configure
        -- script are not tracked. This includes e.g. the ghc source path.
        historyDisable

        skip <- not <$> cmdConfigure
        if skip
        then unlessM (doesFileExist configFile) $
            error $ "Configuration file " ++ configFile ++ " is missing.\n"
                ++ "Run the configure script manually or let Hadrian run it "
                ++ "automatically by passing the flag --configure."
        else do
            -- We cannot use windowsHost here due to a cyclic dependency.
            when windowsHost $ do
                putBuild "| Checking for Windows tarballs..."
                pythonPath <- builderPath Python
                quietly $ cmd [pythonPath, "mk/get-win32-tarballs.py", "download", System.arch]
            let srcs    = map (<.> "in") outs
                context = vanillaContext Stage0 compiler
            need srcs
            build $ target context (Configure ".") srcs outs
            -- TODO: This is fragile: we should remove this from behind the
            -- @--configure@ flag and add a proper dependency tracking.
            -- We need to copy the directory with unpacked Windows tarball to
            -- the build directory, so that the built GHC has access to it.
            -- See https://github.com/snowleopard/hadrian/issues/564.
            when windowsHost $ do
                root <- buildRoot
                copyDirectory "inplace/mingw" (root -/- "mingw")
                mingwFiles <- liftIO $ getDirectoryFilesIO "." [root -/- "mingw/**"]
                produces mingwFiles

    ["configure", configH <.> "in"] &%> \_ -> do
        skip <- not <$> cmdConfigure
        if skip
        then unlessM (doesFileExist "configure") $
            error $ "The configure script is missing.\nRun the boot script "
                ++ "manually let Hadrian run it automatically by passing the "
                ++ "flag --configure."
        else do
            need ["configure.ac"]
            putBuild "| Running boot..."
            verbosity <- getVerbosity
            quietly $ cmd [EchoStdout (verbosity >= Loud)] "python3 boot --hadrian"