forked from gentoo/gentoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel-2.eclass
1637 lines (1381 loc) · 49.6 KB
/
kernel-2.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-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: kernel-2.eclass
# @MAINTAINER:
# Gentoo Kernel project <[email protected]>
# @AUTHOR:
# John Mylchreest <[email protected]>
# Mike Pagano <[email protected]>
# <so many, many others, please add yourself>
# @SUPPORTED_EAPIS: 2 3 4 5 6
# @BLURB: Eclass for kernel packages
# @DESCRIPTION:
# This is the kernel.eclass rewrite for a clean base regarding the 2.6
# series of kernel with back-compatibility for 2.4
# Please direct your bugs to the current eclass maintainer :)
# added functionality:
# unipatch - a flexible, singular method to extract, add and remove patches.
# @ECLASS-VARIABLE: K_USEPV
# @DEFAULT_UNSET
# @DESCRIPTION:
# When setting the EXTRAVERSION variable, it should
# add PV to the end.
# this is useful for things like wolk. IE:
# EXTRAVERSION would be something like : -wolk-4.19-r1
# @ECLASS-VARIABLE: K_NOSETEXTRAVERSION
# @DEFAULT_UNSET
# @DESCRIPTION:
# if this is set then EXTRAVERSION will not be
# automatically set within the kernel Makefile
# @ECLASS-VARIABLE: K_NOUSENAME
# @DEFAULT_UNSET
# @DESCRIPTION:
# if this is set then EXTRAVERSION will not include the
# first part of ${PN} in EXTRAVERSION
# @ECLASS-VARIABLE: K_NOUSEPR
# @DEFAULT_UNSET
# @DESCRIPTION:
# if this is set then EXTRAVERSION will not include the
# anything based on ${PR}.
# @ECLASS-VARIABLE: K_PREPATCHED
# @DEFAULT_UNSET
# @DESCRIPTION:
# if the patchset is prepatched (ie: mm-sources,
# ck-sources, ac-sources) it will use PR (ie: -r5) as
# the patchset version for
# and not use it as a true package revision
# @ECLASS-VARIABLE: K_EXTRAEINFO
# @DEFAULT_UNSET
# @DESCRIPTION:
# this is a new-line seperated list of einfo displays in
# postinst and can be used to carry additional postinst
# messages
# @ECLASS-VARIABLE: K_EXTRAELOG
# @DEFAULT_UNSET
# @DESCRIPTION:
# same as K_EXTRAEINFO except using elog instead of einfo
# @ECLASS-VARIABLE: K_EXTRAEWARN
# @DEFAULT_UNSET
# @DESCRIPTION:
# same as K_EXTRAEINFO except using ewarn instead of einfo
# @ECLASS-VARIABLE: K_SYMLINK
# @DEFAULT_UNSET
# @DESCRIPTION:
# if this is set, then forcably create symlink anyway
# @ECLASS-VARIABLE: K_BASE_VER
# @DEFAULT_UNSET
# @DESCRIPTION:
# for git-sources, declare the base version this patch is
# based off of.
# @ECLASS-VARIABLE: K_DEFCONFIG
# @DEFAULT_UNSET
# @DESCRIPTION:
# Allow specifying a different defconfig target.
# If length zero, defaults to "defconfig".
# @ECLASS-VARIABLE: K_WANT_GENPATCHES
# @DEFAULT_UNSET
# @DESCRIPTION:
# Apply genpatches to kernel source. Provide any
# combination of "base", "extras" or "experimental".
# @ECLASS-VARIABLE: K_EXP_GENPATCHES_PULL
# @DEFAULT_UNSET
# @DESCRIPTION:
# If set, we pull "experimental" regardless of the USE FLAG
# but expect the ebuild maintainer to use K_EXP_GENPATCHES_LIST.
# @ECLASS-VARIABLE: K_EXP_GENPATCHES_NOUSE
# @DEFAULT_UNSET
# @DESCRIPTION:
# If set, no USE flag will be provided for "experimental";
# as a result the user cannot choose to apply those patches.
# @ECLASS-VARIABLE: K_EXP_GENPATCHES_LIST
# @DEFAULT_UNSET
# @DESCRIPTION:
# A list of patches to pick from "experimental" to apply when
# the USE flag is unset and K_EXP_GENPATCHES_PULL is set.
# @ECLASS-VARIABLE: K_FROM_GIT
# @DEFAULT_UNSET
# @DESCRIPTION:
# If set, this variable signals that the kernel sources derives
# from a git tree and special handling will be applied so that
# any patches that are applied will actually apply.
# @ECLASS-VARIABLE: K_GENPATCHES_VER
# @DEFAULT_UNSET
# @DESCRIPTION:
# The version of the genpatches tarball(s) to apply.
# A value of "5" would apply genpatches-2.6.12-5 to
# my-sources-2.6.12.ebuild
# @ECLASS-VARIABLE: K_SECURITY_UNSUPPORTED
# @DEFAULT_UNSET
# @DESCRIPTION:
# If set, this kernel is unsupported by Gentoo Security
# to the current eclass maintainer :)
# @ECLASS-VARIABLE: K_DEBLOB_AVAILABLE
# @DEFAULT_UNSET
# @DESCRIPTION:
# A value of "0" will disable all of the optional deblob
# code. If empty, will be set to "1" if deblobbing is
# possible. Test ONLY for "1".
# @ECLASS-VARIABLE: K_DEBLOB_TAG
# @DEFAULT_UNSET
# @DESCRIPTION:
# This will be the version of deblob script. It's a upstream SVN tag
# such asw -gnu or -gnu1.
# @ECLASS-VARIABLE: K_PREDEBLOBBED
# @DEFAULT_UNSET
# @DESCRIPTION:
# This kernel was already deblobbed elsewhere.
# If false, either optional deblobbing will be available
# or the license will note the inclusion of linux-firmware code.
# @ECLASS-VARIABLE: K_LONGTERM
# @DEFAULT_UNSET
# @DESCRIPTION:
# If set, the eclass will search for the kernel source
# in the long term directories on the upstream servers
# as the location has been changed by upstream
# @ECLASS-VARIABLE: H_SUPPORTEDARCH
# @DEFAULT_UNSET
# @DESCRIPTION:
# this should be a space separated list of ARCH's which
# can be supported by the headers ebuild
# @ECLASS-VARIABLE: UNIPATCH_LIST
# @DEFAULT_UNSET
# @DESCRIPTION:
# space delimetered list of patches to be applied to the kernel
# @ECLASS-VARIABLE: UNIPATCH_EXCLUDE
# @DEFAULT_UNSET
# @DESCRIPTION:
# An addition var to support exlusion based completely
# on "<passedstring>*" and not "<passedno#>_*"
# this should _NOT_ be used from the ebuild as this is
# reserved for end users passing excludes from the cli
# @ECLASS-VARIABLE: UNIPATCH_DOCS
# @DEFAULT_UNSET
# @DESCRIPTION:
# space delimemeted list of docs to be installed to
# the doc dir
# @ECLASS-VARIABLE: UNIPATCH_STRICTORDER
# @DEFAULT_UNSET
# @DESCRIPTION:
# if this is set places patches into directories of
# order, so they are applied in the order passed
# Changing any other variable in this eclass is not supported; you can request
# for additional variables to be added by contacting the current maintainer.
# If you do change them, there is a chance that we will not fix resulting bugs;
# that of course does not mean we're not willing to help.
PYTHON_COMPAT=( python{2_6,2_7} )
inherit toolchain-funcs python-any-r1
[[ ${EAPI:-0} == [012345] ]] && inherit epatch
[[ ${EAPI:-0} == [0123456] ]] && inherit estack eapi7-ver
case ${EAPI:-0} in
2|3|4|5|6)
EXPORT_FUNCTIONS src_{unpack,prepare,compile,install,test} \
pkg_{setup,preinst,postinst,postrm} ;;
*) die "${ECLASS}: EAPI ${EAPI} not supported" ;;
esac
# Added by Daniel Ostrow <[email protected]>
# This is an ugly hack to get around an issue with a 32-bit userland on ppc64.
# I will remove it when I come up with something more reasonable.
[[ ${PROFILE_ARCH} == "ppc64" ]] && CHOST="powerpc64-${CHOST#*-}"
export CTARGET=${CTARGET:-${CHOST}}
if [[ ${CTARGET} == ${CHOST} && ${CATEGORY/cross-} != ${CATEGORY} ]]; then
export CTARGET=${CATEGORY/cross-}
fi
HOMEPAGE="https://www.kernel.org/ https://www.gentoo.org/ ${HOMEPAGE}"
: ${LICENSE:="GPL-2"}
# This is the latest KV_PATCH of the deblob tool available from the
# libre-sources upstream. If you bump this, you MUST regenerate the Manifests
# for ALL kernel-2 consumer packages where deblob is available.
: ${DEBLOB_MAX_VERSION:=38}
# No need to run scanelf/strip on kernel sources/headers (bug #134453).
RESTRICT="binchecks strip"
# set LINUX_HOSTCFLAGS if not already set
: ${LINUX_HOSTCFLAGS:="-Wall -Wstrict-prototypes -Os -fomit-frame-pointer -I${S}/include"}
# @FUNCTION: debug-print-kernel2-variables
# @USAGE:
# @DESCRIPTION:
# this function exists only to help debug kernel-2.eclass
# if you are adding new functionality in, put a call to it
# at the start of src_unpack, or during SRC_URI/dep generation.
debug-print-kernel2-variables() {
for v in PVR CKV OKV KV KV_FULL KV_MAJOR KV_MINOR KV_PATCH RELEASETYPE \
RELEASE UNIPATCH_LIST_DEFAULT UNIPATCH_LIST_GENPATCHES \
UNIPATCH_LIST S KERNEL_URI K_WANT_GENPATCHES ; do
debug-print "${v}: ${!v}"
done
}
# @FUNCTION: handle_genpatches
# @USAGE: [--set-unipatch-list]
# @DESCRIPTION:
# add genpatches to list of patches to apply if wanted
handle_genpatches() {
local tarball want_unipatch_list
[[ -z ${K_WANT_GENPATCHES} || -z ${K_GENPATCHES_VER} ]] && return 1
if [[ -n ${1} ]]; then
# set UNIPATCH_LIST_GENPATCHES only on explicit request
# since that requires 'use' call which can be used only in phase
# functions, while the function is also called in global scope
if [[ ${1} == --set-unipatch-list ]]; then
want_unipatch_list=1
else
die "Usage: ${FUNCNAME} [--set-unipatch-list]"
fi
fi
debug-print "Inside handle_genpatches"
local OKV_ARRAY
IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
# for > 3.0 kernels, handle genpatches tarball name
# genpatches for 3.0 and 3.0.1 might be named
# genpatches-3.0-1.base.tar.xz and genpatches-3.0-2.base.tar.xz
# respectively. Handle this.
for i in ${K_WANT_GENPATCHES} ; do
if [[ ${KV_MAJOR} -ge 3 ]]; then
if [[ ${#OKV_ARRAY[@]} -ge 3 ]]; then
tarball="genpatches-${KV_MAJOR}.${KV_MINOR}-${K_GENPATCHES_VER}.${i}.tar.xz"
else
tarball="genpatches-${KV_MAJOR}.${KV_PATCH}-${K_GENPATCHES_VER}.${i}.tar.xz"
fi
else
tarball="genpatches-${OKV}-${K_GENPATCHES_VER}.${i}.tar.xz"
fi
local use_cond_start="" use_cond_end=""
if [[ "${i}" == "experimental" && -z ${K_EXP_GENPATCHES_PULL} && -z ${K_EXP_GENPATCHES_NOUSE} ]] ; then
use_cond_start="experimental? ( "
use_cond_end=" )"
if [[ -n ${want_unipatch_list} ]] && use experimental ; then
UNIPATCH_LIST_GENPATCHES+=" ${DISTDIR}/${tarball}"
debug-print "genpatches tarball: $tarball"
fi
elif [[ -n ${want_unipatch_list} ]]; then
UNIPATCH_LIST_GENPATCHES+=" ${DISTDIR}/${tarball}"
debug-print "genpatches tarball: $tarball"
fi
GENPATCHES_URI+=" ${use_cond_start}mirror://gentoo/${tarball}${use_cond_end}"
done
}
# @FUNCTION: detect_version
# @USAGE:
# @DESCRIPTION:
# this function will detect and set
# - OKV: Original Kernel Version (2.6.0/2.6.0-test11)
# - KV: Kernel Version (2.6.0-gentoo/2.6.0-test11-gentoo-r1)
# - EXTRAVERSION: The additional version appended to OKV (-gentoo/-gentoo-r1)
detect_version() {
# We've already run, so nothing to do here.
[[ -n ${KV_FULL} ]] && return 0
# CKV is used as a comparison kernel version, which is used when
# PV doesnt reflect the genuine kernel version.
# this gets set to the portage style versioning. ie:
# CKV=2.6.11_rc4
CKV=${CKV:-${PV}}
OKV=${OKV:-${CKV}}
OKV=${OKV/_beta/-test}
OKV=${OKV/_rc/-rc}
OKV=${OKV/-r*}
OKV=${OKV/_p*}
KV_MAJOR=$(ver_cut 1 ${OKV})
# handle if OKV is X.Y or X.Y.Z (e.g. 3.0 or 3.0.1)
local OKV_ARRAY
IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
# if KV_MAJOR >= 3, then we have no more KV_MINOR
#if [[ ${KV_MAJOR} -lt 3 ]]; then
if [[ ${#OKV_ARRAY[@]} -ge 3 ]]; then
KV_MINOR=$(ver_cut 2 ${OKV})
KV_PATCH=$(ver_cut 3 ${OKV})
if [[ ${KV_MAJOR}${KV_MINOR}${KV_PATCH} -ge 269 ]]; then
KV_EXTRA=$(ver_cut 4- ${OKV})
KV_EXTRA=${KV_EXTRA/[-_]*}
else
KV_PATCH=$(ver_cut 3- ${OKV})
fi
else
KV_PATCH=$(ver_cut 2 ${OKV})
KV_EXTRA=$(ver_cut 3- ${OKV})
KV_EXTRA=${KV_EXTRA/[-_]*}
fi
debug-print "KV_EXTRA is ${KV_EXTRA}"
KV_PATCH=${KV_PATCH/[-_]*}
local v n=0 missing
#if [[ ${KV_MAJOR} -lt 3 ]]; then
if [[ ${#OKV_ARRAY[@]} -ge 3 ]]; then
for v in CKV OKV KV_{MAJOR,MINOR,PATCH} ; do
[[ -z ${!v} ]] && n=1 && missing="${missing}${v} ";
done
else
for v in CKV OKV KV_{MAJOR,PATCH} ; do
[[ -z ${!v} ]] && n=1 && missing="${missing}${v} ";
done
fi
[[ $n -eq 1 ]] && \
eerror "Missing variables: ${missing}" && \
die "Failed to extract kernel version (try explicit CKV in ebuild)!"
unset v n missing
# if [[ ${KV_MAJOR} -ge 3 ]]; then
if [[ ${#OKV_ARRAY[@]} -lt 3 ]]; then
KV_PATCH_ARR=(${KV_PATCH//\./ })
# at this point 031412, Linus is putting all 3.x kernels in a
# 3.x directory, may need to revisit when 4.x is released
KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.x"
[[ -n "${K_LONGTERM}" ]] &&
KERNEL_BASE_URI="${KERNEL_BASE_URI}/longterm/v${KV_MAJOR}.${KV_PATCH_ARR}"
else
#KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.0"
#KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}"
if [[ ${KV_MAJOR} -ge 3 ]]; then
KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.x"
else
KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}"
fi
[[ -n "${K_LONGTERM}" ]] &&
#KERNEL_BASE_URI="${KERNEL_BASE_URI}/longterm"
KERNEL_BASE_URI="${KERNEL_BASE_URI}/longterm/v${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
fi
debug-print "KERNEL_BASE_URI is ${KERNEL_BASE_URI}"
if [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]]; then
# handle non genpatch using sources correctly
if [[ -z ${K_WANT_GENPATCHES} && -z ${K_GENPATCHES_VER} && ${KV_PATCH} -gt 0 ]]; then
KERNEL_URI="${KERNEL_BASE_URI}/patch-${OKV}.xz"
UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV}.xz"
fi
KERNEL_URI="${KERNEL_URI} ${KERNEL_BASE_URI}/linux-${KV_MAJOR}.${KV_MINOR}.tar.xz"
else
KERNEL_URI="${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
fi
RELEASE=${CKV/${OKV}}
RELEASE=${RELEASE/_beta}
RELEASE=${RELEASE/_rc/-rc}
RELEASE=${RELEASE/_pre/-pre}
# We cannot trivally call kernel_is here, because it calls us to detect the
# version
#kernel_is ge 2 6 && RELEASE=${RELEASE/-pre/-git}
[ $(($KV_MAJOR * 1000 + ${KV_MINOR:-0})) -ge 2006 ] && RELEASE=${RELEASE/-pre/-git}
RELEASETYPE=${RELEASE//[0-9]}
# Now we know that RELEASE is the -rc/-git
# and RELEASETYPE is the same but with its numerics stripped
# we can work on better sorting EXTRAVERSION.
# first of all, we add the release
EXTRAVERSION="${RELEASE}"
debug-print "0 EXTRAVERSION:${EXTRAVERSION}"
[[ -n ${KV_EXTRA} ]] && [[ ${KV_MAJOR} -lt 3 ]] && EXTRAVERSION=".${KV_EXTRA}${EXTRAVERSION}"
debug-print "1 EXTRAVERSION:${EXTRAVERSION}"
if [[ -n "${K_NOUSEPR}" ]]; then
# Don't add anything based on PR to EXTRAVERSION
debug-print "1.0 EXTRAVERSION:${EXTRAVERSION}"
elif [[ -n ${K_PREPATCHED} ]]; then
debug-print "1.1 EXTRAVERSION:${EXTRAVERSION}"
EXTRAVERSION="${EXTRAVERSION}-${PN/-*}${PR/r}"
elif [[ "${ETYPE}" = "sources" ]]; then
debug-print "1.2 EXTRAVERSION:${EXTRAVERSION}"
# For some sources we want to use the PV in the extra version
# This is because upstream releases with a completely different
# versioning scheme.
case ${PN/-*} in
wolk) K_USEPV=1;;
vserver) K_USEPV=1;;
esac
[[ -z "${K_NOUSENAME}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*}"
[[ -n "${K_USEPV}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PV//_/-}"
[[ -n "${PR//r0}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PR}"
fi
debug-print "2 EXTRAVERSION:${EXTRAVERSION}"
# The only messing around which should actually effect this is for KV_EXTRA
# since this has to limit OKV to MAJ.MIN.PAT and strip EXTRA off else
# KV_FULL evaluates to MAJ.MIN.PAT.EXT.EXT after EXTRAVERSION
if [[ -n ${KV_EXTRA} ]]; then
if [[ -n ${KV_MINOR} ]]; then
OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
else
OKV="${KV_MAJOR}.${KV_PATCH}"
fi
KERNEL_URI="${KERNEL_BASE_URI}/patch-${CKV}.xz
${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV}.xz"
fi
# We need to set this using OKV, but we need to set it before we do any
# messing around with OKV based on RELEASETYPE
KV_FULL=${OKV}${EXTRAVERSION}
# we will set this for backwards compatibility.
S="${WORKDIR}"/linux-${KV_FULL}
KV=${KV_FULL}
# -rc-git pulls can be achieved by specifying CKV
# for example:
# CKV="2.6.11_rc3_pre2"
# will pull:
# linux-2.6.10.tar.xz & patch-2.6.11-rc3.xz & patch-2.6.11-rc3-git2.xz
if [[ ${KV_MAJOR}${KV_MINOR} -eq 26 ]]; then
if [[ ${RELEASETYPE} == -rc ]] || [[ ${RELEASETYPE} == -pre ]]; then
OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))"
KERNEL_URI="${KERNEL_BASE_URI}/testing/patch-${CKV//_/-}.xz
${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV//_/-}.xz"
fi
if [[ ${RELEASETYPE} == -git ]]; then
KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${OKV}${RELEASE}.xz
${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${OKV}${RELEASE}.xz"
fi
if [[ ${RELEASETYPE} == -rc-git ]]; then
OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))"
KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.xz
${KERNEL_BASE_URI}/testing/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE/-git*}.xz
${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE/-git*}.xz ${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.xz"
fi
else
KV_PATCH_ARR=(${KV_PATCH//\./ })
# the different majorminor versions have different patch start versions
OKV_DICT=(["2"]="${KV_MAJOR}.$((${KV_PATCH_ARR} - 1))" ["3"]="2.6.39" ["4"]="3.19")
if [[ ${RELEASETYPE} == -rc ]] || [[ ${RELEASETYPE} == -pre ]]; then
OKV=${K_BASE_VER:-$OKV_DICT["${KV_MAJOR}"]}
# as of 12/5/2017, the rc patch is no longer offered as a compressed
# file, and no longer is it mirrored on kernel.org
if ver_test "${KV_MAJOR}.${KV_PATCH}" -ge "4.12"; then
KERNEL_URI="https://git.kernel.org/torvalds/p/v${KV_FULL}/v${OKV} -> patch-${KV_FULL}.patch
${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV//_/-}.patch"
else
KERNEL_URI="${KERNEL_BASE_URI}/testing/patch-${CKV//_/-}.xz
${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV//_/-}.xz"
fi
fi
if [[ ${RELEASETYPE} == -git ]]; then
KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${OKV}${RELEASE}.xz
${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${OKV}${RELEASE}.xz"
fi
if [[ ${RELEASETYPE} == -rc-git ]]; then
OKV=${K_BASE_VER:-$OKV_DICT["${KV_MAJOR}"]}
KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE}.xz
${KERNEL_BASE_URI}/testing/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE/-git*}.xz
${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE/-git*}.xz ${DISTDIR}/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE}.xz"
fi
fi
debug-print-kernel2-variables
handle_genpatches
}
# @FUNCTION: kernel_is
# @USAGE: <conditional version | version>
# @DESCRIPTION:
# user for comparing kernel versions
# or just identifying a version
# e.g kernel_is 2 4
# e.g kernel_is ge 4.8.11
# Note: duplicated in linux-info.eclass
kernel_is() {
# ALL of these should be set before we can safely continue this function.
# some of the sources have in the past had only one set.
local v n=0
for v in OKV KV_{MAJOR,MINOR,PATCH} ; do [[ -z ${!v} ]] && n=1 ; done
[[ $n -eq 1 ]] && detect_version
unset v n
# Now we can continue
local operator test value
case ${1#-} in
lt) operator="-lt"; shift;;
gt) operator="-gt"; shift;;
le) operator="-le"; shift;;
ge) operator="-ge"; shift;;
eq) operator="-eq"; shift;;
*) operator="-eq";;
esac
[[ $# -gt 3 ]] && die "Error in kernel-2_kernel_is(): too many parameters"
: $(( test = (KV_MAJOR << 16) + (KV_MINOR << 8) + KV_PATCH ))
: $(( value = (${1:-${KV_MAJOR}} << 16) + (${2:-${KV_MINOR}} << 8) + ${3:-${KV_PATCH}} ))
[ ${test} ${operator} ${value} ]
}
# @FUNCTION: kernel_is_2_4
# @USAGE:
# @DESCRIPTION:
# return true if kernel is version 2.4
kernel_is_2_4() {
kernel_is 2 4
}
# @FUNCTION: kernel_is_2_6
# @USAGE:
# @DESCRIPTION:
# return true if kernel is version 2.6
kernel_is_2_6() {
kernel_is 2 6 || kernel_is 2 5
}
# Capture the sources type and set DEPENDs
if [[ ${ETYPE} == sources ]]; then
DEPEND="!build? (
sys-apps/sed
>=sys-devel/binutils-2.11.90.0.31
)"
RDEPEND="!build? (
dev-lang/perl
sys-devel/bc
sys-devel/bison
sys-devel/flex
sys-devel/make
>=sys-libs/ncurses-5.2
virtual/libelf
)"
SLOT="${PVR}"
DESCRIPTION="Sources based on the Linux Kernel."
IUSE="symlink build"
# Bug #266157, deblob for libre support
if [[ -z ${K_PREDEBLOBBED} ]] ; then
# Bug #359865, force a call to detect_version if needed
kernel_is ge 2 6 27 && \
[[ -z "${K_DEBLOB_AVAILABLE}" ]] && \
kernel_is le 2 6 ${DEBLOB_MAX_VERSION} && \
K_DEBLOB_AVAILABLE=1
if [[ ${K_DEBLOB_AVAILABLE} == "1" ]] ; then
IUSE="${IUSE} deblob"
# Reflect that kernels contain firmware blobs unless otherwise
# stripped
LICENSE="${LICENSE} !deblob? ( linux-firmware )"
DEPEND+=" deblob? ( ${PYTHON_DEPS} )"
if [[ -n KV_MINOR ]]; then
DEBLOB_PV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
else
DEBLOB_PV="${KV_MAJOR}.${KV_PATCH}"
fi
if [[ ${KV_MAJOR} -ge 3 ]]; then
DEBLOB_PV="${KV_MAJOR}.${KV_MINOR}"
fi
# deblob svn tag, default is -gnu, to change, use K_DEBLOB_TAG in ebuild
K_DEBLOB_TAG=${K_DEBLOB_TAG:--gnu}
DEBLOB_A="deblob-${DEBLOB_PV}"
DEBLOB_CHECK_A="deblob-check-${DEBLOB_PV}"
DEBLOB_HOMEPAGE="https://www.fsfla.org/svn/fsfla/software/linux-libre/releases/tags/"
DEBLOB_URI_PATH="${DEBLOB_PV}${K_DEBLOB_TAG}"
DEBLOB_CHECK_URI="${DEBLOB_HOMEPAGE}/${DEBLOB_URI_PATH}/deblob-check -> ${DEBLOB_CHECK_A}"
DEBLOB_URI="${DEBLOB_HOMEPAGE}/${DEBLOB_URI_PATH}/${DEBLOB_A}"
HOMEPAGE="${HOMEPAGE} ${DEBLOB_HOMEPAGE}"
KERNEL_URI="${KERNEL_URI}
deblob? (
${DEBLOB_URI}
${DEBLOB_CHECK_URI}
)"
else
# We have no way to deblob older kernels, so just mark them as
# tainted with non-libre materials.
LICENSE="${LICENSE} linux-firmware"
fi
fi
elif [[ ${ETYPE} == headers ]]; then
DESCRIPTION="Linux system headers"
IUSE="headers-only"
# Since we should NOT honour KBUILD_OUTPUT in headers
# lets unset it here.
unset KBUILD_OUTPUT
SLOT="0"
fi
# Cross-compile support functions
# @FUNCTION: kernel_header_destdir
# @USAGE:
# @DESCRIPTION:
# return header destination directory
kernel_header_destdir() {
[[ ${CTARGET} == ${CHOST} ]] \
&& echo /usr/include \
|| echo /usr/${CTARGET}/usr/include
}
# @FUNCTION: cross_pre_c_headers
# @USAGE:
# @DESCRIPTION:
# set use if necessary for cross compile support
cross_pre_c_headers() {
use headers-only && [[ ${CHOST} != ${CTARGET} ]]
}
# @FUNCTION: env_setup_xmakeopts
# @USAGE:
# @DESCRIPTION:
# set the ARCH/CROSS_COMPILE when cross compiling
env_setup_xmakeopts() {
# Kernel ARCH != portage ARCH
export KARCH=$(tc-arch-kernel)
# When cross-compiling, we need to set the ARCH/CROSS_COMPILE
# variables properly or bad things happen !
xmakeopts="ARCH=${KARCH}"
if [[ ${CTARGET} != ${CHOST} ]] && ! cross_pre_c_headers ; then
xmakeopts="${xmakeopts} CROSS_COMPILE=${CTARGET}-"
elif type -p ${CHOST}-ar > /dev/null ; then
xmakeopts="${xmakeopts} CROSS_COMPILE=${CHOST}-"
fi
export xmakeopts
}
# @FUNCTION: unpack_2_4
# @USAGE:
# @DESCRIPTION:
# unpack and generate .config for 2.4 kernels
unpack_2_4() {
# this file is required for other things to build properly,
# so we autogenerate it
make -s mrproper ${xmakeopts} || die "make mrproper failed"
make -s symlinks ${xmakeopts} || die "make symlinks failed"
make -s include/linux/version.h ${xmakeopts} || die "make include/linux/version.h failed"
echo ">>> version.h compiled successfully."
}
# @FUNCTION: unpack_2_6
# @USAGE:
# @DESCRIPTION:
# unpack and generate .config for 2.6 kernels
unpack_2_6() {
# this file is required for other things to build properly, so we
# autogenerate it ... generate a .config to keep version.h build from
# spitting out an annoying warning
make -s mrproper ${xmakeopts} 2>/dev/null \
|| die "make mrproper failed"
# quick fix for bug #132152 which triggers when it cannot include linux
# headers (ie, we have not installed it yet)
if ! make -s defconfig ${xmakeopts} &>/dev/null 2>&1 ; then
touch .config
eerror "make defconfig failed."
eerror "assuming you dont have any headers installed yet and continuing"
fi
make -s include/linux/version.h ${xmakeopts} 2>/dev/null \
|| die "make include/linux/version.h failed"
rm -f .config >/dev/null
}
# @FUNCTION: universal_unpack
# @USAGE:
# @DESCRIPTION:
# unpack kernel sources
universal_unpack() {
debug-print "Inside universal_unpack"
local OKV_ARRAY
IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
cd "${WORKDIR}"
if [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]]; then
unpack linux-${KV_MAJOR}.${KV_MINOR}.tar.xz
else
unpack linux-${OKV}.tar.xz
fi
if [[ -d "linux" ]]; then
debug-print "Moving linux to linux-${KV_FULL}"
mv linux linux-${KV_FULL} \
|| die "Unable to move source tree to ${KV_FULL}."
elif [[ "${OKV}" != "${KV_FULL}" ]]; then
if [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]] &&
[[ "${ETYPE}" = "sources" ]]; then
debug-print "moving linux-${KV_MAJOR}.${KV_MINOR} to linux-${KV_FULL} "
mv linux-${KV_MAJOR}.${KV_MINOR} linux-${KV_FULL} \
|| die "Unable to move source tree to ${KV_FULL}."
else
debug-print "moving linux-${OKV} to linux-${KV_FULL} "
mv linux-${OKV} linux-${KV_FULL} \
|| die "Unable to move source tree to ${KV_FULL}."
fi
elif [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]]; then
mv linux-${KV_MAJOR}.${KV_MINOR} linux-${KV_FULL} \
|| die "Unable to move source tree to ${KV_FULL}."
fi
cd "${S}"
# remove all backup files
find . -iname "*~" -exec rm {} \; 2> /dev/null
}
# @FUNCTION: unpack_set_extraversion
# @USAGE:
# @DESCRIPTION:
# handle EXTRAVERSION
unpack_set_extraversion() {
cd "${S}"
sed -i -e "s:^\(EXTRAVERSION =\).*:\1 ${EXTRAVERSION}:" Makefile
cd "${OLDPWD}"
}
# @FUNCTION: unpack_fix_install_path
# @USAGE:
# @DESCRIPTION:
# Should be done after patches have been applied
# Otherwise patches that modify the same area of Makefile will fail
unpack_fix_install_path() {
cd "${S}"
sed -i -e 's:#export\tINSTALL_PATH:export\tINSTALL_PATH:' Makefile
}
# Compile Functions
# @FUNCTION: compile_headers
# @USAGE:
# @DESCRIPTION:
# header compilation
compile_headers() {
env_setup_xmakeopts
# if we couldnt obtain HOSTCFLAGS from the Makefile,
# then set it to something sane
local HOSTCFLAGS=$(getfilevar HOSTCFLAGS "${S}"/Makefile)
HOSTCFLAGS=${HOSTCFLAGS:--Wall -Wstrict-prototypes -O2 -fomit-frame-pointer}
if kernel_is 2 4; then
yes "" | make oldconfig ${xmakeopts}
echo ">>> make oldconfig complete"
make dep ${xmakeopts}
elif kernel_is 2 6; then
# 2.6.18 introduces headers_install which means we dont need any
# of this crap anymore :D
kernel_is ge 2 6 18 && return 0
# autoconf.h isnt generated unless it already exists. plus, we have
# no guarantee that any headers are installed on the system...
[[ -f ${EROOT}usr/include/linux/autoconf.h ]] \
|| touch include/linux/autoconf.h
# if K_DEFCONFIG isn't set, force to "defconfig"
# needed by mips
if [[ -z ${K_DEFCONFIG} ]]; then
if kernel_is ge 2 6 16 ; then
case ${CTARGET} in
powerpc64*) K_DEFCONFIG="ppc64_defconfig";;
powerpc*) K_DEFCONFIG="pmac32_defconfig";;
*) K_DEFCONFIG="defconfig";;
esac
else
K_DEFCONFIG="defconfig"
fi
fi
# if there arent any installed headers, then there also isnt an asm
# symlink in /usr/include/, and make defconfig will fail, so we have
# to force an include path with $S.
HOSTCFLAGS="${HOSTCFLAGS} -I${S}/include/"
ln -sf asm-${KARCH} "${S}"/include/asm || die
cross_pre_c_headers && return 0
make ${K_DEFCONFIG} HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "defconfig failed (${K_DEFCONFIG})"
if compile_headers_tweak_config ; then
yes "" | make oldconfig HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "2nd oldconfig failed"
fi
make prepare HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "prepare failed"
make prepare-all HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "prepare failed"
fi
}
# @FUNCTION: compile_headers_tweak_config
# @USAGE:
# @DESCRIPTION:
# some targets can be very very picky, so let's finesse the
# .config based upon any info we may have
compile_headers_tweak_config() {
case ${CTARGET} in
sh*)
sed -i '/CONFIG_CPU_SH/d' .config || die
echo "CONFIG_CPU_SH${CTARGET:2:1}=y" >> .config
return 0;;
esac
# no changes, so lets do nothing
return 1
}
# install functions
# @FUNCTION: install_universal
# @USAGE:
# @DESCRIPTION:
# Fix permissions in tarball
install_universal() {
cd "${WORKDIR}"
chown -R 0:0 * >& /dev/null
chmod -R a+r-w+X,u+w *
cd ${OLDPWD}
}
# @FUNCTION: install_headers
# @USAGE:
# @DESCRIPTION:
# Install headers
install_headers() {
local ddir=$(kernel_header_destdir)
# 2.6.18 introduces headers_install which means we dont need any
# of this crap anymore :D
if kernel_is ge 2 6 18 ; then
env_setup_xmakeopts
emake headers_install INSTALL_HDR_PATH="${ED}"${ddir}/.. ${xmakeopts} || die
# let other packages install some of these headers
rm -rf "${ED}"${ddir}/scsi || die #glibc/uclibc/etc...
return 0
fi
# Do not use "linux/*" as that can cause problems with very long
# $S values where the cmdline to cp is too long
pushd "${S}" >/dev/null
dodir ${ddir}/linux
cp -pPR "${S}"/include/linux "${ED}"${ddir}/ || die
rm -rf "${ED}"${ddir}/linux/modules || die
dodir ${ddir}/asm
cp -pPR "${S}"/include/asm/* "${ED}"${ddir}/asm || die
if kernel_is 2 6 ; then
dodir ${ddir}/asm-generic
cp -pPR "${S}"/include/asm-generic/* "${ED}"${ddir}/asm-generic || die
fi
# clean up
find "${D}" -name '*.orig' -exec rm -f {} \;
popd >/dev/null
}
# @FUNCTION: install_sources
# @USAGE:
# @DESCRIPTION:
# Install sources
install_sources() {
local file
cd "${S}"
dodir /usr/src
echo ">>> Copying sources ..."
file="$(find ${WORKDIR} -iname "docs" -type d)"
if [[ -n ${file} ]]; then
for file in $(find ${file} -type f); do
echo "${file//*docs\/}" >> "${S}"/patches.txt
echo "===================================================" >> "${S}"/patches.txt
cat ${file} >> "${S}"/patches.txt
echo "===================================================" >> "${S}"/patches.txt
echo "" >> "${S}"/patches.txt
done
fi
mv "${WORKDIR}"/linux* "${ED}"usr/src || die
if [[ -n "${UNIPATCH_DOCS}" ]] ; then
for i in ${UNIPATCH_DOCS}; do
dodoc "${T}"/${i}
done
fi
}
# @FUNCTION: preinst_headers
# @USAGE:
# @DESCRIPTION:
# Headers preinst steps
preinst_headers() {
local ddir=$(kernel_header_destdir)
[[ -L ${EPREFIX}${ddir}/linux ]] && { rm "${EPREFIX}"${ddir}/linux || die; }
[[ -L ${EPREFIX}${ddir}/asm ]] && { rm "${EPREFIX}"${ddir}/asm || die; }
}
# @FUNCTION: postinst_sources
# @USAGE:
# @DESCRIPTION:
# Sources post installation function.
# see inline comments
postinst_sources() {