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