2 module Main (main) where
6 import Distribution.PackageDescription
7 import Distribution.PackageDescription.Parse
8 import Distribution.Simple
9 import Distribution.Simple.Utils
10 import Distribution.Verbosity
11 import System.Directory
12 import System.Environment
13 import System.FilePath
15 import qualified Distribution.Make as Make
16 import qualified Distribution.Simple as Simple
23 unprocessedArgs <- getArgs
24 let verbosity = verbose
25 case unprocessedArgs of
26 ghc : packageConf : args ->
27 doit verbosity ghc packageConf args
30 doit :: Verbosity -> FilePath -> FilePath -> [String] -> IO ()
31 doit verbosity ghc packageConf args = do
32 exists <- doesFileExist setupProg
33 if exists then rawSystemExit verbosity setupProg args
35 gpdFile <- defaultPackageDesc verbosity
36 gpd <- readPackageDescription verbosity gpdFile
37 let pd = packageDescription gpd
39 Just Simple -> Simple.defaultMainArgs args
40 Just Make -> Make.defaultMainArgs args
41 Just Configure -> defaultMainWithHooksArgs autoconfUserHooks args
42 _ | packageName pd == PackageName "Cabal" ->
43 -- Cabal is special...*sigh*
44 Simple.defaultMainArgs args
45 | otherwise -> runSetup verbosity ghc packageConf args
47 runSetup :: Verbosity -> FilePath -> FilePath -> [String] -> IO ()
48 runSetup verbosity ghc packageConf args = do
49 -- Don't bother building Setup if we are cleaning. If we need to
50 -- build Setup in order to build, and Setup isn't built already,
51 -- then there shouldn't be anything to clean anyway.
53 rawSystemExit verbosity ghc ["-package-conf", packageConf,
54 "--make", "Setup", "-o", "Setup"]
55 rawSystemExit verbosity "./Setup" args
56 where cleaning = case args of