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