2 import Distribution.PackageDescription
3 import Distribution.Simple
4 import Distribution.Simple.Configure
5 import Distribution.Simple.LocalBuildInfo
6 import Distribution.Simple.Program
7 import Distribution.Simple.Setup
8 import Distribution.Verbosity
9 import System.Environment
12 main = do args <- getArgs
14 destdir : pref : ghcpkg : ghcpkgconf : args' ->
15 let verbosity = case args' of
22 _ -> error ("Bad arguments: " ++ show args)
23 in doit destdir pref ghcpkg ghcpkgconf verbosity
25 error "Missing arguments"
27 doit :: FilePath -> FilePath -> FilePath -> FilePath -> Verbosity -> IO ()
28 doit destdir pref ghcpkg ghcpkgconf verbosity =
29 do let userHooks = simpleUserHooks
30 copyto = if null destdir then NoCopyDest else CopyTo destdir
31 copyFlags = (emptyCopyFlags copyto) {
32 copyVerbose = verbosity
34 registerFlags = emptyRegisterFlags {
35 regUser = MaybeUserGlobal,
36 regVerbose = verbosity,
40 lbi <- getPersistBuildConfig
41 let pd = localPkgDescr lbi
42 i = installDirTemplates lbi
43 -- XXX This is an almighty hack, shadowing the base
45 mkLib filt = case library pd of
47 let ems = filter filt $ exposedModules lib
52 error "Expected a library, but none found"
53 -- There's no files for GHC.Prim, so we will fail if we
55 pd_copy = pd { library = Just (mkLib ("GHC.Prim" /=)) }
56 pd_reg = pd { library = Just (mkLib (const True)) }
57 -- When coying, we need to actually give a concrete
58 -- directory to copy to rather than "$topdir"
59 i_copy = i { prefixDirTemplate = toPathTemplate pref }
60 lbi_copy = lbi { installDirTemplates = i_copy }
61 -- When we run GHC we give it a $topdir that includes the
62 -- $compiler/lib/ part of libsubdir, so we only want the
63 -- $pkgid part in the package.conf file. This is a bit of
65 progs = withPrograms lbi
66 prog = ConfiguredProgram {
67 programId = programName ghcPkgProgram,
68 programVersion = Nothing,
69 programArgs = ["--global-conf", ghcpkgconf],
70 programLocation = UserSpecified ghcpkg
72 progs' = updateProgram prog progs
73 i_reg = i { libSubdirTemplate = toPathTemplate "$pkgid" }
74 lbi_reg = lbi { installDirTemplates = i_reg,
75 withPrograms = progs' }
76 (copyHook simpleUserHooks) pd_copy lbi_copy userHooks copyFlags
77 (regHook simpleUserHooks) pd_reg lbi_reg userHooks registerFlags