blob: 5f6df1b17fd52f077859556ac58e63ea68329c18 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001do_rootfs[depends] += "mklibs-native:do_populate_sysroot"
2
3IMAGE_PREPROCESS_COMMAND += "mklibs_optimize_image; "
4
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05005inherit linuxloader
6
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007mklibs_optimize_image_doit() {
8 rm -rf ${WORKDIR}/mklibs
9 mkdir -p ${WORKDIR}/mklibs/dest
10 cd ${IMAGE_ROOTFS}
11 du -bs > ${WORKDIR}/mklibs/du.before.mklibs.txt
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050013 # Build a list of dynamically linked executable ELF files.
14 # Omit libc/libpthread as a special case because it has an interpreter
15 # but is primarily what we intend to strip down.
16 for i in `find . -type f -executable ! -name 'libc-*' ! -name 'libpthread-*'`; do
17 file $i | grep -q ELF || continue
18 ${HOST_PREFIX}readelf -l $i | grep -q INTERP || continue
19 echo $i
20 done > ${WORKDIR}/mklibs/executables.list
21
22 dynamic_loader=$(linuxloader)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023
24 mklibs -v \
25 --ldlib ${dynamic_loader} \
26 --libdir ${baselib} \
27 --sysroot ${PKG_CONFIG_SYSROOT_DIR} \
28 --gcc-options "--sysroot=${PKG_CONFIG_SYSROOT_DIR}" \
29 --root ${IMAGE_ROOTFS} \
30 --target `echo ${TARGET_PREFIX} | sed 's/-$//' ` \
31 -d ${WORKDIR}/mklibs/dest \
32 `cat ${WORKDIR}/mklibs/executables.list`
33
34 cd ${WORKDIR}/mklibs/dest
35 for i in *
36 do
37 cp $i `find ${IMAGE_ROOTFS} -name $i`
38 done
39
40 cd ${IMAGE_ROOTFS}
41 du -bs > ${WORKDIR}/mklibs/du.after.mklibs.txt
42
43 echo rootfs size before mklibs optimization: `cat ${WORKDIR}/mklibs/du.before.mklibs.txt`
44 echo rootfs size after mklibs optimization: `cat ${WORKDIR}/mklibs/du.after.mklibs.txt`
45}
46
47mklibs_optimize_image() {
48 for img in ${MKLIBS_OPTIMIZED_IMAGES}
49 do
50 if [ "${img}" = "${PN}" ] || [ "${img}" = "all" ]
51 then
52 mklibs_optimize_image_doit
53 break
54 fi
55 done
56}