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 : ibindir : ilibdir : ilibexecdir
17 : idatadir : idocdir : ihtmldir
18 : ghcpkg : ghcpkgconf : args' ->
19 let verbosity = case args' of
26 _ -> error ("Bad arguments: " ++ show args)
27 in doit destdir pref ibindir ilibdir ilibexecdir idatadir
29 ghcpkg ghcpkgconf verbosity
31 error "Missing arguments"
33 doit :: FilePath -> FilePath -> FilePath -> FilePath -> FilePath
34 -> FilePath -> FilePath -> FilePath -> FilePath -> FilePath
37 doit destdir pref ibindir ilibdir ilibexecdir idatadir idocdir
38 ihtmldir ghcpkg ghcpkgconf verbosity =
39 do let userHooks = simpleUserHooks
40 copyto = if null destdir then NoCopyDest else CopyTo destdir
41 copyFlags = (emptyCopyFlags copyto) {
42 copyVerbose = verbosity
44 registerFlags = emptyRegisterFlags {
45 regPackageDB = Just GlobalPackageDB,
46 regVerbose = verbosity,
50 lbi <- getConfig verbosity
51 let pd = localPkgDescr lbi
52 i = installDirTemplates lbi
53 -- XXX This is an almighty hack, shadowing the base
55 mkLib filt = case library pd of
57 let ems = filter filt $ exposedModules lib
62 error "Expected a library, but none found"
63 -- There's no files for GHC.Prim, so we will fail if we
65 pd_copy = pd { library = Just (mkLib ("GHC.Prim" /=)) }
66 pd_reg = pd { library = Just (mkLib (const True)) }
67 -- When coying, we need to actually give a concrete
68 -- directory to copy to rather than "$topdir"
69 i_copy = i { prefixDirTemplate = toPathTemplate pref,
70 binDirTemplate = toPathTemplate ibindir,
71 libDirTemplate = toPathTemplate ilibdir,
72 libexecDirTemplate = toPathTemplate ilibexecdir,
73 dataDirTemplate = toPathTemplate idatadir,
74 docDirTemplate = toPathTemplate idocdir,
75 htmlDirTemplate = toPathTemplate ihtmldir
77 lbi_copy = lbi { installDirTemplates = i_copy }
78 -- When we run GHC we give it a $topdir that includes the
79 -- $compiler/lib/ part of libsubdir, so we only want the
80 -- $pkgid part in the package.conf file. This is a bit of
82 progs = withPrograms lbi
83 prog = ConfiguredProgram {
84 programId = programName ghcPkgProgram,
85 programVersion = Nothing,
86 programArgs = ["--global-conf", ghcpkgconf],
87 programLocation = UserSpecified ghcpkg
89 progs' = updateProgram prog progs
90 i_reg = i { libSubdirTemplate = toPathTemplate "$pkgid" }
91 lbi_reg = lbi { installDirTemplates = i_reg,
92 withPrograms = progs' }
93 (copyHook simpleUserHooks) pd_copy lbi_copy userHooks copyFlags
94 (regHook simpleUserHooks) pd_reg lbi_reg userHooks registerFlags
97 -- Get the build info, merging the setup-config and buildinfo files.
98 getConfig :: Verbosity -> IO LocalBuildInfo
99 getConfig verbosity = do
100 lbi <- getPersistBuildConfig
101 maybe_infoFile <- defaultHookedPackageDesc
102 case maybe_infoFile of
103 Nothing -> return lbi
105 hbi <- readHookedBuildInfo verbosity infoFile
106 return lbi { localPkgDescr = updatePackageDescription hbi (localPkgDescr lbi)}