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 : useCabalVersion : args ->
27 doit verbosity ghc packageConf useCabalVersion args
30 doit :: Verbosity -> FilePath -> FilePath -> String -> [String] -> IO ()
31 doit verbosity ghc packageConf useCabalVersion 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
46 runSetup verbosity ghc packageConf useCabalVersion args
48 runSetup :: Verbosity -> FilePath -> FilePath -> String -> [String] -> IO ()
49 runSetup verbosity ghc packageConf useCabalVersion args = do
50 -- Don't bother building Setup if we are cleaning. If we need to
51 -- build Setup in order to build, and Setup isn't built already,
52 -- then there shouldn't be anything to clean anyway.
54 rawSystemExit verbosity ghc ["-package-conf", packageConf,
56 "-package", "Cabal-" ++ useCabalVersion,
58 rawSystemExit verbosity "./Setup" args
59 where cleaning = case args of