When registering base during installation, don't hide GHC.Prim
[ghc-hetmet.git] / libraries / installPackage.hs
1
2 import Distribution.PackageDescription
3 import Distribution.Setup
4 import Distribution.Simple
5 import Distribution.Simple.Configure
6 import Distribution.Simple.LocalBuildInfo
7 import Distribution.Simple.Utils
8 import Distribution.Verbosity
9 import System.Environment
10 import System.Info
11
12 main :: IO ()
13 main = do args <- getArgs
14           case args of
15               pref : ghcpkg : args' ->
16                   let verbosity = case args' of
17                               [] -> normal
18                               ['-':'v':v] ->
19                                   let m = case v of
20                                               "" -> Nothing
21                                               _ -> Just v
22                                   in flagToVerbosity m
23                               _ -> error ("Bad arguments: " ++ show args)
24                   in doit pref ghcpkg verbosity
25               _ ->
26                   error "Missing arguments"
27
28 doit :: FilePath -> FilePath -> Verbosity -> IO ()
29 doit pref ghcpkg verbosity =
30        do let userHooks = simpleUserHooks
31               copyFlags = CopyFlags {
32                               copyDest = NoCopyDest,
33                               copyVerbose = verbosity
34                           }
35               registerFlags = RegisterFlags {
36                                   regUser = MaybeUserGlobal,
37                                   regGenScript = False,
38                                   regInPlace = False,
39                                   regWithHcPkg = Just ghcpkg,
40                                   regVerbose = verbosity
41                               }
42           pdFile <- defaultPackageDesc verbosity
43           pd <- readPackageDescription verbosity pdFile
44           lbi <- getPersistBuildConfig
45           let -- XXX These are almighty hacks, shadowing the base
46               -- Setup.hs hacks
47               extraExtraLibs = if (os == "mingw32") &&
48                                   (pkgName (package pd) == "base")
49                                then ["wsock32", "msvcrt", "kernel32",
50                                      "user32", "shell32"]
51                                else []
52               mkLib filt = case library pd of
53                            Just lib ->
54                                let ems = filter filt $ exposedModules lib
55                                    lib_bi = libBuildInfo lib
56                                    lib_bi' = lib_bi {
57                                                  extraLibs = extraExtraLibs
58                                                          ++ extraLibs lib_bi
59                                              }
60                                in lib {
61                                       exposedModules = ems,
62                                       libBuildInfo = lib_bi'
63                                    }
64                            Nothing ->
65                                error "Expected a library, but none found"
66               -- There's no files for GHC.Prim, so we will fail if we
67               -- try to copy them
68               pd_copy = pd { library = Just (mkLib ("GHC.Prim" /=)) }
69               pd_reg  = pd { library = Just (mkLib (const True)) }
70               -- When coying, we need to actually give a concrete
71               -- directory to copy to rather than "$topdir"
72               lbi_copy = lbi { prefix = pref }
73               -- When we run GHC we give it a $topdir that includes the
74               -- $compiler/lib/ part of libsubdir, so we only want the
75               -- $pkgid part in the package.conf file. This is a bit of
76               -- a hack, really.
77               lbi_reg = lbi { libsubdir = "$pkgid" }
78           (copyHook simpleUserHooks) pd_copy lbi_copy userHooks copyFlags
79           (regHook simpleUserHooks)  pd_reg  lbi_reg  userHooks registerFlags
80           return ()
81