3 # Copyright (C) 2009 Nick Bowler
4 # Copying and distribution of this file, with or without modification,
5 # are permitted in any medium without royalty provided the copyright
6 # notice and this notice are preserved. This file is offered as-is,
7 # without any warranty.
9 # Determine library dependencies for dynamically linked binaries and output
10 # directives suitable for gen_init_cpio to include all required libraries
11 # in an initramfs archive. Users of this script will probably need to adjust
12 # the BASE, LDD and LOADER variables appropriately.
14 # Directory in which the libraries are located.
15 BASE=/usr/x86_64-pc-linux-uclibc
17 # How to run ldd. The uClibc dynamic loader explodes wonderfully if
18 # LD_LIBRARY_PATH is not set correctly.
19 LDD="LD_LIBRARY_PATH=$BASE/lib:$BASE/usr/lib x86_64-pc-linux-uclibc-ldd"
21 # Where the dynamic loader is located. Always included in the output.
22 LOADER="/lib/ld64-uClibc.so.0"
27 if test -u "$1" -o -g "$1"; then
32 eval "$LDD '$file'" | sed -n 's/.*=> \(.*\) (0x[[:xdigit:]]*)/\1/p'
34 if [ "$file" != "$1" ]; then
39 libs=(`for i in "$@"; do getlibs "$i"; done | sort -u`)
41 output="file $LOADER $BASE$LOADER 0755 0 0"
43 while [ $#libs -gt 0 ]; do
47 if ! [[ "$i" =~ "^$BASE" ]]; then continue; fi
52 output="$output\nslink $dest $(readlink "$i") 0644 0 0"
54 if [ "$next[0]" != "/" ]; then
55 next="$(dirname "$i")/$next"
58 elif test -f "$i"; then
59 output="$output\nfile $dest $i 0644 0 0"
63 echo "$output" | sort -u