summaryrefslogtreecommitdiff
blob: 40e509758c70fbd4bef9b3950cbab0573430a511 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

# @ECLASS: prefix.eclass
# @MAINTAINER:
# Feel free to contact the Prefix team through <prefix@gentoo.org> if
# you have problems, suggestions or questions.
# @BLURB: Eclass to provide Prefix functionality
# @DESCRIPTION:
# Gentoo Prefix allows users to install into a self defined offset
# located somewhere in the filesystem.  Prefix ebuilds require
# additional functions and variables which are defined by this eclass.

# @ECLASS-VARIABLE: EPREFIX
# @DESCRIPTION:
# The offset prefix of a Gentoo Prefix installation.  When Gentoo Prefix
# is not used, ${EPREFIX} should be "".  Prefix Portage sets EPREFIX,
# hence this eclass has nothing to do here in that case.
# Note that setting EPREFIX in the environment with Prefix Portage sets
# Portage into cross-prefix mode.
if [[ ! ${EPREFIX+set} ]]; then
	export EPREFIX=''
fi


# @FUNCTION: eprefixify
# @USAGE: <list of to be eprefixified files>
# @DESCRIPTION:
# replaces @GENTOO_PORTAGE_EPREFIX@ with ${EPREFIX} for the given files,
# tries a set of heuristics if @GENTOO_PORTAGE_EPREFIX@ is not found,
# dies if no arguments are given, a file does not exist, or changing a
# file failed.
eprefixify() {
	[[ $# -lt 1 ]] && die "at least one argument required"

	einfo "Adjusting to prefix ${EPREFIX:-/}"
	local x
	for x in "$@" ; do
		if [[ -e ${x} ]] ; then
			ebegin "  ${x##*/}"
			if grep -q @GENTOO_PORTAGE_EPREFIX@ "${x}" ; then
				sed -i -e "s|@GENTOO_PORTAGE_EPREFIX@|${EPREFIX}|g" "${x}"
			else
				sed -r \
					-e "s,([^[:alnum:]}])/(usr|etc|bin|sbin|var|opt)/,\1${EPREFIX}/\2/,g" \
					-i "${x}"
			fi
			eend $? || die "failed to eprefixify ${x}"
		else
			die "${x} does not exist"
		fi
	done

	return 0
}

# @FUNCTION: __temp_prefixify
# @USAGE: on a single file
# @DESCRIPTION:
# copies the files to ${T}, calls eprefixify, echos the new file.
__temp_prefixify() {
	if [[ -e $1 ]] ; then
		local f=${1##*/}
		cp "$1" "${T}" || die "failed to copy file"
		eprefixify "${T}"/${f} > /dev/null
		echo "${T}"/${f}
	else
		die "$1 does not exist"
	fi
}

# @FUNCTION: fprefixify
# @USAGE: fprefixfy function files
# @DESCRIPTION:
# prefixify a function call.
# copies the files to ${T}, calls eprefixify, and calls the function.
#
# For example:
# fprefixify doexe ${FILESDIR}/fix_libtool_files.sh
# fprefixify epatch ${FILESDIR}/${PN}-4.0.2-path.patch
fprefixify() {
	[[ $# -lt 2 ]] && die "at least two arguments required"

	local func=$1 f
	einfo "Adjusting ${func} to prefix ${EPREFIX:-/}"
	shift
	case ${func} in
		new*)
			[[ $# -ne 2 ]] && die "${func} takes two arguments"
			ebegin "  ${1##*/}"
			f=$(__temp_prefixify "$1")
			${func} "${f}" "$2"
			eend $? || die "failed to execute ${func}"
			;;
		*)
			for x in "$@" ; do
				ebegin "  ${x##*/}"
				f=$(__temp_prefixify "${x}")
				${func} "${f}"
				eend $? || die "failed to execute ${func}"
			done
	esac

	return 0
}

# vim: tw=72: