ansible-later: 2.0.22 -> 2.0.23
[NixPkgs.git] / pkgs / build-support / pkg-config-wrapper / default.nix
blob312d2fe02610adeabadd63cde9cfa31785029d92
1 # The wrapper script ensures variables like PKG_CONFIG_PATH and
2 # PKG_CONFIG_PATH_FOR_BUILD work properly.
4 { stdenvNoCC
5 , lib
6 , buildPackages
7 , pkg-config
8 , baseBinName ? "pkg-config"
9 , propagateDoc ? pkg-config != null && pkg-config ? man
10 , extraPackages ? [], extraBuildCommands ? ""
13 with lib;
15 let
16   stdenv = stdenvNoCC;
17   inherit (stdenv) hostPlatform targetPlatform;
19   # Prefix for binaries. Customarily ends with a dash separator.
20   #
21   # TODO(@Ericson2314) Make unconditional, or optional but always true by
22   # default.
23   targetPrefix = lib.optionalString (targetPlatform != hostPlatform)
24                                         (targetPlatform.config + "-");
26   # See description in cc-wrapper.
27   suffixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config;
31 stdenv.mkDerivation {
32   pname = targetPrefix + pkg-config.pname + "-wrapper";
33   inherit (pkg-config) version;
35   enableParallelBuilding = true;
37   preferLocalBuild = true;
39   shell = getBin stdenvNoCC.shell + stdenvNoCC.shell.shellPath or "";
41   inherit targetPrefix suffixSalt baseBinName;
43   outputs = [ "out" ] ++ optionals propagateDoc ([ "man" ] ++ optional (pkg-config ? doc) "doc");
45   passthru = {
46     inherit pkg-config;
47   };
49   strictDeps = true;
50   dontBuild = true;
51   dontConfigure = true;
53   # Additional flags passed to pkg-config.
54   addFlags = lib.optional stdenv.targetPlatform.isStatic "--static";
56   unpackPhase = ''
57     src=$PWD
58   '';
60   installPhase =
61     ''
62       mkdir -p $out/bin $out/nix-support
64       wrap() {
65         local dst="$1"
66         local wrapper="$2"
67         export prog="$3"
68         substituteAll "$wrapper" "$out/bin/$dst"
69         chmod +x "$out/bin/$dst"
70       }
72       echo $pkg-config > $out/nix-support/orig-pkg-config
74       wrap ${targetPrefix}${baseBinName} ${./pkg-config-wrapper.sh} "${getBin pkg-config}/bin/${baseBinName}"
75     ''
76     # symlink in share for autoconf to find macros
78     # TODO(@Ericson2314): in the future just make the unwrapped pkg-config a
79     # propagated dep once we can rely on downstream deps comming first in
80     # search paths. (https://github.com/NixOS/nixpkgs/pull/31414 took a crack
81     # at this.)
82     + ''
83       ln -s ${pkg-config}/share $out/share
84     '';
86   wrapperName = "PKG_CONFIG_WRAPPER";
88   setupHooks = [
89     ../setup-hooks/role.bash
90     ./setup-hook.sh
91   ];
93   postFixup =
94     ##
95     ## User env support
96     ##
98     # Propagate the underling unwrapped pkg-config so that if you
99     # install the wrapper, you get anything else it might provide.
100     ''
101       printWords ${pkg-config} > $out/nix-support/propagated-user-env-packages
102     ''
104     ##
105     ## Man page and doc support
106     ##
107     + optionalString propagateDoc (''
108       ln -s ${pkg-config.man} $man
109     '' + optionalString (pkg-config ? doc) ''
110       ln -s ${pkg-config.doc} $doc
111     '')
113     + ''
114       substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
115       substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
116     ''
118     ##
119     ## Extra custom steps
120     ##
121     + extraBuildCommands;
123   meta =
124     let pkg-config_ = if pkg-config != null then pkg-config else {}; in
125     (if pkg-config_ ? meta then removeAttrs pkg-config.meta ["priority"] else {}) //
126     { description =
127         lib.attrByPath ["meta" "description"] "pkg-config" pkg-config_
128         + " (wrapper script)";
129       priority = 10;
130   };