2 module Main (main) where
5 import Distribution.PackageDescription
6 import Distribution.PackageDescription.Parse
7 import Distribution.Simple
8 import Distribution.Simple.Utils
9 import Distribution.Verbosity
10 import System.Directory
11 import System.Environment
12 import System.FilePath
14 import qualified Distribution.Make as Make
15 import qualified Distribution.Simple as Simple
22 unprocessedArgs <- getArgs
23 let verbosity = verbose
24 case unprocessedArgs of
25 ghc : packageConf : args ->
26 doit verbosity ghc packageConf args
29 doit :: Verbosity -> FilePath -> FilePath -> [String] -> IO ()
30 doit verbosity ghc packageConf args = do
31 exists <- doesFileExist setupProg
32 if exists then rawSystemExit verbosity setupProg args
34 gpdFile <- defaultPackageDesc verbosity
35 gpd <- readPackageDescription verbosity gpdFile
36 let pd = packageDescription gpd
38 Just Simple -> Simple.defaultMainArgs args
39 Just Make -> Make.defaultMainArgs args
40 Just Configure -> defaultMainWithHooksArgs autoconfUserHooks args
41 _ | packageName pd == PackageName "Cabal" ->
42 -- Cabal is special...*sigh*
43 Simple.defaultMainArgs args
44 | otherwise -> runSetup verbosity ghc packageConf args
46 runSetup :: Verbosity -> FilePath -> FilePath -> [String] -> IO ()
47 runSetup verbosity ghc packageConf args = do
48 rawSystemExit verbosity ghc ["-package-conf", packageConf,
49 "--make", "Setup", "-o", "Setup"]
50 rawSystemExit verbosity "./Setup" args