nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1
2fixupOutputHooks+=(_linkDLLs)
3
4# For every *.{exe,dll} in $output/bin/ we try to find all (potential)
5# transitive dependencies and symlink those DLLs into $output/bin
6# so they are found on invocation.
7# (DLLs are first searched in the directory of the running exe file.)
8# The links are relative, so relocating whole /nix/store won't break them.
9_linkDLLs() {
10(
11 if [ ! -d "$prefix/bin" ]; then exit; fi
12 cd "$prefix/bin"
13
14 # Compose path list where DLLs should be located:
15 # prefix $PATH by currently-built outputs
16 local DLLPATH=""
17 local outName
18 for outName in $(getAllOutputNames); do
19 addToSearchPath DLLPATH "${!outName}/bin"
20 done
21 DLLPATH="$DLLPATH:$PATH"
22
23 echo DLLPATH="'$DLLPATH'"
24
25 linkCount=0
26 # Iterate over any DLL that we depend on.
27 local dll
28 for dll in $($OBJDUMP -p *.{exe,dll} | sed -n 's/.*DLL Name: \(.*\)/\1/p' | sort -u); do
29 if [ -e "./$dll" ]; then continue; fi
30 # Locate the DLL - it should be an *executable* file on $DLLPATH.
31 local dllPath="$(PATH="$DLLPATH" type -P "$dll")"
32 if [ -z "$dllPath" ]; then continue; fi
33 # That DLL might have its own (transitive) dependencies,
34 # so add also all DLLs from its directory to be sure.
35 local dllPath2
36 for dllPath2 in "$dllPath" "$(dirname $(readlink "$dllPath" || echo "$dllPath"))"/*.dll; do
37 if [ -e ./"$(basename "$dllPath2")" ]; then continue; fi
38 CYGWIN+=\ winsymlinks:nativestrict ln -sr "$dllPath2" .
39 linkCount=$(($linkCount+1))
40 done
41 done
42 echo "Created $linkCount DLL link(s) in $prefix/bin"
43)
44}
45