|
# Color defines |
|
|
|
RED='\033[0;31m' |
|
NC='\033[0m' # No Color |
|
# Regular Colors |
|
Black='\033[0;30m' # Black |
|
Red='\033[0;31m' # Red |
|
Green='\033[0;32m' # Green |
|
Yellow='\033[0;33m' # Yellow |
|
Blue='\033[0;34m' # Blue |
|
Purple='\033[0;35m' # Purple |
|
Cyan='\033[0;36m' # Cyan |
|
White='\033[0;37m' # White |
|
|
|
# Set correct path to readelf binary in Yocto toolchain |
|
READELF=/opt/poky/4.0.4/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux-musl/aarch64-poky-linux-musl-readelf |
|
SYSROOT=/opt/poky/4.0.4/sysroots/cortexa72-poky-linux-musl/usr/lib/ |
|
|
|
# List libraries that exist in /system/lib |
|
STANDARD_LIBS=(c dl m stdc++ log z) |
|
declare -A DEPS |
|
|
|
echo $SYSROOT |
|
|
|
has() { |
|
local p=$1 |
|
echo p |
|
shift |
|
local x |
|
for x in "$@"; do |
|
[[ "${x}" == "${p}" ]] && return 0 |
|
done |
|
return 1 |
|
} |
|
|
|
LIBS=() |
|
|
|
findSecondaryDependencies() { |
|
|
|
local lib=$1 |
|
# if [ ! -f "lib$lib.so.*" ]; then |
|
# return |
|
# fi |
|
|
|
local i |
|
for i in `$READELF -d $lib | grep NEEDED | sed -e "s/.*\[//g" | sed -e "s/\].*$//g" | xargs`; do |
|
if has $i ${STANDARD_LIBS[*]}; then |
|
continue |
|
fi |
|
|
|
findSecondaryDependencies $i |
|
|
|
if has $i ${LIBS[*]}; then |
|
continue |
|
fi |
|
LIBS+=($i) |
|
done |
|
|
|
if has $lib ${LIBS[*]}; then |
|
continue |
|
fi |
|
if [ ! -f "lib$lib.so.*" ]; then |
|
return |
|
fi |
|
LIBS+=($lib) |
|
} |
|
|
|
findDependencies() { |
|
local lib=$1 |
|
local i |
|
for i in `$READELF -d $lib | grep NEEDED | sed -e "s/.*\[//g" | sed -e "s/\].*$//g" | xargs`; do |
|
if has $i ${STANDARD_LIBS[*]}; then |
|
continue |
|
fi |
|
|
|
findSecondaryDependencies $i |
|
|
|
if has $i ${LIBS[*]}; then |
|
continue |
|
fi |
|
echo "----------------- $i" |
|
LIBS+=($i) |
|
done |
|
} |
|
|
|
findDependencies $1 |
|
|
|
for lib in ${LIBS[*]}; do |
|
echo $SYSROOT$lib |
|
findSecondaryDependencies $SYSROOT$lib |
|
done |
|
# x $1 |
|
echo $1 |
|
|
|
for lib in ${LIBS[*]}; do |
|
echo -e "[$1] dependent -> ${RED}(\"$lib\")${NC}" |
|
done |
|
|
|
mkdir -p dependencies |
|
pushd dependencies |
|
for lib in ${LIBS[*]}; do |
|
echo -e "copied lib: (${Green}(\"$lib\")${NC})" |
|
find /opt/poky/ -iname "$lib" -exec cp "{}" . \; |
|
done |
|
popd |
|
echo -e "(${Cyan} copied all deps ${NC})" |