diff --git a/Cabal/Distribution/Simple/Configure.hs b/Cabal/Distribution/Simple/Configure.hs index 3604f186a85a6c315863d28092091a47938ed906..5af7a39774114bedb517e111b6fdb072a25d8865 100644 --- a/Cabal/Distribution/Simple/Configure.hs +++ b/Cabal/Distribution/Simple/Configure.hs @@ -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 $ diff --git a/Cabal/changelog b/Cabal/changelog index c29e98e8014fd4bcc168f1b6b89e56bcdc1b4a46..e84468f23f0b8123c8d1dab4a1704fae76c71a54 100644 --- a/Cabal/changelog +++ b/Cabal/changelog @@ -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. diff --git a/Cabal/doc/installing-packages.markdown b/Cabal/doc/installing-packages.markdown index b90df2152d01120b4ade8a96e3a5ed60edab09e3..299f3677eb46a650e9e79c578150411998828ad4 100644 --- a/Cabal/doc/installing-packages.markdown +++ b/Cabal/doc/installing-packages.markdown @@ -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 diff --git a/Cabal/tests/PackageTests/TestSuiteExeV10/Check.hs b/Cabal/tests/PackageTests/TestSuiteExeV10/Check.hs index e140ff958357fa6b7bfb3cd70db5a71314bff36c..2b25cab1911f5882ef86f4e5a088db6f41a80ae9 100644 --- a/Cabal/tests/PackageTests/TestSuiteExeV10/Check.hs +++ b/Cabal/tests/PackageTests/TestSuiteExeV10/Check.hs @@ -1,5 +1,6 @@ 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"