2 import Distribution.PackageDescription
3 import Distribution.Setup
4 import Distribution.Simple
5 import Distribution.Simple.Configure
6 import Distribution.Simple.LocalBuildInfo
7 import Distribution.Simple.Utils
8 import Distribution.Verbosity
9 import System.Environment
12 main = do args <- getArgs
13 let verbosity = case args of
20 _ -> error ("Bad arguments: " ++ show args)
21 userHooks = simpleUserHooks
22 installFlags = InstallFlags {
23 installUserFlags = MaybeUserGlobal,
24 installVerbose = verbosity
26 pdFile <- defaultPackageDesc verbosity
27 pd <- readPackageDescription verbosity pdFile
28 lbi <- getPersistBuildConfig
29 let -- XXX This is an almighty hack, shadowing the base Setup.hs hack
30 lib' = case library pd of
33 exposedModules = filter (("GHC.Prim" /=))
37 error "Expected a library, but none found"
38 pd' = pd { library = Just lib' }
39 -- When installing we need to use the non-inplace ghc-pkg.
40 -- We also set the compiler to be non-inplace, but that
41 -- probably doesn't matter.
43 c' = c { compilerPath = dropInPlace (compilerPath c),
44 compilerPkgTool = dropInPlace (compilerPkgTool c)
46 lbi' = lbi { compiler = c' }
47 (instHook simpleUserHooks) pd' lbi' userHooks installFlags
49 dropInPlace :: FilePath -> FilePath
51 dropInPlace xs@(x:xs') = case dropPrefix "-inplace" xs of
52 Nothing -> x : dropInPlace xs'
53 Just xs'' -> dropInPlace xs''
55 dropPrefix :: Eq a => [a] -> [a] -> Maybe [a]
56 dropPrefix [] ys = Just ys
57 dropPrefix (x:xs) (y:ys)
58 | x == y = dropPrefix xs ys
59 dropPrefix _ _ = Nothing