#!	/bin/sh

set -e

if [ $# -lt 1 ]; then
	echo "Usage: $0 file [file ...]" 1>&2
	echo
	echo "	Strip any executable files in the argument list, leave" 1>&2
	echo "	other kinds of files alone." 1>&2
	exit -1
fi

EXEC1=`file $* | grep ELF | sed 's/:.*$//'`
EXECUTABLES=""
for i in $EXEC1; do {
	x=`file $i`
	if { echo $x | grep -q 'executable' ; }; then
		EXECUTABLES=$EXECUTABLES" "$i
	else
		if { echo $x | grep -q 'shared object' ; }; then
			EXECUTABLES=$EXECUTABLES" "$i
		fi
	fi
}; done
EXEC1=""

# _dl_debug_state is a symbol of ld-linux.so that is used by GDB to breakpoint
# debug dynamicaly-loaded code. I explicitly keep it here. There will no doubt
# be other symbols like this. Saving 10 or 20 of them is probably cheap enough
# that you'd never notice the space.

strip --remove-section=.note --remove-section=.comment --keep-symbol _dl_debug_state $EXECUTABLES
exit 0
