module Distribution.Simple.Program.Builtin
(
builtinPrograms
, ghcProgram
, ghcPkgProgram
, runghcProgram
, ghcjsProgram
, ghcjsPkgProgram
, hmakeProgram
, jhcProgram
, haskellSuiteProgram
, haskellSuitePkgProgram
, uhcProgram
, gccProgram
, arProgram
, stripProgram
, happyProgram
, alexProgram
, hsc2hsProgram
, c2hsProgram
, cpphsProgram
, hscolourProgram
, doctestProgram
, haddockProgram
, greencardProgram
, ldProgram
, tarProgram
, cppProgram
, pkgConfigProgram
, hpcProgram
) where
import Distribution.Compat.Prelude
import Prelude ()
import Distribution.Simple.Program.Find
import Distribution.Simple.Program.GHC
import Distribution.Simple.Program.Internal
import Distribution.Simple.Program.Run
import Distribution.Simple.Program.Types
import Distribution.Simple.Utils
import Distribution.Verbosity
import Distribution.Version
import qualified Data.Map as Map
builtinPrograms :: [Program]
builtinPrograms :: [Program]
builtinPrograms =
[
Program
ghcProgram
, Program
runghcProgram
, Program
ghcPkgProgram
, Program
ghcjsProgram
, Program
ghcjsPkgProgram
, Program
haskellSuiteProgram
, Program
haskellSuitePkgProgram
, Program
hmakeProgram
, Program
jhcProgram
, Program
uhcProgram
, Program
hpcProgram
,
Program
hscolourProgram
, Program
doctestProgram
, Program
haddockProgram
, Program
happyProgram
, Program
alexProgram
, Program
hsc2hsProgram
, Program
c2hsProgram
, Program
cpphsProgram
, Program
greencardProgram
,
Program
gccProgram
, Program
arProgram
, Program
stripProgram
, Program
ldProgram
, Program
tarProgram
,
Program
pkgConfigProgram
]
ghcProgram :: Program
ghcProgram :: Program
ghcProgram =
(String -> Program
simpleProgram String
"ghc")
{ programFindVersion = findProgramVersion "--numeric-version" id
,
programPostConf = \Verbosity
_verbosity ConfiguredProgram
ghcProg ->
do
let ghcProg' :: ConfiguredProgram
ghcProg' =
ConfiguredProgram
ghcProg
{ programOverrideEnv =
("LANGUAGE", Just "en")
: programOverrideEnv ghcProg
}
affectedVersionRange :: VersionRange
affectedVersionRange =
VersionRange -> VersionRange -> VersionRange
intersectVersionRanges
(Version -> VersionRange
laterVersion (Version -> VersionRange) -> Version -> VersionRange
forall a b. (a -> b) -> a -> b
$ [Int] -> Version
mkVersion [Int
7, Int
8, Int
0])
(Version -> VersionRange
earlierVersion (Version -> VersionRange) -> Version -> VersionRange
forall a b. (a -> b) -> a -> b
$ [Int] -> Version
mkVersion [Int
7, Int
8, Int
4])
ConfiguredProgram -> IO ConfiguredProgram
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ConfiguredProgram -> IO ConfiguredProgram)
-> ConfiguredProgram -> IO ConfiguredProgram
forall a b. (a -> b) -> a -> b
$
ConfiguredProgram
-> (Version -> ConfiguredProgram)
-> Maybe Version
-> ConfiguredProgram
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
ConfiguredProgram
ghcProg
( \Version
v ->
if Version -> VersionRange -> Bool
withinRange Version
v VersionRange
affectedVersionRange
then ConfiguredProgram
ghcProg'
else ConfiguredProgram
ghcProg
)
(ConfiguredProgram -> Maybe Version
programVersion ConfiguredProgram
ghcProg)
, programNormaliseArgs = normaliseGhcArgs
}
runghcProgram :: Program
runghcProgram :: Program
runghcProgram =
(String -> Program
simpleProgram String
"runghc")
{ programFindVersion = findProgramVersion "--version" $ \String
str ->
case String -> [String]
words String
str of
(String
_ : String
ver : [String]
_) -> String
ver
[String]
_ -> String
""
}
ghcPkgProgram :: Program
ghcPkgProgram :: Program
ghcPkgProgram =
(String -> Program
simpleProgram String
"ghc-pkg")
{ programFindVersion = findProgramVersion "--version" $ \String
str ->
case String -> [String]
words String
str of
(String
_ : String
_ : String
_ : String
_ : String
ver : [String]
_) -> String
ver
[String]
_ -> String
""
}
ghcjsProgram :: Program
ghcjsProgram :: Program
ghcjsProgram =
(String -> Program
simpleProgram String
"ghcjs")
{ programFindVersion = findProgramVersion "--numeric-ghcjs-version" id
}
ghcjsPkgProgram :: Program
ghcjsPkgProgram :: Program
ghcjsPkgProgram =
(String -> Program
simpleProgram String
"ghcjs-pkg")
{ programFindVersion = findProgramVersion "--version" $ \String
str ->
case String -> [String]
words String
str of
(String
_ : String
_ : String
_ : String
_ : String
ver : [String]
_) -> String
ver
[String]
_ -> String
""
}
hmakeProgram :: Program
hmakeProgram :: Program
hmakeProgram =
(String -> Program
simpleProgram String
"hmake")
{ programFindVersion = findProgramVersion "--version" $ \String
str ->
case String -> [String]
words String
str of
(String
_ : String
ver : [String]
_) -> String
ver
[String]
_ -> String
""
}
jhcProgram :: Program
jhcProgram :: Program
jhcProgram =
(String -> Program
simpleProgram String
"jhc")
{ programFindVersion = findProgramVersion "--version" $ \String
str ->
case String -> [String]
words String
str of
(String
_ : String
ver : [String]
_) -> String
ver
[String]
_ -> String
""
}
uhcProgram :: Program
uhcProgram :: Program
uhcProgram =
(String -> Program
simpleProgram String
"uhc")
{ programFindVersion = findProgramVersion "--version-dotted" id
}
hpcProgram :: Program
hpcProgram :: Program
hpcProgram =
(String -> Program
simpleProgram String
"hpc")
{ programFindVersion = findProgramVersion "version" $ \String
str ->
case String -> [String]
words String
str of
(String
_ : String
_ : String
_ : String
ver : [String]
_) -> String
ver
[String]
_ -> String
""
}
haskellSuiteProgram :: Program
haskellSuiteProgram :: Program
haskellSuiteProgram =
String -> Program
simpleProgram String
"haskell-suite"
haskellSuitePkgProgram :: Program
haskellSuitePkgProgram :: Program
haskellSuitePkgProgram =
String -> Program
simpleProgram String
"haskell-suite-pkg"
happyProgram :: Program
happyProgram :: Program
happyProgram =
(String -> Program
simpleProgram String
"happy")
{ programFindVersion = findProgramVersion "--version" $ \String
str ->
case String -> [String]
words String
str of
(String
_ : String
_ : String
ver : [String]
_) -> String
ver
[String]
_ -> String
""
}
alexProgram :: Program
alexProgram :: Program
alexProgram =
(String -> Program
simpleProgram String
"alex")
{ programFindVersion = findProgramVersion "--version" $ \String
str ->
case String -> [String]
words String
str of
(String
_ : String
_ : String
ver : [String]
_) -> (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (\Char
x -> Char -> Bool
isDigit Char
x Bool -> Bool -> Bool
|| Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'.') String
ver
[String]
_ -> String
""
}
gccProgram :: Program
gccProgram :: Program
gccProgram =
(String -> Program
simpleProgram String
"gcc")
{ programFindVersion = findProgramVersion "-dumpversion" id
}
arProgram :: Program
arProgram :: Program
arProgram = String -> Program
simpleProgram String
"ar"
stripProgram :: Program
stripProgram :: Program
stripProgram =
(String -> Program
simpleProgram String
"strip")
{ programFindVersion = \Verbosity
verbosity ->
String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version" String -> String
stripExtractVersion (Verbosity -> Verbosity
lessVerbose Verbosity
verbosity)
}
hsc2hsProgram :: Program
hsc2hsProgram :: Program
hsc2hsProgram =
(String -> Program
simpleProgram String
"hsc2hs")
{ programFindVersion =
findProgramVersion "--version" $ \String
str ->
case String -> [String]
words String
str of
(String
_ : String
_ : String
ver : [String]
_) -> String
ver
[String]
_ -> String
""
}
c2hsProgram :: Program
c2hsProgram :: Program
c2hsProgram =
(String -> Program
simpleProgram String
"c2hs")
{ programFindVersion = findProgramVersion "--numeric-version" id
}
cpphsProgram :: Program
cpphsProgram :: Program
cpphsProgram =
(String -> Program
simpleProgram String
"cpphs")
{ programFindVersion = findProgramVersion "--version" $ \String
str ->
case String -> [String]
words String
str of
(String
_ : String
ver : [String]
_) -> String
ver
[String]
_ -> String
""
}
hscolourProgram :: Program
hscolourProgram :: Program
hscolourProgram =
(String -> Program
simpleProgram String
"hscolour")
{ programFindLocation = \Verbosity
v ProgramSearchPath
p -> Verbosity
-> ProgramSearchPath -> String -> IO (Maybe (String, [String]))
findProgramOnSearchPath Verbosity
v ProgramSearchPath
p String
"HsColour"
, programFindVersion = findProgramVersion "-version" $ \String
str ->
case String -> [String]
words String
str of
(String
_ : String
ver : [String]
_) -> String
ver
[String]
_ -> String
""
}
doctestProgram :: Program
doctestProgram :: Program
doctestProgram =
(String -> Program
simpleProgram String
"doctest")
{ programFindLocation = \Verbosity
v ProgramSearchPath
p -> Verbosity
-> ProgramSearchPath -> String -> IO (Maybe (String, [String]))
findProgramOnSearchPath Verbosity
v ProgramSearchPath
p String
"doctest"
, programFindVersion = findProgramVersion "--version" $ \String
str ->
case String -> [String]
words String
str of
(String
_ : String
_ : String
ver : [String]
_) -> String
ver
[String]
_ -> String
""
}
haddockProgram :: Program
haddockProgram :: Program
haddockProgram =
(String -> Program
simpleProgram String
"haddock")
{ programFindVersion = findProgramVersion "--version" $ \String
str ->
case String -> [String]
words String
str of
(String
_ : String
_ : String
ver : [String]
_) -> (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (Char
'.' Char -> String -> String
forall a. a -> [a] -> [a]
: [Char
'0' .. Char
'9'])) String
ver
[String]
_ -> String
""
, programNormaliseArgs = \Maybe Version
_ PackageDescription
_ [String]
args -> [String]
args
}
greencardProgram :: Program
greencardProgram :: Program
greencardProgram = String -> Program
simpleProgram String
"greencard"
ldProgram :: Program
ldProgram :: Program
ldProgram =
(String -> Program
simpleProgram String
"ld")
{ programPostConf = \Verbosity
verbosity ConfiguredProgram
ldProg -> do
String
ldHelpOutput <-
Verbosity -> ProgramInvocation -> IO String
getProgramInvocationOutput
Verbosity
verbosity
(ConfiguredProgram -> [String] -> ProgramInvocation
programInvocation ConfiguredProgram
ldProg [String
"--help"])
IO String -> (IOException -> IO String) -> IO String
forall a. IO a -> (IOException -> IO a) -> IO a
`catchIO` (\IOException
_ -> String -> IO String
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return String
"")
let k :: String
k = String
"Supports relocatable output"
v :: String
v
| String
"-relocatable" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isInfixOf` String
ldHelpOutput = String
"YES"
| String
"ld64:" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` String
ldHelpOutput = String
"YES"
| Bool
otherwise = String
"NO"
m :: Map String String
m = String -> String -> Map String String -> Map String String
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert String
k String
v (ConfiguredProgram -> Map String String
programProperties ConfiguredProgram
ldProg)
ConfiguredProgram -> IO ConfiguredProgram
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ConfiguredProgram -> IO ConfiguredProgram)
-> ConfiguredProgram -> IO ConfiguredProgram
forall a b. (a -> b) -> a -> b
$ ConfiguredProgram
ldProg{programProperties = m}
}
tarProgram :: Program
tarProgram :: Program
tarProgram =
(String -> Program
simpleProgram String
"tar")
{
programPostConf = \Verbosity
verbosity ConfiguredProgram
tarProg -> do
String
tarHelpOutput <-
Verbosity -> ProgramInvocation -> IO String
getProgramInvocationOutput
Verbosity
verbosity
(ConfiguredProgram -> [String] -> ProgramInvocation
programInvocation ConfiguredProgram
tarProg [String
"--help"])
IO String -> (IOException -> IO String) -> IO String
forall a. IO a -> (IOException -> IO a) -> IO a
`catchIO` (\IOException
_ -> String -> IO String
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return String
"")
let k :: String
k = String
"Supports --format"
v :: String
v = if (String
"--format" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isInfixOf` String
tarHelpOutput) then String
"YES" else String
"NO"
m :: Map String String
m = String -> String -> Map String String -> Map String String
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert String
k String
v (ConfiguredProgram -> Map String String
programProperties ConfiguredProgram
tarProg)
ConfiguredProgram -> IO ConfiguredProgram
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ConfiguredProgram -> IO ConfiguredProgram)
-> ConfiguredProgram -> IO ConfiguredProgram
forall a b. (a -> b) -> a -> b
$ ConfiguredProgram
tarProg{programProperties = m}
}
cppProgram :: Program
cppProgram :: Program
cppProgram = String -> Program
simpleProgram String
"cpp"
pkgConfigProgram :: Program
pkgConfigProgram :: Program
pkgConfigProgram =
(String -> Program
simpleProgram String
"pkg-config")
{ programFindVersion = findProgramVersion "--version" id
, programPostConf = \Verbosity
_ ConfiguredProgram
pkgConfProg ->
let programOverrideEnv' :: [(String, Maybe String)]
programOverrideEnv' =
ConfiguredProgram -> [(String, Maybe String)]
programOverrideEnv ConfiguredProgram
pkgConfProg
[(String, Maybe String)]
-> [(String, Maybe String)] -> [(String, Maybe String)]
forall a. [a] -> [a] -> [a]
++ [ (String
"PKG_CONFIG_ALLOW_SYSTEM_CFLAGS", String -> Maybe String
forall a. a -> Maybe a
Just String
"1")
, (String
"PKG_CONFIG_ALLOW_SYSTEM_LIBS", String -> Maybe String
forall a. a -> Maybe a
Just String
"1")
]
in ConfiguredProgram -> IO ConfiguredProgram
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ConfiguredProgram -> IO ConfiguredProgram)
-> ConfiguredProgram -> IO ConfiguredProgram
forall a b. (a -> b) -> a -> b
$ ConfiguredProgram
pkgConfProg{programOverrideEnv = programOverrideEnv'}
}