Elliot Lee 03bb29
#!/bin/sh
Elliot Lee 03bb29
# If using normal root, avoid changing anything.
Elliot Lee 03bb29
if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then
Elliot Lee 03bb29
	exit 0
Elliot Lee 03bb29
fi
Elliot Lee 03bb29
Elliot Lee 1de7d8
[ -z "$STRIP" -a -n "$1" ] && STRIP="$1"
Elliot Lee 1de7d8
[ -z "$OBJDUMP" -a -n "$2" ] && OBJDUMP="$2"
Elliot Lee 1de7d8
[ -z "$STRIP" ] && STRIP=strip
Elliot Lee 1de7d8
[ -z "$OBJDUMP" ] && OBJDUMP=objdump
Elliot Lee 1de7d8
Elliot Lee 03bb29
# Strip .comment and .note sections (the latter only if it is not allocated)
Elliot Lee 03bb29
# for already stripped elf files in the build root
Elliot Lee 03bb29
for f in `find $RPM_BUILD_ROOT -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 \) -exec file {} \; | \
27ac14
        grep -v "^${RPM_BUILD_ROOT}/\?usr/lib/debug"  | \
Elliot Lee 03bb29
	sed -n -e 's/^\(.*\):[ 	]*ELF.*, stripped/\1/p'`; do
Elliot Lee 03bb29
	note="-R .note"
Elliot Lee 1de7d8
	if $OBJDUMP -h $f | grep '^[ 	]*[0-9]*[ 	]*.note[ 	]' -A 1 | \
Elliot Lee 03bb29
		grep ALLOC >/dev/null; then
Elliot Lee 03bb29
		note=
Elliot Lee 03bb29
	fi
Elliot Lee 1de7d8
	$STRIP -R .comment $note $f || :
Elliot Lee 03bb29
done