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 haddockHook = build_primitive_sources
27 $ haddockHook defaultUserHooks,
28 instHook = filter_modules_hook
29 $ instHook defaultUserHooks }
30 defaultMainWithHooks hooks
32 type Hook a = PackageDescription -> LocalBuildInfo -> UserHooks -> a -> IO ()
34 build_primitive_sources :: Hook a -> Hook a
35 build_primitive_sources f pd lbi uhs x
36 = do when (compilerFlavor (compiler lbi) == GHC) $ do
37 let genprimopcode = joinPath ["..", "..", "utils",
38 "genprimopcode", "genprimopcode"]
39 primops = joinPath ["..", "..", "compiler", "prelude",
41 primhs = joinPath ["GHC", "Prim.hs"]
42 primopwrappers = joinPath ["GHC", "PrimopWrappers.hs"]
43 maybeExit $ system (genprimopcode ++ " --make-haskell-source < "
44 ++ primops ++ " > " ++ primhs)
45 maybeExit $ system (genprimopcode ++ " --make-haskell-wrappers < "
46 ++ primops ++ " > " ++ primopwrappers)
49 filter_modules_hook :: Hook a -> Hook a
50 filter_modules_hook f pd lbi uhs x
51 = let lib' = case library pd of
53 let ems = filter ("GHC.Prim" /=) (exposedModules lib)
54 in lib { exposedModules = ems }
55 Nothing -> error "Expected a library"
56 pd' = pd { library = Just lib' }