2002-03-25 23:37:46 +03:00
#!/bin/sh -e
#
# brp-strip - strip ELF binaries.
# Inspired by brp-strip script from RPM source code.
#
2003-11-08 22:52:04 +03:00
# $Id$
2003-11-09 19:47:45 +03:00
# Copyright (C) 2000,2003 Dmitry V. Levin <ldv@altlinux.org>
2002-03-25 23:37:46 +03:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
2003-11-09 17:30:36 +03:00
. @RPMCONFIGDIR@/functions
2003-11-09 19:47:45 +03:00
ValidateBuildRoot
2002-03-25 23:37:46 +03:00
2003-11-09 17:30:36 +03:00
Usage()
2002-03-25 23:37:46 +03:00
{
2003-11-09 17:30:36 +03:00
[ "$1" = 0 ] || exec >&2
2002-03-25 23:37:46 +03:00
cat <<EOF
brp-strip - strip ELF binaries.
brp-strip is free software, covered by the GNU General Public License.
brp-strip comes with ABSOLUTELY NO WARRANTY, see license for details.
Usage: $PROG [options] [files]
Valid options are:
-h, --help
Show a summary of the options to brp-strip and exit.
-p, --preserve-dates
Preserve modified/access timestamps of stripped files.
-R <name>, --remove-section=<name>
Remove the named section from files. This option may be given more than once.
-s, --strip-all
Remove all symbols.
-g, -S, --strip-debug
Remove all debugging symbols.
2002-09-05 15:55:30 +04:00
--skip-files=<pattern>
Skip files matched by specified pattern.
2002-03-25 23:37:46 +03:00
--strip-unneeded
Remove all symbols not needed by relocations.
2002-09-05 15:55:30 +04:00
-N, --strip-symbol=<name>
2002-03-25 23:37:46 +03:00
Do not copy named symbol.
2002-09-05 15:55:30 +04:00
-K, --keep-symbol=<name>
2002-03-25 23:37:46 +03:00
Only copy named symbol.
-x, --discard-all
Remove all non-global symbols.
-X, --discard-locals
Remove any compiler-generated symbols.
-v, --verbose
List all object files modified.
-T <name>, --topdir=<name>
Start file lookup at named directory, \$RPM_BUILD_ROOT by default.
files is list of files or directory trees where files to be stripped.
By default, all files in TOPDIR, specified by \$RPM_STRIP_METHOD, will be stripped.
EOF
[ -n "$1" ] && exit "$1" || exit
}
2003-11-09 17:30:36 +03:00
TEMP=`getopt -n "$PROG" -o hpR:sgSN:K:xXvT: -l help,preserve-dates,remove-section:,skip-files:,strip-all,strip-unneeded,strip-symbol:,keep-symbol:,discard-all,discard-locals,verbose,topdir: -- "$@"` || Usage
2002-03-25 23:37:46 +03:00
eval set -- "$TEMP"
2002-09-27 17:41:26 +04:00
: ${RPM_STRIP_SKIPLIST:=}
: ${RPM_STRIP_TOPDIR:=}
export RPM_STRIP_SKIPLIST
2002-03-25 23:37:46 +03:00
export STRIP_FORCED=
export STRIP_FORCED_OPTS=
AddForcedOpts()
{
if [ -z "$STRIP_FORCED_OPTS" ]; then
STRIP_FORCED_OPTS="$*"
else
STRIP_FORCED_OPTS="$STRIP_FORCED_OPTS $*"
fi
}
while :; do
case "$1" in
-h|--help)
2003-11-09 17:30:36 +03:00
Usage 0
2002-03-25 23:37:46 +03:00
;;
-p|--preserve-dates)
AddForcedOpts -p
shift
;;
-R|--remove-section)
shift
AddForcedOpts -R "$1"
shift
STRIP_FORCED=1
;;
2002-09-05 15:55:30 +04:00
--skip-files)
shift
2002-09-27 17:41:26 +04:00
RPM_STRIP_SKIPLIST="$RPM_STRIP_SKIPLIST $1"
2002-09-05 15:55:30 +04:00
shift
;;
2002-03-25 23:37:46 +03:00
-s|--strip-all)
AddForcedOpts -s
shift
STRIP_FORCED=1
;;
-g|-S|--strip-debug)
AddForcedOpts -g
shift
STRIP_FORCED=1
;;
--strip-unneeded)
AddForcedOpts --strip-unneeded
shift
STRIP_FORCED=1
;;
-N|--strip-symbol)
shift
AddForcedOpts -N "$1"
shift
STRIP_FORCED=1
;;
-K|--keep-symbol)
shift
AddForcedOpts -K "$1"
shift
STRIP_FORCED=1
;;
-x|--discard-all)
AddForcedOpts -x
shift
STRIP_FORCED=1
;;
-X|--discard-locals)
AddForcedOpts -X
shift
STRIP_FORCED=1
;;
-v|--verbose)
AddForcedOpts -v
shift
;;
-T|--topdir)
shift
TOPDIR="$1"
shift
;;
--)
shift
break
;;
*)
2003-11-09 17:30:36 +03:00
Fatal "unrecognized option: $1"
2002-03-25 23:37:46 +03:00
;;
esac
done
2002-09-27 17:41:26 +04:00
if [ -z "$TOPDIR" ]; then
TOPDIR="$RPM_BUILD_ROOT"
cd "$TOPDIR"
cd "$OLDPWD"
[ -d "$TOPDIR$RPM_STRIP_TOPDIR" ] || exit 0
TOPDIR="$TOPDIR$RPM_STRIP_TOPDIR"
else
cd "$TOPDIR"
cd "$OLDPWD"
fi
2002-03-25 23:37:46 +03:00
2003-11-07 20:45:11 +03:00
TOPDIR="$(printf %s "$TOPDIR" |sed '
2002-03-25 23:37:46 +03:00
s:/\(\./\)\+:/:g
s:/\+:/:g
s:/$::
')"
SHOW_METHODS=
AddShowMethods()
{
if [ -z "$SHOW_METHODS" ]; then
SHOW_METHODS="$*"
else
SHOW_METHODS="$SHOW_METHODS,$*"
fi
}
export STRIP_EXECUTABLE=
export STRIP_RELOCATABLE=
export STRIP_SHARED=
export STRIP_STATIC=
2003-11-07 20:45:11 +03:00
for t in `printf %s "$RPM_STRIP_METHOD" |tr , ' '`; do
2002-08-28 19:06:42 +04:00
case "$t" in
2002-03-25 23:37:46 +03:00
no|none|off|false)
exit 0
;;
exec*)
STRIP_EXECUTABLE=executable
AddShowMethods executable
;;
reloc*)
STRIP_RELOCATABLE=relocatable
AddShowMethods relocatable
;;
share*)
STRIP_SHARED=shared
AddShowMethods shared
;;
static*)
STRIP_STATIC=static
AddShowMethods static
;;
*)
2003-11-09 17:30:36 +03:00
Fatal "Unrecognized strip method: $t"
2002-03-25 23:37:46 +03:00
;;
esac
done
if [ -z "$STRIP_EXECUTABLE" -a -z "$STRIP_RELOCATABLE" -a -z "$STRIP_SHARED" -a -z "$STRIP_STATIC" ]; then
# Nothing to do
exit 0
fi
StripTree()
{
echo "Stripping binaries in $1 ($SHOW_METHODS)"
2003-05-14 15:26:46 +04:00
find "$1" -type f -print0 |xargs -r0 @RPMCONFIGDIR@/strip_files || return 1
2002-03-25 23:37:46 +03:00
}
if [ -n "$*" ]; then
for d in "$@"; do
if [ -d "$d" ]; then
StripTree "$d"
else
@RPMCONFIGDIR@/strip_files "$d"
fi
done
else
2003-11-09 17:30:36 +03:00
[ -n "$TOPDIR" ] || Fatal "non-/ TOPDIR expected"
2002-03-25 23:37:46 +03:00
StripTree "$TOPDIR"
fi