perl-functions.eclass: should 'just work' in EAPI=6
[gentoo.git] / eclass / prefix.eclass
1 # Copyright 1999-2009 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: prefix.eclass
6 # @MAINTAINER:
7 # Feel free to contact the Prefix team through <prefix@gentoo.org> if
8 # you have problems, suggestions or questions.
9 # @BLURB: Eclass to provide Prefix functionality
10 # @DESCRIPTION:
11 # Gentoo Prefix allows users to install into a self defined offset
12 # located somewhere in the filesystem.  Prefix ebuilds require
13 # additional functions and variables which are defined by this eclass.
14
15 # @ECLASS-VARIABLE: EPREFIX
16 # @DESCRIPTION:
17 # The offset prefix of a Gentoo Prefix installation.  When Gentoo Prefix
18 # is not used, ${EPREFIX} should be "".  Prefix Portage sets EPREFIX,
19 # hence this eclass has nothing to do here in that case.
20 # Note that setting EPREFIX in the environment with Prefix Portage sets
21 # Portage into cross-prefix mode.
22 if [[ ! ${EPREFIX+set} ]]; then
23         export EPREFIX=''
24 fi
25
26
27 # @FUNCTION: eprefixify
28 # @USAGE: <list of to be eprefixified files>
29 # @DESCRIPTION:
30 # replaces @GENTOO_PORTAGE_EPREFIX@ with ${EPREFIX} for the given files,
31 # dies if no arguments are given, a file does not exist, or changing a
32 # file failed.
33 eprefixify() {
34         [[ $# -lt 1 ]] && die "at least one argument required"
35
36         einfo "Adjusting to prefix ${EPREFIX:-/}"
37         local x
38         for x in "$@" ; do
39                 if [[ -e ${x} ]] ; then
40                         ebegin "  ${x##*/}"
41                         sed -i -e "s|@GENTOO_PORTAGE_EPREFIX@|${EPREFIX}|g" "${x}"
42                         eend $? || die "failed to eprefixify ${x}"
43                 else
44                         die "${x} does not exist"
45                 fi
46         done
47
48         return 0
49 }
50
51
52 # vim: tw=72: