Skip to content

Commit 261f14f

Browse files
nh2alexbiehl
authored andcommitted
Pass --static to pkg-config on --enable-executable-static.
This improves static building of packages with pkg-config depends, by using the pkg-config feature designed for just that. It results in more `-l` flags being emitted by `pkg-config --libs`, namely those of all recursive `.a` file dependencies.
1 parent 1be581d commit 261f14f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Cabal/src/Distribution/Simple/Configure.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,15 @@ configure (pkg_descr0, pbi) cfg = do
574574
configureAllKnownPrograms (lessVerbose verbosity) programDb
575575
>>= configureRequiredPrograms verbosity requiredBuildTools
576576

577+
let withFullyStaticExe_ = fromFlag $ configFullyStaticExe cfg
578+
577579
(pkg_descr', programDb'') <-
578-
configurePkgconfigPackages verbosity pkg_descr programDb' enabled
580+
configurePkgconfigPackages
581+
verbosity
582+
pkg_descr
583+
programDb'
584+
enabled
585+
withFullyStaticExe_
579586

580587
-- Compute internal component graph
581588
--
@@ -678,7 +685,6 @@ configure (pkg_descr0, pbi) cfg = do
678685

679686
withDynExe_ = fromFlag $ configDynExe cfg
680687

681-
withFullyStaticExe_ = fromFlag $ configFullyStaticExe cfg
682688
when (withDynExe_ && not withSharedLib_) $ warn verbosity $
683689
"Executables will use dynamic linking, but a shared library "
684690
++ "is not being built. Linking will fail if any executables "
@@ -1562,8 +1568,9 @@ configureRequiredProgram verbosity progdb
15621568

15631569
configurePkgconfigPackages :: Verbosity -> PackageDescription
15641570
-> ProgramDb -> ComponentRequestedSpec
1571+
-> Bool
15651572
-> IO (PackageDescription, ProgramDb)
1566-
configurePkgconfigPackages verbosity pkg_descr progdb enabled
1573+
configurePkgconfigPackages verbosity pkg_descr progdb enabled fullyStatic
15671574
| null allpkgs = return (pkg_descr, progdb)
15681575
| otherwise = do
15691576
(_, _, progdb') <- requireProgramVersion
@@ -1637,7 +1644,7 @@ configurePkgconfigPackages verbosity pkg_descr progdb enabled
16371644
pkgconfigBuildInfo pkgdeps = do
16381645
let pkgs = nub [ prettyShow pkg | PkgconfigDependency pkg _ <- pkgdeps ]
16391646
ccflags <- pkgconfig ("--cflags" : pkgs)
1640-
ldflags <- pkgconfig ("--libs" : pkgs)
1647+
ldflags <- pkgconfig ("--libs" : (["--static" | fullyStatic] ++ pkgs))
16411648
return (ccLdOptionsBuildInfo (words ccflags) (words ldflags))
16421649

16431650
-- | Makes a 'BuildInfo' from C compiler and linker flags.

0 commit comments

Comments
 (0)