download: switch to different mirror
[qi-bootmenu-system.git] / initramfs.sh
blobb44fa89fdd8891fa6aa3a4680d5cd658b072bd3d
1 #!/bin/bash
3 source sources/include.sh || exit 1
5 cd $TOP || dienow
7 # copy root overlay
9 tar -C "$ROOT_OVERLAY" -cf - . | tar -C "$ROOT_DIR" -xf -
11 libs=""
13 # remove all shared libraries which aren't needed
15 if [ -z "$NO_STRIP" ]; then
17 # get library dependencies of binaries
19 for f in `find $ROOT_DIR/usr/bin $ROOT_DIR/usr/sbin -type f -perm +0111`; do
20 if [ ! -z "`file $f | grep ELF | grep executable`" ]; then
21 for l in `${CROSS}objdump -p $f | awk '/NEEDED/ { print $2 }'`; do
22 libs="$libs $l"
23 done
25 done
27 # get dependencies of the dependencies (should use recursion)
29 for l in `find $ROOT_DIR/usr/lib -type f -perm +0111`; do
30 soname="`${CROSS}objdump -p $l | awk '/SONAME/ { print $2 }'`"
31 if [[ ! -z $soname && ! -z "`echo $libs | grep $soname`" ]]; then
32 needed="`${CROSS}objdump -p $l | awk '/NEEDED/ { print $2 }'`"
33 libs="$libs $needed"
35 done
37 # remove unused sub directories which contain plugin/modules
39 for l in `find $ROOT_DIR/usr/lib -mindepth 1 -maxdepth 1 -type d -perm +0111`; do
40 if [ ! -z "`echo $libs | grep $l`" ]; then
41 echo deleteing $l
42 rm -rf "$l"
43 else
44 # modules required so get all dependencies
45 for m in `find $l -type f -perm +0111`; do
46 for ml in `${CROSS}objdump -p $m | awk '/NEEDED/ { print $2 }'`; do
47 libs="$libs $ml"
48 done
49 done
51 done
53 # delete all libraries which aren't referenced by others
55 for l in `find $ROOT_DIR/usr/lib -maxdepth 1 ! -type d -perm +0111`; do
56 if [ ! -e "$l" ]; then # remove broken symlinks
57 rm -f "$l"
58 else
59 soname="`${CROSS}objdump -p $l | awk '/SONAME/ { print $2 }' 2> /dev/null`"
60 if [[ ! -z $soname && -z "`echo $libs | grep $soname`" ]]; then
61 rm "$l"
64 done
66 # strip binaries and libraries
68 ${STRIP} -s -R .note -R .comment "$ROOT_DIR"/usr/{bin/*,sbin/*} 2> /dev/null
69 find "$ROOT_DIR/usr/lib" -name '*.so' | xargs ${STRIP} --strip-unneeded 2>/dev/null
70 [ -e "$ROOT_DIR/lib/modules" ] && find "$ROOT_DIR/lib/modules" -name '*.ko' | xargs ${STRIP}
72 # remove libthread_db which is used for cross debuging with gdb
73 rm -f "$ROOT_DIR"/lib/libthread_db*
75 fi # $NO_STRIP
77 # generate file with the contents of the initramfs it's later used
78 # by the kernel build system to create a gziped cpio archive which
79 # is then embedded into the kernel binary.
81 $SCRIPTS/gen_initramfs_list.sh -u squash -g squash $ROOT_DIR > \
82 initramfs-files
84 echo "Now run './build.sh kernel' which will build a kernel with initramfs-files as"
85 echo "CONFIG_INITRAMFS_SOURCE or run ./package.sh to create a rootfs.tar.gz tarball"
86 echo "that you can extract on a SD card."