1 # The wrapper script ensures variables like PKG_CONFIG_PATH and
2 # PKG_CONFIG_PATH_FOR_BUILD work properly.
8 , baseBinName ? "pkg-config"
9 , propagateDoc ? pkg-config != null && pkg-config ? man
10 , extraPackages ? [], extraBuildCommands ? ""
17 inherit (stdenv) hostPlatform targetPlatform;
19 # Prefix for binaries. Customarily ends with a dash separator.
21 # TODO(@Ericson2314) Make unconditional, or optional but always true by
23 targetPrefix = lib.optionalString (targetPlatform != hostPlatform)
24 (targetPlatform.config + "-");
26 # See description in cc-wrapper.
27 suffixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config;
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");
53 # Additional flags passed to pkg-config.
54 addFlags = lib.optional stdenv.targetPlatform.isStatic "--static";
62 mkdir -p $out/bin $out/nix-support
68 substituteAll "$wrapper" "$out/bin/$dst"
69 chmod +x "$out/bin/$dst"
72 echo $pkg-config > $out/nix-support/orig-pkg-config
74 wrap ${targetPrefix}${baseBinName} ${./pkg-config-wrapper.sh} "${getBin pkg-config}/bin/${baseBinName}"
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
83 ln -s ${pkg-config}/share $out/share
86 wrapperName = "PKG_CONFIG_WRAPPER";
89 ../setup-hooks/role.bash
98 # Propagate the underling unwrapped pkg-config so that if you
99 # install the wrapper, you get anything else it might provide.
101 printWords ${pkg-config} > $out/nix-support/propagated-user-env-packages
105 ## Man page and doc support
107 + optionalString propagateDoc (''
108 ln -s ${pkg-config.man} $man
109 '' + optionalString (pkg-config ? doc) ''
110 ln -s ${pkg-config.doc} $doc
114 substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
115 substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
119 ## Extra custom steps
121 + extraBuildCommands;
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 {}) //
127 lib.attrByPath ["meta" "description"] "pkg-config" pkg-config_
128 + " (wrapper script)";