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
10 import System.Environment
13 main = do args <- getArgs
15 pref : ghcpkg : args' ->
16 let verbosity = case args' of
23 _ -> error ("Bad arguments: " ++ show args)
24 in doit pref ghcpkg verbosity
26 error "Missing arguments"
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
35 registerFlags = RegisterFlags {
36 regUser = MaybeUserGlobal,
39 regWithHcPkg = Just ghcpkg,
40 regVerbose = verbosity
42 pdFile <- defaultPackageDesc verbosity
43 pd <- readPackageDescription verbosity pdFile
44 lbi <- getPersistBuildConfig
45 let -- XXX These are almighty hacks, shadowing the base
47 extraExtraLibs = if pkgName (package pd) == "base"
48 then ["wsock32", "msvcrt", "kernel32",
51 lib' = case library pd of
53 let ems = filter (("GHC.Prim" /=))
55 lib_bi = libBuildInfo lib
57 extraLibs = extraExtraLibs
62 libBuildInfo = lib_bi'
65 error "Expected a library, but none found"
66 pd' = pd { library = Just lib' }
67 -- When coying, we need to actually give a concrete
68 -- directory to copy to rather than "$topdir"
69 lbi_copy = lbi { prefix = pref }
70 -- When we run GHC we give it a $topdir that includes the
71 -- $compiler/lib/ part of libsubdir, so we only want the
72 -- $pkgid part in the package.conf file. This is a bit of
74 lbi_register = lbi { libsubdir = "$pkgid" }
75 (copyHook simpleUserHooks) pd' lbi_copy userHooks copyFlags
76 (regHook simpleUserHooks) pd' lbi_register userHooks registerFlags