forked from gentoo/gentoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoolchain.eclass
2879 lines (2476 loc) · 88.4 KB
/
toolchain.eclass
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: toolchain.eclass
# @MAINTAINER:
# Toolchain Ninjas <[email protected]>
# @SUPPORTED_EAPIS: 7 8
# @BLURB: Common code for sys-devel/gcc ebuilds
# @DESCRIPTION:
# Common code for sys-devel/gcc ebuilds (and occasionally GCC forks, like
# GNAT for Ada). If not building GCC itself, please use toolchain-funcs.eclass
# instead.
case ${EAPI} in
7|8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
if [[ -z ${_TOOLCHAIN_ECLASS} ]]; then
_TOOLCHAIN_ECLASS=1
DESCRIPTION="The GNU Compiler Collection"
HOMEPAGE="https://gcc.gnu.org/"
inherit edo flag-o-matic gnuconfig libtool multilib pax-utils toolchain-funcs prefix
[[ -n ${TOOLCHAIN_HAS_TESTS} ]] && inherit python-any-r1
tc_is_live() {
[[ ${PV} == *9999* ]]
}
if tc_is_live ; then
EGIT_REPO_URI="https://gcc.gnu.org/git/gcc.git https://github.com/gcc-mirror/gcc"
# Naming style:
# gcc-10.1.0_pre9999 -> gcc-10-branch
# Note that the micro version is required or lots of stuff will break.
# To checkout master set gcc_LIVE_BRANCH="master" in the ebuild before
# inheriting this eclass.
EGIT_BRANCH="releases/${PN}-${PV%.?.?_pre9999}"
EGIT_BRANCH=${EGIT_BRANCH//./_}
inherit git-r3
elif [[ -n ${TOOLCHAIN_USE_GIT_PATCHES} ]] ; then
inherit git-r3
fi
FEATURES=${FEATURES/multilib-strict/}
#---->> globals <<----
export CTARGET=${CTARGET:-${CHOST}}
if [[ ${CTARGET} = ${CHOST} ]] ; then
if [[ ${CATEGORY} == cross-* ]] ; then
export CTARGET=${CATEGORY#cross-}
fi
fi
: "${TARGET_ABI:=${ABI}}"
: "${TARGET_MULTILIB_ABIS:=${MULTILIB_ABIS}}"
: "${TARGET_DEFAULT_ABI:=${DEFAULT_ABI}}"
is_crosscompile() {
[[ ${CHOST} != ${CTARGET} ]]
}
# @FUNCTION: tc_version_is_at_least
# @USAGE: ver1 [ver2]
# @DESCRIPTION:
# General purpose version check. Without a second argument, matches
# up to minor version (x.x.x).
tc_version_is_at_least() {
ver_test "${2:-${GCC_RELEASE_VER}}" -ge "$1"
}
# @FUNCTION: tc_version_is_between
# @USAGE: ver1 ver2
# @DESCRIPTION:
# General purpose version range check.
# Note that it matches up to but NOT including the second version
tc_version_is_between() {
tc_version_is_at_least "${1}" && ! tc_version_is_at_least "${2}"
}
# @ECLASS_VARIABLE: TOOLCHAIN_GCC_PV
# @DEFAULT_UNSET
# @DESCRIPTION:
# Used to override GCC version. Useful for e.g. live ebuilds or snapshots.
# Defaults to ${PV}.
# @ECLASS_VARIABLE: TOOLCHAIN_GCC_VALIDATE_FAILURES_VERSION
# @DESCRIPTION:
# Version of test comparison script (validate_failures.py) to use.
: "${GCC_VALIDATE_FAILURES_VERSION:=a447cd6dee206facb66720bdacf0c765a8b09f33}"
# @ECLASS_VARIABLE: TOOLCHAIN_USE_GIT_PATCHES
# @DEFAULT_UNSET
# @DESCRIPTION:
# Used to force fetching patches from git. Useful for non-released versions
# of GCC where we don't want to keep creating patchset tarballs for a new
# release series (e.g. suppose 12.0 just got released, then adding snapshots
# for 13.0, we don't want to create new patchsets for every single 13.0 snapshot,
# so just grab patches from git each time if this variable is set).
# @ECLASS_VARIABLE: GCC_TESTS_COMPARISON_DIR
# @USER_VARIABLE
# @DESCRIPTION:
# Source of previous GCC test results and location to store new results.
: "${GCC_TESTS_COMPARISON_DIR:=${BROOT}/var/cache/gcc/testresults/${CHOST}}"
# @ECLASS_VARIABLE: GCC_TESTS_COMPARISON_SLOT
# @USER_VARIABLE
# @DESCRIPTION:
# Slot to compare test results with. Defaults to current slot.
: "${GCC_TESTS_COMPARISON_SLOT:=${SLOT}}"
# @ECLASS_VARIABLE: GCC_TESTS_IGNORE_NO_BASELINE
# @DEFAULT_UNSET
# @USER_VARIABLE
# @DESCRIPTION:
# Ignore missing baseline/reference data and create new baseline.
: "${GCC_TESTS_IGNORE_NO_BASELINE:=}"
# @ECLASS_VARIABLE: GCC_TESTS_REGEN_BASELINE
# @DEFAULT_UNSET
# @USER_VARIABLE
# @DESCRIPTION:
# Ignore baseline/reference data and create new baseline.
: "${GCC_TESTS_REGEN_BASELINE:=}"
# @ECLASS_VARIABLE: GCC_TESTS_CHECK_TARGET
# @USER_VARIABLE
# @DESCRIPTION:
# Defaults to 'check'. Allows choosing a different test target, e.g.
# 'test-gcc' (https://gcc.gnu.org/install/test.html).
: "${GCC_TESTS_CHECK_TARGET:=check}"
# @ECLASS_VARIABLE: GCC_TESTS_RUNTESTFLAGS
# @DEFAULT_UNSET
# @USER_VARIABLE
# @DESCRIPTION:
# Extra options to pass to DejaGnu as RUNTESTFLAGS.
: "${GCC_TESTS_RUNTESTFLAGS:=}"
# @ECLASS_VARIABLE: TOOLCHAIN_PATCH_DEV
# @DEFAULT_UNSET
# @DESCRIPTION:
# Indicate the developer who hosts the patchset for an ebuild.
# @ECLASS_VARIABLE: TOOLCHAIN_HAS_TESTS
# @DEFAULT_UNSET
# @DESCRIPTION:
# Controls whether python-any-r1 is inherited and validate_failures.py
# is used.
# @ECLASS_VARIABLE: GCC_PV
# @INTERNAL
# @DESCRIPTION:
# Internal variable representing (spoofed) GCC version.
GCC_PV=${TOOLCHAIN_GCC_PV:-${PV}}
# @ECLASS_VARIABLE: GCC_PVR
# @INTERNAL
# @DESCRIPTION:
# Full GCC version including revision.
GCC_PVR=${GCC_PV}
[[ ${PR} != "r0" ]] && GCC_PVR=${GCC_PVR}-${PR}
# @ECLASS_VARIABLE: GCC_RELEASE_VER
# @INTERNAL
# @DESCRIPTION:
# GCC_RELEASE_VER must always match 'gcc/BASE-VER' value.
# It's an internal representation of gcc version used for:
# - versioned paths on disk
# - 'gcc -dumpversion' output. Must always match <digit>.<digit>.<digit>.
GCC_RELEASE_VER=$(ver_cut 1-3 ${GCC_PV})
# @ECLASS_VARIABLE: GCC_BRANCH_VER
# @INTERNAL
# @DESCRIPTION:
# GCC branch version.
GCC_BRANCH_VER=$(ver_cut 1-2 ${GCC_PV})
# @ECLASS_VARIABLE: GCCMAJOR
# @INTERNAL
# @DESCRIPTION:
# Major GCC version.
GCCMAJOR=$(ver_cut 1 ${GCC_PV})
# @ECLASS_VARIABLE: GCCMINOR
# @INTERNAL
# @DESCRIPTION:
# Minor GCC version.
GCCMINOR=$(ver_cut 2 ${GCC_PV})
# @ECLASS_VARIABLE: GCCMICRO
# @INTERNAL
# @DESCRIPTION:
# GCC micro version.
GCCMICRO=$(ver_cut 3 ${GCC_PV})
# @ECLASS_VARIABLE: GCC_RUN_FIXINCLUDES
# @INTERNAL
# @DESCRIPTION:
# Controls whether fixincludes should be used.
GCC_RUN_FIXINCLUDES=0
tc_use_major_version_only() {
local use_major_version_only=0
if ! tc_version_is_at_least 10 ; then
return 1
fi
if [[ ${GCCMAJOR} -eq 10 ]] && ver_test ${PV} -ge 10.4.1_p20220929 ; then
use_major_version_only=1
elif [[ ${GCCMAJOR} -eq 11 ]] && ver_test ${PV} -ge 11.3.1_p20220930 ; then
use_major_version_only=1
elif [[ ${GCCMAJOR} -eq 12 ]] && ver_test ${PV} -ge 12.2.1_p20221001 ; then
use_major_version_only=1
elif [[ ${GCCMAJOR} -eq 13 ]] && ver_test ${PV} -ge 13.0.0_pre20221002 ; then
use_major_version_only=1
elif [[ ${GCCMAJOR} -gt 13 ]] ; then
use_major_version_only=1
fi
if [[ ${use_major_version_only} -eq 1 ]] ; then
return 0
fi
return 1
}
# @ECLASS_VARIABLE: GCC_CONFIG_VER
# @INTERNAL
# @DESCRIPTION:
# Ideally this variable should allow for custom gentoo versioning
# of binary and gcc-config names not directly tied to upstream
# versioning. In practice it's hard to untangle from gcc/BASE-VER
# (GCC_RELEASE_VER) value.
if tc_use_major_version_only ; then
GCC_CONFIG_VER=${GCCMAJOR}
else
GCC_CONFIG_VER=${GCC_RELEASE_VER}
fi
# Pre-release support. Versioning schema:
# 1.0.0_pre9999: live ebuild
# 1.2.3_pYYYYMMDD (or 1.2.3_preYYYYMMDD for unreleased major versions): weekly snapshots
# 1.2.3_rcYYYYMMDD: release candidates
if [[ ${GCC_PV} == *_pre* ]] ; then
# Weekly snapshots
SNAPSHOT=${GCCMAJOR}-${GCC_PV##*_pre}
elif [[ ${GCC_PV} == *_p* ]] ; then
# Weekly snapshots
SNAPSHOT=${GCCMAJOR}-${GCC_PV##*_p}
elif [[ ${GCC_PV} == *_rc* ]] ; then
# Release candidates
SNAPSHOT=${GCC_PV%_rc*}-RC-${GCC_PV##*_rc}
fi
# Require minimum gcc version to simplify assumptions.
# Normally we would require gcc-6+ (based on sys-devel/gcc)
# but we still have sys-devel/gcc-apple-4.2.1_p5666.
tc_version_is_at_least 8 || die "${ECLASS}: ${GCC_RELEASE_VER} is too old."
PREFIX=${TOOLCHAIN_PREFIX:-${EPREFIX}/usr}
LIBPATH=${TOOLCHAIN_LIBPATH:-${PREFIX}/lib/gcc/${CTARGET}/${GCC_CONFIG_VER}}
INCLUDEPATH=${TOOLCHAIN_INCLUDEPATH:-${LIBPATH}/include}
if is_crosscompile ; then
BINPATH=${TOOLCHAIN_BINPATH:-${PREFIX}/${CHOST}/${CTARGET}/gcc-bin/${GCC_CONFIG_VER}}
HOSTLIBPATH=${PREFIX}/${CHOST}/${CTARGET}/lib/${GCC_CONFIG_VER}
else
BINPATH=${TOOLCHAIN_BINPATH:-${PREFIX}/${CTARGET}/gcc-bin/${GCC_CONFIG_VER}}
fi
DATAPATH=${TOOLCHAIN_DATAPATH:-${PREFIX}/share/gcc-data/${CTARGET}/${GCC_CONFIG_VER}}
# Don't install in /usr/include/g++-v3/, but instead to gcc's internal directory.
# We will handle /usr/include/g++-v3/ with gcc-config ...
STDCXX_INCDIR=${TOOLCHAIN_STDCXX_INCDIR:-${LIBPATH}/include/g++-v${GCC_BRANCH_VER/\.*/}}
#---->> LICENSE+SLOT+IUSE logic <<----
LICENSE="GPL-3+ LGPL-3+ || ( GPL-3+ libgcc libstdc++ gcc-runtime-library-exception-3.1 ) FDL-1.3+"
IUSE="test vanilla +nls"
RESTRICT="!test? ( test )"
[[ -z ${TOOLCHAIN_HAS_TESTS} ]] && RESTRICT+=" test"
TC_FEATURES=()
tc_has_feature() {
has "$1" "${TC_FEATURES[@]}"
}
if [[ ${PN} != kgcc64 && ${PN} != gcc-* ]] ; then
IUSE+=" debug +cxx"
IUSE+=" +fortran" TC_FEATURES+=( fortran )
IUSE+=" doc hardened multilib objc"
IUSE+=" pgo"
IUSE+=" objc-gc" TC_FEATURES+=( objc-gc )
IUSE+=" libssp objc++"
# Stop forcing openmp on by default in the eclass. Gradually phase it out.
# See bug #890999.
if tc_version_is_at_least 13.0.0_pre20221218 ; then
IUSE+=" openmp"
else
IUSE+=" +openmp"
fi
IUSE+=" fixed-point"
IUSE+=" go"
IUSE+=" +sanitize" TC_FEATURES+=( sanitize )
IUSE+=" graphite" TC_FEATURES+=( graphite )
IUSE+=" ada" TC_FEATURES+=( ada )
IUSE+=" vtv"
IUSE+=" jit"
IUSE+=" +pie +ssp pch"
IUSE+=" systemtap" TC_FEATURES+=( systemtap )
tc_version_is_at_least 9.0 && IUSE+=" d" TC_FEATURES+=( d )
tc_version_is_at_least 9.1 && IUSE+=" lto"
tc_version_is_at_least 10 && IUSE+=" cet"
tc_version_is_at_least 10 && IUSE+=" zstd" TC_FEATURES+=( zstd )
tc_version_is_at_least 11 && IUSE+=" valgrind" TC_FEATURES+=( valgrind )
tc_version_is_at_least 11 && IUSE+=" custom-cflags"
tc_version_is_at_least 12 && IUSE+=" ieee-long-double"
tc_version_is_at_least 12.2.1_p20221203 ${PV} && IUSE+=" default-znow"
tc_version_is_at_least 12.2.1_p20221203 ${PV} && IUSE+=" default-stack-clash-protection"
tc_version_is_at_least 13.0.0_pre20221218 ${PV} && IUSE+=" modula2"
# See https://gcc.gnu.org/pipermail/gcc-patches/2023-April/615944.html
# and https://rust-gcc.github.io/2023/04/24/gccrs-and-gcc13-release.html for why
# it was disabled in 13.
tc_version_is_at_least 14.0.0_pre20230423 ${PV} && IUSE+=" rust" TC_FEATURES+=( rust )
fi
if tc_version_is_at_least 10; then
# Note: currently we pull in releases, snapshots and
# git versions into the same SLOT.
SLOT="${GCCMAJOR}"
else
SLOT="${GCC_CONFIG_VER}"
fi
#---->> DEPEND <<----
RDEPEND="
sys-libs/zlib
virtual/libiconv
nls? ( virtual/libintl )
"
GMP_MPFR_DEPS=">=dev-libs/gmp-4.3.2:0= >=dev-libs/mpfr-2.4.2:0="
RDEPEND+=" ${GMP_MPFR_DEPS}"
RDEPEND+=" >=dev-libs/mpc-0.8.1:0="
if tc_has_feature objc-gc ; then
RDEPEND+=" objc-gc? ( >=dev-libs/boehm-gc-7.4.2 )"
fi
if tc_has_feature graphite ; then
RDEPEND+=" graphite? ( >=dev-libs/isl-0.14:0= )"
fi
BDEPEND="
app-alternatives/yacc
sys-devel/binutils:*
>=sys-devel/flex-2.5.4
nls? ( sys-devel/gettext )
test? (
${PYTHON_DEPS}
>=dev-util/dejagnu-1.4.4
>=sys-devel/autogen-5.5.4
)
"
DEPEND="${RDEPEND}"
if [[ ${PN} == gcc && ${PV} == *_p* ]] ; then
# Snapshots don't contain info pages.
# If they start to, adjust gcc_cv_prog_makeinfo_modern logic in toolchain_src_configure.
# Needed unless/until https://gcc.gnu.org/PR106899 is fixed
BDEPEND+=" sys-apps/texinfo"
fi
if tc_has_feature sanitize ; then
# libsanitizer relies on 'crypt.h' to be present
# on target. glibc user to provide it unconditionally.
# Nowadays it's a standalone library: bug #802648
DEPEND+=" sanitize? ( virtual/libcrypt )"
fi
if tc_has_feature systemtap ; then
# gcc needs sys/sdt.h headers on target
DEPEND+=" systemtap? ( dev-debug/systemtap )"
fi
if tc_has_feature zstd ; then
DEPEND+=" zstd? ( app-arch/zstd:= )"
RDEPEND+=" zstd? ( app-arch/zstd:= )"
fi
if tc_has_feature valgrind ; then
BDEPEND+=" valgrind? ( dev-debug/valgrind )"
fi
if [[ ${PN} != gnat-gpl ]] && tc_has_feature ada ; then
BDEPEND+=" ada? ( || ( sys-devel/gcc[ada] dev-lang/gnat-gpl[ada] ) )"
fi
# TODO: Add a pkg_setup & pkg_pretend check for whether the active compiler
# supports D.
if tc_has_feature d && tc_version_is_at_least 12.0 ; then
# D in 12+ is self-hosting and needs D to bootstrap.
# TODO: package some binary we can use, like for Ada
# bug #840182
BDEPEND+=" d? ( || ( sys-devel/gcc[d(-)] <sys-devel/gcc-12[d(-)] ) )"
fi
if tc_has_feature rust && tc_version_is_at_least 14.0.0_pre20230421 ; then
# This was added upstream in r14-9968-g3e1e73fc995844 as a temporary measure.
# See https://inbox.sourceware.org/gcc/[email protected]/
BDEPEND+=" rust? ( virtual/rust )"
fi
PDEPEND=">=sys-devel/gcc-config-2.11"
#---->> S + SRC_URI essentials <<----
# @ECLASS_VARIABLE: TOOLCHAIN_PATCH_SUFFIX
# @DESCRIPTION:
# Used to override compression used for for patchsets.
# Default is xz for EAPI 8+ and bz2 for older EAPIs.
if [[ ${EAPI} == 8 ]] ; then
: "${TOOLCHAIN_PATCH_SUFFIX:=xz}"
else
# Older EAPIs
: "${TOOLCHAIN_PATCH_SUFFIX:=bz2}"
fi
# @ECLASS_VARIABLE: TOOLCHAIN_SET_S
# @DESCRIPTION:
# Used to override value of S for snapshots and such. Mainly useful
# if needing to set GCC_TARBALL_SRC_URI.
: "${TOOLCHAIN_SET_S:=yes}"
# Set the source directory depending on whether we're using
# a live git tree, snapshot, or release tarball.
if [[ ${TOOLCHAIN_SET_S} == yes ]] ; then
if tc_is_live ; then
S=${EGIT_CHECKOUT_DIR}
elif [[ -n ${SNAPSHOT} ]] ; then
S=${WORKDIR}/gcc-${SNAPSHOT}
else
S=${WORKDIR}/gcc-${GCC_RELEASE_VER}
fi
fi
gentoo_urls() {
# the list is sorted by likelihood of getting the patches tarball from
# respective devspace
# slyfox's distfiles are mirrored to sam's devspace
declare -A devspace_urls=(
[soap]=HTTP~soap/distfiles/URI
[sam]=HTTP~sam/distfiles/sys-devel/gcc/URI
[slyfox]=HTTP~sam/distfiles/URI
[xen0n]=HTTP~xen0n/distfiles/sys-devel/gcc/URI
[tamiko]=HTTP~tamiko/distfiles/URI
[zorry]=HTTP~zorry/patches/gcc/URI
[vapier]=HTTP~vapier/dist/URI
[blueness]=HTTP~blueness/dist/URI
)
# Newer ebuilds should set TOOLCHAIN_PATCH_DEV and we'll just
# return the full URL from the array.
if [[ -n ${TOOLCHAIN_PATCH_DEV} ]] ; then
local devspace_url=${devspace_urls[${TOOLCHAIN_PATCH_DEV}]}
if [[ -n ${devspace_url} ]] ; then
local devspace_url_exp=${devspace_url//HTTP/https:\/\/dev.gentoo.org\/}
devspace_url_exp=${devspace_url_exp//URI/$1}
echo ${devspace_url_exp}
return
fi
fi
# But we keep the old fallback list for compatibility with
# older ebuilds (overlays etc).
local devspace="
HTTP~soap/distfiles/URI
HTTP~sam/distfiles/URI
HTTP~sam/distfiles/sys-devel/gcc/URI
HTTP~tamiko/distfiles/URI
HTTP~zorry/patches/gcc/URI
HTTP~vapier/dist/URI
HTTP~blueness/dist/URI
"
devspace=${devspace//HTTP/https:\/\/dev.gentoo.org\/}
echo ${devspace//URI/$1} mirror://gentoo/$1
}
# This function handles the basics of setting the SRC_URI for a gcc ebuild.
# To use, set SRC_URI with:
#
# SRC_URI="$(get_gcc_src_uri)"
#
# Other than the variables normally set by portage, this function's behavior
# can be altered by setting the following:
#
# GCC_TARBALL_SRC_URI
# Override link to main tarball into SRC_URI. Used by dev-lang/gnat-gpl
# to provide gcc tarball snapshots. Patches are usually reused as-is.
#
# SNAPSHOT
# If set, this variable signals that we should be using a snapshot of
# gcc. It is expected to be in the format "YYYY-MM-DD". Note that if
# the ebuild has a _pre suffix, this variable is ignored and the
# prerelease tarball is used instead.
#
# PATCH_VER
# PATCH_GCC_VER
# This should be set to the version of the gentoo patch tarball.
# The resulting filename of this tarball will be:
# gcc-${PATCH_GCC_VER:-${GCC_RELEASE_VER}}-patches-${PATCH_VER}.tar.xz
#
get_gcc_src_uri() {
export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
export MUSL_GCC_VER=${MUSL_GCC_VER:-${PATCH_GCC_VER}}
# Set where to download gcc itself depending on whether we're using a
# live git tree, snapshot, or release tarball.
if tc_is_live ; then
: # Nothing to do w/git snapshots.
elif [[ -n ${GCC_TARBALL_SRC_URI} ]] ; then
# Pull gcc tarball from another location. Frequently used by gnat-gpl.
GCC_SRC_URI="${GCC_TARBALL_SRC_URI}"
elif [[ -n ${SNAPSHOT} ]] ; then
GCC_SRC_URI="mirror://gcc/snapshots/${SNAPSHOT}/gcc-${SNAPSHOT}.tar.xz"
else
GCC_SRC_URI="
mirror://gcc/releases/gcc-${GCC_PV}/gcc-${GCC_RELEASE_VER}.tar.xz
mirror://gnu/gcc/gcc-${GCC_PV}/gcc-${GCC_RELEASE_VER}.tar.xz
"
fi
[[ -n ${PATCH_VER} ]] && \
GCC_SRC_URI+=" $(gentoo_urls gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.${TOOLCHAIN_PATCH_SUFFIX})"
[[ -n ${MUSL_VER} ]] && \
GCC_SRC_URI+=" $(gentoo_urls gcc-${MUSL_GCC_VER}-musl-patches-${MUSL_VER}.tar.${TOOLCHAIN_PATCH_SUFFIX})"
[[ -n ${TOOLCHAIN_HAS_TESTS} ]] && \
GCC_SRC_URI+=" test? ( https://gitweb.gentoo.org/proj/gcc-patches.git/plain/scripts/testsuite-management/validate_failures.py?id=${GCC_VALIDATE_FAILURES_VERSION} -> gcc-validate-failures-${GCC_VALIDATE_FAILURES_VERSION}.py )"
echo "${GCC_SRC_URI}"
}
SRC_URI=$(get_gcc_src_uri)
#---->> pkg_pretend <<----
toolchain_pkg_pretend() {
if ! _tc_use_if_iuse cxx ; then
_tc_use_if_iuse ada && \
ewarn 'Ada requires a C++ compiler, disabled due to USE="-cxx"'
_tc_use_if_iuse go && \
ewarn 'Go requires a C++ compiler, disabled due to USE="-cxx"'
_tc_use_if_iuse objc++ && \
ewarn 'Obj-C++ requires a C++ compiler, disabled due to USE="-cxx"'
fi
}
#---->> pkg_setup <<----
toolchain_pkg_setup() {
# We don't want to use the installed compiler's specs to build gcc
unset GCC_SPECS
# bug #265283
unset LANGUAGES
# bug #932245
[[ ${LIBTOOL} = rlibtool ]] && die "\$LIBTOOL is using rlibtool from dev-build/slibtool. You must not use rlibtool, only rclibtool."
# See https://www.gnu.org/software/make/manual/html_node/Parallel-Output.html
# Avoid really confusing logs from subconfigure spam, makes logs far
# more legible.
MAKEOPTS="--output-sync=line ${MAKEOPTS}"
[[ -n ${TOOLCHAIN_HAS_TESTS} ]] && use test && python-any-r1_pkg_setup
}
#---->> src_unpack <<----
# @FUNCTION: toolchain_fetch_git_patches
# @INTERNAL
# @DESCRIPTION:
# Fetch patches from Gentoo's gcc-patches repository.
toolchain_fetch_git_patches() {
local gcc_patches_repo="https://anongit.gentoo.org/git/proj/gcc-patches.git https://github.com/gentoo/gcc-patches"
# If we weren't given a patchset number, pull it from git too.
einfo "Fetching patchset from git as PATCH_VER is unset"
EGIT_REPO_URI=${gcc_patches_repo} EGIT_BRANCH="master" \
EGIT_CHECKOUT_DIR="${WORKDIR}"/patch.tmp \
git-r3_src_unpack
mkdir "${WORKDIR}"/patch || die
mv "${WORKDIR}"/patch.tmp/${PATCH_GCC_VER}/gentoo/* "${WORKDIR}"/patch || die
if [[ -z ${MUSL_VER} || -d "${WORKDIR}"/musl ]] && [[ ${CTARGET} == *musl* ]] ; then
mkdir "${WORKDIR}"/musl || die
mv "${WORKDIR}"/patch.tmp/${PATCH_GCC_VER}/musl/* "${WORKDIR}"/musl || die
fi
}
toolchain_src_unpack() {
if tc_is_live ; then
git-r3_src_unpack
# Needed for gcc --version to include the upstream commit used
# rather than only the commit after we apply our patches.
# It includes both with this.
echo "${EGIT_VERSION}" > "${S}"/gcc/REVISION || die
if [[ -z ${PATCH_VER} ]] && ! use vanilla ; then
toolchain_fetch_git_patches
fi
elif [[ -z ${PATCH_VER} && -n ${TOOLCHAIN_USE_GIT_PATCHES} ]] ; then
toolchain_fetch_git_patches
fi
default
}
#---->> src_prepare <<----
toolchain_src_prepare() {
export BRANDING_GCC_PKGVERSION="Gentoo ${GCC_PVR}"
cd "${S}" || die
do_gcc_gentoo_patches
if tc_is_live ; then
BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, commit ${EGIT_VERSION}"
fi
eapply_user
if ! use vanilla ; then
tc_enable_hardened_gcc
fi
if [[ -n ${TOOLCHAIN_HAS_TESTS} ]] && use test ; then
cp "${DISTDIR}"/gcc-validate-failures-${GCC_VALIDATE_FAILURES_VERSION}.py "${T}"/validate_failures.py || die
chmod +x "${T}"/validate_failures.py || die
fi
# Make sure the pkg-config files install into multilib dirs.
# Since we configure with just one --libdir, we can't use that
# (as gcc itself takes care of building multilibs). bug #435728
find "${S}" -name Makefile.in \
-exec sed -i '/^pkgconfigdir/s:=.*:=$(toolexeclibdir)/pkgconfig:' {} + || die
setup_multilib_osdirnames
local actual_version=$(< "${S}"/gcc/BASE-VER)
if ! tc_is_live && [[ "${GCC_RELEASE_VER}" != "${actual_version}" ]] ; then
eerror "'${S}/gcc/BASE-VER' contains '${actual_version}', expected '${GCC_RELEASE_VER}'"
die "Please set 'TOOLCHAIN_GCC_PV' to '${actual_version}'"
fi
# Fixup libtool to correctly generate .la files with portage
elibtoolize --portage --shallow --no-uclibc
gnuconfig_update
if ! use prefix-guest && [[ -n ${EPREFIX} ]] ; then
einfo "Prefixifying dynamic linkers..."
for f in gcc/config/*/*linux*.h ; do
ebegin " Updating ${f}"
if [[ ${f} == gcc/config/rs6000/linux*.h ]]; then
sed -i -r "s,(DYNAMIC_LINKER_PREFIX\s+)\"\",\1\"${EPREFIX}\",g" "${f}" || die
else
sed -i -r "/_DYNAMIC_LINKER/s,([\":])(/lib),\1${EPREFIX}\2,g" "${f}" || die
fi
eend $?
done
fi
einfo "Touching generated files"
./contrib/gcc_update --touch | \
while read f ; do
einfo " ${f%%...}"
done
}
do_gcc_gentoo_patches() {
if ! use vanilla ; then
if [[ -n ${PATCH_VER} || -d "${WORKDIR}"/patch ]] ; then
einfo "Applying Gentoo patches ..."
eapply "${WORKDIR}"/patch/*.patch
BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION} p${PATCH_VER}"
fi
if [[ -n ${MUSL_VER} || -d "${WORKDIR}"/musl ]] && [[ ${CTARGET} == *musl* ]] ; then
if [[ ${CATEGORY} == cross-* ]] ; then
# We don't want to apply some patches when cross-compiling.
if [[ -d "${WORKDIR}"/musl/nocross ]] ; then
rm -fv "${WORKDIR}"/musl/nocross/*.patch || die
else
# Just make an empty directory to make the glob below easier.
mkdir -p "${WORKDIR}"/musl/nocross || die
fi
fi
local shopt_save=$(shopt -p nullglob)
shopt -s nullglob
einfo "Applying musl patches ..."
eapply "${WORKDIR}"/musl/{,nocross/}*.patch
${shopt_save}
fi
fi
}
# configure to build with the hardened GCC specs as the default
tc_enable_hardened_gcc() {
local hardened_gcc_flags=""
if _tc_use_if_iuse pie ; then
einfo "Updating gcc to use automatic PIE building ..."
fi
if _tc_use_if_iuse ssp ; then
einfo "Updating gcc to use automatic SSP building ..."
fi
if _tc_use_if_iuse default-stack-clash-protection ; then
# The define DEF_GENTOO_SCP is checked in 24_all_DEF_GENTOO_SCP-fstack-clash-protection.patch
einfo "Updating gcc to use automatic stack clash protection ..."
hardened_gcc_flags+=" -DDEF_GENTOO_SCP"
fi
if _tc_use_if_iuse default-znow ; then
# The define DEF_GENTOO_ZNOW is checked in 23_all_DEF_GENTOO_ZNOW-z-now.patch
einfo "Updating gcc to request symbol resolution at start (-z now) ..."
hardened_gcc_flags+=" -DDEF_GENTOO_ZNOW"
fi
if _tc_use_if_iuse cet && [[ ${CTARGET} == *x86_64*-linux-gnu* ]] ; then
einfo "Updating gcc to use x86-64 control flow protection by default ..."
hardened_gcc_flags+=" -DEXTRA_OPTIONS_CF"
fi
if _tc_use_if_iuse hardened ; then
# Will add some hardened options as default, e.g. for gcc-12
# * -fstack-clash-protection
# * -z now
# See gcc *_all_extra-options.patch patches.
hardened_gcc_flags+=" -DEXTRA_OPTIONS"
# Default to -D_FORTIFY_SOURCE=3 instead of -D_FORTIFY_SOURCE=2
hardened_gcc_flags+=" -DGENTOO_FORTIFY_SOURCE_LEVEL=3"
# Add -D_GLIBCXX_ASSERTIONS
hardened_gcc_flags+=" -DDEF_GENTOO_GLIBCXX_ASSERTIONS"
# Rebrand to make bug reports easier
BRANDING_GCC_PKGVERSION=${BRANDING_GCC_PKGVERSION/Gentoo/Gentoo Hardened}
fi
# We want to be able to control the PIE patch logic via something other
# than ALL_CFLAGS...
sed -e '/^ALL_CFLAGS/iHARD_CFLAGS = ' \
-e 's|^ALL_CFLAGS = |ALL_CFLAGS = $(HARD_CFLAGS) |' \
-i "${S}"/gcc/Makefile.in || die
sed -e '/^ALL_CXXFLAGS/iHARD_CFLAGS = ' \
-e 's|^ALL_CXXFLAGS = |ALL_CXXFLAGS = $(HARD_CFLAGS) |' \
-i "${S}"/gcc/Makefile.in || die
sed -i \
-e "/^HARD_CFLAGS = /s|=|= ${hardened_gcc_flags} |" \
"${S}"/gcc/Makefile.in || die
}
# This is a historical wart. The original Gentoo/amd64 port used:
# lib32 - 32bit binaries (x86)
# lib64 - 64bit binaries (x86_64)
# lib - "native" binaries (a symlink to lib64)
# Most other distros use the logic (including mainline gcc):
# lib - 32bit binaries (x86)
# lib64 - 64bit binaries (x86_64)
# Over time, Gentoo is migrating to the latter form (17.1 profiles).
#
# Unfortunately, due to distros picking the lib32 behavior, newer gcc
# versions will dynamically detect whether to use lib or lib32 for its
# 32bit multilib. So, to keep the automagic from getting things wrong
# while people are transitioning from the old style to the new style,
# we always set the MULTILIB_OSDIRNAMES var for relevant targets.
setup_multilib_osdirnames() {
is_multilib || return 0
local config
local libdirs="../lib64 ../lib32"
# This only makes sense for some Linux targets
case ${CTARGET} in
x86_64*-linux*) config="i386" ;;
powerpc64*-linux*) config="rs6000" ;;
sparc64*-linux*) config="sparc" ;;
s390x*-linux*) config="s390" ;;
*) return 0 ;;
esac
config+="/t-linux64"
local sed_args=()
sed_args+=( -e 's:$[(]call if_multiarch[^)]*[)]::g' )
if [[ ${SYMLINK_LIB} == "yes" ]] ; then
einfo "Updating multilib directories to be: ${libdirs}"
sed_args+=( -e '/^MULTILIB_OSDIRNAMES.*lib32/s:[$][(]if.*):../lib32:' )
else
einfo "Using upstream multilib; disabling lib32 autodetection"
sed_args+=( -r -e 's:[$][(]if.*,(.*)[)]:\1:' )
fi
sed -i "${sed_args[@]}" "${S}"/gcc/config/${config} || die
}
#---->> src_configure <<----
toolchain_src_configure() {
BUILD_CONFIG_TARGETS=()
is-flagq '-O3' && BUILD_CONFIG_TARGETS+=( bootstrap-O3 )
downgrade_arch_flags
gcc_do_filter_flags
if ! tc_version_is_at_least 11 && [[ $(gcc-major-version) -ge 12 ]] ; then
# https://gcc.gnu.org/PR105695
# bug #849359
export ac_cv_std_swap_in_utility=no
fi
einfo "CFLAGS=\"${CFLAGS}\""
einfo "CXXFLAGS=\"${CXXFLAGS}\""
einfo "LDFLAGS=\"${LDFLAGS}\""
# Force internal zip based jar script to avoid random
# issues with 3rd party jar implementations. bug #384291
export JAR=no
local confgcc=( --host=${CHOST} )
if is_crosscompile || tc-is-cross-compiler ; then
# Straight from the GCC install doc:
# "GCC has code to correctly determine the correct value for target
# for nearly all native systems. Therefore, we highly recommend you
# not provide a configure target when configuring a native compiler."
confgcc+=( --target=${CTARGET} )
fi
[[ -n ${CBUILD} ]] && confgcc+=( --build=${CBUILD} )
_need_ada_bootstrap_mangling() {
if [[ ${CATEGORY}/${PN} == dev-lang/gnat-gpl ]] ; then
_tc_use_if_iuse system-bootstrap && return 0
return 1
fi
_tc_use_if_iuse ada
}
if _need_ada_bootstrap_mangling ; then
local latest_gcc=$(best_version -b "sys-devel/gcc")
latest_gcc="${latest_gcc#sys-devel/gcc-}"
latest_gcc=$(ver_cut 1 ${latest_gcc})
local ada_bootstrap
local ada_candidate
# We always prefer the version being built if possible
# as it has the greatest chance of success. Failing that,
# try GCC 10 and iterate upwards.
for ada_candidate in ${SLOT} $(seq 10 ${latest_gcc}) ; do
has_version -b "sys-devel/gcc:${ada_candidate}" || continue
ebegin "Testing sys-devel/gcc:${ada_candidate} for Ada"
if has_version -b "sys-devel/gcc:${ada_candidate}[ada(-)]" ; then
# Make sure we set a path to the Ada bootstrap if gcc[ada] is not already
# installed. GNAT can usually be built using the last major version and
# the current version, at least.
ada_bootstrap=${ada_candidate}
eend 0
break
fi
eend 1
done
# As a last resort, use dev-lang/gnat-gpl.
# TODO: Make gnat-gpl coinstallable with gcc:10.
if ver_test ${ada_bootstrap} -gt ${PV} || [[ -z ${ada_bootstrap} ]] ; then
ebegin "Testing dev-lang/gnat-gpl for Ada"
if has_version -b "dev-lang/gnat-gpl" ; then
ada_bootstrap=10
eend 0
else
eend 1
fi
fi
# OK, even gnat-gpl didn't work. Give up for now.
# TODO: Source a newer, or build our own, bootstrap tarball.
if [[ -z ${ada_bootstrap} ]] ; then
die "Fallback ada-bootstrap path not yet implemented!"
#einfo "Using bootstrap GNAT compiler..."
#export PATH="${BROOT}/opt/ada-bootstrap-${GCCMAJOR}/bin:${PATH}"
fi
cat <<-"EOF" > "${T}"/ada.spec || die
# Extracted from gcc/ada/gcc-interface/lang-specs.h
.adb:
@ada
.ads:
@ada
# TODO: ADA_DUMPS_OPTIONS
@ada:
%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}} \
%{!S:%{!c:%e-c or -S required for Ada}} \
${BROOT}/usr/libexec/gcc/${CBUILD}/${ada_bootstrap}/gnat1 %{I*} %{k8:-gnatk8} %{!Q:-quiet} \
%{nostdinc*} %{nostdlib*} \
%{fcompare-debug-second:-gnatd_A} \
%{O*} %{W*} %{w} %{p} %{pg:-p} \
%{coverage:-fprofile-arcs -ftest-coverage} \
%{Wall:-gnatwa} %{Werror:-gnatwe} %{w:-gnatws} \
%{gnatea:-gnatez} %{g*&m*&f*} \
%1 %{!S:%{o*:%w%*-gnatO}} \
%i %{S:%W{o*}%{!o*:-o %w%b.s}} \
%{gnatc*|gnats*: -o %j} %{-param*} \
%{!gnatc*:%{!gnats*:%(invoke_as)}}
@adawhy:
%{!c:%e-c required for gnat2why} \
gnat1why %{I*} %{k8:-gnatk8} %{!Q:-quiet} \
%{nostdinc*} %{nostdlib*} \
%{a} \
%{gnatea:-gnatez} %{g*&m*&f*} \
%1 %{o*:%w%*-gnatO} \
%i \
%{gnatc*|gnats*: -o %j} %{-param*}
@adascil:
%{!c:%e-c required for gnat2scil} \
gnat1scil %{I*} %{k8:-gnatk8} %{!Q:-quiet} \
%{nostdinc*} %{nostdlib*} \
%{a} \
%{gnatea:-gnatez} %{g*&m*&f*} \
%1 %{o*:%w%*-gnatO} \
%i \
%{gnatc*|gnats*: -o %j} %{-param*}
EOF
# Easier to substitute these values in rather than escape
# lots of bits above in heredoc.
sed -i \
-e "s:\${BROOT}:${BROOT}:" \
-e "s:\${CBUILD}:${CBUILD}:" \
-e "s:\${ada_bootstrap}:${ada_bootstrap}:" \
"${T}"/ada.spec || die
# The Makefile tries to find libgnat by querying $(CC) which
# won't work for us as the stage1 compiler doesn't necessarily
# have Ada support. Substitute the Ada compiler we found earlier.
local adalib
adalib=$(${CBUILD}-gcc-${ada_bootstrap} -print-libgcc-file-name || die "Finding adalib dir failed")
adalib="${adalib%/*}/adalib"
sed -i \
-e "s:adalib=.*:adalib=${adalib}:" \
"${S}"/gcc/ada/gcc-interface/Make-lang.in || die
# Create bin wrappers because not all of the build system
# respects GNATBIND or GNATMAKE.
mkdir "${T}"/ada-wrappers || die
local tool
for tool in gnat{,bind,chop,clean,kr,link,ls,make,name,prep} ; do
cat <<-EOF > "${T}"/ada-wrappers/${tool} || die
#!/bin/bash
exec $(type -P ${CBUILD}-${tool}-${ada_bootstrap}) -specs=${T}/ada.spec "\$@"
EOF
chmod +x "${T}"/ada-wrappers/${tool} || die
export "${tool^^}"=${CBUILD}-${tool}-${ada_bootstrap}
done
export PATH="${T}/ada-wrappers:${PATH}"
export CC="$(tc-getCC) -specs=${T}/ada.spec"
fi
if _tc_use_if_iuse d ; then
local latest_gcc=$(best_version -b "sys-devel/gcc")
latest_gcc="${latest_gcc#sys-devel/gcc-}"
latest_gcc=$(ver_cut 1 ${latest_gcc})
local d_bootstrap
local d_candidate