2 import Distribution.PackageDescription
3 import Distribution.Program
4 import Distribution.Setup
5 import Distribution.Simple
6 import Distribution.Simple.Configure
7 import Distribution.Simple.LocalBuildInfo
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 copyFlags = (emptyCopyFlags (CopyTo destdir)) {
31 copyVerbose = verbosity
33 registerFlags = emptyRegisterFlags {
34 regUser = MaybeUserGlobal,
35 regVerbose = verbosity,
39 lbi <- getPersistBuildConfig
40 let pd = localPkgDescr lbi
41 i = installDirTemplates lbi
42 -- XXX This is an almighty hack, shadowing the base
44 mkLib filt = case library pd of
46 let ems = filter filt $ exposedModules lib
51 error "Expected a library, but none found"
52 -- There's no files for GHC.Prim, so we will fail if we
54 pd_copy = pd { library = Just (mkLib ("GHC.Prim" /=)) }
55 pd_reg = pd { library = Just (mkLib (const True)) }
56 -- When coying, we need to actually give a concrete
57 -- directory to copy to rather than "$topdir"
58 i_copy = i { prefixDirTemplate = toPathTemplate pref }
59 lbi_copy = lbi { installDirTemplates = i_copy }
60 -- When we run GHC we give it a $topdir that includes the
61 -- $compiler/lib/ part of libsubdir, so we only want the
62 -- $pkgid part in the package.conf file. This is a bit of
64 progs = withPrograms lbi
65 prog = ConfiguredProgram {
66 programId = programName ghcPkgProgram,
67 programVersion = Nothing,
68 programArgs = ["--global-conf", ghcpkgconf],
69 programLocation = UserSpecified ghcpkg
71 progs' = updateProgram prog progs
72 i_reg = i { libSubdirTemplate = toPathTemplate "$pkgid" }
73 lbi_reg = lbi { installDirTemplates = i_reg,
74 withPrograms = progs' }
75 (copyHook simpleUserHooks) pd_copy lbi_copy userHooks copyFlags
76 (regHook simpleUserHooks) pd_reg lbi_reg userHooks registerFlags