Filter out GHC.Prim also for the Haddock step
[ghc-base.git] / Setup.hs
1 {-
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.
4 -}
5
6 module Main (main) where
7
8 import Control.Monad
9 import Data.List
10 import Distribution.PackageDescription
11 import Distribution.Simple
12 import Distribution.Simple.LocalBuildInfo
13 import Distribution.Simple.Utils
14 import System.Cmd
15 import System.FilePath
16
17 main :: IO ()
18 main = do let hooks = defaultUserHooks {
19                   buildHook = build_primitive_sources
20                             $ filter_modules_hook
21                             $ buildHook defaultUserHooks,
22                   makefileHook = build_primitive_sources
23                                $ filter_modules_hook
24                                $ makefileHook defaultUserHooks,
25                   haddockHook = build_primitive_sources
26                                $ filter_modules_hook
27                                $ haddockHook defaultUserHooks,
28                    instHook = filter_modules_hook
29                            $ instHook defaultUserHooks }
30           defaultMainWithHooks hooks
31
32 type Hook a = PackageDescription -> LocalBuildInfo -> UserHooks -> a -> IO ()
33
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",
40                                   "primops.txt"]
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)
47       f pd lbi uhs x
48
49 filter_modules_hook :: Hook a -> Hook a
50 filter_modules_hook f pd lbi uhs x
51  = let lib' = case library pd of
52                   Just lib ->
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' }
57    in f pd' lbi uhs x
58