1 -----------------------------------------------------------------------------
4 -- Module : Distribution.Simple.Program.Builtin
5 -- Copyright : Isaac Jones 2006, Duncan Coutts 2007-2009
7 -- Maintainer : cabal-devel@haskell.org
8 -- Portability : portable
10 -- The module defines all the known built-in 'Program's.
12 -- Where possible we try to find their version numbers.
13 module Distribution
.Simple
.Program
.Builtin
14 ( -- * The collection of unconfigured and configured programs
17 -- * Programs that Cabal knows about
26 , haskellSuitePkgProgram
47 import Distribution
.Compat
.Prelude
50 import Distribution
.Simple
.Program
.Find
51 import Distribution
.Simple
.Program
.GHC
52 import Distribution
.Simple
.Program
.Internal
53 import Distribution
.Simple
.Program
.Run
54 import Distribution
.Simple
.Program
.Types
55 import Distribution
.Simple
.Utils
56 import Distribution
.Verbosity
57 import Distribution
.Version
59 import qualified Data
.Map
as Map
61 -- ------------------------------------------------------------
65 -- ------------------------------------------------------------
67 -- | The default list of programs.
68 -- These programs are typically used internally to Cabal.
69 builtinPrograms
:: [Program
]
71 [ -- compilers and related progs
78 , haskellSuitePkgProgram
93 , -- platform toolchain
99 , -- configuration tools
103 ghcProgram
:: Program
105 (simpleProgram
"ghc")
106 { programFindVersion
= findProgramVersion
"--numeric-version" id
107 , -- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/8825
108 -- (spurious warning on non-english locales)
109 programPostConf
= \_verbosity ghcProg
->
113 { programOverrideEnv
=
114 ("LANGUAGE", Just
"en")
115 : programOverrideEnv ghcProg
117 -- Only the 7.8 branch seems to be affected. Fixed in 7.8.4.
118 affectedVersionRange
=
119 intersectVersionRanges
120 (laterVersion
$ mkVersion
[7, 8, 0])
121 (earlierVersion
$ mkVersion
[7, 8, 4])
126 if withinRange v affectedVersionRange
130 (programVersion ghcProg
)
131 , programNormaliseArgs
= normaliseGhcArgs
134 runghcProgram
:: Program
136 (simpleProgram
"runghc")
137 { programFindVersion
= findProgramVersion
"--version" $ \str
->
144 ghcPkgProgram
:: Program
146 (simpleProgram
"ghc-pkg")
147 { programFindVersion
= findProgramVersion
"--version" $ \str
->
148 -- Invoking "ghc-pkg --version" gives a string like
149 -- "GHC package manager version 6.4.1"
151 (_
: _
: _
: _
: ver
: _
) -> ver
155 ghcjsProgram
:: Program
157 (simpleProgram
"ghcjs")
158 { programFindVersion
= findProgramVersion
"--numeric-ghcjs-version" id
161 -- note: version is the version number of the GHC version that ghcjs-pkg was built with
162 ghcjsPkgProgram
:: Program
164 (simpleProgram
"ghcjs-pkg")
165 { programFindVersion
= findProgramVersion
"--version" $ \str
->
166 -- Invoking "ghcjs-pkg --version" gives a string like
167 -- "GHCJS package manager version 6.4.1"
169 (_
: _
: _
: _
: ver
: _
) -> ver
173 hmakeProgram
:: Program
175 (simpleProgram
"hmake")
176 { programFindVersion
= findProgramVersion
"--version" $ \str
->
177 -- Invoking "hmake --version" gives a string line
178 -- "/usr/local/bin/hmake: 3.13 (2006-11-01)"
184 jhcProgram
:: Program
186 (simpleProgram
"jhc")
187 { programFindVersion
= findProgramVersion
"--version" $ \str
->
188 -- invoking "jhc --version" gives a string like
189 -- "jhc 0.3.20080208 (wubgipkamcep-2)
190 -- compiled by ghc-6.8 on a x86_64 running linux"
196 uhcProgram
:: Program
198 (simpleProgram
"uhc")
199 { programFindVersion
= findProgramVersion
"--version-dotted" id
202 hpcProgram
:: Program
204 (simpleProgram
"hpc")
205 { programFindVersion
= findProgramVersion
"version" $ \str
->
207 (_
: _
: _
: ver
: _
) -> ver
211 -- This represents a haskell-suite compiler. Of course, the compiler
212 -- itself probably is not called "haskell-suite", so this is not a real
213 -- program. (But we don't know statically the name of the actual compiler,
214 -- so this is the best we can do.)
216 -- Having this Program value serves two purposes:
218 -- 1. We can accept options for the compiler in the form of
220 -- --haskell-suite-option(s)=...
222 -- 2. We can find a program later using this static id (with
225 -- The path to the real compiler is found and recorded in the ProgramDb
226 -- during the configure phase.
227 haskellSuiteProgram
:: Program
228 haskellSuiteProgram
=
229 simpleProgram
"haskell-suite"
231 -- This represent a haskell-suite package manager. See the comments for
232 -- haskellSuiteProgram.
233 haskellSuitePkgProgram
:: Program
234 haskellSuitePkgProgram
=
235 simpleProgram
"haskell-suite-pkg"
237 happyProgram
:: Program
239 (simpleProgram
"happy")
240 { programFindVersion
= findProgramVersion
"--version" $ \str
->
241 -- Invoking "happy --version" gives a string like
242 -- "Happy Version 1.16 Copyright (c) ...."
244 (_
: _
: ver
: _
) -> ver
248 alexProgram
:: Program
250 (simpleProgram
"alex")
251 { programFindVersion
= findProgramVersion
"--version" $ \str
->
252 -- Invoking "alex --version" gives a string like
253 -- "Alex version 2.1.0, (c) 2003 Chris Dornan and Simon Marlow"
255 (_
: _
: ver
: _
) -> takeWhile (\x
-> isDigit x || x
== '.') ver
259 gccProgram
:: Program
261 (simpleProgram
"gcc")
262 { programFindVersion
= findProgramVersion
"-dumpversion" id
266 arProgram
= simpleProgram
"ar"
268 stripProgram
:: Program
270 (simpleProgram
"strip")
271 { programFindVersion
= \verbosity
->
272 findProgramVersion
"--version" stripExtractVersion
(lessVerbose verbosity
)
275 hsc2hsProgram
:: Program
277 (simpleProgram
"hsc2hs")
278 { programFindVersion
=
279 findProgramVersion
"--version" $ \str
->
280 -- Invoking "hsc2hs --version" gives a string like "hsc2hs version 0.66"
282 (_
: _
: ver
: _
) -> ver
286 c2hsProgram
:: Program
288 (simpleProgram
"c2hs")
289 { programFindVersion
= findProgramVersion
"--numeric-version" id
292 cpphsProgram
:: Program
294 (simpleProgram
"cpphs")
295 { programFindVersion
= findProgramVersion
"--version" $ \str
->
296 -- Invoking "cpphs --version" gives a string like "cpphs 1.3"
302 hscolourProgram
:: Program
304 (simpleProgram
"hscolour")
305 { programFindLocation
= \v p
-> findProgramOnSearchPath v p
"HsColour"
306 , programFindVersion
= findProgramVersion
"-version" $ \str
->
307 -- Invoking "HsColour -version" gives a string like "HsColour 1.7"
313 -- TODO: Ensure that doctest is built against the same GHC as the one
314 -- that's being used. Same for haddock. @phadej pointed this out.
315 doctestProgram
:: Program
317 (simpleProgram
"doctest")
318 { programFindLocation
= \v p
-> findProgramOnSearchPath v p
"doctest"
319 , programFindVersion
= findProgramVersion
"--version" $ \str
->
320 -- "doctest version 0.11.2"
322 (_
: _
: ver
: _
) -> ver
326 haddockProgram
:: Program
328 (simpleProgram
"haddock")
329 { programFindVersion
= findProgramVersion
"--version" $ \str
->
330 -- Invoking "haddock --version" gives a string like
331 -- "Haddock version 0.8, (c) Simon Marlow 2006"
333 (_
: _
: ver
: _
) -> takeWhile (`
elem`
('.' : ['0' .. '9'])) ver
335 , programNormaliseArgs
= \_ _ args
-> args
338 greencardProgram
:: Program
339 greencardProgram
= simpleProgram
"greencard"
344 { programPostConf
= \verbosity ldProg
-> do
345 -- The `lld` linker cannot create merge (relocatable) objects so we
346 -- want to detect this.
347 -- If the linker does support relocatable objects, we want to use that
348 -- to create partially pre-linked objects for GHCi, so we get much
349 -- faster loading as we do not have to do the separate loading and
350 -- in-memory linking the static linker in GHC does, but can offload
351 -- parts of this process to a pre-linking step.
352 -- However this requires the linker to support this features. Not all
353 -- linkers do, and notably as of this writing `lld` which is a popular
354 -- choice for windows linking does not support this feature. However
355 -- if using binutils ld or another linker that supports --relocatable,
356 -- we should still be good to generate pre-linked objects.
358 getProgramInvocationOutput
360 (programInvocation ldProg
["--help"])
361 -- In case the linker does not support '--help'. Eg the LLVM linker,
362 -- `lld` only accepts `-help`.
363 `catchIO`
(\_
-> return "")
364 let k
= "Supports relocatable output"
365 -- Standard GNU `ld` uses `--relocatable` while `ld.gold` uses
366 -- `-relocatable` (single `-`).
368 |
"-relocatable" `isInfixOf` ldHelpOutput
= "YES"
369 -- ld64 on macOS has this lovely response for "--help"
371 -- ld64: For information on command line options please use 'man ld'.
373 -- it does however support -r, if you read the manpage
374 -- (e.g. https://www.manpagez.com/man/1/ld64/)
375 |
"ld64:" `
isPrefixOf` ldHelpOutput
= "YES"
378 m
= Map
.insert k v
(programProperties ldProg
)
379 return $ ldProg
{programProperties
= m
}
382 tarProgram
:: Program
384 (simpleProgram
"tar")
385 { -- See #1901. Some versions of 'tar' (OpenBSD, NetBSD, ...) don't support the
386 -- '--format' option.
387 programPostConf
= \verbosity tarProg
-> do
389 getProgramInvocationOutput
391 (programInvocation tarProg
["--help"])
392 -- Some versions of tar don't support '--help'.
393 `catchIO`
(\_
-> return "")
394 let k
= "Supports --format"
395 v
= if ("--format" `isInfixOf` tarHelpOutput
) then "YES" else "NO"
396 m
= Map
.insert k v
(programProperties tarProg
)
397 return $ tarProg
{programProperties
= m
}
400 cppProgram
:: Program
401 cppProgram
= simpleProgram
"cpp"
403 pkgConfigProgram
:: Program
405 (simpleProgram
"pkg-config")
406 { programFindVersion
= findProgramVersion
"--version" id
407 , programPostConf
= \_ pkgConfProg
->
408 let programOverrideEnv
' =
409 programOverrideEnv pkgConfProg
410 ++ [ ("PKG_CONFIG_ALLOW_SYSTEM_CFLAGS", Just
"1")
411 , ("PKG_CONFIG_ALLOW_SYSTEM_LIBS", Just
"1")
413 in pure
$ pkgConfProg
{programOverrideEnv
= programOverrideEnv
'}