Gentoo Archives: gentoo-commits

From: "Andreas K. Hüttel" <dilfridge@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/riscv:master commit in: eclass/
Date: Sun, 28 Apr 2019 19:49:05
Message-Id: 1556480920.600cd135463c4bd9b86a3db5fdfb3daf7919786d.dilfridge@gentoo
1 commit: 600cd135463c4bd9b86a3db5fdfb3daf7919786d
2 Author: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
3 AuthorDate: Sun Apr 28 19:48:40 2019 +0000
4 Commit: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
5 CommitDate: Sun Apr 28 19:48:40 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/riscv.git/commit/?id=600cd135
7
8 eclass: Add multilib.eclass unmodified from main tree
9
10 Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>
11
12 eclass/multilib.eclass | 473 +++++++++++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 473 insertions(+)
14
15 diff --git a/eclass/multilib.eclass b/eclass/multilib.eclass
16 new file mode 100644
17 index 0000000..393f0db
18 --- /dev/null
19 +++ b/eclass/multilib.eclass
20 @@ -0,0 +1,473 @@
21 +# Copyright 1999-2015 Gentoo Foundation
22 +# Distributed under the terms of the GNU General Public License v2
23 +
24 +# @ECLASS: multilib.eclass
25 +# @MAINTAINER:
26 +# amd64@g.o
27 +# toolchain@g.o
28 +# @BLURB: This eclass is for all functions pertaining to handling multilib configurations.
29 +# @DESCRIPTION:
30 +# This eclass is for all functions pertaining to handling multilib configurations.
31 +
32 +if [[ -z ${_MULTILIB_ECLASS} ]]; then
33 +_MULTILIB_ECLASS=1
34 +
35 +inherit toolchain-funcs
36 +
37 +# Defaults:
38 +export MULTILIB_ABIS=${MULTILIB_ABIS:-"default"}
39 +export DEFAULT_ABI=${DEFAULT_ABI:-"default"}
40 +export CFLAGS_default
41 +export LDFLAGS_default
42 +export CHOST_default=${CHOST_default:-${CHOST}}
43 +export CTARGET_default=${CTARGET_default:-${CTARGET:-${CHOST_default}}}
44 +export LIBDIR_default=${CONF_LIBDIR:-"lib"}
45 +export KERNEL_ABI=${KERNEL_ABI:-${DEFAULT_ABI}}
46 +
47 +# @FUNCTION: has_multilib_profile
48 +# @DESCRIPTION:
49 +# Return true if the current profile is a multilib profile and lists more than
50 +# one abi in ${MULTILIB_ABIS}. When has_multilib_profile returns true, that
51 +# profile should enable the 'multilib' use flag. This is so you can DEPEND on
52 +# a package only for multilib or not multilib.
53 +has_multilib_profile() {
54 + [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ]
55 +}
56 +
57 +# @FUNCTION: get_libdir
58 +# @RETURN: the libdir for the selected ABI
59 +# @DESCRIPTION:
60 +# This function simply returns the desired lib directory. With portage
61 +# 2.0.51, we now have support for installing libraries to lib32/lib64
62 +# to accomidate the needs of multilib systems. It's no longer a good idea
63 +# to assume all libraries will end up in lib. Replace any (sane) instances
64 +# where lib is named directly with $(get_libdir) if possible.
65 +#
66 +# Jeremy Huddleston <eradicator@g.o> (23 Dec 2004):
67 +# Added support for ${ABI} and ${DEFAULT_ABI}. If they're both not set,
68 +# fall back on old behavior. Any profile that has these set should also
69 +# depend on a newer version of portage (not yet released) which uses these
70 +# over CONF_LIBDIR in econf, dolib, etc...
71 +if has "${EAPI:-0}" 0 1 2 3 4 5; then
72 + get_libdir() {
73 + local CONF_LIBDIR
74 + if [ -n "${CONF_LIBDIR_OVERRIDE}" ] ; then
75 + # if there is an override, we want to use that... always.
76 + echo ${CONF_LIBDIR_OVERRIDE}
77 + else
78 + get_abi_LIBDIR
79 + fi
80 + }
81 +fi
82 +
83 +# @FUNCTION: get_abi_var
84 +# @USAGE: <VAR> [ABI]
85 +# @RETURN: returns the value of ${<VAR>_<ABI>} which should be set in make.defaults
86 +# @INTERNAL
87 +# @DESCRIPTION:
88 +# ex:
89 +# CFLAGS=$(get_abi_var CFLAGS sparc32) # CFLAGS=-m32
90 +#
91 +# Note that the prefered method is to set CC="$(tc-getCC) $(get_abi_CFLAGS)"
92 +# This will hopefully be added to portage soon...
93 +#
94 +# If <ABI> is not specified, ${ABI} is used.
95 +# If <ABI> is not specified and ${ABI} is not defined, ${DEFAULT_ABI} is used.
96 +# If <ABI> is not specified and ${ABI} and ${DEFAULT_ABI} are not defined, we return an empty string.
97 +get_abi_var() {
98 + local flag=$1
99 + local abi=${2:-${ABI:-${DEFAULT_ABI:-default}}}
100 + local var="${flag}_${abi}"
101 + echo ${!var}
102 +}
103 +
104 +# @FUNCTION: get_abi_CFLAGS
105 +# @USAGE: [ABI]
106 +# @DESCRIPTION:
107 +# Alias for 'get_abi_var CFLAGS'
108 +get_abi_CFLAGS() { get_abi_var CFLAGS "$@"; }
109 +
110 +# @FUNCTION: get_abi_LDFLAGS
111 +# @USAGE: [ABI]
112 +# @DESCRIPTION:
113 +# Alias for 'get_abi_var LDFLAGS'
114 +get_abi_LDFLAGS() { get_abi_var LDFLAGS "$@"; }
115 +
116 +# @FUNCTION: get_abi_CHOST
117 +# @USAGE: [ABI]
118 +# @DESCRIPTION:
119 +# Alias for 'get_abi_var CHOST'
120 +get_abi_CHOST() { get_abi_var CHOST "$@"; }
121 +
122 +# @FUNCTION: get_abi_CTARGET
123 +# @USAGE: [ABI]
124 +# @DESCRIPTION:
125 +# Alias for 'get_abi_var CTARGET'
126 +get_abi_CTARGET() { get_abi_var CTARGET "$@"; }
127 +
128 +# @FUNCTION: get_abi_FAKE_TARGETS
129 +# @USAGE: [ABI]
130 +# @DESCRIPTION:
131 +# Alias for 'get_abi_var FAKE_TARGETS'
132 +get_abi_FAKE_TARGETS() { get_abi_var FAKE_TARGETS "$@"; }
133 +
134 +# @FUNCTION: get_abi_LIBDIR
135 +# @USAGE: [ABI]
136 +# @DESCRIPTION:
137 +# Alias for 'get_abi_var LIBDIR'
138 +get_abi_LIBDIR() { get_abi_var LIBDIR "$@"; }
139 +
140 +# @FUNCTION: get_install_abis
141 +# @DESCRIPTION:
142 +# Return a list of the ABIs we want to install for with
143 +# the last one in the list being the default.
144 +get_install_abis() {
145 + local x order=""
146 +
147 + if [[ -z ${MULTILIB_ABIS} ]] ; then
148 + echo "default"
149 + return 0
150 + fi
151 +
152 + if [[ ${EMULTILIB_PKG} == "true" ]] ; then
153 + for x in ${MULTILIB_ABIS} ; do
154 + if [[ ${x} != "${DEFAULT_ABI}" ]] ; then
155 + has ${x} ${ABI_DENY} || order="${order} ${x}"
156 + fi
157 + done
158 + has ${DEFAULT_ABI} ${ABI_DENY} || order="${order} ${DEFAULT_ABI}"
159 +
160 + if [[ -n ${ABI_ALLOW} ]] ; then
161 + local ordera=""
162 + for x in ${order} ; do
163 + if has ${x} ${ABI_ALLOW} ; then
164 + ordera="${ordera} ${x}"
165 + fi
166 + done
167 + order=${ordera}
168 + fi
169 + else
170 + order=${DEFAULT_ABI}
171 + fi
172 +
173 + if [[ -z ${order} ]] ; then
174 + die "The ABI list is empty. Are you using a proper multilib profile? Perhaps your USE flags or MULTILIB_ABIS are too restrictive for this package."
175 + fi
176 +
177 + echo ${order}
178 + return 0
179 +}
180 +
181 +# @FUNCTION: get_all_abis
182 +# @DESCRIPTION:
183 +# Return a list of the ABIs supported by this profile.
184 +# the last one in the list being the default.
185 +get_all_abis() {
186 + local x order="" mvar dvar
187 +
188 + mvar="MULTILIB_ABIS"
189 + dvar="DEFAULT_ABI"
190 + if [[ -n $1 ]] ; then
191 + mvar="$1_${mvar}"
192 + dvar="$1_${dvar}"
193 + fi
194 +
195 + if [[ -z ${!mvar} ]] ; then
196 + echo "default"
197 + return 0
198 + fi
199 +
200 + for x in ${!mvar}; do
201 + if [[ ${x} != ${!dvar} ]] ; then
202 + order="${order:+${order} }${x}"
203 + fi
204 + done
205 + order="${order:+${order} }${!dvar}"
206 +
207 + echo ${order}
208 + return 0
209 +}
210 +
211 +# @FUNCTION: get_all_libdirs
212 +# @DESCRIPTION:
213 +# Returns a list of all the libdirs used by this profile. This includes
214 +# those that might not be touched by the current ebuild and always includes
215 +# "lib".
216 +get_all_libdirs() {
217 + local libdirs abi
218 +
219 + for abi in ${MULTILIB_ABIS}; do
220 + libdirs+=" $(get_abi_LIBDIR ${abi})"
221 + done
222 + [[ " ${libdirs} " != *" lib "* ]] && libdirs+=" lib"
223 +
224 + echo "${libdirs}"
225 +}
226 +
227 +# @FUNCTION: is_final_abi
228 +# @DESCRIPTION:
229 +# Return true if ${ABI} is the last ABI on our list (or if we're not
230 +# using the new multilib configuration. This can be used to determine
231 +# if we're in the last (or only) run through src_{unpack,compile,install}
232 +is_final_abi() {
233 + has_multilib_profile || return 0
234 + set -- $(get_install_abis)
235 + local LAST_ABI=$#
236 + [[ ${!LAST_ABI} == ${ABI} ]]
237 +}
238 +
239 +# @FUNCTION: number_abis
240 +# @DESCRIPTION:
241 +# echo the number of ABIs we will be installing for
242 +number_abis() {
243 + set -- `get_install_abis`
244 + echo $#
245 +}
246 +
247 +# @FUNCTION: get_exeext
248 +# @DESCRIPTION:
249 +# Returns standard executable program suffix (null, .exe, etc.)
250 +# for the current platform identified by CHOST.
251 +#
252 +# Example:
253 +# get_exeext
254 +# Returns: null string (almost everywhere) || .exe (mingw*) || ...
255 +get_exeext() {
256 + case ${CHOST} in
257 + *-cygwin*|mingw*|*-mingw*) echo ".exe";;
258 + esac
259 +}
260 +
261 +# @FUNCTION: get_libname
262 +# @USAGE: [version]
263 +# @DESCRIPTION:
264 +# Returns libname with proper suffix {.so,.dylib,.dll,etc} and optionally
265 +# supplied version for the current platform identified by CHOST.
266 +#
267 +# Example:
268 +# get_libname ${PV}
269 +# Returns: .so.${PV} (ELF) || .${PV}.dylib (MACH) || ...
270 +get_libname() {
271 + local libname
272 + local ver=$1
273 + case ${CHOST} in
274 + *-cygwin*) libname="dll.a";; # import lib
275 + mingw*|*-mingw*) libname="dll";;
276 + *-darwin*) libname="dylib";;
277 + *-mint*) libname="irrelevant";;
278 + hppa*-hpux*) libname="sl";;
279 + *) libname="so";;
280 + esac
281 +
282 + if [[ -z $* ]] ; then
283 + echo ".${libname}"
284 + else
285 + for ver in "$@" ; do
286 + case ${CHOST} in
287 + *-cygwin*) echo ".${ver}.${libname}";;
288 + *-darwin*) echo ".${ver}.${libname}";;
289 + *-mint*) echo ".${libname}";;
290 + *) echo ".${libname}.${ver}";;
291 + esac
292 + done
293 + fi
294 +}
295 +
296 +# @FUNCTION: get_modname
297 +# @USAGE:
298 +# @DESCRIPTION:
299 +# Returns modulename with proper suffix {.so,.bundle,etc} for the current
300 +# platform identified by CHOST.
301 +#
302 +# Example:
303 +# libfoo$(get_modname)
304 +# Returns: libfoo.so (ELF) || libfoo.bundle (MACH) || ...
305 +get_modname() {
306 + local modname
307 + local ver=$1
308 + case ${CHOST} in
309 + *-darwin*) modname="bundle";;
310 + *) modname="so";;
311 + esac
312 +
313 + echo ".${modname}"
314 +}
315 +
316 +# This is for the toolchain to setup profile variables when pulling in
317 +# a crosscompiler (and thus they aren't set in the profile)
318 +multilib_env() {
319 + local CTARGET=${1:-${CTARGET}}
320 + local cpu=${CTARGET%%*-}
321 +
322 + case ${cpu} in
323 + aarch64*)
324 + # Not possible to do multilib with aarch64 and a single toolchain.
325 + export CFLAGS_arm=${CFLAGS_arm-}
326 + case ${cpu} in
327 + aarch64*be) export CHOST_arm="armv8b-${CTARGET#*-}";;
328 + *) export CHOST_arm="armv8l-${CTARGET#*-}";;
329 + esac
330 + CHOST_arm=${CHOST_arm/%-gnu/-gnueabi}
331 + export CTARGET_arm=${CHOST_arm}
332 + export LIBDIR_arm="lib"
333 +
334 + export CFLAGS_arm64=${CFLAGS_arm64-}
335 + export CHOST_arm64=${CTARGET}
336 + export CTARGET_arm64=${CHOST_arm64}
337 + export LIBDIR_arm64="lib64"
338 +
339 + : ${MULTILIB_ABIS=arm64}
340 + : ${DEFAULT_ABI=arm64}
341 + ;;
342 + x86_64*)
343 + export CFLAGS_x86=${CFLAGS_x86--m32}
344 + export CHOST_x86=${CTARGET/x86_64/i686}
345 + CHOST_x86=${CHOST_x86/%-gnux32/-gnu}
346 + export CTARGET_x86=${CHOST_x86}
347 + if [[ ${SYMLINK_LIB} == "yes" ]] ; then
348 + export LIBDIR_x86="lib32"
349 + else
350 + export LIBDIR_x86="lib"
351 + fi
352 +
353 + export CFLAGS_amd64=${CFLAGS_amd64--m64}
354 + export CHOST_amd64=${CTARGET/%-gnux32/-gnu}
355 + export CTARGET_amd64=${CHOST_amd64}
356 + export LIBDIR_amd64="lib64"
357 +
358 + export CFLAGS_x32=${CFLAGS_x32--mx32}
359 + export CHOST_x32=${CTARGET/%-gnu/-gnux32}
360 + export CTARGET_x32=${CHOST_x32}
361 + export LIBDIR_x32="libx32"
362 +
363 + case ${CTARGET} in
364 + *-gnux32)
365 + : ${MULTILIB_ABIS=x32 amd64 x86}
366 + : ${DEFAULT_ABI=x32}
367 + ;;
368 + *)
369 + : ${MULTILIB_ABIS=amd64 x86}
370 + : ${DEFAULT_ABI=amd64}
371 + ;;
372 + esac
373 + ;;
374 + mips64*|mipsisa64*)
375 + export CFLAGS_o32=${CFLAGS_o32--mabi=32}
376 + export CHOST_o32=${CTARGET/mips64/mips}
377 + export CHOST_o32=${CHOST_o32/mipsisa64/mipsisa32}
378 + export CTARGET_o32=${CHOST_o32}
379 + export LIBDIR_o32="lib"
380 +
381 + export CFLAGS_n32=${CFLAGS_n32--mabi=n32}
382 + export CHOST_n32=${CTARGET}
383 + export CTARGET_n32=${CHOST_n32}
384 + export LIBDIR_n32="lib32"
385 +
386 + export CFLAGS_n64=${CFLAGS_n64--mabi=64}
387 + export CHOST_n64=${CTARGET}
388 + export CTARGET_n64=${CHOST_n64}
389 + export LIBDIR_n64="lib64"
390 +
391 + : ${MULTILIB_ABIS=n64 n32 o32}
392 + : ${DEFAULT_ABI=n32}
393 + ;;
394 + powerpc64*)
395 + export CFLAGS_ppc=${CFLAGS_ppc--m32}
396 + export CHOST_ppc=${CTARGET/powerpc64/powerpc}
397 + export CTARGET_ppc=${CHOST_ppc}
398 + export LIBDIR_ppc="lib"
399 +
400 + export CFLAGS_ppc64=${CFLAGS_ppc64--m64}
401 + export CHOST_ppc64=${CTARGET}
402 + export CTARGET_ppc64=${CHOST_ppc64}
403 + export LIBDIR_ppc64="lib64"
404 +
405 + : ${MULTILIB_ABIS=ppc64 ppc}
406 + : ${DEFAULT_ABI=ppc64}
407 + ;;
408 + s390x*)
409 + export CFLAGS_s390=${CFLAGS_s390--m31} # the 31 is not a typo
410 + export CHOST_s390=${CTARGET/s390x/s390}
411 + export CTARGET_s390=${CHOST_s390}
412 + export LIBDIR_s390="lib"
413 +
414 + export CFLAGS_s390x=${CFLAGS_s390x--m64}
415 + export CHOST_s390x=${CTARGET}
416 + export CTARGET_s390x=${CHOST_s390x}
417 + export LIBDIR_s390x="lib64"
418 +
419 + : ${MULTILIB_ABIS=s390x s390}
420 + : ${DEFAULT_ABI=s390x}
421 + ;;
422 + sparc64*)
423 + export CFLAGS_sparc32=${CFLAGS_sparc32--m32}
424 + export CHOST_sparc32=${CTARGET/sparc64/sparc}
425 + export CTARGET_sparc32=${CHOST_sparc32}
426 + export LIBDIR_sparc32="lib"
427 +
428 + export CFLAGS_sparc64=${CFLAGS_sparc64--m64}
429 + export CHOST_sparc64=${CTARGET}
430 + export CTARGET_sparc64=${CHOST_sparc64}
431 + export LIBDIR_sparc64="lib64"
432 +
433 + : ${MULTILIB_ABIS=sparc64 sparc32}
434 + : ${DEFAULT_ABI=sparc64}
435 + ;;
436 + *)
437 + : ${MULTILIB_ABIS=default}
438 + : ${DEFAULT_ABI=default}
439 + ;;
440 + esac
441 +
442 + export MULTILIB_ABIS DEFAULT_ABI
443 +}
444 +
445 +# @FUNCTION: multilib_toolchain_setup
446 +# @DESCRIPTION:
447 +# Hide multilib details here for packages which are forced to be compiled for a
448 +# specific ABI when run on another ABI (like x86-specific packages on amd64)
449 +multilib_toolchain_setup() {
450 + local v vv
451 +
452 + export ABI=$1
453 +
454 + # First restore any saved state we have laying around.
455 + if [[ ${_DEFAULT_ABI_SAVED} == "true" ]] ; then
456 + for v in CHOST CBUILD AS CC CXX F77 FC LD PKG_CONFIG_{LIBDIR,PATH} ; do
457 + vv="_abi_saved_${v}"
458 + [[ ${!vv+set} == "set" ]] && export ${v}="${!vv}" || unset ${v}
459 + unset ${vv}
460 + done
461 + unset _DEFAULT_ABI_SAVED
462 + fi
463 +
464 + # We want to avoid the behind-the-back magic of gcc-config as it
465 + # screws up ccache and distcc. See #196243 for more info.
466 + if [[ ${ABI} != ${DEFAULT_ABI} ]] ; then
467 + # Back that multilib-ass up so we can restore it later
468 + for v in CHOST CBUILD AS CC CXX F77 FC LD PKG_CONFIG_{LIBDIR,PATH} ; do
469 + vv="_abi_saved_${v}"
470 + [[ ${!v+set} == "set" ]] && export ${vv}="${!v}" || unset ${vv}
471 + done
472 + export _DEFAULT_ABI_SAVED="true"
473 +
474 + # Set CBUILD only if not cross-compiling.
475 + if [[ ${CBUILD} == "${CHOST}" ]]; then
476 + export CBUILD=$(get_abi_CHOST $1)
477 + fi
478 +
479 + # Set the CHOST native first so that we pick up the native
480 + # toolchain and not a cross-compiler by accident #202811.
481 + export CHOST=$(get_abi_CHOST ${DEFAULT_ABI})
482 + export CC="$(tc-getCC) $(get_abi_CFLAGS)"
483 + export CXX="$(tc-getCXX) $(get_abi_CFLAGS)"
484 + export F77="$(tc-getF77) $(get_abi_CFLAGS)"
485 + export FC="$(tc-getFC) $(get_abi_CFLAGS)"
486 + export LD="$(tc-getLD) $(get_abi_LDFLAGS)"
487 + export CHOST=$(get_abi_CHOST $1)
488 + export PKG_CONFIG_LIBDIR=${EPREFIX}/usr/$(get_libdir)/pkgconfig
489 + export PKG_CONFIG_PATH=${EPREFIX}/usr/share/pkgconfig
490 + fi
491 +}
492 +
493 +fi