Fix bindist creation on Windows
[ghc.git] / libraries / installPackage.hs
1
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
10
11 main :: IO ()
12 main
13 = do args <- getArgs
14 case args of
15 destdir : pref : idatadir : idocdir : ghcpkg : ghcpkgconf : args' ->
16 let verbosity = case args' of
17 [] -> normal
18 ['-':'v':v] ->
19 let m = case v of
20 "" -> Nothing
21 _ -> Just v
22 in flagToVerbosity m
23 _ -> error ("Bad arguments: " ++ show args)
24 in doit destdir pref idatadir idocdir ghcpkg ghcpkgconf
25 verbosity
26 _ ->
27 error "Missing arguments"
28
29 doit :: FilePath -> FilePath -> FilePath -> FilePath -> FilePath -> FilePath
30 -> Verbosity
31 -> IO ()
32 doit destdir pref idatadir idocdir ghcpkg ghcpkgconf verbosity =
33 do let userHooks = simpleUserHooks
34 copyto = if null destdir then NoCopyDest else CopyTo destdir
35 copyFlags = (emptyCopyFlags copyto) {
36 copyVerbose = verbosity
37 }
38 registerFlags = emptyRegisterFlags {
39 regUser = MaybeUserGlobal,
40 regVerbose = verbosity,
41 regGenScript = False,
42 regInPlace = False
43 }
44 lbi <- getPersistBuildConfig
45 let pd = localPkgDescr lbi
46 i = installDirTemplates lbi
47 -- XXX This is an almighty hack, shadowing the base
48 -- Setup.hs hack
49 mkLib filt = case library pd of
50 Just lib ->
51 let ems = filter filt $ exposedModules lib
52 in lib {
53 exposedModules = ems
54 }
55 Nothing ->
56 error "Expected a library, but none found"
57 -- There's no files for GHC.Prim, so we will fail if we
58 -- try to copy them
59 pd_copy = pd { library = Just (mkLib ("GHC.Prim" /=)) }
60 pd_reg = pd { library = Just (mkLib (const True)) }
61 -- When coying, we need to actually give a concrete
62 -- directory to copy to rather than "$topdir"
63 i_copy = i { prefixDirTemplate = toPathTemplate pref,
64 dataDirTemplate = toPathTemplate idatadir,
65 docDirTemplate = toPathTemplate idocdir
66 }
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
71 -- a hack, really.
72 progs = withPrograms lbi
73 prog = ConfiguredProgram {
74 programId = programName ghcPkgProgram,
75 programVersion = Nothing,
76 programArgs = ["--global-conf", ghcpkgconf],
77 programLocation = UserSpecified ghcpkg
78 }
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
85 return ()
86