diff --git a/eclass/prefix.eclass b/eclass/prefix.eclass index c0675cd..0c1cc55 100644 --- a/eclass/prefix.eclass +++ b/eclass/prefix.eclass @@ -12,6 +12,8 @@ # located somewhere in the filesystem. Prefix ebuilds require # additional functions and variables which are defined by this eclass. +DEPEND="dev-util/patchelf" + # @ECLASS-VARIABLE: EPREFIX # @DESCRIPTION: # The offset prefix of a Gentoo Prefix installation. When Gentoo Prefix @@ -23,7 +25,6 @@ if [[ ! ${EPREFIX+set} ]]; then export EPREFIX='' fi - # @FUNCTION: eprefixify # @USAGE: # @DESCRIPTION: @@ -48,6 +49,33 @@ eprefixify() { return 0 } +# @FUNCTION: bprefixify +# @USAGE: +# @DESCRIPTION: +# prefixifies INTERP fields of program headers sections of ELF binaries. +# dies if no arguments are given, a file does not exist, or changing a +# file failed. +bprefixify() { + { use prefix && ! use prefix-guest; } || return 0 + + [[ $# -lt 1 ]] && die "at least one argument required" + + einfo "Adjusting to prefix ${EPREFIX:-/}" + local x interp + for x in "$@" ; do + if [[ -e ${x} ]] ; then + ebegin " ${x##*/}" + interp=$(patchelf --print-interpreter "${x}") + patchelf --set-interpreter "${EPREFIX}"/${interp} "${x}" + eend $? || die "failed to prefixify ${x}" + else + die "${x} does not exist" + fi + done + + return 0 +} + # @FUNCTION: hprefixify # @USAGE: [ -w ] [-e ] # @DESCRIPTION: