1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: prefix.eclass
6 # Feel free to contact the Prefix team through <prefix@gentoo.org> if
7 # you have problems, suggestions or questions.
8 # @BLURB: Eclass to provide Prefix functionality
10 # Gentoo Prefix allows users to install into a self defined offset
11 # located somewhere in the filesystem. Prefix ebuilds require
12 # additional functions and variables which are defined by this eclass.
14 # @ECLASS-VARIABLE: EPREFIX
16 # The offset prefix of a Gentoo Prefix installation. When Gentoo Prefix
17 # is not used, ${EPREFIX} should be "". Prefix Portage sets EPREFIX,
18 # hence this eclass has nothing to do here in that case.
19 # Note that setting EPREFIX in the environment with Prefix Portage sets
20 # Portage into cross-prefix mode.
21 if [[ ! ${EPREFIX+set} ]]; then
26 # @FUNCTION: eprefixify
27 # @USAGE: <list of to be eprefixified files>
29 # replaces @GENTOO_PORTAGE_EPREFIX@ with ${EPREFIX} for the given files,
30 # dies if no arguments are given, a file does not exist, or changing a
33 [[ $# -lt 1 ]] && die "at least one argument required"
35 einfo "Adjusting to prefix ${EPREFIX:-/}"
38 if [[ -e ${x} ]] ; then
40 sed -i -e "s|@GENTOO_PORTAGE_EPREFIX@|${EPREFIX}|g" "${x}"
41 eend $? || die "failed to eprefixify ${x}"
43 die "${x} does not exist"
50 # @FUNCTION: hprefixify
51 # @USAGE: [ -w <line match> ] [ -e <extended regex> ] [ -q <quotation char> ] <list of files>
53 # Tries a set of heuristics to prefixify the given files. Dies if no
54 # arguments are given, a file does not exist, or changing a file failed.
56 # Additional extended regular expression can be passed by -e or
57 # environment variable PREFIX_EXTRA_REGEX. The default heuristics can
58 # be constrained to lines that match a sed expression passed by -w or
59 # environment variable PREFIX_LINE_MATCH. Quotation characters can be
60 # specified by -q or environment variable PREFIX_QUOTE_CHAR, unless
64 # Only prefixify the 30th line,
65 # hprefixify -w 30 configure
66 # Only prefixify lines that contain "PATH",
67 # hprefixify -w "/PATH/" configure
68 # Also delete all the /opt/gnu search paths,
69 # hprefixify -e "/\/opt\/gnu/d" configure
70 # Quote the inserted EPREFIX
71 # hprefixify -q '"' etc/profile
73 use prefix || return 0
76 while [[ $# -gt 0 ]]; do
78 -e) local PREFIX_EXTRA_REGEX="$2"
81 -w) local PREFIX_LINE_MATCH="$2"
84 -q) local PREFIX_QUOTE_CHAR="${EPREFIX:+$2}"
93 local dirs="/(usr|lib(|[onx]?32|n?64)|etc|bin|sbin|var|opt|run)" \
94 eprefix="${PREFIX_QUOTE_CHAR}${EPREFIX}${PREFIX_QUOTE_CHAR}"
96 [[ ${#xl[@]} -lt 1 ]] && die "at least one file operand is required"
97 einfo "Adjusting to prefix ${EPREFIX:-/}"
98 for x in "${xl[@]}" ; do
99 if [[ -e ${x} ]] ; then
102 -e "${PREFIX_LINE_MATCH}s,([^[:alnum:]}\)\.])${dirs},\1${eprefix}/\2,g" \
103 -e "${PREFIX_LINE_MATCH}s,^${dirs},${eprefix}/\1," \
104 -e "${PREFIX_EXTRA_REGEX}" \
106 eend $? || die "failed to prefixify ${x}"
108 die "${x} does not exist"
113 # @FUNCTION: prefixify_ro
116 # prefixify a read-only file.
117 # copies the files to ${T}, prefixies it, echos the new file.
119 # doexe "$(prefixify_ro "${FILESDIR}"/fix_libtool_files.sh)"
120 # epatch "$(prefixify_ro "${FILESDIR}"/${PN}-4.0.2-path.patch)"
122 if [[ -e $1 ]] ; then
124 cp "$1" "${T}" || die "failed to copy file"
126 # redirect to stderr because stdout is used to
127 # return the prefixified file.
128 if grep -qs @GENTOO_PORTAGE_EPREFIX@ "${x}" ; then
129 eprefixify "${T}"/${f} 1>&2
131 hprefixify "${T}"/${f} 1>&2
135 die "$1 does not exist"