Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | do_rootfs[depends] += "mklibs-native:do_populate_sysroot" |
| 2 | |
| 3 | IMAGE_PREPROCESS_COMMAND += "mklibs_optimize_image; " |
| 4 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 5 | inherit linuxloader |
| 6 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | mklibs_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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 13 | # 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | |
| 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 | |
| 47 | mklibs_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 | } |