PortableLinuxGames/copyMissingLibraries

84 lines
1.7 KiB
Plaintext
Raw Normal View History

2013-03-06 14:54:22 -08:00
#!/bin/bash
2013-04-14 05:05:22 -07:00
# Author : Ismael Barros² <ismael@barros2.org>
# License : BSD http://en.wikipedia.org/wiki/BSD_license
2013-03-06 14:54:22 -08:00
EXCEPTIONS=libGL.so.1
2013-11-01 10:28:10 -07:00
DESTINATION="$PWD/usr/lib/"
2013-03-06 14:54:22 -08:00
2013-04-02 00:48:20 -07:00
findFiles() {
2013-12-15 13:01:39 -08:00
find "$DESTINATION" -iname "*.so"
find "$DESTINATION" -iname "*.so.*"
for i in $@; do
[ -d "$i" ] && find "$i" -type f -perm /a+x
[ -f "$i" ] && echo "$i"
done
2013-03-06 14:54:22 -08:00
}
2013-04-02 00:48:20 -07:00
extractDependencies() {
2013-04-06 10:00:55 -07:00
#objdump -p "$@" 2>/dev/null | egrep NEEDED | awk '{ print $2 }' | grep -v "$PWD" | egrep "^/" | sort | uniq
2013-12-15 13:01:39 -08:00
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$DESTINATION" ldd "$@" | grep "not found" | sort | uniq >&2
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$DESTINATION" ldd "$@" 2>/dev/null | grep -v "not a dynamic executable" | grep -v "^\." | grep -v "$PWD" | cut -d" " -f3 | grep "^/" | sort | uniq
2013-03-06 14:54:22 -08:00
}
2013-11-01 10:28:10 -07:00
extractRuntimeDependencies() {
2013-11-25 15:45:01 -08:00
strings "$@" | egrep \\.so
2013-11-01 10:28:10 -07:00
}
mkdir -p "$DESTINATION"
2013-03-16 05:23:53 -07:00
2013-11-25 15:45:01 -08:00
OIFS=$IFS
NIFS=$'\n'
IFS=$NIFS
2013-03-06 14:54:22 -08:00
prev_libs=
while true; do
2013-11-25 15:45:01 -08:00
files=$(findFiles "$@")
2013-11-01 10:28:10 -07:00
libs=$(extractDependencies $files)
#runlibs=$(extractRuntimeDependencies $@)
#if [ -n "$libs" ]; then
#echo "Libraries: $libs"
#fi
#if [ -n "$runlibs" ]; then
#echo "Runtime libraries: $runlibs"
#libs+=" $runlibs"
#fi
2013-03-06 14:54:22 -08:00
for i in $EXCEPTIONS; do
#echo "Ignoring $i"
2013-11-01 10:28:10 -07:00
#libs=${libs//$i/}
for j in $libs; do
[[ "$j" =~ "$i" ]] && {
echo "Ignoring $j"
libs=${libs//$j/}
}
done
2013-03-06 14:54:22 -08:00
done
for i in $libs; do
2013-11-01 10:28:10 -07:00
dest_lib=$DESTINATION/$(basename "$i")
if [ ! -f "$dest_lib" ]; then
if [ -f "$i" ]; then
cp -v "$i" "$dest_lib"
chmod +x "$dest_lib"
else
echo "!! Could not find dependency $i"
fi
fi
2013-03-06 14:54:22 -08:00
done
# If no new libraries have been found, break the loop
if [ "$prev_libs" = "$libs" ]; then
break;
fi
prev_libs=$libs
done
cp -v /lib/ld-linux.so.2 usr/lib/