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.Simple.Utils
9 import Distribution.Verbosity
10 import System.Environment
16 destdir : pref : ihtmldir : ghcpkg : ghcpkgconf : args' ->
17 let verbosity = case args' of
24 _ -> error ("Bad arguments: " ++ show args)
25 in doit destdir pref ihtmldir ghcpkg ghcpkgconf
28 error "Missing arguments"
30 doit :: FilePath -> FilePath -> FilePath -> FilePath -> FilePath
33 doit destdir pref ihtmldir ghcpkg ghcpkgconf verbosity =
34 do let userHooks = simpleUserHooks
35 copyto = if null destdir then NoCopyDest else CopyTo destdir
36 copyFlags = (emptyCopyFlags copyto) {
37 copyVerbose = verbosity
39 registerFlags = emptyRegisterFlags {
40 regPackageDB = Just GlobalPackageDB,
41 regVerbose = verbosity,
45 lbi <- getConfig verbosity
46 let pd = localPkgDescr lbi
47 i = installDirTemplates lbi
48 -- XXX This is an almighty hack, shadowing the base
50 mkLib filt = case library pd of
52 let ems = filter filt $ exposedModules lib
57 error "Expected a library, but none found"
58 -- There's no files for GHC.Prim, so we will fail if we
60 pd_copy = pd { library = Just (mkLib ("GHC.Prim" /=)) }
61 pd_reg = pd { library = Just (mkLib (const True)) }
62 -- When coying, we need to actually give a concrete
63 -- directory to copy to rather than "$topdir"
64 i_copy = i { prefixDirTemplate = toPathTemplate pref,
65 htmlDirTemplate = toPathTemplate ihtmldir
67 lbi_copy = lbi { installDirTemplates = i_copy }
68 -- When we run GHC we give it a $topdir that includes the
69 -- $compiler/lib/ part of libsubdir, so we only want the
70 -- $pkgid part in the package.conf file. This is a bit of
72 progs = withPrograms lbi
73 prog = ConfiguredProgram {
74 programId = programName ghcPkgProgram,
75 programVersion = Nothing,
76 programArgs = ["--global-conf", ghcpkgconf],
77 programLocation = UserSpecified ghcpkg
79 progs' = updateProgram prog progs
80 i_reg = i { libSubdirTemplate = toPathTemplate "$pkgid" }
81 lbi_reg = lbi { installDirTemplates = i_reg,
82 withPrograms = progs' }
83 (copyHook simpleUserHooks) pd_copy lbi_copy userHooks copyFlags
84 (regHook simpleUserHooks) pd_reg lbi_reg userHooks registerFlags
87 -- Get the build info, merging the setup-config and buildinfo files.
88 getConfig :: Verbosity -> IO LocalBuildInfo
89 getConfig verbosity = do
90 lbi <- getPersistBuildConfig
91 maybe_infoFile <- defaultHookedPackageDesc
92 case maybe_infoFile of
95 hbi <- readHookedBuildInfo verbosity infoFile
96 return lbi { localPkgDescr = updatePackageDescription hbi (localPkgDescr lbi)}