File brp-strip-unneeded.sh of Package rpm-macros-extra

#!/bin/sh

# If using normal root, avoid changing anything.
if [ -z "${RPM_BUILD_ROOT#/}" ]; then
	echo "RPM_BUILD_ROOT is not set or set to / : skipping strip"
	exit 0
fi
if [ "$NO_BRP_STRIP_UNNEEDED" = "true" ] ; then
	echo "NO_BRP_STRIP_UNNEEDED is set: skipping strip"
	exit 0
fi

# Strip unneeded info from ELF binaries, but not static libraries
find $RPM_BUILD_ROOT \
	\( -path $RPM_BUILD_ROOT/usr/lib/debug -o -path $RPM_BUILD_ROOT/opt/cross -o -path $RPM_BUILD_ROOT/proc \) -prune -o \
	-name '*.a' -prune -o \
	-type f \( -perm /0111 -o -name '*.so*' \) -print |
	file -N -F'	' -f - 2> /dev/null |
	grep '^.*	 *ELF.*, not stripped' |
	cut -f1 |
while read f; do
	m=$(stat -c%a "$f")
	chmod u+w "$f"
	strip -p --strip-unneeded "$f"
	chmod $m "$f"
done

# Strip static libs
find $RPM_BUILD_ROOT \
	\( -path $RPM_BUILD_ROOT/usr/lib/debug -o -path $RPM_BUILD_ROOT/lib/modules -o -path $RPM_BUILD_ROOT/opt/cross -o -path $RPM_BUILD_ROOT/proc \) -prune -o \
	-type f -name '*.a' -print |
	file -N -F'	' -f - 2> /dev/null |
	grep -e '^.*	 *(ELF.*, not stripped|current ar)' |
	cut -f1 |
while read f; do
	strip -p --strip-debug "$f"
done
exit 0