summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenda Xu <heroxbd@gentoo.org>2016-07-21 10:40:18 +0900
committerBenda Xu <heroxbd@gentoo.org>2016-07-21 10:41:29 +0900
commitecdc2eb2332ef6c9abce6fee0feaaaf0b138d46a (patch)
treea9416007ed4783df212dcad951a6355799980fd6 /eclass/prefix.eclass
parentnet-misc/tinc: use use_enable() to correct USE=upnp (diff)
downloadgentoo-ecdc2eb2332ef6c9abce6fee0feaaaf0b138d46a.tar.gz
gentoo-ecdc2eb2332ef6c9abce6fee0feaaaf0b138d46a.tar.bz2
gentoo-ecdc2eb2332ef6c9abce6fee0feaaaf0b138d46a.zip
prefix.eclass: introduce hprefixify and prefixify_ro
Bug: 583740
Diffstat (limited to 'eclass/prefix.eclass')
-rw-r--r--eclass/prefix.eclass78
1 files changed, 78 insertions, 0 deletions
diff --git a/eclass/prefix.eclass b/eclass/prefix.eclass
index 1f3c4b0c4a5b..c0675cd37032 100644
--- a/eclass/prefix.eclass
+++ b/eclass/prefix.eclass
@@ -48,5 +48,83 @@ eprefixify() {
return 0
}
+# @FUNCTION: hprefixify
+# @USAGE: [ -w <line match> ] [-e <extended regex> ] <list of files>
+# @DESCRIPTION:
+# Tries a set of heuristics to prefixify the given files. Dies if no
+# arguments are given, a file does not exist, or changing a file failed.
+#
+# Additional extended regular expression can be passed by -e or
+# environment variable PREFIX_EXTRA_REGEX. The default heuristics can
+# be constrained to lines that match a sed expression passed by -w or
+# environment variable PREFIX_LINE_MATCH.
+# @EXAMPLE:
+# Only prefixify the 30th line,
+# hprefixify -w 30 configure
+# Only prefixify lines that contain "PATH",
+# hprefixify -w "/PATH/" configure
+# Also delete all the /opt/gnu search paths,
+# hprefixify -e "/\/opt\/gnu/d" configure
+hprefixify() {
+ use prefix || return 0
+
+ local PREFIX_EXTRA_REGEX PREFIX_LINE_MATCH xl=() x
+ while [[ $# -gt 0 ]]; do
+ case $1 in
+ -e)
+ PREFIX_EXTRA_REGEX="$2"
+ shift
+ ;;
+ -w)
+ PREFIX_LINE_MATCH="$2"
+ shift
+ ;;
+ *)
+ xl+=( "$1" )
+ ;;
+ esac
+ shift
+ done
+
+ [[ ${#xl[@]} -lt 1 ]] && die "at least one file operand is required"
+ einfo "Adjusting to prefix ${EPREFIX:-/}"
+ for x in "${xl[@]}" ; do
+ if [[ -e ${x} ]] ; then
+ ebegin " ${x##*/}"
+ sed -r \
+ -e "${PREFIX_LINE_MATCH}s,([^[:alnum:]}\)\.])/(usr|lib(|[onx]?32|n?64)|etc|bin|sbin|var|opt),\1${EPREFIX}/\2,g" \
+ -e "${PREFIX_EXTRA_REGEX}" \
+ -i "${x}"
+ eend $? || die "failed to prefixify ${x}"
+ else
+ die "${x} does not exist"
+ fi
+ done
+}
+# @FUNCTION: prefixify_ro
+# @USAGE: prefixify_ro <file>.
+# @DESCRIPTION:
+# prefixify a read-only file.
+# copies the files to ${T}, prefixies it, echos the new file.
+# @EXAMPLE:
+# doexe "$(prefixify_ro "${FILESDIR}"/fix_libtool_files.sh)"
+# epatch "$(prefixify_ro "${FILESDIR}"/${PN}-4.0.2-path.patch)"
+prefixify_ro() {
+ if [[ -e $1 ]] ; then
+ local f=${1##*/}
+ cp "$1" "${T}" || die "failed to copy file"
+ local x="${T}"/${f}
+ # redirect to stderr because stdout is used to
+ # return the prefixified file.
+ if grep -qs @GENTOO_PORTAGE_EPREFIX@ "${x}" ; then
+ eprefixify "${T}"/${f} 1>&2
+ else
+ hprefixify "${T}"/${f} 1>&2
+ fi
+ echo "${x}"
+ else
+ die "$1 does not exist"
+ fi
+}
# vim: tw=72: