···11+# See cc-wrapper for comments.
22+var_templates_list=(
33+ PKG_CONFIG_PATH
44+)
55+66+accumulateRoles
77+88+for var in "${var_templates_list[@]}"; do
99+ mangleVarList "$var" ${role_suffixes[@]+"${role_suffixes[@]}"}
1010+done
1111+1212+export NIX_PKG_CONFIG_WRAPPER_FLAGS_SET_@suffixSalt@=1
+117
pkgs/build-support/pkg-config-wrapper/default.nix
···11+# The wrapper script ensures variables like PKG_CONFIG_PATH and
22+# PKG_CONFIG_PATH_FOR_BUILD work properly.
33+44+{ stdenvNoCC
55+, buildPackages
66+, pkg-config
77+, propagateDoc ? pkg-config != null && pkg-config ? man
88+, extraPackages ? [], extraBuildCommands ? ""
99+}:
1010+1111+with stdenvNoCC.lib;
1212+1313+let
1414+ stdenv = stdenvNoCC;
1515+ inherit (stdenv) hostPlatform targetPlatform;
1616+1717+ # Prefix for binaries. Customarily ends with a dash separator.
1818+ #
1919+ # TODO(@Ericson2314) Make unconditional, or optional but always true by
2020+ # default.
2121+ targetPrefix = stdenv.lib.optionalString (targetPlatform != hostPlatform)
2222+ (targetPlatform.config + "-");
2323+2424+ # See description in cc-wrapper.
2525+ suffixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config;
2626+2727+in
2828+2929+stdenv.mkDerivation {
3030+ pname = targetPrefix + pkg-config.pname + "-wrapper";
3131+ inherit (pkg-config) version;
3232+3333+ preferLocalBuild = true;
3434+3535+ shell = getBin stdenvNoCC.shell + stdenvNoCC.shell.shellPath or "";
3636+3737+ inherit targetPrefix suffixSalt;
3838+3939+ outputs = [ "out" ] ++ optionals propagateDoc [ "man" ];
4040+4141+ passthru = {
4242+ inherit pkg-config;
4343+ };
4444+4545+ dontBuild = true;
4646+ dontConfigure = true;
4747+4848+ unpackPhase = ''
4949+ src=$PWD
5050+ '';
5151+5252+ installPhase =
5353+ ''
5454+ mkdir -p $out/bin $out/nix-support
5555+5656+ wrap() {
5757+ local dst="$1"
5858+ local wrapper="$2"
5959+ export prog="$3"
6060+ substituteAll "$wrapper" "$out/bin/$dst"
6161+ chmod +x "$out/bin/$dst"
6262+ }
6363+6464+ echo $pkg-config > $out/nix-support/orig-pkg-config
6565+6666+ wrap ${targetPrefix}pkg-config ${./pkg-config-wrapper.sh} "${getBin pkg-config}/bin/pkg-config"
6767+ '';
6868+6969+ strictDeps = true;
7070+7171+ wrapperName = "PKG_CONFIG_WRAPPER";
7272+7373+ setupHooks = [
7474+ ../setup-hooks/role.bash
7575+ ./setup-hook.sh
7676+ ];
7777+7878+ postFixup =
7979+ ''
8080+8181+ ##
8282+ ## User env support
8383+ ##
8484+8585+ # Propagate the underling unwrapped pkg-config so that if you
8686+ # install the wrapper, you get anything else it might provide.
8787+ printWords ${pkg-config} > $out/nix-support/propagated-user-env-packages
8888+ ''
8989+9090+ + optionalString propagateDoc ''
9191+ ##
9292+ ## Man page and info support
9393+ ##
9494+9595+ ln -s ${pkg-config.man} $man
9696+ ''
9797+9898+ + ''
9999+ substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
100100+ substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
101101+102102+ ##
103103+ ## Extra custom steps
104104+ ##
105105+ ''
106106+107107+ + extraBuildCommands;
108108+109109+ meta =
110110+ let pkg-config_ = if pkg-config != null then pkg-config else {}; in
111111+ (if pkg-config_ ? meta then removeAttrs pkg-config.meta ["priority"] else {}) //
112112+ { description =
113113+ stdenv.lib.attrByPath ["meta" "description"] "pkg-config" pkg-config_
114114+ + " (wrapper script)";
115115+ priority = 10;
116116+ };
117117+}