Commit 2976fef4 authored by ttuegel's avatar ttuegel
Browse files

Build shared library when linking executables dynamically

Dynamically linking executables will fail without a shared library
unless the executables do not depend on the library or there is no
library. If there is no library, building shared libraries comes at no
cost. If there is a library, the executables usually depend on it, so it
makes sense to --enable-shared.

If the user passes --disable-shared, it will still be honored, but a
warning will be produced.
parent 6af70b39
......@@ -601,8 +601,12 @@ configure (pkg_descr0, pbi) cfg
not (GHCJS.isDynamic comp)
_ -> False
let sharedLibsByDefault =
case compilerId comp of
let sharedLibsByDefault
| fromFlag (configDynExe cfg) =
-- build a shared library if dynamically-linked
-- executables are requested
True
| otherwise = case compilerId comp of
CompilerId GHC _ ->
-- if ghc is dynamic, then ghci needs a shared
-- library, so we build one by default.
......@@ -610,6 +614,18 @@ configure (pkg_descr0, pbi) cfg
CompilerId GHCJS _ ->
GHCJS.isDynamic comp
_ -> False
withSharedLib_ =
-- build shared libraries if required by GHC or by the
-- executable linking mode, but allow the user to force
-- building only static library archives with
-- --disable-shared.
fromFlagOrDefault sharedLibsByDefault $ configSharedLib cfg
withDynExe_ = fromFlag $ configDynExe cfg
when (withDynExe_ && not withSharedLib_) $
warn verbosity $
"Executables will use dynamic linking, but a shared library "
++ "is not being built. Linking will fail if any executables "
++ "depend on the library."
reloc <-
if not (fromFlag $ configRelocatable cfg)
......@@ -634,9 +650,8 @@ configure (pkg_descr0, pbi) cfg
withPrograms = programsConfig''',
withVanillaLib = fromFlag $ configVanillaLib cfg,
withProfLib = fromFlag $ configProfLib cfg,
withSharedLib = fromFlagOrDefault sharedLibsByDefault $
configSharedLib cfg,
withDynExe = fromFlag $ configDynExe cfg,
withSharedLib = withSharedLib_,
withDynExe = withDynExe_,
withProfExe = fromFlag $ configProfExe cfg,
withOptimization = fromFlag $ configOptimization cfg,
withGHCiLib = fromFlagOrDefault ghciLibByDefault $
......
......@@ -23,6 +23,7 @@
* Drop support for Haddock < 2.0 (#1808, #1718).
* Make 'cabal test'/'cabal bench' build only what's needed for
running tests/benchmarks (#1821).
* Build shared libraries by default when linking executables dynamically.
1.20.0.1 Johan Tibell <johan.tibell@gmail.com> May 2014
* Fix streaming test output.
......
......@@ -692,6 +692,14 @@ be controlled with the following command line options.
`--disable-shared`
: (default) Do not build shared library.
`--enable-executable-dynamic`
: Link executables dynamically. The executable's library dependencies should
be built as shared objects. This implies `--enable-shared` unless
`--disable-shared` is explicitly specified.
`--disable-executable-dynamic`
: (default) Link executables statically.
`--configure-option=`_str_
: An extra option to an external `configure` script, if one is used
(see the section on [system-dependent
......
module PackageTests.TestSuiteExeV10.Check (checks) where
import Data.Maybe (catMaybes)
import System.Directory ( doesFileExist )
import System.FilePath
import qualified Test.Framework as TF
......@@ -33,9 +34,9 @@ hpcTestMatrix ghcPath = do
, if shared then "Shared" else ""
]
enable cond flag
| cond = "--enable-" ++ flag
| otherwise = "--disable-" ++ flag
opts =
| cond = Just $ "--enable-" ++ flag
| otherwise = Nothing
opts = catMaybes
[ enable libProf "library-profiling"
, enable exeProf "executable-profiling"
, enable exeDyn "executable-dynamic"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment