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