2 We need to do some ugly hacks here as base mix of portable and
3 unportable stuff, as well as home to some GHC magic.
6 module Main (main) where
10 import Distribution.PackageDescription
11 import Distribution.Simple
12 import Distribution.Simple.LocalBuildInfo
13 import Distribution.Simple.Utils
15 import System.FilePath
18 main = do let hooks = defaultUserHooks {
19 buildHook = build_primitive_sources
21 $ buildHook defaultUserHooks,
22 makefileHook = build_primitive_sources
24 $ makefileHook defaultUserHooks,
25 instHook = filter_modules_hook
26 $ instHook defaultUserHooks }
27 defaultMainWithHooks hooks
29 type Hook a = PackageDescription -> LocalBuildInfo -> UserHooks -> a -> IO ()
31 build_primitive_sources :: Hook a -> Hook a
32 build_primitive_sources f pd lbi uhs x
33 = do when (compilerFlavor (compiler lbi) == GHC) $ do
34 let genprimopcode = joinPath ["..", "..", "utils",
35 "genprimopcode", "genprimopcode"]
36 primops = joinPath ["..", "..", "compiler", "prelude",
38 primhs = joinPath ["GHC", "Prim.hs"]
39 primopwrappers = joinPath ["GHC", "PrimopWrappers.hs"]
40 maybeExit $ system (genprimopcode ++ " --make-haskell-source < "
41 ++ primops ++ " > " ++ primhs)
42 maybeExit $ system (genprimopcode ++ " --make-haskell-wrappers < "
43 ++ primops ++ " > " ++ primopwrappers)
46 filter_modules_hook :: Hook a -> Hook a
47 filter_modules_hook f pd lbi uhs x
48 = let lib' = case library pd of
50 let ems = filter ("GHC.Prim" /=) (exposedModules lib)
51 in lib { exposedModules = ems }
52 Nothing -> error "Expected a library"
53 pd' = pd { library = Just lib' }