summaryrefslogtreecommitdiff
blob: 48d5e67fd2816f6fc4f983d043faebf2aed40a76 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
#
# @ECLASS: multilib-xlibs.eclass

# temporary stuff to to have some debug info what's going on with
# multilib-xlibs_check_inherited_funcs() and maybe other stuff. Remove this var and 
# the stuff in the phase functions when done...
ECLASS_DEBUG="yes"

IUSE="${IUSE} lib32"

if use lib32; then
	EMULTILIB_PKG="true"
fi

inherit base multilib

case "${EAPI:-0}" in
	2)
		EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install pkg_postinst
		;;
	*)
		EXPORT_FUNCTIONS src_compile src_install pkg_postinst
		;;
esac

EMULTILIB_OCFLAGS=""
EMULTILIB_OCXXFLAGS=""
EMULTILIB_OCHOST=""
EMULTILIB_OSPATH=""

# @FUNCTION: multilib-xlibs_src_prepare
# @USAGE:
# @DESCRIPTION:
multilib-xlibs_src_prepare() {
	multilib-xlibs_src_generic src_prepare
}

# @FUNCTION: multilib-xlibs_src_configure
# @USAGE:
# @DESCRIPTION:
multilib-xlibs_src_configure() {
	multilib-xlibs_src_generic src_configure
}

# @FUNCTION: multilib-xlibs_src_compile
# @USAGE:
# @DESCRIPTION:
multilib-xlibs_src_compile() {
	multilib-xlibs_src_generic src_compile
}

# @FUNCTION: multilib-xlibs_src_install
# @USAGE:
# @DESCRIPTION:
multilib-xlibs_src_install() {
	multilib-xlibs_src_generic src_install
}

# @FUNCTION: multilib-xlibs_pkg_postinst
# @USAGE:
# @DESCRIPTION:
multilib-xlibs_pkg_postinst() {
	multilib-xlibs_src_generic pkg_postinst
}

# @FUNCTION: multilib-xlibs_pkg_postrm
# @USAGE:
# @DESCRIPTION:
multilib-xlibs_pkg_postrm() {
	multilib-xlibs_src_generic pkg_postrm
}

# @FUNCTION: multilib-xlibs_src_generic
# @USAGE:
# @DESCRIPTION:
multilib-xlibs_src_generic() {
	if [[ -n ${EMULTILIB_PKG} ]]; then
		if [[ -z ${OABI} ]] ; then
			local abilist=""
			if has_multilib_profile ; then
				abilist=$(get_install_abis)
				einfo "${1}ing multilib ${PN} for ABIs: ${abilist}"
			elif is_crosscompile || tc-is-cross-compiler ; then
				abilist=${DEFAULT_ABI}
			fi
			if [[ -n ${abilist} ]] ; then
				OABI=${ABI}
				for ABI in ${abilist} ; do
					export ABI
					multilib-xlibs_src_generic ${1}
				done
				ABI=${OABI}
				unset OABI
				return 0
			fi
		fi
	fi
	multilib-xlibs_src_generic_sub ${1}
}

# @FUNCTION: multilib-xlibs_src_generic_sub
# @USAGE:
# @DESCRIPTION:
multilib-xlibs_src_generic_sub() {
	if [[ -n ${EMULTILIB_PKG} ]]; then
		export CC="$(tc-getCC)"
		export CXX="$(tc-getCXX)"

		if has_multilib_profile ; then
			EMULTILIB_OCFLAGS="${CFLAGS}"
			EMULTILIB_OCXXFLAGS="${CXXFLAGS}"
			EMULTILIB_OCHOST="${CHOST}"
			EMULTILIB_OSPATH="${S}"
			if use amd64 || use ppc64 ; then
				case ${ABI} in
					x86)    CHOST="i686-${EMULTILIB_OCHOST#*-}"
					CFLAGS="${EMULTILIB_OCFLAGS} -m32"
					CXXFLAGS="${EMULTILIB_OCXXFLAGS} -m32"
					;;
					amd64)  CHOST="x86_64-${EMULTILIB_OCHOST#*-}"
					CFLAGS="${EMULTILIB_OCFLAGS} -m64"
					CXXFLAGS="${EMULTILIB_OCXXFLAGS} -m64"
					;;
					ppc)   CHOST="powerpc-${EMULTILIB_OCHOST#*-}"
					CFLAGS="${EMULTILIB_OCFLAGS} -m32"
					CXXFLAGS="${EMULTILIB_OCXXFLAGS} -m32"
					;;
					ppc64)   CHOST="powerpc64-${EMULTILIB_OCHOST#*-}"
					CFLAGS="${EMULTILIB_OCFLAGS} -m64"
					CXXFLAGS="${EMULTILIB_OCXXFLAGS} -m64"
					;;
					*)   die "Unknown ABI"
					;;
				esac
			fi
		fi

		#Nice way to avoid the "cannot run test program while cross compiling" :)
		CBUILD=$CHOST

		if [[ ! -d "${WORKDIR}/builddir.${ABI}" ]]; then
			einfo "Copying source tree to ${WORKDIR}/builddir.${ABI}"
			cp -al ${S} ${WORKDIR}/builddir.${ABI}
		fi

		cd ${WORKDIR}/builddir.${ABI}
		S=${WORKDIR}/builddir.${ABI}

		PKG_CONFIG_PATH="/usr/$(get_libdir)/pkgconfig"
	fi
	if [[ -n ${MULTILIBX86_ECLASS} ]]; then
		${MULTILIBX86_ECLASS}_${1}
	else
		multilib-xlibs_${1}_internal
	fi
	if [[ -n ${EMULTILIB_PKG} ]]; then
		if has_multilib_profile; then
			CFLAGS="${EMULTILIB_OCFLAGS}"
			CXXFLAGS="${EMULTILIB_OCXXFLAGS}"
			CHOST="${EMULTILIB_OCHOST}"
			S="${EMULTILIB_OSPATH}"
		fi
	fi
}

# @internal-function multilib-xlibs_check_inherited_funcs
# @USAGE: call it in the phases
# @DESCRIPTION: checks all inherited eclasses for requested phase function
multilib-xlibs_check_inherited_funcs() {
	# check all eclasses for given function, in order of inheritance.
	# if none provides it, the var stays empty. If more have it, the last one wins.
	# Ignore the ones we inherit ourselves, base doesn't matter, as we default
	# on it
	local declared_func=""
	local eclasses=""
	eclasses="${INHERITED/base/}"
	eclasses="${eclasses/multilib-xlibs/}"

	for func in ${eclasses}; do
		if [[ -n $(declare -f ${func}_${1}) ]]; then
			declared_func="${func}_${1}"
		fi
	done

	# now if $declared_func is still empty, none of the inherited eclasses
	# provides it, so default on base.eclass. Do nothing for pkg_post*
	if [[ -z "${declared_func}" ]]; then
		if [[ -z "$(echo ${1}|grep src)" ]]; then
			declared_func=":;"
		else
			declared_func="base_${1}"
		fi
	fi

	echo ${declared_func}
}

# @FUNCTION: multilib-xlibs_src_prepare_internal
# @USAGE: override this function if you arent using x-modules eclass and want to use a custom src_configure.
# @DESCRIPTION:
multilib-xlibs_src_prepare_internal() {
	[[ "${ECLASS_DEBUG}" == "yes" ]] && einfo "Using $(multilib-xlibs_check_inherited_funcs src_prepare) ..."
	$(multilib-xlibs_check_inherited_funcs src_prepare)
}

# @FUNCTION: multilib-xlibs_src_configure_internal
# @USAGE: override this function if you arent using x-modules eclass and want to use a custom src_configure.
# @DESCRIPTION:
multilib-xlibs_src_configure_internal() {
	[[ "${ECLASS_DEBUG}" == "yes" ]] && einfo "Using $(multilib-xlibs_check_inherited_funcs src_configure) ..."
	$(multilib-xlibs_check_inherited_funcs src_configure)
}

# @FUNCTION: multilib-xlibs_src_compile_internal
# @USAGE: override this function if you arent using x-modules eclass and want to use a custom src_compile.
# @DESCRIPTION:
multilib-xlibs_src_compile_internal() {
	[[ "${ECLASS_DEBUG}" == "yes" ]] && einfo "Using $(multilib-xlibs_check_inherited_funcs src_compile) ..."
	$(multilib-xlibs_check_inherited_funcs src_compile)
}

# @FUNCTION: multilib-xlibs_src_install_internal
# @USAGE: override this function if you arent using x-modules eclass and want to use a custom src_install
# @DESCRIPTION:
multilib-xlibs_src_install_internal() {
	[[ "${ECLASS_DEBUG}" == "yes" ]] && einfo "Using $(multilib-xlibs_check_inherited_funcs src_install) ..."
	$(multilib-xlibs_check_inherited_funcs src_install)
}

multilib-xlibs_pkg_postinst_internal() {
	$(multilib-xlibs_check_inherited_funcs pkg_postinst)
}

multilib-xlibs_pkg_postrm_internal() {
	$(multilib-xlibs_check_inherited_funcs pkg_postrm)
}