Make some build smaller
[tomato.git] / toolchain / scripts / rstrip.sh
blob8613b1e9efffc2dd5b3df6fa3b88676f4333a17a
1 #!/usr/bin/env bash
2 #
3 # Copyright (C) 2006 OpenWrt.org
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
9 find_modparams() {
10 FILE="$1"
11 $NM "$FILE" | awk '
12 BEGIN {
13 FS=" "
15 ($3 ~ /^__module_parm_/) && ($3 !~ /^__module_parm_desc/) {
16 gsub(/__module_parm_/, "", $3)
17 printf "-K " $3 " "
19 ($2 ~ /r/) && ($3 ~ /__param_/) {
20 gsub(/__param_/, "", $3)
21 printf "-K " $3 " "
27 SELF=${0##*/}
29 [ -z "$STRIP" ] && {
30 echo "$SELF: strip command not defined (STRIP variable not set)"
31 exit 1
34 TARGETS=$*
36 [ -z "$TARGETS" ] && {
37 echo "$SELF: no directories / files specified"
38 echo "usage: $SELF [PATH...]"
39 exit 1
42 find $TARGETS -type f -a -exec file {} \; | \
43 sed -n -e 's/^\(.*\):.*ELF.*\(executable\|relocatable\|shared object\).*,.* stripped/\1:\2/p' | \
45 IFS=":"
46 while read F S; do
47 echo "$SELF: $F:$S"
48 FEXT=${F##*\.}
49 [ "$FEXT" = "o" -o "$FEXT" = "ko" ] && {
50 eval "$STRIP_KMOD -w -K '__param*' -K '__mod*' $(find_modparams "$F")$F"
51 } || {
52 eval "$STRIP $F"
54 done
55 true