Stop dph/dph-{par,seq} reconfiguring themselves all the time
[ghc-hetmet.git] / libraries / cabal-bin.hs
1
2 module Main (main) where
3
4 import Control.Monad
5 import Data.Maybe
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
14
15 import qualified Distribution.Make   as Make
16 import qualified Distribution.Simple as Simple
17
18 setupProg :: FilePath
19 setupProg = "./Setup"
20
21 main :: IO ()
22 main = do
23     unprocessedArgs <- getArgs
24     let verbosity = verbose
25     case unprocessedArgs of
26         ghc : packageConf : args ->
27             doit verbosity ghc packageConf args
28         _ -> die "Bad args"
29
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
34               else do
35         gpdFile <- defaultPackageDesc verbosity
36         gpd <- readPackageDescription verbosity gpdFile
37         let pd = packageDescription gpd
38         case buildType pd of
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
46
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.
52     unless cleaning $
53         rawSystemExit verbosity ghc ["-package-conf", packageConf,
54                                      "--make", "Setup", "-o", "Setup"]
55     rawSystemExit verbosity "./Setup" args
56   where cleaning = case args of
57                    "clean" : _ -> True
58                    _ -> False
59