diff --git a/doc/stdenv/stdenv.xml b/doc/stdenv/stdenv.xml
index a4174f4f7edc..ee93f39318b8 100644
--- a/doc/stdenv/stdenv.xml
+++ b/doc/stdenv/stdenv.xml
@@ -2081,6 +2081,16 @@ postInstall = ''
+
+
+ validatePkgConfig
+
+
+
+ The validatePkgConfig hook validates all pkg-config (.pc) files in a package. This helps catching some common errors in pkg-config files, such as undefined variables.
+
+
+
cmake
diff --git a/pkgs/build-support/setup-hooks/validate-pkg-config.sh b/pkgs/build-support/setup-hooks/validate-pkg-config.sh
new file mode 100644
index 000000000000..54fc9cc122ca
--- /dev/null
+++ b/pkgs/build-support/setup-hooks/validate-pkg-config.sh
@@ -0,0 +1,19 @@
+# This setup hook validates each pkgconfig file in each output.
+
+fixupOutputHooks+=(_validatePkgConfig)
+
+_validatePkgConfig() {
+ for pc in $(find "$prefix" -name '*.pc'); do
+ local bail=0
+
+ # Do not fail immediately. It's nice to see all errors when
+ # there are multiple pkgconfig files.
+ if ! pkg-config --validate "$pc"; then
+ bail=1
+ fi
+ done
+
+ if [ $bail -eq 1 ]; then
+ exit 1
+ fi
+}
diff --git a/pkgs/development/libraries/science/math/mkl/default.nix b/pkgs/development/libraries/science/math/mkl/default.nix
index 016864abed8c..19f988d965c4 100644
--- a/pkgs/development/libraries/science/math/mkl/default.nix
+++ b/pkgs/development/libraries/science/math/mkl/default.nix
@@ -1,9 +1,9 @@
{ stdenvNoCC
, fetchurl
-, pkgconfig
, rpmextract
, undmg
, darwin
+, validatePkgConfig
, enableStatic ? false
}:
@@ -46,15 +46,11 @@ in stdenvNoCC.mkDerivation {
sha256 = "0v86hrqg15mbc78m9qk8dbkaaq3mlwashgbf9n79kxpl1gilnah8";
});
- nativeBuildInputs = if stdenvNoCC.isDarwin
+ nativeBuildInputs = [ validatePkgConfig ] ++ (if stdenvNoCC.isDarwin
then
[ undmg darwin.cctools ]
else
- [ rpmextract ];
-
- installCheckInputs = [ pkgconfig ];
-
- doInstallCheck = true;
+ [ rpmextract ]);
buildPhase = if stdenvNoCC.isDarwin then ''
for f in Contents/Resources/pkg/*.tgz; do
@@ -152,11 +148,6 @@ in stdenvNoCC.mkDerivation {
install_name_tool -change @rpath/libtbbmalloc.dylib $out/lib/libtbbmalloc.dylib $out/lib/libtbbmalloc_proxy.dylib
'';
- # Validate pkgconfig files, since they break often on updates.
- installCheckPhase = ''
- pkg-config --validate $out/lib/pkgconfig/*.pc
- '';
-
# Per license agreement, do not modify the binary
dontStrip = true;
dontPatchELF = true;
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index f57bff13b6f6..47f8ceb07e05 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -507,6 +507,10 @@ in
iconConvTools = callPackage ../build-support/icon-conv-tools {};
+ validatePkgConfig = makeSetupHook
+ { name = "validate-pkg-config"; deps = [ findutils pkgconfig ]; }
+ ../build-support/setup-hooks/validate-pkg-config.sh;
+
#package writers
writers = callPackage ../build-support/writers {};