-
Notifications
You must be signed in to change notification settings - Fork 2
/
gentoo-build-kernel.docker
executable file
·2429 lines (2314 loc) · 76.3 KB
/
gentoo-build-kernel.docker
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
#! /usr/bin/env bash
# shellcheck disable=SC2207
declare trace="${TRACE:-}"
# shellcheck disable=SC2034
declare debug="${DEBUG:-}"
set -eu
set -o pipefail
[ -n "${trace:-}" ] && set -o xtrace
cd "$( dirname "$( readlink -e "${0}" )" )" || exit 1
# Set by common/vars.sh, sourced below...
#
#declare build_name=''
#declare _command='docker'
#declare use_essential_gcc=''
# shellcheck disable=SC1091
[ ! -s common/vars.sh ] || . common/vars.sh
# shellcheck disable=SC2034 # Set from common/vars.sh
[[ -n "${__COMMON_VARS_INCLUDED:-}" ]] || {
echo >&2 'FATAL: Inclusion of common defaults failed'
exit 1
}
# shellcheck disable=SC2154
declare IMAGE="${build_name}:latest"
# shellcheck disable=SC1091
[ -s common/run.sh ] && . common/run.sh
declare -ir PARALLEL_MEMORY_MIN=4
declare -ir build_space_reqiured=750
declare -ir temp_space_required=2800
declare -ir graph_space_required=8500
declare package_default='sys-kernel/gentoo-sources'
if grep -q -- 'Model.*Raspberry Pi' /proc/cpuinfo; then
package_default='sys-kernel/raspberrypi-sources'
fi
readonly package_default
declare binutils_min_ver='2.25.0'
declare gcc_min_ver='5.1.0' # 12.0.0 on PA-RISC
declare llvm_min_ver='13.0.1' # 11.0.0 before 6.9.0, 15.0.0 on S390, 18.0.0 on loongarch
declare firmware=''
declare microcode=''
declare microcode_blob=''
if grep 'vendor_id' /proc/cpuinfo |
awk '{ print $3 }' |
grep -iqm 1 'intel'
then
microcode='sys-firmware/intel-microcode'
microcode_blob='intel'
elif grep 'vendor_id' /proc/cpuinfo |
awk '{ print $3 }' |
grep -iqm 1 'amd'
then
firmware='sys-kernel/linux-firmware'
case "$( # <- Syntax
grep -Fm 1 'cpu family' /proc/cpuinfo |
cut -d':' -f 2- |
awk '{ print $1 }'
)" in
16|17|18|20)
microcode_blob='amd-ucode/microcode_amd.bin'
;;
21)
microcode_blob='amd-ucode/microcode_amd_fam15h.bin'
;;
22)
microcode_blob='amd-ucode/microcode_amd_fam16h.bin'
;;
23)
microcode_blob='amd-ucode/microcode_amd_fam17h.bin amd/amd_sev_fam17h_model0xh.sbin amd/amd_sev_fam17h_model3xh.sbin'
;;
25)
microcode_blob='amd-ucode/microcode_amd_fam19h.bin amd/amd_sev_fam19h_model0xh.sbin'
;;
esac
fi
readonly microcode microcode_blob
pkgslot() {
local pkg="${1:-}"
local ver="${2:-}"
local usemax="${3:-}"
local -i maxver=0
local -i rc=0
[[ -n "${pkg:-}" ]] || return 1
if [[ -z "${ver:-}" ]]; then
if [[ -n "${usemax:-}" ]]; then
warn "pkgslot(${*}): Third argument of pkgslot() is" \
"ignored when no version is specified"
fi
printf '%s\n' "${pkg}"
return 1
fi
if [[ "${ver:0:1}" == ':' ]]; then
if [[ -n "${usemax:-}" ]]; then
warn "pkgslot(${*}): Third argument of pkgslot() is" \
"ignored when a SLOT is specified"
(( rc = 1 ))
fi
printf '%s:%s\n' "${pkg}" "${ver:1}"
else
[[ "${ver:0:1}" == '-' ]] || ver="-${ver}"
if [[ -n "${usemax:-}" ]]; then
case "${usemax}" in
'1'|'=')
: ;;
*)
warn "pkgslot(${*}): Third argument" \
"is ambiguous (expected '1'" \
"or '=')"
(( rc = 1 ))
;;
esac
(( maxver = $( cut -d'.' -f 1 <<<"${ver:1}" ) + 1 ))
if (( maxver )); then
printf '>=%s%s <%s-%s\n' "${pkg}" "${ver}" \
"${pkg}" "${maxver}"
else
warn "pkgslot(${*}): Unable to determine" \
"maximum version for arguments"
printf '>=%s%s\n' "${pkg}" "${ver}"
(( rc = 1 ))
fi
else
printf '>=%s%s\n' "${pkg}" "${ver}"
fi
fi
return $(( rc ))
} # pkgslot
_docker_setup
if echo " ${*:-} " | grep -Eq -- ' -(h|-help) '; then
declare usage='' options=''
usage="Usage: $( basename "${0}" ) "
# shellcheck disable=SC2116 # echo used for line-splitting
options="$( echo \
'[--config-from=<file> [--force]]|[--defconfig=<target>]' \
'[--no-keep-build|--keep-build[=<dir>]]' \
'[--no-patch|--patch=<path|url> [<path|url> ...]]' \
'[--menuconfig|--nconfig]' \
'[--package=<atom>] [--no-firmware|--firmware] [--clean]' \
'[--clang [--clean-lto] [--llvm-unwind] [--rust]] [-O3]' \
'[--debug] [--force-llvm=<version>]'
)"
output "${usage}${options}" | fold -sw ${COLUMNS:-"80"} - | head -n 1 >&2
output "${options}" | fold -sw $(( ${COLUMNS:-"80"} - ${#usage} )) - | sed "s|^|${usage//?/ }|" | tail -n +2 >&2
output >&2
output >&2 'Options:'
output >&2 ' --config-from <file> Use specified file as kernel base configuration'
output >&2 ' (specify config.gz or /proc/config.gz to'
output >&2 ' auto-extract the active kernel configuration)'
output >&2 ' N.B. To keep the resultant configuration, use'
output >&2 " the '--keep-build' option to save the"
output >&2 ' build output'
output >&2 " --defconfig <target> preconfigure with specified 'make' target"
# Turns out this was never implemented!?
#output >&2 " --target <target> configure with specified 'make' target"
output >&2 ' --keep-build [dir] Cache the kernel build artefacts for re-use'
output >&2 ' (optionally in the specified directory)'
output >&2 ' --force Overwrite build-cache configuration with'
output >&2 ' the specified file'
output >&2 ' --patch <url> Apply patch (-p1) from specified file or URL'
output >&2 ' --clear-linux Apply Intel "Clear Linux" patches'
output >&2 ' --menuconfig Interactively reconfigure the kernel via ncurses'
output >&2 ' --nconfig Interactively reconfigure the kernel via nconfig'
output >&2 ' --package <package> Specify kernel package to build'
output >&2 " (default: '${package_default}')"
output >&2 ' --with <package> Specify additional packages requiring kernel src'
output >&2 " (e.g. 'net-firewall/xtables-addons', etc.)"
output >&2 " --firmware Include 'sys-kernel/linux-firmware'"
output >&2 " -O3 Add 'KCFLAGS=-O3' (and others - see [1])"
output >&2 ' --clang Compile kernel with llvm'
output >&2 ' --llvm-unwind Install LLVM edition of libunwind'
output >&2 " --rust Pull-in rust dependencies"
#output >&2 ' --force-rust <version> Force a specified rust slot'
output >&2 ' --force-llvm <version> Force a specified LLVM version'
output >&2 ' --clean-lto Remove exisitng *.lto.o objects'
output >&2
output >&2 " --clean Run 'make distclean' before build"
output >&2
output >&2 ' --debug Allocate more memory to build-container'
output >&2
output >&2 " --no-install Don't install build-products to /boot"
output >&2 ' --bundle Generate tar output in /usr/src rather than'
output >&2 ' installing the new kernel (implies --no-install)'
output >&2
output >&2 "Running on architecture '${arch:-"${ARCH:-}"}'"
output >&2
output >&2 '[1]: https://github.com/clearlinux-pkgs/linux/blob/main/0133-novector.patch'
output >&2
exit 0
fi
if (( EUID )); then
die "Please re-run '$( basename "${0}" )' as user 'root'"
fi
declare -i keep_build=1
declare -i bundle=0
declare -i clean=0
declare -i clean_lto=0
declare -i force=0
declare -i install=1
declare -i llvm_slot=0
declare -i llvm_slot_override=0
declare -i opt_o3=0
declare -i intel_patch=0
declare -i raise_mem=0
declare -i rust=0
declare build_dir=''
declare bundle_dir=''
declare compiler='gcc'
declare config_file=''
declare defconfig=''
declare llvm_sub_slot_override=''
declare menuconfig=''
declare nconfig=''
declare package_override=''
declare extra_packages=''
declare patch=''
declare rust_llvm_use=''
declare unwind=''
if [[ -n "${kbuild_opt:-}" ]]; then
declare arg=''
for arg in "${@:-}"; do
shift
if [[ -n "${arg:-}" ]] &&
! [[ " ${*} ${kbuild_opt} " == *" ${arg} "* ]]
then
set -- ${@+"${@}"} "${arg}"
else
print "Skipping duplicate argument '${arg:-}'"
fi
done
unset arg
set -- "${*:-}" "${kbuild_opt}"
print "After processing environment variables, arguments are '${*:-}'"
fi
unset kbuild_opt
# Process --menuconfig and --nconfig first, as --config-from refers to them...
#
if echo " ${*:-} " | grep -Fq -- ' --menuconfig '; then
menuconfig='menuconfig' # Just has to be set...
nconfig=''
fi
if echo " ${*:-} " | grep -Fq -- ' --nconfig '; then
menuconfig=''
nconfig='nconfig' # Just has to be set...
fi
# Process options in --help output order where possible...
#
if echo " ${*:-} " | grep -Eq -- ' --config(-from)?[= ]'; then
if echo " ${*:-} " | grep -Eq -- ' --config(-from)?=[^ ]+ '; then
config_file="$( # <- Syntax
echo " ${*} " |
grep -Eo -- '--config(-from)?=[^ ]+ ' |
cut -d'=' -f 2- |
sed 's/ $//'
)"
elif echo " ${*:-} " | grep -Eq -- ' --config(-from)? [^ -][^ ]* '; then
config_file="$( # <- Syntax
echo " ${*} " |
grep -Eo -- '--config(-from)? [^ ]+ ' |
cut -d' ' -f 2- |
sed 's/ $//'
)"
else
warn "Invalid config option '$( # <- Syntax
echo " ${*:-} " |
grep -Eo -- '--config(-from)?[^ ]*[= ][^ ]+ ' |
sed 's/ $//'
)'"
fi
if echo " ${*:-} " | grep -Fq -- ' --force '; then
force=1
fi
else
if echo " ${*:-} " | grep -Fq -- ' --force '; then
warn "'--force' is not a valid option without '--config-from'"
fi
# Use bash syntax to avoid shellcheck SC2166
if [[ -n "${menuconfig:-}" || -n "${nconfig:-}" ]] &&
! grep -Fq -- ' --keep-build ' <<<" ${*:-} "
then
warn 'Changes made to configuration will not be saved externally'
fi
fi
if echo " ${*:-} " | grep -q -- ' --defconfig[= ]'; then
if echo " ${*:-} " | grep -Eq -- ' --defconfig=[^ ]+ '; then
defconfig="$( # <- Syntax
echo " ${*} " |
grep -Eo -- '--defconfig=[^ ]+ ' |
cut -d'=' -f 2- |
sed 's/ $//'
)"
elif echo " ${*:-} " | grep -q -- ' --defconfig [^ -][^ ]* '; then
defconfig="$( # <- Syntax
echo " ${*} " |
grep -Eo -- '--defconfig [^ ]+ ' |
cut -d' ' -f 2- |
sed 's/ $//'
)"
else
warn "Invalid defconfig option '$( # <- Syntax
echo " ${*:-} " |
grep -Eo -- '--defconfig[^ ]*[= ][^ ]+ ' |
sed 's/ $//'
)'"
fi
fi
if echo " ${*:-} " | grep -Fq -- ' --keep-build'; then
if echo " ${*:-} " | grep -Eq -- ' --keep-build=[^ ]+ '; then
build_dir="$( # <- Syntax
echo " ${*} " |
grep -Eo -- '--keep-build=[^ ]+ ' |
cut -d'=' -f 2- |
sed 's/ $//'
)"
elif echo " ${*:-} " | grep -q -- ' --keep-build [^ -][^ ]* '; then
build_dir="$( # <- Syntax
echo " ${*} " |
grep -Eo -- '--keep-build [^ ]+ ' |
cut -d' ' -f 2- |
sed 's/ $//'
)"
elif echo " ${*:-} " | grep -Fq -- ' --keep-build '; then
:
else
warn "Invalid build option '$( # <- Syntax
echo " ${*:-} " |
grep -Eo -- '--keep-build[^ ]+ ' |
sed 's/ $//'
)'"
keep_build=0
fi
elif echo " ${*:-} " | grep -Fq -- ' --no-keep-build '; then
keep_build=0
fi
# --force: see above
# --patch: see below
if echo " ${*:-} " | grep -Fq -- ' --clear-linux '; then
if type -pf curl >/dev/null 2>&1; then
intel_patch=1
else
warn "Disabling '--clear-linux' since net-misc/curl is not installed"
fi
fi
# --menuconfig: see above
# --nconfig: see above
if echo " ${*:-} " | grep -Fq -- ' --package'; then
if echo " ${*:-} " | grep -Eq -- ' --package=[^ ]+ '; then
package_override="$( # <- Syntax
echo " ${*} " |
grep -Eo -- '--package=[^ ]+ ' |
cut -d'=' -f 2- |
sed 's/ $//'
)"
elif echo " ${*:-} " | grep -q -- ' --package [^ -][^ ]* '; then
package_override="$( # <- Syntax
echo " ${*} " |
grep -Eo -- '--package [^ ]+ ' |
cut -d' ' -f 2- |
sed 's/ $//'
)"
else
warn "Invalid package version '$( # <- Syntax
echo " ${*:-} " |
grep -Eo -- ' --package[^ ]+ ' |
sed 's/ $//'
)'"
fi
fi
if echo " ${*:-} " | grep -Fq -- ' --with'; then
if echo " ${*:-} " | grep -Eq -- ' --with=[^ ]+ '; then
extra_packages="$( # <- Syntax
echo " ${*} " |
grep -Eo -- '--with=[^ ]+' |
while read -r pkg; do
echo "${pkg}" |
cut -d'=' -f 2- |
sed 's/ $//'
done
)"
elif echo " ${*:-} " | grep -q -- ' --with [^ -][^ ]* '; then
extra_packages="$( # <- Syntax
echo " ${*} " |
grep -Eo -- '--with [^ ]+' |
while read -r pkg; do
echo "${pkg}" |
cut -d' ' -f 2- |
sed 's/ $//'
done
)"
else
warn "Invalid package version '$( # <- Syntax
echo " ${*:-} " |
grep -Eo -- ' --with[^ ]+ ' |
sed 's/ $//'
)'"
fi
fi
# --firmware: see below
if echo " ${*:-} " | grep -Fq -- ' -O3 '; then
opt_o3=1
else
if (( intel_patch )); then
warn "Intel Clear Linux '-O3' patches are excluded due to specifying" \
"'-march=westmere': invoke with '-O3' to restore other tunings"
fi
fi
if echo " ${*:-} " | grep -Eq -- ' --(clang|llvm) '; then
compiler='clang'
if echo " ${*:-} " | grep -Fq -- ' --clean-lto '; then
clean_lto=1
fi
if echo " ${*:-} " | grep -Eq -- ' --(llvm-)?(lib)?unwind '; then
unwind='llvm'
fi
if echo " ${*:-} " | grep -Fq -- ' --rust '; then
rust=1
fi
if echo " ${*:-} " | grep -Fq -- ' --force-llvm'; then
if echo " ${*:-} " | grep -Eq -- ' --force-llvm=[^ ]+ '; then
llvm_sub_slot_override="$( # <- Syntax
echo " ${*} " |
grep -Eo -- '--force-llvm=[^ ]+ ' |
cut -d'=' -f 2- |
sed 's/-r.*$// ; s/ $//' |
sort -V |
tail -n 1
)"
elif echo " ${*:-} " | grep -q -- ' --force-llvm [^ -][^ ]* '; then
llvm_sub_slot_override="$( # <- Syntax
echo " ${*} " |
grep -Eo -- '--force-llvm [^ ]+ ' |
cut -d' ' -f 2- |
sed 's/-r.*$// ; s/ $//' |
sort -V |
tail -n 1
)"
else
warn "Invalid LLVM version '$( # <- Syntax
echo " ${*:-} " |
grep -Eo -- ' --force-llvm[^ ]+ ' |
sed 's/ $//'
)'"
fi
if [[ -n "${llvm_sub_slot_override:-}" ]]; then
print "Override llvm_sub_slot is '${llvm_sub_slot_override}'" \
"from '${*}'"
(( llvm_slot_override = $( # <- Syntax
cut -d'.' -f 1 <<<"${llvm_sub_slot_override}"
) ))
rust_llvm_use='-system-llvm'
fi
fi
else
if echo " ${*:-} " | grep -Fq -- ' --clean-lto '; then
warn "'--clean-lto' is not a valid option without '--clang'"
fi
if echo " ${*:-} " | grep -Eq -- ' --(llvm-)?(lib)?unwind '; then
warn "'--llvm-unwind' is not a valid option without '--clang'"
fi
if echo " ${*:-} " | grep -Fq -- ' --rust '; then
warn "'--rust' is not a valid option without '--clang'"
fi
if echo " ${*:-} " | grep -q -- ' --force-llvm[ =]'; then
warn "'--force-llvm' is not a valid option without '--clang'"
fi
fi
if echo " ${*:-} " | grep -Fq -- ' --clean '; then
clean=1
fi
if echo " ${*:-} " | grep -Fq -- ' --debug '; then
raise_mem=1
fi
# --(no-)install: see below
if echo " ${*:-} " | grep -Eq -- ' --bundle[= ]'; then
if echo " ${*:-} " | grep -Eq -- ' --bundle=[^ ]+ '; then
bundle_dir="$( # <- Syntax
echo " ${*} " |
grep -Eo -- '--bundle=[^ ]+ ' |
cut -d'=' -f 2- | sed 's/ $//'
)"
elif echo " ${*:-} " | grep -Eq -- ' --bundle [^ -][^ ]* '; then
bundle_dir="$( # <- Syntax
echo " ${*} " |
grep -Eo -- '--bundle [^ ]+ ' |
cut -d' ' -f 2- |
sed 's/ $//'
)"
else
bundle_dir='/usr/src'
fi
bundle=1
install=0
fi
if echo " ${*:-} " | grep -Fq -- ' --no-install '; then
install=0
elif echo " ${*:-} " | grep -Fq -- ' --install '; then
install=1
fi
if [[ -n "${config_file:-}" && -n "${defconfig:-}" ]]; then
warn "'--defconfig' (${defconfig}) overrides '--config-from'" \
"(${config_file}) - using former value"
fi
declare package=''
declare package_version=''
declare container_name=''
declare distro=''
if ! echo "${package_override:-"${package_default}"}" | grep -Fq -- '/'; then
package_override="$( # <- Syntax
sed -r 's|^([^a-zA-Z])*([a-zA-Z].*)$|\1sys-kernel/\2|' \
<<<"${package_override:-"${package_default}"}"
)"
print "Searching for package name '${package_override}' ..."
fi
_docker_resolve "${package_override:-"${package_default}"}"
if ! echo "${package}" | grep -Fq -- '/'; then
error "Resolved package '${package}' with version '${package_version}'" \
"lacks a category"
die "Essential package data not found - aborting"
fi
print "Using package '=${package}' ..."
# shellcheck disable=SC2001 # POSIX sh compatibility
container_name="$( echo "${package}" | sed 's|/|.|' )"
export container_name
case "${package}" in
*gentoo*)
distro='-gentoo'
;;
esac
# --patch
#
# Unless noted, the patches below are for the highest supported GCC version...
declare kpatch=''
if ! echo " ${*:-} " | grep -q -- ' --no-patch'; then
declare kpatchprefix='https://raw.githubusercontent.com/graysky2/kernel_compiler_patch/refs/heads/master'
# The first gcc release was gcc-2.95 (preceeded by egcs-1.1.2), since
# gcc-4.0.0 there have been no gcc-{x}.0 releases...
declare gcc_ver=''
case "${package_version}" in
3.[2-9].*|3.1[0-4].*)
if type -pf gcc >/dev/null 2>&1; then
gcc_ver="$( gcc --version | awk '( NR == 1 ) {print $NF}' | cut -d'.' -f 1-2 )"
case "${gcc_ver:-}" in
[23].*|4.[01])
warn "gcc${gcc_ver:+" ${gcc_ver}"} is too old to apply microarchitectures patch to kernel ${package_version}" ;;
4.[2-8])
kpatch="${kpatchprefix}/outdated_versions/linux-3.2%2B/gcc-4.2%2B/enable_additional_cpu_optimizations_for_gcc.patch" ;;
*)
kpatch="${kpatchprefix}/outdated_versions/linux-3.2%2B/gcc-4.9%2B/enable_additional_cpu_optimizations_for_gcc_v4.9%2B.patch" ;;
esac
else
warn "Could not determine gcc location or version, not applying microarchitectures patch to kernel ${package_version}"
fi ;;
3.1[5-9].*|4.[0-9].*|4.1[0-2].*)
if type -pf gcc >/dev/null 2>&1; then
gcc_ver="$( gcc --version | awk '( NR == 1 ) {print $NF}' | cut -d'.' -f 1-2 )"
case "${gcc_ver:-}" in
[23].*|4.[01])
warn "gcc${gcc_ver:+" ${gcc_ver}"} is too old to apply microarchitectures patch to kernel ${package_version}" ;;
4.[2-8])
kpatch="${kpatchprefix}/outdated_versions/linux-3.15%2B/gcc-4.2%2B/enable_additional_cpu_optimizations_for_gcc_kernel_v3.15%2B.patch" ;;
*)
kpatch="${kpatchprefix}/outdated_versions/enable_additional_cpu_optimizations_for_gcc_v4.9%2B_kernel_v3.15%2B.patch" ;;
esac
else
warn "Could not determine gcc location or version, not applying microarchitectures patch to kernel ${package_version}"
fi ;;
4.1[3-8].*)
if type -pf gcc >/dev/null 2>&1; then
gcc_ver="$( gcc --version | awk '( NR == 1 ) {print $NF}' | cut -d'.' -f 1-2 )"
case "${gcc_ver:-}" in
[23].*|4.[0-8])
warn "gcc${gcc_ver:+" ${gcc_ver}"} is too old to apply microarchitectures patch to kernel ${package_version}" ;;
4.9|[5-7].*)
kpatch="${kpatchprefix}/outdated_versions/enable_additional_cpu_optimizations_for_gcc_v4.9+_kernel_v4.13+.patch" ;;
*)
kpatch="${kpatchprefix}/outdated_versions/enable_additional_cpu_optimizations_for_gcc_v8.1%2B_kernel_v4.13%2B.patch" ;;
esac
else
warn "Could not determine gcc location or version, not applying microarchitectures patch to kernel ${package_version}"
fi ;;
4.19.*|5.[0-4].*)
kpatch="${kpatchprefix}/more-ISA-levels-and-uarches-for-kernel-4.19-5.4.patch" ;;
5.[56].*)
if type -pf gcc >/dev/null 2>&1; then
gcc_ver="$( gcc --version | awk '( NR == 1 ) {print $NF}' | cut -d'.' -f 1-2 )"
case "${gcc_ver:-}" in
[2-8].*)
warn "gcc${gcc_ver:+" ${gcc_ver}"} is too old to apply microarchitectures patch to kernel ${package_version}" ;;
9.*)
kpatch="${kpatchprefix}/outdated_versions/enable_additional_cpu_optimizations_for_gcc_v9.1%2B_kernel_v5.5%2B.patch" ;;
*)
kpatch="${kpatchprefix}/outdated_versions/enable_additional_cpu_optimizations_for_gcc_v10.1%2B_kernel_v5.5-v5.6.patch" ;;
esac
else
warn "Could not determine gcc location or version, not applying microarchitectures patch to kernel ${package_version}"
fi ;;
5.7.*)
if type -pf gcc >/dev/null 2>&1; then
gcc_ver="$( gcc --version | awk '( NR == 1 ) {print $NF}' | cut -d'.' -f 1-2 )"
case "${gcc_ver:-}" in
[2-8].*)
warn "gcc${gcc_ver:+" ${gcc_ver}"} is too old to apply microarchitectures patch to kernel ${package_version}" ;;
9.*)
kpatch="${kpatchprefix}/outdated_versions/enable_additional_cpu_optimizations_for_gcc_v9.1%2B_kernel_v5.7%2B.patch" ;;
*)
kpatch="${kpatchprefix}/outdated_versions/enable_additional_cpu_optimizations_for_gcc_v10.1%2B_kernel_v5.7.patch" ;;
esac
else
warn "Could not determine gcc location or version, not applying microarchitectures patch to kernel ${package_version}"
fi ;;
5.[89].*|5.1[0-4].*)
kpatch="${kpatchprefix}/more-ISA-levels-and-uarches-for-kernel-5.8-5.14.patch"
case "${package_version}" in
5.11.*)
kpatch+=" https://lore.kernel.org/linux-btrfs/206d121e2e2b609ffe31217e6d90bfabe1c4e121.1616066404.git.fdmanana@suse.com/raw" ;;
esac
;;
5.15.*|5.16.*)
kpatch="${kpatchprefix}/more-ISA-levels-and-uarches-for-kernel-5.15-5.16.patch" ;;
5.1[7-9].*|6.0.*|6.1.[0-6][0-9]*|6.1.7[0-8]*)
kpatch="${kpatchprefix}/more-ISA-levels-and-uarches-for-kernel-5.17-6.1.78.patch"
case "${package_version}" in
5.19.*)
kpatch+=" https://lore.kernel.org/all/[email protected]/raw"
esac
;;
#6.1.79*|6.1.[89][0-9]*|6.1.[1-9][0-9][0-9]*|6.[2-7].*)
# kpatch="${kpatchprefix}/more-ISA-levels-and-uarches-for-kernel-6.1.79%2B.patch" ;;
#6.[89].*|6.1[0-9].*)
# kpatch="${kpatchprefix}/lite-more-x86-64-ISA-levels-for-kernel-6.8-rc4%2B.patch" ;;
6.1.79*|6.1.[89][0-9]*|6.1.[1-9][0-9][0-9]|6.[2-9].*|6.[1-9][0-9].*)
kpatch="${kpatchprefix}/more-ISA-levels-and-uarches-for-kernel-6.1.79%2B.patch" ;;
'')
: ;;
*)
warn "No known patch for kernel ${package_version} from https://github.com/graysky2/kernel_compiler_patch"
;;
esac
unset gcc_ver kpatchprefix
fi
case "${arch:-"${ARCH:-}"}" in
arm64)
# This patch is specific to the Raspberry Pi 4/BCM2711/Cortex-A72;
# the RPi5/BCM2712 uses a Cortex-A76
# FIXME: This patch could itself be trivially patched to account for
# this...
if [[ "$( # <- Syntax
emerge --info 2>/dev/null |
grep '^USE=' |
cut -d'"' -f 2
)" =~ pi4 ]]
then
kpatch="${kpatch:+"${kpatch} "}https://raw.githubusercontent.com/graysky2/kernel_compiler_patch/refs/heads/master/other/build-with-mcpu-for-cortex-a72.patch"
fi
;;
esac
print "Kernel patch(es) are: '${kpatch:-}'"
# Allow '--no-patch --patch=...' to exclude default kernel patches...
if echo " ${*:-} " | grep -q -- ' --no-patch'; then
kpatch=''
fi
if echo " ${*:-} " | grep -q -- ' --patch'; then
if echo " ${*:-} " | grep -q -- ' --patch=[^ ]\+ '; then
patch="$( # <- Syntax
echo " ${*} " |
grep -o -- '--patch=[^ ]\+ ' |
cut -d'=' -f 2- |
sed 's/ $// ; s/,/ /g'
)"
elif echo " ${*:-} " | grep -q -- ' --patch [^ -][^ ]* '; then
patch="$( # <- Syntax
echo " ${*} " |
grep -o -- '--patch [^ ]\+ ' |
cut -d' ' -f 2- |
sed 's/ $// ; s/,/ /g'
)"
else
warn "Invalid patch option '$( # <- Syntax
echo " ${*:-} " |
grep -o -- ' --patch[^ ]\+ ' |
sed 's/ $//'
)'"
fi
fi
if (( intel_patch )); then
declare clear_commit='' clear_patch=''
clear_commit="$( # <- Syntax
curl -fLSs 'https://api.github.com/repos/clearlinux-pkgs/linux/tags' |
jq -r "map_values(select(.name | startswith(\"${package_version%-r*}\")))[].commit.sha" |
head -n 1
)"
if [[ -z "${clear_commit:-}" ]]; then
error "Intel Clear Linux has no patches for kernel" \
"${package_version%-r*}"
intel_patch=0
else
info >&2 "Clear Linux patches for kernel ${package_version%-r*} are" \
"commit '${clear_commit}'"
while read -r clear_patch; do
patch="${patch:+"${patch} "}https://raw.githubusercontent.com/clearlinux-pkgs/linux/${clear_commit}/${clear_patch}"
done < <( # <- Syntax
# We replace '0133-novector.patch' with a more specific patch of
# our own, but several of Intel's patches targeted at specific
# releases are outdated and simply won't apply :(
# We don't want to filter those here, though, as they may update
# them for future releases: the only harm is noise when we warn
# that a bad patch didn't apply cleanly.
#
curl -fLSs "https://raw.githubusercontent.com/clearlinux-pkgs/linux/${clear_commit}/linux.spec" |
grep -- '^Patch[0-9]' |
awk '{print $2}' |
grep -v '0133-novector.patch'
)
fi
unset clear_patch clear_commit
fi
if [[ -n "${kpatch:-}" ]]; then
patch="${kpatch}${patch:+" ${patch}"}"
fi
print "All patch(es) are: '${patch:-}'"
unset kpatch
# --firmware
#
if echo " ${*:-} " | grep -q -- ' --firmware'; then
firmware='sys-kernel/linux-firmware'
elif echo " ${*:-} " | grep -q -- ' --no-firmware'; then
firmware=''
fi
# End of argument handling
# scripts/min-tool-version.sh first appeared in Linux v5.12
case "${package_version}" in
[01234].*|5.[0123456789].*|5.1[01].*)
die "Minimum supported kernel version is 5.12.0, found" \
"'${package_version}'"
;;
5.12.*)
binutils_min_ver='2.23.0'
case "${arch:-"${ARCH:-}"}" in
arm64)
gcc_min_ver='5.1.0'
;;
*)
gcc_min_ver='4.9.0'
;;
esac
llvm_min_ver='10.0.1'
;;
5.13.*)
binutils_min_ver='2.23.0'
case "${arch:-"${ARCH:-}"}" in
arm64)
gcc_min_ver='5.1.0'
;;
*)
gcc_min_ver='4.9.0'
;;
esac
case "${arch:-"${ARCH:-}"}" in
s390)
llvm_min_ver='13.0.0'
;;
*)
llvm_min_ver='10.0.1'
;;
esac
;;
5.1[45].*)
binutils_min_ver='2.23.0'
gcc_min_ver='5.1.0'
case "${arch:-"${ARCH:-}"}" in
s390)
llvm_min_ver='13.0.0'
;;
*)
llvm_min_ver='10.0.1'
;;
esac
;;
5.1[67].*)
binutils_min_ver='2.23.0'
gcc_min_ver='5.1.0'
case "${arch:-"${ARCH:-}"}" in
s390)
llvm_min_ver='13.0.0'
;;
*)
llvm_min_ver='11.0.0'
;;
esac
;;
5.1[89].*|6.0.*)
binutils_min_ver='2.23.0'
gcc_min_ver='5.1.0'
case "${arch:-"${ARCH:-}"}" in
s390)
llvm_min_ver='14.0.0'
;;
*)
llvm_min_ver='11.0.0'
;;
esac
;;
6.[123].*)
binutils_min_ver='2.25.0'
gcc_min_ver='5.1.0'
case "${arch:-"${ARCH:-}"}" in
s390)
llvm_min_ver='15.0.0'
;;
*)
llvm_min_ver='11.0.0'
;;
esac
;;
6.[456].*)
binutils_min_ver='2.25.0'
case "${arch:-"${ARCH:-}"}" in
hppa)
gcc_min_ver='12.0.0'
;;
*)
gcc_min_ver='5.1.0'
;;
esac
case "${arch:-"${ARCH:-}"}" in
s390)
llvm_min_ver='15.0.0'
;;
*)
llvm_min_ver='11.0.0'
;;
esac
;;
6.7.*)
binutils_min_ver='2.25.0'
case "${arch:-"${ARCH:-}"}" in
hppa)
gcc_min_ver='12.0.0'
;;
*)
gcc_min_ver='5.1.0'
;;
esac
case "${arch:-"${ARCH:-}"}" in
loong)
llvm_min_ver='18.0.0'
;;
s390)
llvm_min_ver='15.0.0'
;;
*)
llvm_min_ver='11.0.0'
;;
esac
;;
#6.8.*)
*)
binutils_min_ver='2.25.0'
case "${arch:-"${ARCH:-}"}" in
hppa)
gcc_min_ver='12.0.0'
;;
*)
gcc_min_ver='5.1.0'
;;
esac
case "${arch:-"${ARCH:-}"}" in
loong)
llvm_min_ver='18.0.0'
;;
s390)
llvm_min_ver='15.0.0'
;;
*)
llvm_min_ver='13.0.1'
;;
esac
;;
esac
if [[ "${compiler}" == 'clang' ]]; then
declare rust_slot=''
# https://github.com/rust-lang/rust-bindgen/issues/2312
declare bindgen_ver='0.56.0'
declare -i llvm_min_slot=0
declare -i llvm_default_slot=0
declare llvm_sub_slot=''
(( llvm_min_slot = $( cut -d'.' -f 1 <<<"${llvm_min_ver}" ) ))
(( llvm_default_slot = llvm_min_slot ))
case "${package_version}" in
[12345].*|6.0.*)
if (( rust )); then
warn 'Disabling dev-lang/rust support prior to kernel 6.1.x'
rust=0
fi
;;
6.[1234].*)
#rust_slot='1.62.0'
(( llvm_default_slot = 14 ))
;;
6.5.*)
#rust_slot='1.68.2'
(( llvm_default_slot = 15 ))
;;
6.6.*)
rust_slot='1.71.1'
bindgen_ver='0.65.1'
(( llvm_default_slot = 16 ))
;;
6.7.*)
rust_slot='1.73.0'
bindgen_ver='0.65.1'
(( llvm_default_slot = 17 ))
;;
6.8.*)
rust_slot='1.74.1'
bindgen_ver='0.65.1'
(( llvm_default_slot = 17 ))
;;
6.9.*)
rust_slot='1.76.0'
bindgen_ver='0.65.1'
(( llvm_default_slot = 17 ))
;;
6.1[0-9].*)
# Gentoo skipped rust-1.78.0 and jumped straight from rust-1.77.1
# to rust-1.79.0 ...
#rust_slot='1.78.0'
rust_slot='1.79.0'
bindgen_ver='0.65.1'
(( llvm_default_slot = 17 ))
;;
*)
if (( rust )); then
warn "Disabling dev-lang/rust support for unknown kernel" \
"${package_version}"
rust=0
fi
;;
esac
if ! (( llvm_slot_override )); then
# No command-line override...
(( llvm_slot = llvm_default_slot ))
unset llvm_default_slot llvm_sub_slot_override llvm_slot_override
else
# Overrides in llvm_sub_slot_override & llvm_slot_override...
declare last_bad_llvm_ver=''
for last_bad_llvm_ver in \
"$(( llvm_default_slot - 1 )).999.999" \