X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Setup.hs;h=7fb1d87506744bd75f5e392de5db83b6cb1dc9b7;hb=4b26136ab82fb1ff12e49477c4833a9586d368c5;hp=f7a4a0ca24f62e5949a3a92beba59f33bfed5798;hpb=f64a8e4d516f6c285cc47dd2ef05e716998014d6;p=haskell-directory.git diff --git a/Setup.hs b/Setup.hs index f7a4a0c..7fb1d87 100644 --- a/Setup.hs +++ b/Setup.hs @@ -10,9 +10,7 @@ import Control.Monad import Data.List import Distribution.Simple import Distribution.PackageDescription -import Distribution.PreProcess import Distribution.Setup -import Distribution.Simple.Configure import Distribution.Simple.LocalBuildInfo import System.Environment import System.Exit @@ -20,30 +18,40 @@ import System.Exit main :: IO () main = do args <- getArgs let (ghcArgs, args') = extractGhcArgs args - let hooks = defaultUserHooks { + (confArgs, args'') = extractConfigureArgs args' + hooks = defaultUserHooks { confHook = add_extra_deps $ confHook defaultUserHooks, + postConf = add_configure_options confArgs + $ postConf defaultUserHooks, buildHook = add_ghc_options ghcArgs $ filter_modules_hook $ buildHook defaultUserHooks, instHook = filter_modules_hook $ instHook defaultUserHooks } - withArgs args' $ defaultMainWithHooks hooks + withArgs args'' $ defaultMainWithHooks hooks extractGhcArgs :: [String] -> ([String], [String]) -extractGhcArgs args +extractGhcArgs = extractPrefixArgs "--ghc-option=" + +extractConfigureArgs :: [String] -> ([String], [String]) +extractConfigureArgs = extractPrefixArgs "--configure-option=" + +extractPrefixArgs :: String -> [String] -> ([String], [String]) +extractPrefixArgs the_prefix args = let f [] = ([], []) f (x:xs) = case f xs of - (ghcArgs, otherArgs) -> - case removePrefix "--ghc-option=" x of - Just ghcArg -> - (ghcArg:ghcArgs, otherArgs) + (wantedArgs, otherArgs) -> + case removePrefix the_prefix x of + Just wantedArg -> + (wantedArg:wantedArgs, otherArgs) Nothing -> - (ghcArgs, x:otherArgs) + (wantedArgs, x:otherArgs) in f args removePrefix :: String -> String -> Maybe String removePrefix "" ys = Just ys +removePrefix _ "" = Nothing removePrefix (x:xs) (y:ys) | x == y = removePrefix xs ys | otherwise = Nothing @@ -51,6 +59,8 @@ removePrefix (x:xs) (y:ys) type Hook a = PackageDescription -> LocalBuildInfo -> Maybe UserHooks -> a -> IO () type ConfHook = PackageDescription -> ConfigFlags -> IO LocalBuildInfo +type PostConfHook = Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo + -> IO ExitCode -- type PDHook = PackageDescription -> ConfigFlags -> IO () @@ -66,6 +76,10 @@ add_ghc_options args f pd lbi muhs x pd' = pd { library = Just lib' } f pd' lbi muhs x +add_configure_options :: [String] -> PostConfHook -> PostConfHook +add_configure_options args f as cfs pd lbi + = f (as ++ args) cfs pd lbi + filter_modules_hook :: Hook a -> Hook a filter_modules_hook f pd lbi muhs x = let build_filter = case compilerFlavor $ compiler lbi of