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: Wed, 02 Sep 2020 19:39:40
Message-Id: 1599075365.52d3837d7233aadb8f1c79ed9bc17c38a27e5388.dilfridge@gentoo
1 commit: 52d3837d7233aadb8f1c79ed9bc17c38a27e5388
2 Author: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
3 AuthorDate: Wed Sep 2 19:36:05 2020 +0000
4 Commit: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
5 CommitDate: Wed Sep 2 19:36:05 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/riscv.git/commit/?id=52d3837d
7
8 multilib.eclass: Copy from main tree
9
10 Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>
11
12 eclass/multilib.eclass | 530 +++++++++++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 530 insertions(+)
14
15 diff --git a/eclass/multilib.eclass b/eclass/multilib.eclass
16 new file mode 100644
17 index 0000000..342d21a
18 --- /dev/null
19 +++ b/eclass/multilib.eclass
20 @@ -0,0 +1,530 @@
21 +# Copyright 1999-2020 Gentoo Authors
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 + if [[ ${CTARGET} = *-musl* ]]; then
323 + # musl has no multilib support and can run only in 'lib':
324 + # - https://bugs.gentoo.org/675954
325 + # - https://gcc.gnu.org/PR90077
326 + # - https://github.com/gentoo/musl/issues/245
327 + : ${MULTILIB_ABIS=default}
328 + : ${DEFAULT_ABI=default}
329 + export MULTILIB_ABIS DEFAULT_ABI
330 + return
331 + fi
332 +
333 + case ${cpu} in
334 + aarch64*)
335 + # Not possible to do multilib with aarch64 and a single toolchain.
336 + export CFLAGS_arm=${CFLAGS_arm-}
337 + case ${cpu} in
338 + aarch64*be) export CHOST_arm="armv8b-${CTARGET#*-}";;
339 + *) export CHOST_arm="armv8l-${CTARGET#*-}";;
340 + esac
341 + CHOST_arm=${CHOST_arm/%-gnu/-gnueabi}
342 + export CTARGET_arm=${CHOST_arm}
343 + export LIBDIR_arm="lib"
344 +
345 + export CFLAGS_arm64=${CFLAGS_arm64-}
346 + export CHOST_arm64=${CTARGET}
347 + export CTARGET_arm64=${CHOST_arm64}
348 + export LIBDIR_arm64="lib64"
349 +
350 + : ${MULTILIB_ABIS=arm64}
351 + : ${DEFAULT_ABI=arm64}
352 + ;;
353 + x86_64*)
354 + export CFLAGS_x86=${CFLAGS_x86--m32}
355 + export CHOST_x86=${CTARGET/x86_64/i686}
356 + CHOST_x86=${CHOST_x86/%-gnux32/-gnu}
357 + export CTARGET_x86=${CHOST_x86}
358 + if [[ ${SYMLINK_LIB} == "yes" ]] ; then
359 + export LIBDIR_x86="lib32"
360 + else
361 + export LIBDIR_x86="lib"
362 + fi
363 +
364 + export CFLAGS_amd64=${CFLAGS_amd64--m64}
365 + export CHOST_amd64=${CTARGET/%-gnux32/-gnu}
366 + export CTARGET_amd64=${CHOST_amd64}
367 + export LIBDIR_amd64="lib64"
368 +
369 + export CFLAGS_x32=${CFLAGS_x32--mx32}
370 + export CHOST_x32=${CTARGET/%-gnu/-gnux32}
371 + export CTARGET_x32=${CHOST_x32}
372 + export LIBDIR_x32="libx32"
373 +
374 + case ${CTARGET} in
375 + *-gnux32)
376 + : ${MULTILIB_ABIS=x32 amd64 x86}
377 + : ${DEFAULT_ABI=x32}
378 + ;;
379 + *)
380 + : ${MULTILIB_ABIS=amd64 x86}
381 + : ${DEFAULT_ABI=amd64}
382 + ;;
383 + esac
384 + ;;
385 + mips64*|mipsisa64*)
386 + export CFLAGS_o32=${CFLAGS_o32--mabi=32}
387 + export CHOST_o32=${CTARGET/mips64/mips}
388 + export CHOST_o32=${CHOST_o32/mipsisa64/mipsisa32}
389 + export CTARGET_o32=${CHOST_o32}
390 + export LIBDIR_o32="lib"
391 +
392 + export CFLAGS_n32=${CFLAGS_n32--mabi=n32}
393 + export CHOST_n32=${CTARGET}
394 + export CTARGET_n32=${CHOST_n32}
395 + export LIBDIR_n32="lib32"
396 +
397 + export CFLAGS_n64=${CFLAGS_n64--mabi=64}
398 + export CHOST_n64=${CTARGET}
399 + export CTARGET_n64=${CHOST_n64}
400 + export LIBDIR_n64="lib64"
401 +
402 + : ${MULTILIB_ABIS=n64 n32 o32}
403 + : ${DEFAULT_ABI=n32}
404 + ;;
405 + powerpc64*)
406 + export CFLAGS_ppc=${CFLAGS_ppc--m32}
407 + export CHOST_ppc=${CTARGET/powerpc64/powerpc}
408 + export CTARGET_ppc=${CHOST_ppc}
409 + export LIBDIR_ppc="lib"
410 +
411 + export CFLAGS_ppc64=${CFLAGS_ppc64--m64}
412 + export CHOST_ppc64=${CTARGET}
413 + export CTARGET_ppc64=${CHOST_ppc64}
414 + export LIBDIR_ppc64="lib64"
415 +
416 + : ${MULTILIB_ABIS=ppc64 ppc}
417 + : ${DEFAULT_ABI=ppc64}
418 + ;;
419 + riscv64*)
420 + export CFLAGS_lp64d=${CFLAGS_lp64d--mabi=lp64d}
421 + export CHOST_lp64d=${CTARGET}
422 + export CTARGET_lp64d=${CTARGET}
423 + export LIBDIR_lp64d="lib64/lp64d"
424 +
425 + export CFLAGS_lp64=${CFLAGS_lp64--mabi=lp64}
426 + export CHOST_lp64=${CTARGET}
427 + export CTARGET_lp64=${CTARGET}
428 + export LIBDIR_lp64="lib64/lp64"
429 +
430 + : ${MULTILIB_ABIS=lp64d lp64}
431 + : ${DEFAULT_ABI=lp64d}
432 + ;;
433 + s390x*)
434 + export CFLAGS_s390=${CFLAGS_s390--m31} # the 31 is not a typo
435 + export CHOST_s390=${CTARGET/s390x/s390}
436 + export CTARGET_s390=${CHOST_s390}
437 + export LIBDIR_s390="lib"
438 +
439 + export CFLAGS_s390x=${CFLAGS_s390x--m64}
440 + export CHOST_s390x=${CTARGET}
441 + export CTARGET_s390x=${CHOST_s390x}
442 + export LIBDIR_s390x="lib64"
443 +
444 + : ${MULTILIB_ABIS=s390x s390}
445 + : ${DEFAULT_ABI=s390x}
446 + ;;
447 + sparc64*)
448 + export CFLAGS_sparc32=${CFLAGS_sparc32--m32}
449 + export CHOST_sparc32=${CTARGET/sparc64/sparc}
450 + export CTARGET_sparc32=${CHOST_sparc32}
451 + export LIBDIR_sparc32="lib"
452 +
453 + export CFLAGS_sparc64=${CFLAGS_sparc64--m64}
454 + export CHOST_sparc64=${CTARGET}
455 + export CTARGET_sparc64=${CHOST_sparc64}
456 + export LIBDIR_sparc64="lib64"
457 +
458 + : ${MULTILIB_ABIS=sparc64 sparc32}
459 + : ${DEFAULT_ABI=sparc64}
460 + ;;
461 + *)
462 + : ${MULTILIB_ABIS=default}
463 + : ${DEFAULT_ABI=default}
464 + ;;
465 + esac
466 +
467 + export MULTILIB_ABIS DEFAULT_ABI
468 +}
469 +
470 +# @FUNCTION: multilib_toolchain_setup
471 +# @DESCRIPTION:
472 +# Hide multilib details here for packages which are forced to be compiled for a
473 +# specific ABI when run on another ABI (like x86-specific packages on amd64)
474 +multilib_toolchain_setup() {
475 + local v vv
476 +
477 + export ABI=$1
478 +
479 + local save_restore_variables=(
480 + CBUILD
481 + CHOST
482 + AR
483 + CC
484 + CXX
485 + F77
486 + FC
487 + LD
488 + NM
489 + OBJDUMP
490 + PKG_CONFIG
491 + RANLIB
492 + READELF
493 + STRINGS
494 + STRIP
495 + PKG_CONFIG_LIBDIR
496 + PKG_CONFIG_PATH
497 + PKG_CONFIG_SYSTEM_LIBRARY_PATH
498 + )
499 +
500 + # First restore any saved state we have laying around.
501 + if [[ ${_DEFAULT_ABI_SAVED} == "true" ]] ; then
502 + for v in "${save_restore_variables[@]}" ; do
503 + vv="_abi_saved_${v}"
504 + [[ ${!vv+set} == "set" ]] && export ${v}="${!vv}" || unset ${v}
505 + unset ${vv}
506 + done
507 + unset _DEFAULT_ABI_SAVED
508 + fi
509 +
510 + if [[ ${ABI} != ${DEFAULT_ABI} ]] ; then
511 + # Back that multilib-ass up so we can restore it later
512 + for v in "${save_restore_variables[@]}" ; do
513 + vv="_abi_saved_${v}"
514 + [[ ${!v+set} == "set" ]] && export ${vv}="${!v}" || unset ${vv}
515 + done
516 + export _DEFAULT_ABI_SAVED="true"
517 +
518 + # Set CBUILD only if not cross-compiling.
519 + if [[ ${CBUILD} == "${CHOST}" ]]; then
520 + export CBUILD=$(get_abi_CHOST $1)
521 + fi
522 +
523 + # Set the CHOST native first so that we pick up the native
524 + # toolchain and not a cross-compiler by accident #202811.
525 + #
526 + # Make sure ${save_restore_variables[@]} list matches below.
527 + export CHOST=$(get_abi_CHOST ${DEFAULT_ABI})
528 +
529 + export AR="$(tc-getAR)" # Avoid 'ar', use '${CHOST}-ar'
530 + export CC="$(tc-getCC) $(get_abi_CFLAGS)"
531 + export CXX="$(tc-getCXX) $(get_abi_CFLAGS)"
532 + export F77="$(tc-getF77) $(get_abi_CFLAGS)"
533 + export FC="$(tc-getFC) $(get_abi_CFLAGS)"
534 + export LD="$(tc-getLD) $(get_abi_LDFLAGS)"
535 + export NM="$(tc-getNM)" # Avoid 'nm', use '${CHOST}-nm'
536 + export OBJDUMP="$(tc-getOBJDUMP)" # Avoid 'objdump', use '${CHOST}-objdump'
537 + export PKG_CONFIG="$(tc-getPKG_CONFIG)"
538 + export RANLIB="$(tc-getRANLIB)" # Avoid 'ranlib', use '${CHOST}-ranlib'
539 + export READELF="$(tc-getREADELF)" # Avoid 'readelf', use '${CHOST}-readelf'
540 + export STRINGS="$(tc-getSTRINGS)" # Avoid 'strings', use '${CHOST}-strings'
541 + export STRIP="$(tc-getSTRIP)" # Avoid 'strip', use '${CHOST}-strip'
542 +
543 + export CHOST=$(get_abi_CHOST $1)
544 + export PKG_CONFIG_LIBDIR=${EPREFIX}/usr/$(get_libdir)/pkgconfig
545 + export PKG_CONFIG_PATH=${EPREFIX}/usr/share/pkgconfig
546 + export PKG_CONFIG_SYSTEM_LIBRARY_PATH=${EPREFIX}/usr/$(get_libdir)
547 + fi
548 +}
549 +
550 +fi