summaryrefslogtreecommitdiffstats
path: root/bin/prepstrip
blob: 47130e694ba6d2eede24a3b7a3bfc25f1860d248 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: /var/cvsroot/gentoo-src/portage/bin/prepstrip,v 1.23.2.3 2005/08/15 02:58:20 vapier Exp $

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

STRIP="${STRIP:-${CHOST}-strip}"
type -p -- ${STRIP} > /dev/null || STRIP=strip

PORTAGE_STRIP_FLAGS=${PORTAGE_STRIP_FLAGS:---strip-unneeded}

banner=1

save_elf_debug() {
	local x=$1
	local y="${D}/usr/lib/debug/${x:${#D}:${#x}}"

	[ "${FEATURES//*splitdebug*/true}" != "true" ] && return 0

	mkdir -p $(dirname ${y})
	${CHOST}-objcopy --only-keep-debug ${x} ${y}.debug
	${CHOST}-objcopy --add-gnu-debuglink=${y}.debug ${x}

	[ "${FEATURES//*installsources*/true}" != "true" ] && return 0

	if [ -x /usr/bin/debugedit ] ; then
		debugedit -b ${WORKDIR} -d /usr/src/debug/${P} -l ${T}/debug.sources "$x"
		if [ -s ${T}/debug.sources ]; then 
			[ -d ${D}/usr/src/debug/${P} ] || mkdir -p ${D}/usr/src/debug/${P}
			cat ${T}/debug.sources | (cd ${WORKDIR}; LANG=C sort -z -u | xargs -0 -- cp --parents -p --target-directory="${D}/usr/src/debug/${P}" )
		fi
	fi
}

for x in $(scanelf -yRBF%F "$@") $(for y in "$@"; do find $y -type f -name '*.a' -print0 ; done); do
	if [ ${banner} -eq 1 ] ; then
		echo "strip: ${STRIP} ${PORTAGE_STRIP_FLAGS}"
		banner=0
	fi

	f=$(file "${x}") || continue
	[ -z "${f}" ] && continue

	if [[ ${f} == *"current ar archive"* ]] ; then
		echo "   ${x:${#D}:${#x}}"
		${STRIP} -g "${x}"
	fi
	if [[ ${f} == *"SB executable"* || ${f} == *"SB shared object"* ]] ; then
		echo "   ${x:${#D}:${#x}}"
		save_elf_debug "${x}"
		${STRIP} ${PORTAGE_STRIP_FLAGS} "${x}"
	fi
done