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
20 main = do let hooks = defaultUserHooks {
21 confHook = add_extra_deps
22 $ confHook defaultUserHooks,
23 buildHook = build_primitive_sources
25 $ buildHook defaultUserHooks,
26 makefileHook = build_primitive_sources
28 $ makefileHook defaultUserHooks,
29 regHook = add_extra_libs
30 $ regHook defaultUserHooks,
31 instHook = filter_modules_hook
32 $ instHook defaultUserHooks }
33 defaultMainWithHooks hooks
35 type Hook a = PackageDescription -> LocalBuildInfo -> UserHooks -> a -> IO ()
36 type ConfHook = PackageDescription -> ConfigFlags -> IO LocalBuildInfo
38 -- type PDHook = PackageDescription -> ConfigFlags -> IO ()
40 build_primitive_sources :: Hook a -> Hook a
41 build_primitive_sources f pd lbi uhs x
42 = do when (compilerFlavor (compiler lbi) == GHC) $ do
43 let genprimopcode = joinPath ["..", "..", "utils",
44 "genprimopcode", "genprimopcode"]
45 primops = joinPath ["..", "..", "compiler", "prelude",
47 primhs = joinPath ["GHC", "Prim.hs"]
48 primopwrappers = joinPath ["GHC", "PrimopWrappers.hs"]
49 maybeExit $ system (genprimopcode ++ " --make-haskell-source < "
50 ++ primops ++ " > " ++ primhs)
51 maybeExit $ system (genprimopcode ++ " --make-haskell-wrappers < "
52 ++ primops ++ " > " ++ primopwrappers)
55 filter_modules_hook :: Hook a -> Hook a
56 filter_modules_hook f pd lbi uhs x
57 = let build_filter = case compilerFlavor $ compiler lbi of
60 lib' = case library pd of
62 let ems = filter build_filter (exposedModules lib)
63 in lib { exposedModules = ems }
64 Nothing -> error "Expected a library"
65 pd' = pd { library = Just lib' }
68 isPortableBuild :: String -> Bool
70 | "GHC" `isPrefixOf` s = False
71 | "Data.Generics" `isPrefixOf` s = False
72 | otherwise = s `notElem` ["Foreign.Concurrent", "System.Timeout"]
74 forGHCBuild :: String -> Bool
75 forGHCBuild = ("GHC.Prim" /=)
77 add_extra_deps :: ConfHook -> ConfHook
78 add_extra_deps f pd cf
80 case compilerFlavor (compiler lbi) of
82 do -- Euch. We should just add the right thing to the lbi
83 -- ourselves rather than rerunning configure.
84 let pd' = pd { buildDepends = Dependency "rts" AnyVersion
90 add_extra_libs :: Hook a -> Hook a
91 add_extra_libs f pd lbi uhs x
92 = let pd' = if (os == "mingw32") && (compilerFlavor (compiler lbi) == GHC)
93 then case library pd of
95 let lib_bi = libBuildInfo lib
96 lib_bi' = lib_bi { extraLibs = "wsock32"
102 lib' = lib { libBuildInfo = lib_bi' }
103 in pd { library = Just lib' }
104 Nothing -> error "Expected a library"