at 25.11-pre 2.0 kB view raw
1 2usage() { 3 echo " 4$0 <path to unpacked binary distribution directory> 5 6This program return the list of libraries and where to find them based on 7your currently installed programs. 8"; 9 exit 1 10} 11 12if test $# -ne 1; then 13 usage 14fi 15 16binaryDist=$1 17 18hasBinaries=false 19for bin in $(find $binaryDist -executable -type f) :; do 20 if test $bin = ":"; then 21 $hasBinaries || \ 22 echo "No patchable found in this directory." 23 break 24 fi 25 hasBinaries=true 26 27 echo "" 28 echo "$bin:" 29 hasLibraries=false 30 unset interpreter 31 unset addRPath 32 for lib in $(strings $bin | grep '^\(/\|\)lib.*\.so' | sort | uniq) :; do 33 if test $lib = ":"; then 34 $hasLibraries || \ 35 echo " This program is a script or it is statically linked." 36 break 37 fi 38 hasLibraries=true 39 40 echo " $lib:"; 41 42 libPath=$lib 43 lib=$(basename $lib) 44 45 #versionLessLib=$(echo $lib | sed 's,[.][.0-9]*$,,') 46 47 libs="$( 48 find /nix/store/*/lib* \( -type f -or -type l \) -name $lib | 49 grep -v '\(bootstrap-tools\|system-path\|user-environment\|extra-utils\)' 50 )" 51 52 echo "$libs" | 53 sed 's,^/nix/store/[a-z0-9]*-\([^/]*\)/.*/\([^/]*\)$, \1 -> \2,' | 54 sort | 55 uniq; 56 57 names=$( 58 echo "$libs" | 59 sed 's,^/nix/store/[a-z0-9]*-\([^/]*\)-[.0-9]*/.*$,\1,' | 60 sort | 61 uniq; 62 ) 63 64 if test "$names" = "glibc"; then names="glibc"; fi 65 if echo $names | grep -c "gcc" &> /dev/null; then names="stdenv.cc.cc"; fi 66 67 if test $lib != $libPath; then 68 interpreter="--interpreter \${$names}/lib/$lib" 69 elif echo $addRPath | grep -c "$names" &> /dev/null; then 70 : 71 else 72 addRPath=${addRPath+$addRPath:}"\${$names}/lib" 73 fi 74 done; 75 $hasLibraries && \ 76 echo " 77 Patchelf command: 78 79 patchelf $interpreter \\ 80 ${addRPath+--set-rpath $addRPath \\ 81} \$out/$bin 82 83" 84done;