2020-04-28 04:39:58 +02:00
|
|
|
# The wrapper script ensures variables like PKG_CONFIG_PATH and
|
|
|
|
# PKG_CONFIG_PATH_FOR_BUILD work properly.
|
|
|
|
|
|
|
|
{ stdenvNoCC
|
2021-01-24 01:40:18 +01:00
|
|
|
, lib
|
2020-04-28 04:39:58 +02:00
|
|
|
, buildPackages
|
|
|
|
, pkg-config
|
2020-05-21 17:13:27 +02:00
|
|
|
, baseBinName ? "pkg-config"
|
2020-04-28 04:39:58 +02:00
|
|
|
, propagateDoc ? pkg-config != null && pkg-config ? man
|
|
|
|
, extraPackages ? [], extraBuildCommands ? ""
|
|
|
|
}:
|
|
|
|
|
2021-01-24 04:02:59 +01:00
|
|
|
with lib;
|
2020-04-28 04:39:58 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
stdenv = stdenvNoCC;
|
|
|
|
inherit (stdenv) hostPlatform targetPlatform;
|
|
|
|
|
|
|
|
# Prefix for binaries. Customarily ends with a dash separator.
|
|
|
|
#
|
|
|
|
# TODO(@Ericson2314) Make unconditional, or optional but always true by
|
|
|
|
# default.
|
2021-01-24 01:40:18 +01:00
|
|
|
targetPrefix = lib.optionalString (targetPlatform != hostPlatform)
|
2020-04-28 04:39:58 +02:00
|
|
|
(targetPlatform.config + "-");
|
|
|
|
|
|
|
|
# See description in cc-wrapper.
|
|
|
|
suffixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
pname = targetPrefix + pkg-config.pname + "-wrapper";
|
|
|
|
inherit (pkg-config) version;
|
|
|
|
|
|
|
|
preferLocalBuild = true;
|
|
|
|
|
|
|
|
shell = getBin stdenvNoCC.shell + stdenvNoCC.shell.shellPath or "";
|
|
|
|
|
2020-05-21 17:13:27 +02:00
|
|
|
inherit targetPrefix suffixSalt baseBinName;
|
2020-04-28 04:39:58 +02:00
|
|
|
|
2020-05-21 14:52:41 +02:00
|
|
|
outputs = [ "out" ] ++ optionals propagateDoc ([ "man" ] ++ optional (pkg-config ? doc) "doc");
|
2020-04-28 04:39:58 +02:00
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit pkg-config;
|
|
|
|
};
|
|
|
|
|
|
|
|
dontBuild = true;
|
|
|
|
dontConfigure = true;
|
|
|
|
|
|
|
|
unpackPhase = ''
|
|
|
|
src=$PWD
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase =
|
|
|
|
''
|
|
|
|
mkdir -p $out/bin $out/nix-support
|
|
|
|
|
|
|
|
wrap() {
|
|
|
|
local dst="$1"
|
|
|
|
local wrapper="$2"
|
|
|
|
export prog="$3"
|
|
|
|
substituteAll "$wrapper" "$out/bin/$dst"
|
|
|
|
chmod +x "$out/bin/$dst"
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $pkg-config > $out/nix-support/orig-pkg-config
|
|
|
|
|
2020-05-21 17:13:27 +02:00
|
|
|
wrap ${targetPrefix}${baseBinName} ${./pkg-config-wrapper.sh} "${getBin pkg-config}/bin/${baseBinName}"
|
2020-05-21 15:16:34 +02:00
|
|
|
''
|
|
|
|
# symlink in share for autoconf to find macros
|
|
|
|
|
|
|
|
# TODO(@Ericson2314): in the future just make the unwrapped pkg-config a
|
|
|
|
# propagated dep once we can rely on downstream deps comming first in
|
|
|
|
# search paths. (https://github.com/NixOS/nixpkgs/pull/31414 took a crack
|
|
|
|
# at this.)
|
|
|
|
+ ''
|
|
|
|
ln -s ${pkg-config}/share $out/share
|
2020-04-28 04:39:58 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
strictDeps = true;
|
|
|
|
|
|
|
|
wrapperName = "PKG_CONFIG_WRAPPER";
|
|
|
|
|
|
|
|
setupHooks = [
|
|
|
|
../setup-hooks/role.bash
|
|
|
|
./setup-hook.sh
|
|
|
|
];
|
|
|
|
|
|
|
|
postFixup =
|
2020-05-21 17:15:15 +02:00
|
|
|
##
|
|
|
|
## User env support
|
|
|
|
##
|
2020-04-28 04:39:58 +02:00
|
|
|
|
2020-05-21 17:15:15 +02:00
|
|
|
# Propagate the underling unwrapped pkg-config so that if you
|
|
|
|
# install the wrapper, you get anything else it might provide.
|
|
|
|
''
|
2020-04-28 04:39:58 +02:00
|
|
|
printWords ${pkg-config} > $out/nix-support/propagated-user-env-packages
|
|
|
|
''
|
|
|
|
|
2020-05-21 17:15:15 +02:00
|
|
|
##
|
|
|
|
## Man page and doc support
|
|
|
|
##
|
2020-05-21 14:52:41 +02:00
|
|
|
+ optionalString propagateDoc (''
|
2020-04-28 04:39:58 +02:00
|
|
|
ln -s ${pkg-config.man} $man
|
2020-05-21 14:52:41 +02:00
|
|
|
'' + optionalString (pkg-config ? doc) ''
|
|
|
|
ln -s ${pkg-config.doc} $doc
|
|
|
|
'')
|
2020-04-28 04:39:58 +02:00
|
|
|
|
|
|
|
+ ''
|
|
|
|
substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
|
2020-09-07 16:31:59 +02:00
|
|
|
substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
|
2020-04-28 04:39:58 +02:00
|
|
|
''
|
|
|
|
|
2020-05-21 17:15:15 +02:00
|
|
|
##
|
|
|
|
## Extra custom steps
|
|
|
|
##
|
2020-04-28 04:39:58 +02:00
|
|
|
+ extraBuildCommands;
|
|
|
|
|
|
|
|
meta =
|
|
|
|
let pkg-config_ = if pkg-config != null then pkg-config else {}; in
|
|
|
|
(if pkg-config_ ? meta then removeAttrs pkg-config.meta ["priority"] else {}) //
|
|
|
|
{ description =
|
2021-01-24 01:40:18 +01:00
|
|
|
lib.attrByPath ["meta" "description"] "pkg-config" pkg-config_
|
2020-04-28 04:39:58 +02:00
|
|
|
+ " (wrapper script)";
|
|
|
|
priority = 10;
|
|
|
|
};
|
|
|
|
}
|