| #!/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 $ |
| |
| source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh |
| |
| if hasq nostrip ${FEATURES} ${RESTRICT} || \ |
| hasq strip RESTRICT |
| then |
| exit 0 |
| fi |
| |
| STRIP=${STRIP:-${CHOST}-strip} |
| type -p -- ${STRIP} > /dev/null || STRIP=strip |
| OBJCOPY=${OBJCOPY:-${CHOST}-objcopy} |
| type -p -- ${OBJCOPY} > /dev/null || OBJCOPY=objcopy |
| |
| export 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}}.debug" |
| |
| hasq splitdebug ${FEATURES} || return 0 |
| |
| # dont save debug info twice. |
| [[ ${x:7} == ".debug" ]] && return 0 |
| |
| mkdir -p $(dirname "${y}") |
| ${OBJCOPY} --only-keep-debug "${x}" "${y}" |
| ${OBJCOPY} --add-gnu-debuglink="${y}" "${x}" |
| chmod a-x,o-w "${y}" |
| |
| hasq installsources ${FEATURES} || return 0 |
| |
| if [[ -x "/usr/bin/debugedit" ]] ; then |
| debugedit -b "${WORKDIR}" -d /usr/src/debug/${PF} -l "${T}"/debug.sources "${x}" |
| if [[ -s ${T}/debug.sources ]] ; then |
| [[ -d ${D}/usr/src/debug/${PF} ]] || mkdir -p "${D}/usr/src/debug/${PF}" |
| cat "${T}"/debug.sources | (cd "${WORKDIR}"; LANG=C sort -z -u | xargs -0 -- cp --parents -p --target-directory="${D}/usr/src/debug/${PF}" ) |
| 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 |
| vecho "strip: ${STRIP} ${PORTAGE_STRIP_FLAGS}" |
| banner=0 |
| fi |
| |
| f=$(file "${x}") || continue |
| [[ -z ${f} ]] && continue |
| |
| # The noglob funk is to support STRIP_MASK="/*/booga" and to keep |
| # the for loop from expanding the globs. |
| # The eval echo is to support STRIP_MASK="/*/{booga,bar}" sex. |
| set -o noglob |
| stripitbaby=1 |
| for m in $(eval echo ${STRIP_MASK}) ; do |
| [[ ${x} == ${m} ]] && stripitbaby=1 && break |
| done |
| set +o noglob |
| |
| if [[ ${f} == *"current ar archive"* ]] ; then |
| vecho " ${x:${#D}:${#x}}" |
| [[ ${stripitbaby} -eq 1 ]] && ${STRIP} -g "${x}" |
| fi |
| if [[ ${f} == *"SB executable"* || ${f} == *"SB shared object"* ]] ; then |
| vecho " ${x:${#D}:${#x}}" |
| save_elf_debug "${x}" |
| [[ ${stripitbaby} -eq 1 ]] && ${STRIP} ${PORTAGE_STRIP_FLAGS} "${x}" |
| fi |
| done |