{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
module Distribution.Make (
module Distribution.Package,
License(..), Version,
defaultMain, defaultMainArgs
) where
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Package
import Distribution.Simple.Program
import Distribution.Simple.Setup
import Distribution.Simple.Command
import Distribution.Simple.Utils
import Distribution.License
import Distribution.Version
import Distribution.Pretty
import System.Environment (getArgs, getProgName)
defaultMain :: IO ()
defaultMain :: IO ()
defaultMain = IO [String]
getArgs forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [String] -> IO ()
defaultMainArgs
defaultMainArgs :: [String] -> IO ()
defaultMainArgs :: [String] -> IO ()
defaultMainArgs = [String] -> IO ()
defaultMainHelper
defaultMainHelper :: [String] -> IO ()
defaultMainHelper :: [String] -> IO ()
defaultMainHelper [String]
args =
case forall a action.
CommandUI a
-> [Command action]
-> [String]
-> CommandParse (a, CommandParse action)
commandsRun (forall action. [Command action] -> CommandUI GlobalFlags
globalCommand [Command (IO ())]
commands) [Command (IO ())]
commands [String]
args of
CommandHelp String -> String
help -> (String -> String) -> IO ()
printHelp String -> String
help
CommandList [String]
opts -> [String] -> IO ()
printOptionsList [String]
opts
CommandErrors [String]
errs -> forall {b}. [String] -> IO b
printErrors [String]
errs
CommandReadyToGo (GlobalFlags
flags, CommandParse (IO ())
commandParse) ->
case CommandParse (IO ())
commandParse of
CommandParse (IO ())
_ | forall a. WithCallStack (Flag a -> a)
fromFlag (GlobalFlags -> Flag Bool
globalVersion GlobalFlags
flags) -> IO ()
printVersion
| forall a. WithCallStack (Flag a -> a)
fromFlag (GlobalFlags -> Flag Bool
globalNumericVersion GlobalFlags
flags) -> IO ()
printNumericVersion
CommandHelp String -> String
help -> (String -> String) -> IO ()
printHelp String -> String
help
CommandList [String]
opts -> [String] -> IO ()
printOptionsList [String]
opts
CommandErrors [String]
errs -> forall {b}. [String] -> IO b
printErrors [String]
errs
CommandReadyToGo IO ()
action -> IO ()
action
where
printHelp :: (String -> String) -> IO ()
printHelp String -> String
help = IO String
getProgName forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> IO ()
putStr forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
help
printOptionsList :: [String] -> IO ()
printOptionsList = String -> IO ()
putStr forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> String
unlines
printErrors :: [String] -> IO b
printErrors [String]
errs = do
String -> IO ()
putStr (forall a. [a] -> [[a]] -> [a]
intercalate String
"\n" [String]
errs)
forall a. ExitCode -> IO a
exitWith (Int -> ExitCode
ExitFailure Int
1)
printNumericVersion :: IO ()
printNumericVersion = String -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ forall a. Pretty a => a -> String
prettyShow Version
cabalVersion
printVersion :: IO ()
printVersion = String -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ String
"Cabal library version "
forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> String
prettyShow Version
cabalVersion
progs :: ProgramDb
progs = ProgramDb
defaultProgramDb
commands :: [Command (IO ())]
commands =
[ProgramDb -> CommandUI ConfigFlags
configureCommand ProgramDb
progs forall flags action.
CommandUI flags -> (flags -> [String] -> action) -> Command action
`commandAddAction` ConfigFlags -> [String] -> IO ()
configureAction
,ProgramDb -> CommandUI BuildFlags
buildCommand ProgramDb
progs forall flags action.
CommandUI flags -> (flags -> [String] -> action) -> Command action
`commandAddAction` BuildFlags -> [String] -> IO ()
buildAction
,CommandUI InstallFlags
installCommand forall flags action.
CommandUI flags -> (flags -> [String] -> action) -> Command action
`commandAddAction` InstallFlags -> [String] -> IO ()
installAction
,CommandUI CopyFlags
copyCommand forall flags action.
CommandUI flags -> (flags -> [String] -> action) -> Command action
`commandAddAction` CopyFlags -> [String] -> IO ()
copyAction
,CommandUI HaddockFlags
haddockCommand forall flags action.
CommandUI flags -> (flags -> [String] -> action) -> Command action
`commandAddAction` HaddockFlags -> [String] -> IO ()
haddockAction
,CommandUI CleanFlags
cleanCommand forall flags action.
CommandUI flags -> (flags -> [String] -> action) -> Command action
`commandAddAction` CleanFlags -> [String] -> IO ()
cleanAction
,CommandUI SDistFlags
sdistCommand forall flags action.
CommandUI flags -> (flags -> [String] -> action) -> Command action
`commandAddAction` SDistFlags -> [String] -> IO ()
sdistAction
,CommandUI RegisterFlags
registerCommand forall flags action.
CommandUI flags -> (flags -> [String] -> action) -> Command action
`commandAddAction` RegisterFlags -> [String] -> IO ()
registerAction
,CommandUI RegisterFlags
unregisterCommand forall flags action.
CommandUI flags -> (flags -> [String] -> action) -> Command action
`commandAddAction` RegisterFlags -> [String] -> IO ()
unregisterAction
]
configureAction :: ConfigFlags -> [String] -> IO ()
configureAction :: ConfigFlags -> [String] -> IO ()
configureAction ConfigFlags
flags [String]
args = do
[String] -> IO ()
noExtraFlags [String]
args
let verbosity :: Verbosity
verbosity = forall a. WithCallStack (Flag a -> a)
fromFlag (ConfigFlags -> Flag Verbosity
configVerbosity ConfigFlags
flags)
Verbosity -> String -> [String] -> IO ()
rawSystemExit Verbosity
verbosity String
"sh" forall a b. (a -> b) -> a -> b
$
String
"configure"
forall a. a -> [a] -> [a]
: Bool -> ConfigFlags -> [String]
configureArgs Bool
backwardsCompatHack ConfigFlags
flags
where backwardsCompatHack :: Bool
backwardsCompatHack = Bool
True
copyAction :: CopyFlags -> [String] -> IO ()
copyAction :: CopyFlags -> [String] -> IO ()
copyAction CopyFlags
flags [String]
args = do
[String] -> IO ()
noExtraFlags [String]
args
let destArgs :: [String]
destArgs = case forall a. WithCallStack (Flag a -> a)
fromFlag forall a b. (a -> b) -> a -> b
$ CopyFlags -> Flag CopyDest
copyDest CopyFlags
flags of
CopyDest
NoCopyDest -> [String
"install"]
CopyTo String
path -> [String
"copy", String
"destdir=" forall a. [a] -> [a] -> [a]
++ String
path]
CopyToDb String
_ -> forall a. HasCallStack => String -> a
error String
"CopyToDb not supported via Make"
Verbosity -> String -> [String] -> IO ()
rawSystemExit (forall a. WithCallStack (Flag a -> a)
fromFlag forall a b. (a -> b) -> a -> b
$ CopyFlags -> Flag Verbosity
copyVerbosity CopyFlags
flags) String
"make" [String]
destArgs
installAction :: InstallFlags -> [String] -> IO ()
installAction :: InstallFlags -> [String] -> IO ()
installAction InstallFlags
flags [String]
args = do
[String] -> IO ()
noExtraFlags [String]
args
Verbosity -> String -> [String] -> IO ()
rawSystemExit (forall a. WithCallStack (Flag a -> a)
fromFlag forall a b. (a -> b) -> a -> b
$ InstallFlags -> Flag Verbosity
installVerbosity InstallFlags
flags) String
"make" [String
"install"]
Verbosity -> String -> [String] -> IO ()
rawSystemExit (forall a. WithCallStack (Flag a -> a)
fromFlag forall a b. (a -> b) -> a -> b
$ InstallFlags -> Flag Verbosity
installVerbosity InstallFlags
flags) String
"make" [String
"register"]
haddockAction :: HaddockFlags -> [String] -> IO ()
haddockAction :: HaddockFlags -> [String] -> IO ()
haddockAction HaddockFlags
flags [String]
args = do
[String] -> IO ()
noExtraFlags [String]
args
Verbosity -> String -> [String] -> IO ()
rawSystemExit (forall a. WithCallStack (Flag a -> a)
fromFlag forall a b. (a -> b) -> a -> b
$ HaddockFlags -> Flag Verbosity
haddockVerbosity HaddockFlags
flags) String
"make" [String
"docs"]
forall a. IO a -> (IOException -> IO a) -> IO a
`catchIO` \IOException
_ ->
Verbosity -> String -> [String] -> IO ()
rawSystemExit (forall a. WithCallStack (Flag a -> a)
fromFlag forall a b. (a -> b) -> a -> b
$ HaddockFlags -> Flag Verbosity
haddockVerbosity HaddockFlags
flags) String
"make" [String
"doc"]
buildAction :: BuildFlags -> [String] -> IO ()
buildAction :: BuildFlags -> [String] -> IO ()
buildAction BuildFlags
flags [String]
args = do
[String] -> IO ()
noExtraFlags [String]
args
Verbosity -> String -> [String] -> IO ()
rawSystemExit (forall a. WithCallStack (Flag a -> a)
fromFlag forall a b. (a -> b) -> a -> b
$ BuildFlags -> Flag Verbosity
buildVerbosity BuildFlags
flags) String
"make" []
cleanAction :: CleanFlags -> [String] -> IO ()
cleanAction :: CleanFlags -> [String] -> IO ()
cleanAction CleanFlags
flags [String]
args = do
[String] -> IO ()
noExtraFlags [String]
args
Verbosity -> String -> [String] -> IO ()
rawSystemExit (forall a. WithCallStack (Flag a -> a)
fromFlag forall a b. (a -> b) -> a -> b
$ CleanFlags -> Flag Verbosity
cleanVerbosity CleanFlags
flags) String
"make" [String
"clean"]
sdistAction :: SDistFlags -> [String] -> IO ()
sdistAction :: SDistFlags -> [String] -> IO ()
sdistAction SDistFlags
flags [String]
args = do
[String] -> IO ()
noExtraFlags [String]
args
Verbosity -> String -> [String] -> IO ()
rawSystemExit (forall a. WithCallStack (Flag a -> a)
fromFlag forall a b. (a -> b) -> a -> b
$ SDistFlags -> Flag Verbosity
sDistVerbosity SDistFlags
flags) String
"make" [String
"dist"]
registerAction :: RegisterFlags -> [String] -> IO ()
registerAction :: RegisterFlags -> [String] -> IO ()
registerAction RegisterFlags
flags [String]
args = do
[String] -> IO ()
noExtraFlags [String]
args
Verbosity -> String -> [String] -> IO ()
rawSystemExit (forall a. WithCallStack (Flag a -> a)
fromFlag forall a b. (a -> b) -> a -> b
$ RegisterFlags -> Flag Verbosity
regVerbosity RegisterFlags
flags) String
"make" [String
"register"]
unregisterAction :: RegisterFlags -> [String] -> IO ()
unregisterAction :: RegisterFlags -> [String] -> IO ()
unregisterAction RegisterFlags
flags [String]
args = do
[String] -> IO ()
noExtraFlags [String]
args
Verbosity -> String -> [String] -> IO ()
rawSystemExit (forall a. WithCallStack (Flag a -> a)
fromFlag forall a b. (a -> b) -> a -> b
$ RegisterFlags -> Flag Verbosity
regVerbosity RegisterFlags
flags) String
"make" [String
"unregister"]