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.Setup
12 import Distribution.Simple
13 import Distribution.Simple.LocalBuildInfo
14 import Distribution.Simple.Utils
16 import System.FilePath
19 main = do let hooks = defaultUserHooks {
20 buildHook = build_primitive_sources
22 $ buildHook defaultUserHooks,
23 makefileHook = build_primitive_sources
25 $ makefileHook defaultUserHooks,
26 instHook = filter_modules_hook
27 $ instHook defaultUserHooks }
28 defaultMainWithHooks hooks
30 type Hook a = PackageDescription -> LocalBuildInfo -> UserHooks -> a -> IO ()
32 build_primitive_sources :: Hook a -> Hook a
33 build_primitive_sources f pd lbi uhs x
34 = do when (compilerFlavor (compiler lbi) == GHC) $ do
35 let genprimopcode = joinPath ["..", "..", "utils",
36 "genprimopcode", "genprimopcode"]
37 primops = joinPath ["..", "..", "compiler", "prelude",
39 primhs = joinPath ["GHC", "Prim.hs"]
40 primopwrappers = joinPath ["GHC", "PrimopWrappers.hs"]
41 maybeExit $ system (genprimopcode ++ " --make-haskell-source < "
42 ++ primops ++ " > " ++ primhs)
43 maybeExit $ system (genprimopcode ++ " --make-haskell-wrappers < "
44 ++ primops ++ " > " ++ primopwrappers)
47 filter_modules_hook :: Hook a -> Hook a
48 filter_modules_hook f pd lbi uhs x
49 = let lib' = case library pd of
51 let ems = filter ("GHC.Prim" /=) (exposedModules lib)
52 in lib { exposedModules = ems }
53 Nothing -> error "Expected a library"
54 pd' = pd { library = Just lib' }