#!/bin/bash
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /home/cvsroot/gentoo-src/portage/bin/prepstrip,v 1.12 2003/05/12 09:10:31 carpaski Exp $

if [ "${FEATURES//*nostrip*/tree}" == "true" ] || [ "${RESTRICT//*nostrip*/true}" == "true" ] ; then
	echo "nostrip"
	exit 0
fi

if [ ! -z "${CBUILD}" ] && [ "${CBUILD}" != "${CHOST}" ]; then
	STRIP=${CHOST}-strip
else
	STRIP=strip
fi

echo "strip: "
for x in "$@"; do # "$@" quotes each element... Plays nice with spaces.
	if [ -d "${x}" ]; then
		# We only want files. So make a pass for each directory and call again.
		find "${x}" -type f \( -perm +0111 -or -regex '\.so$|\.so\.' \) -print0 |
				xargs -0 -r -n500 prepstrip
	else
		f=$(file "${x}")
		if [ -z "${f/*SB executable*/}" ]; then
			echo "   ${x:${#D}:${#x}}"
			${STRIP} "${x}"
		fi
		if [ -z "${f/*SB shared object*/}" ]; then
			echo "   ${x:${#D}:${#x}}"
			${STRIP} --strip-debug "${x}"
		fi
	fi
done
