3 import Distribution.PackageDescription
4 import Distribution.PackageDescription.Parse
5 import Distribution.ReadE
6 import Distribution.Simple
7 import Distribution.Simple.Configure
8 import Distribution.Simple.LocalBuildInfo
9 import Distribution.Simple.Program
10 import Distribution.Simple.Setup
11 import Distribution.Simple.Utils
12 import Distribution.Text
13 import Distribution.Verbosity
14 import System.Environment
20 "install" : ghcpkg : ghcpkgconf : destdir : topdir :
21 iprefix : ibindir : ilibdir : ilibexecdir : idynlibdir :
22 idatadir : idocdir : ihtmldir : ihaddockdir :
24 case parseArgs args' of
25 (verbosity, distPref, enableShellWrappers) ->
26 doInstall verbosity distPref enableShellWrappers
27 ghcpkg ghcpkgconf destdir topdir
28 iprefix ibindir ilibdir ilibexecdir
29 idynlibdir idatadir idocdir ihtmldir
32 error ("Bad arguments: " ++ show args)
34 -- XXX We should really make Cabal do the hardwork here
36 -> (Verbosity, -- verbosity
37 FilePath, -- dist prefix
38 Bool) -- enable shell wrappers?
39 parseArgs = f normal defaultDistPref False
40 where f v dp esw (('-':'v':val):args)
41 = f (readEOrFail flagToVerbosity val) dp esw args
42 f v _ esw ("--distpref":dp:args) = f v dp esw args
43 f v dp _ ("--enable-shell-wrappers":args) = f v dp True args
44 f v dp esw [] = (v, dp, esw)
45 f _ _ _ args = error ("Bad arguments: " ++ show args)
47 doInstall :: Verbosity -> FilePath -> Bool
48 -> FilePath -> FilePath -> FilePath -> FilePath
49 -> FilePath -> FilePath -> FilePath -> FilePath -> FilePath
50 -> FilePath -> FilePath -> FilePath -> FilePath
52 doInstall verbosity distPref enableShellWrappers
53 ghcpkg ghcpkgconf destdir topdir
54 iprefix ibindir ilibdir ilibexecdir idynlibdir idatadir
55 idocdir ihtmldir ihaddockdir =
56 do let userHooks = simpleUserHooks
57 copyto = if null destdir then NoCopyDest else CopyTo destdir
58 copyFlags = defaultCopyFlags {
59 copyUseWrapper = toFlag enableShellWrappers,
60 copyDest = toFlag copyto,
61 copyVerbosity = toFlag verbosity
63 registerFlags = defaultRegisterFlags {
64 regPackageDB = toFlag GlobalPackageDB,
65 regVerbosity = toFlag verbosity,
66 regGenScript = toFlag $ False,
67 regInPlace = toFlag $ False
69 lbi <- getConfig verbosity distPref
70 let pd = localPkgDescr lbi
71 i = installDirTemplates lbi
72 -- This is an almighty hack. We need to register
73 -- ghc-prim:GHC.Prim, but it doesn't exist, get built, get
74 -- haddocked, get copied, etc.
75 pd_reg = if packageName pd == PackageName "ghc-prim"
76 then case library pd of
78 let ems = fromJust (simpleParse "GHC.Prim")
80 lib' = lib { exposedModules = ems }
81 in pd { library = Just lib' }
83 error "Expected a library, but none found"
85 -- When coying, we need to actually give a concrete
86 -- directory to copy to rather than "$topdir"
87 toPathTemplate' = toPathTemplate . replaceTopdir topdir
88 i_copy = i { prefix = toPathTemplate' iprefix,
89 bindir = toPathTemplate' ibindir,
90 libdir = toPathTemplate' ilibdir,
91 dynlibdir = toPathTemplate' idynlibdir,
92 libexecdir = toPathTemplate' ilibexecdir,
93 datadir = toPathTemplate' idatadir,
94 docdir = toPathTemplate' idocdir,
95 htmldir = toPathTemplate' ihtmldir,
96 haddockdir = toPathTemplate' ihaddockdir
98 lbi_copy = lbi { installDirTemplates = i_copy }
99 -- When we run GHC we give it a $topdir that includes the
100 -- $compiler/lib/ part of libsubdir, so we only want the
101 -- $pkgid part in the package.conf file. This is a bit of
103 progs = withPrograms lbi
104 prog = ConfiguredProgram {
105 programId = programName ghcPkgProgram,
106 programVersion = Nothing,
107 programArgs = ["--force", "--global-conf", ghcpkgconf],
108 programLocation = UserSpecified ghcpkg
110 progs' = updateProgram prog progs
111 i_reg = i { prefix = toPathTemplate iprefix,
112 bindir = toPathTemplate ibindir,
113 libdir = toPathTemplate ilibdir,
114 dynlibdir = toPathTemplate idynlibdir,
115 libexecdir = toPathTemplate ilibexecdir,
116 datadir = toPathTemplate idatadir,
117 docdir = toPathTemplate idocdir,
118 htmldir = toPathTemplate ihtmldir,
119 haddockdir = toPathTemplate ihaddockdir
121 lbi_reg = lbi { installDirTemplates = i_reg,
122 withPrograms = progs' }
123 (copyHook simpleUserHooks) pd lbi_copy userHooks copyFlags
124 (regHook simpleUserHooks) pd_reg lbi_reg userHooks registerFlags
127 replaceTopdir :: FilePath -> FilePath -> FilePath
128 replaceTopdir topdir ('$':'t':'o':'p':'d':'i':'r':p) = topdir ++ p
129 replaceTopdir topdir ('$':'h':'t':'t':'p':'t':'o':'p':'d':'i':'r':p)
131 replaceTopdir _ p = p
133 -- Get the build info, merging the setup-config and buildinfo files.
134 getConfig :: Verbosity -> FilePath -> IO LocalBuildInfo
135 getConfig verbosity distPref = do
136 lbi <- getPersistBuildConfig distPref
137 maybe_infoFile <- defaultHookedPackageDesc
138 case maybe_infoFile of
139 Nothing -> return lbi
141 hbi <- readHookedBuildInfo verbosity infoFile
142 return lbi { localPkgDescr = updatePackageDescription hbi (localPkgDescr lbi)}