kernel-2.eclass: sort RDEPEND alphabetically
[gentoo.git] / eclass / kernel-2.eclass
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: kernel-2.eclass
5 # @MAINTAINER:
6 # Gentoo Kernel project <kernel@gentoo.org>
7 # @AUTHOR:
8 # John Mylchreest <johnm@gentoo.org>
9 # Mike Pagano <mpagano@gentoo.org>
10 # <so many, many others, please add yourself>
11 # @BLURB: Eclass for kernel packages
12 # @DESCRIPTION:
13 # This is the kernel.eclass rewrite for a clean base regarding the 2.6
14 # series of kernel with back-compatibility for 2.4
15 # Please direct your bugs to the current eclass maintainer :)
16 # added functionality:
17 # unipatch              - a flexible, singular method to extract, add and remove patches.
18
19 # @ECLASS-VARIABLE: K_USEPV
20 # @DEFAULT_UNSET
21 # @DESCRIPTION:
22 # When setting the EXTRAVERSION variable, it should
23 # add PV to the end.
24 # this is useful for things like wolk. IE:
25 # EXTRAVERSION would be something like : -wolk-4.19-r1
26
27 # @ECLASS-VARIABLE:  K_NOSETEXTRAVERSION
28 # @DEFAULT_UNSET
29 # @DESCRIPTION:
30 # if this is set then EXTRAVERSION will not be
31 # automatically set within the kernel Makefile
32
33 # @ECLASS-VARIABLE: K_NOUSENAME
34 # @DEFAULT_UNSET
35 # @DESCRIPTION:
36 # if this is set then EXTRAVERSION will not include the
37 # first part of ${PN} in EXTRAVERSION
38
39 # @ECLASS-VARIABLE: K_NOUSEPR
40 # @DEFAULT_UNSET
41 # @DESCRIPTION:
42 # if this is set then EXTRAVERSION will not include the
43 # anything based on ${PR}.
44
45 # @ECLASS-VARIABLE: K_PREPATCHED
46 # @DEFAULT_UNSET
47 # @DESCRIPTION:
48 # if the patchset is prepatched (ie: mm-sources,
49 # ck-sources, ac-sources) it will use PR (ie: -r5) as
50 # the patchset version for
51 # and not use it as a true package revision
52
53 # @ECLASS-VARIABLE:  K_EXTRAEINFO
54 # @DEFAULT_UNSET
55 # @DESCRIPTION:
56 # this is a new-line seperated list of einfo displays in
57 # postinst and can be used to carry additional postinst
58 # messages
59
60 # @ECLASS-VARIABLE:  K_EXTRAELOG
61 # @DEFAULT_UNSET
62 # @DESCRIPTION:
63 # same as K_EXTRAEINFO except using elog instead of einfo
64
65 # @ECLASS-VARIABLE:  K_EXTRAEWARN
66 # @DEFAULT_UNSET
67 # @DESCRIPTION:
68 # same as K_EXTRAEINFO except using ewarn instead of einfo
69
70 # @ECLASS-VARIABLE:  K_SYMLINK
71 # @DEFAULT_UNSET
72 # @DESCRIPTION:
73 # if this is set, then forcably create symlink anyway
74
75 # @ECLASS-VARIABLE:  K_BASE_VER
76 # @DEFAULT_UNSET
77 # @DESCRIPTION:
78 # for git-sources, declare the base version this patch is
79 # based off of.
80
81 # @ECLASS-VARIABLE:  K_DEFCONFIG
82 # @DEFAULT_UNSET
83 # @DESCRIPTION:
84 # Allow specifying a different defconfig target.
85 # If length zero, defaults to "defconfig".
86
87 # @ECLASS-VARIABLE:  K_WANT_GENPATCHES
88 # @DEFAULT_UNSET
89 # @DESCRIPTION:
90 # Apply genpatches to kernel source. Provide any
91 # combination of "base", "extras" or "experimental".
92
93 # @ECLASS-VARIABLE:  K_EXP_GENPATCHES_PULL
94 # @DEFAULT_UNSET
95 # @DESCRIPTION:
96 # If set, we pull "experimental" regardless of the USE FLAG
97 # but expect the ebuild maintainer to use K_EXP_GENPATCHES_LIST.
98
99 # @ECLASS-VARIABLE:  K_EXP_GENPATCHES_NOUSE
100 # @DEFAULT_UNSET
101 # @DESCRIPTION:
102 # If set, no USE flag will be provided for "experimental";
103 # as a result the user cannot choose to apply those patches.
104
105 # @ECLASS-VARIABLE:  K_EXP_GENPATCHES_LIST
106 # @DEFAULT_UNSET
107 # @DESCRIPTION:
108 # A list of patches to pick from "experimental" to apply when
109 # the USE flag is unset and K_EXP_GENPATCHES_PULL is set.
110
111 # @ECLASS-VARIABLE:  K_FROM_GIT
112 # @DEFAULT_UNSET
113 # @DESCRIPTION:
114 # If set, this variable signals that the kernel sources derives
115 # from a git tree and special handling will be applied so that
116 # any patches that are applied will actually apply.
117
118 # @ECLASS-VARIABLE:  K_GENPATCHES_VER
119 # @DEFAULT_UNSET
120 # @DESCRIPTION:
121 # The version of the genpatches tarball(s) to apply.
122 # A value of "5" would apply genpatches-2.6.12-5 to
123 # my-sources-2.6.12.ebuild
124
125 # @ECLASS-VARIABLE:  K_SECURITY_UNSUPPORTED
126 # @DEFAULT_UNSET
127 # @DESCRIPTION:
128 # If set, this kernel is unsupported by Gentoo Security
129 # to the current eclass maintainer :)
130
131 # @ECLASS-VARIABLE:  K_DEBLOB_AVAILABLE
132 # @DEFAULT_UNSET
133 # @DESCRIPTION:
134 # A value of "0" will disable all of the optional deblob
135 # code. If empty, will be set to "1" if deblobbing is
136 # possible. Test ONLY for "1".
137
138 # @ECLASS-VARIABLE:  K_DEBLOB_TAG
139 # @DEFAULT_UNSET
140 # @DESCRIPTION:
141 # This will be the version of deblob script. It's a upstream SVN tag
142 # such asw -gnu or -gnu1.
143
144 # @ECLASS-VARIABLE:  K_PREDEBLOBBED
145 # @DEFAULT_UNSET
146 # @DESCRIPTION:
147 # This kernel was already deblobbed elsewhere.
148 # If false, either optional deblobbing will be available
149 # or the license will note the inclusion of linux-firmware code.
150
151 # @ECLASS-VARIABLE:  K_LONGTERM
152 # @DEFAULT_UNSET
153 # @DESCRIPTION:
154 # If set, the eclass will search for the kernel source
155 # in the long term directories on the upstream servers
156 # as the location has been changed by upstream
157
158 # @ECLASS-VARIABLE:  H_SUPPORTEDARCH
159 # @DEFAULT_UNSET
160 # @DESCRIPTION:
161 # this should be a space separated list of ARCH's which
162 # can be supported by the headers ebuild
163
164 # @ECLASS-VARIABLE:  UNIPATCH_LIST
165 # @DEFAULT_UNSET
166 # @DESCRIPTION:
167 # space delimetered list of patches to be applied to the kernel
168
169 # @ECLASS-VARIABLE:  UNIPATCH_EXCLUDE
170 # @DEFAULT_UNSET
171 # @DESCRIPTION:
172 # An addition var to support exlusion based completely
173 # on "<passedstring>*" and not "<passedno#>_*"
174 # this should _NOT_ be used from the ebuild as this is
175 # reserved for end users passing excludes from the cli
176
177 # @ECLASS-VARIABLE:  UNIPATCH_DOCS
178 # @DEFAULT_UNSET
179 # @DESCRIPTION:
180 # space delimemeted list of docs to be installed to
181 # the doc dir
182
183 # @ECLASS-VARIABLE:  UNIPATCH_STRICTORDER
184 # @DEFAULT_UNSET
185 # @DESCRIPTION:
186 # if this is set places patches into directories of
187 # order, so they are applied in the order passed
188 # Changing any other variable in this eclass is not supported; you can request
189 # for additional variables to be added by contacting the current maintainer.
190 # If you do change them, there is a chance that we will not fix resulting bugs;
191 # that of course does not mean we're not willing to help.
192
193 PYTHON_COMPAT=( python{2_6,2_7} )
194
195 inherit toolchain-funcs python-any-r1
196 [[ ${EAPI:-0} == [012345] ]] && inherit epatch
197 [[ ${EAPI:-0} == [0123456] ]] && inherit estack eapi7-ver
198 case ${EAPI:-0} in
199         2|3|4|5|6)
200                 EXPORT_FUNCTIONS src_{unpack,prepare,compile,install,test} \
201                         pkg_{setup,preinst,postinst,postrm} ;;
202         *) die "${ECLASS}: EAPI ${EAPI} not supported" ;;
203 esac
204
205 # Added by Daniel Ostrow <dostrow@gentoo.org>
206 # This is an ugly hack to get around an issue with a 32-bit userland on ppc64.
207 # I will remove it when I come up with something more reasonable.
208 [[ ${PROFILE_ARCH} == "ppc64" ]] && CHOST="powerpc64-${CHOST#*-}"
209
210 export CTARGET=${CTARGET:-${CHOST}}
211 if [[ ${CTARGET} == ${CHOST} && ${CATEGORY/cross-} != ${CATEGORY} ]]; then
212         export CTARGET=${CATEGORY/cross-}
213 fi
214
215 HOMEPAGE="https://www.kernel.org/ https://www.gentoo.org/ ${HOMEPAGE}"
216 : ${LICENSE:="GPL-2"}
217
218 # This is the latest KV_PATCH of the deblob tool available from the
219 # libre-sources upstream. If you bump this, you MUST regenerate the Manifests
220 # for ALL kernel-2 consumer packages where deblob is available.
221 : ${DEBLOB_MAX_VERSION:=38}
222
223 # No need to run scanelf/strip on kernel sources/headers (bug #134453).
224 RESTRICT="binchecks strip"
225
226 # set LINUX_HOSTCFLAGS if not already set
227 : ${LINUX_HOSTCFLAGS:="-Wall -Wstrict-prototypes -Os -fomit-frame-pointer -I${S}/include"}
228
229
230 # @FUNCTION: debug-print-kernel2-variables
231 # @USAGE:
232 # @DESCRIPTION:
233 # this function exists only to help debug kernel-2.eclass
234 # if you are adding new functionality in, put a call to it
235 # at the start of src_unpack, or during SRC_URI/dep generation.
236
237 debug-print-kernel2-variables() {
238         for v in PVR CKV OKV KV KV_FULL KV_MAJOR KV_MINOR KV_PATCH RELEASETYPE \
239                         RELEASE UNIPATCH_LIST_DEFAULT UNIPATCH_LIST_GENPATCHES \
240                         UNIPATCH_LIST S KERNEL_URI K_WANT_GENPATCHES ; do
241                 debug-print "${v}: ${!v}"
242         done
243 }
244
245 # @FUNCTION: handle_genpatches
246 # @USAGE: [--set-unipatch-list]
247 # @DESCRIPTION:
248 # add genpatches to list of patches to apply if wanted
249
250 handle_genpatches() {
251         local tarball want_unipatch_list
252         [[ -z ${K_WANT_GENPATCHES} || -z ${K_GENPATCHES_VER} ]] && return 1
253
254         if [[ -n ${1} ]]; then
255                 # set UNIPATCH_LIST_GENPATCHES only on explicit request
256                 # since that requires 'use' call which can be used only in phase
257                 # functions, while the function is also called in global scope
258                 if [[ ${1} == --set-unipatch-list ]]; then
259                         want_unipatch_list=1
260                 else
261                         die "Usage: ${FUNCNAME} [--set-unipatch-list]"
262                 fi
263         fi
264
265         debug-print "Inside handle_genpatches"
266         local OKV_ARRAY
267         IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
268
269         # for > 3.0 kernels, handle genpatches tarball name
270         # genpatches for 3.0 and 3.0.1 might be named
271         # genpatches-3.0-1.base.tar.xz and genpatches-3.0-2.base.tar.xz
272         # respectively.  Handle this.
273
274         for i in ${K_WANT_GENPATCHES} ; do
275                 if [[ ${KV_MAJOR} -ge 3 ]]; then
276                         if [[ ${#OKV_ARRAY[@]} -ge 3 ]]; then
277                                 tarball="genpatches-${KV_MAJOR}.${KV_MINOR}-${K_GENPATCHES_VER}.${i}.tar.xz"
278                         else
279                                 tarball="genpatches-${KV_MAJOR}.${KV_PATCH}-${K_GENPATCHES_VER}.${i}.tar.xz"
280                         fi
281                 else
282                         tarball="genpatches-${OKV}-${K_GENPATCHES_VER}.${i}.tar.xz"
283                 fi
284
285                 local use_cond_start="" use_cond_end=""
286
287                 if [[ "${i}" == "experimental" && -z ${K_EXP_GENPATCHES_PULL} && -z ${K_EXP_GENPATCHES_NOUSE} ]] ; then
288                         use_cond_start="experimental? ( "
289                         use_cond_end=" )"
290
291                         if [[ -n ${want_unipatch_list} ]] && use experimental ; then
292                                 UNIPATCH_LIST_GENPATCHES+=" ${DISTDIR}/${tarball}"
293                                 debug-print "genpatches tarball: $tarball"
294                         fi
295                 elif [[ -n ${want_unipatch_list} ]]; then
296                         UNIPATCH_LIST_GENPATCHES+=" ${DISTDIR}/${tarball}"
297                         debug-print "genpatches tarball: $tarball"
298                 fi
299                 GENPATCHES_URI+=" ${use_cond_start}mirror://gentoo/${tarball}${use_cond_end}"
300         done
301 }
302
303 # @FUNCTION: detect_version
304 # @USAGE:
305 # @DESCRIPTION:
306 # this function will detect and set
307 # - OKV: Original Kernel Version (2.6.0/2.6.0-test11)
308 # - KV: Kernel Version (2.6.0-gentoo/2.6.0-test11-gentoo-r1)
309 # - EXTRAVERSION: The additional version appended to OKV (-gentoo/-gentoo-r1)
310 detect_version() {
311
312         # We've already run, so nothing to do here.
313         [[ -n ${KV_FULL} ]] && return 0
314
315         # CKV is used as a comparison kernel version, which is used when
316         # PV doesnt reflect the genuine kernel version.
317         # this gets set to the portage style versioning. ie:
318         #   CKV=2.6.11_rc4
319         CKV=${CKV:-${PV}}
320         OKV=${OKV:-${CKV}}
321         OKV=${OKV/_beta/-test}
322         OKV=${OKV/_rc/-rc}
323         OKV=${OKV/-r*}
324         OKV=${OKV/_p*}
325
326         KV_MAJOR=$(ver_cut 1 ${OKV})
327         # handle if OKV is X.Y or X.Y.Z (e.g. 3.0 or 3.0.1)
328         local OKV_ARRAY
329         IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
330
331         # if KV_MAJOR >= 3, then we have no more KV_MINOR
332         #if [[ ${KV_MAJOR} -lt 3 ]]; then
333         if [[ ${#OKV_ARRAY[@]} -ge 3 ]]; then
334                 KV_MINOR=$(ver_cut 2 ${OKV})
335                 KV_PATCH=$(ver_cut 3 ${OKV})
336                 if [[ ${KV_MAJOR}${KV_MINOR}${KV_PATCH} -ge 269 ]]; then
337                         KV_EXTRA=$(ver_cut 4- ${OKV})
338                         KV_EXTRA=${KV_EXTRA/[-_]*}
339                 else
340                         KV_PATCH=$(ver_cut 3- ${OKV})
341                 fi
342         else
343                 KV_PATCH=$(ver_cut 2 ${OKV})
344                 KV_EXTRA=$(ver_cut 3- ${OKV})
345                 KV_EXTRA=${KV_EXTRA/[-_]*}
346         fi
347
348         debug-print "KV_EXTRA is ${KV_EXTRA}"
349
350         KV_PATCH=${KV_PATCH/[-_]*}
351
352         local v n=0 missing
353         #if [[ ${KV_MAJOR} -lt 3 ]]; then
354         if [[ ${#OKV_ARRAY[@]} -ge 3 ]]; then
355                 for v in CKV OKV KV_{MAJOR,MINOR,PATCH} ; do
356                         [[ -z ${!v} ]] && n=1 && missing="${missing}${v} ";
357                 done
358         else
359                 for v in CKV OKV KV_{MAJOR,PATCH} ; do
360                         [[ -z ${!v} ]] && n=1 && missing="${missing}${v} ";
361                 done
362         fi
363
364         [[ $n -eq 1 ]] && \
365                 eerror "Missing variables: ${missing}" && \
366                 die "Failed to extract kernel version (try explicit CKV in ebuild)!"
367         unset v n missing
368
369 #       if [[ ${KV_MAJOR} -ge 3 ]]; then
370         if [[ ${#OKV_ARRAY[@]} -lt 3 ]]; then
371                 KV_PATCH_ARR=(${KV_PATCH//\./ })
372
373                 # at this point 031412, Linus is putting all 3.x kernels in a
374                 # 3.x directory, may need to revisit when 4.x is released
375                 KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.x"
376
377                 [[ -n "${K_LONGTERM}" ]] &&
378                         KERNEL_BASE_URI="${KERNEL_BASE_URI}/longterm/v${KV_MAJOR}.${KV_PATCH_ARR}"
379         else
380                 #KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.0"
381                 #KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}"
382                 if [[ ${KV_MAJOR} -ge 3 ]]; then
383                         KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.x"
384                 else
385                         KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}"
386                 fi
387
388                 [[ -n "${K_LONGTERM}" ]] &&
389                         #KERNEL_BASE_URI="${KERNEL_BASE_URI}/longterm"
390                         KERNEL_BASE_URI="${KERNEL_BASE_URI}/longterm/v${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
391         fi
392
393         debug-print "KERNEL_BASE_URI is ${KERNEL_BASE_URI}"
394
395         if [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]]; then
396                 # handle non genpatch using sources correctly
397                 if [[ -z ${K_WANT_GENPATCHES} && -z ${K_GENPATCHES_VER} && ${KV_PATCH} -gt 0 ]]; then
398                         KERNEL_URI="${KERNEL_BASE_URI}/patch-${OKV}.xz"
399                         UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV}.xz"
400                 fi
401                 KERNEL_URI="${KERNEL_URI} ${KERNEL_BASE_URI}/linux-${KV_MAJOR}.${KV_MINOR}.tar.xz"
402         else
403                 KERNEL_URI="${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
404         fi
405
406         RELEASE=${CKV/${OKV}}
407         RELEASE=${RELEASE/_beta}
408         RELEASE=${RELEASE/_rc/-rc}
409         RELEASE=${RELEASE/_pre/-pre}
410         # We cannot trivally call kernel_is here, because it calls us to detect the
411         # version
412         #kernel_is ge 2 6 && RELEASE=${RELEASE/-pre/-git}
413         [ $(($KV_MAJOR * 1000 + ${KV_MINOR:-0})) -ge 2006 ] && RELEASE=${RELEASE/-pre/-git}
414         RELEASETYPE=${RELEASE//[0-9]}
415
416         # Now we know that RELEASE is the -rc/-git
417         # and RELEASETYPE is the same but with its numerics stripped
418         # we can work on better sorting EXTRAVERSION.
419         # first of all, we add the release
420         EXTRAVERSION="${RELEASE}"
421         debug-print "0 EXTRAVERSION:${EXTRAVERSION}"
422         [[ -n ${KV_EXTRA} ]] && [[ ${KV_MAJOR} -lt 3 ]] && EXTRAVERSION=".${KV_EXTRA}${EXTRAVERSION}"
423
424         debug-print "1 EXTRAVERSION:${EXTRAVERSION}"
425         if [[ -n "${K_NOUSEPR}" ]]; then
426                 # Don't add anything based on PR to EXTRAVERSION
427                 debug-print "1.0 EXTRAVERSION:${EXTRAVERSION}"
428         elif [[ -n ${K_PREPATCHED} ]]; then
429                 debug-print "1.1 EXTRAVERSION:${EXTRAVERSION}"
430                 EXTRAVERSION="${EXTRAVERSION}-${PN/-*}${PR/r}"
431         elif [[ "${ETYPE}" = "sources" ]]; then
432                 debug-print "1.2 EXTRAVERSION:${EXTRAVERSION}"
433                 # For some sources we want to use the PV in the extra version
434                 # This is because upstream releases with a completely different
435                 # versioning scheme.
436                 case ${PN/-*} in
437                      wolk) K_USEPV=1;;
438                   vserver) K_USEPV=1;;
439                 esac
440
441                 [[ -z "${K_NOUSENAME}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*}"
442                 [[ -n "${K_USEPV}" ]]     && EXTRAVERSION="${EXTRAVERSION}-${PV//_/-}"
443                 [[ -n "${PR//r0}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PR}"
444         fi
445         debug-print "2 EXTRAVERSION:${EXTRAVERSION}"
446
447         # The only messing around which should actually effect this is for KV_EXTRA
448         # since this has to limit OKV to MAJ.MIN.PAT and strip EXTRA off else
449         # KV_FULL evaluates to MAJ.MIN.PAT.EXT.EXT after EXTRAVERSION
450
451         if [[ -n ${KV_EXTRA} ]]; then
452                 if [[ -n ${KV_MINOR} ]]; then
453                         OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
454                 else
455                         OKV="${KV_MAJOR}.${KV_PATCH}"
456                 fi
457                 KERNEL_URI="${KERNEL_BASE_URI}/patch-${CKV}.xz
458                                         ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
459                 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV}.xz"
460         fi
461
462         # We need to set this using OKV, but we need to set it before we do any
463         # messing around with OKV based on RELEASETYPE
464         KV_FULL=${OKV}${EXTRAVERSION}
465
466         # we will set this for backwards compatibility.
467         S="${WORKDIR}"/linux-${KV_FULL}
468         KV=${KV_FULL}
469
470         # -rc-git pulls can be achieved by specifying CKV
471         # for example:
472         #   CKV="2.6.11_rc3_pre2"
473         # will pull:
474         #   linux-2.6.10.tar.xz & patch-2.6.11-rc3.xz & patch-2.6.11-rc3-git2.xz
475
476         if [[ ${KV_MAJOR}${KV_MINOR} -eq 26 ]]; then
477
478                 if [[ ${RELEASETYPE} == -rc ]] || [[ ${RELEASETYPE} == -pre ]]; then
479                         OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))"
480                         KERNEL_URI="${KERNEL_BASE_URI}/testing/patch-${CKV//_/-}.xz
481                                                 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
482                         UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV//_/-}.xz"
483                 fi
484
485                 if [[ ${RELEASETYPE} == -git ]]; then
486                         KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${OKV}${RELEASE}.xz
487                                                 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
488                         UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${OKV}${RELEASE}.xz"
489                 fi
490
491                 if [[ ${RELEASETYPE} == -rc-git ]]; then
492                         OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))"
493                         KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.xz
494                                                 ${KERNEL_BASE_URI}/testing/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE/-git*}.xz
495                                                 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
496
497                         UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE/-git*}.xz ${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.xz"
498                 fi
499         else
500                 KV_PATCH_ARR=(${KV_PATCH//\./ })
501
502                 # the different majorminor versions have different patch start versions
503                 OKV_DICT=(["2"]="${KV_MAJOR}.$((${KV_PATCH_ARR} - 1))" ["3"]="2.6.39" ["4"]="3.19")
504
505                 if [[ ${RELEASETYPE} == -rc ]] || [[ ${RELEASETYPE} == -pre ]]; then
506
507                         OKV=${K_BASE_VER:-$OKV_DICT["${KV_MAJOR}"]}
508
509                         # as of 12/5/2017, the rc patch is no longer offered as a compressed
510                         # file, and no longer is it mirrored on kernel.org
511                         if [[ ${KV_MAJOR} -ge 4 ]] && [[ ${KV_PATCH} -ge 12 ]]; then
512                                 KERNEL_URI="https://git.kernel.org/torvalds/p/v${KV_FULL}/v${OKV} -> patch-${KV_FULL}.patch
513                                                         ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
514                                 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV//_/-}.patch"
515                         else
516                                 KERNEL_URI="${KERNEL_BASE_URI}/testing/patch-${CKV//_/-}.xz
517                                                         ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
518                                 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV//_/-}.xz"
519                         fi
520                 fi
521
522                 if [[ ${RELEASETYPE} == -git ]]; then
523                         KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${OKV}${RELEASE}.xz
524                                                 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
525                         UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${OKV}${RELEASE}.xz"
526                 fi
527
528                 if [[ ${RELEASETYPE} == -rc-git ]]; then
529                         OKV=${K_BASE_VER:-$OKV_DICT["${KV_MAJOR}"]}
530                         KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE}.xz
531                                                 ${KERNEL_BASE_URI}/testing/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE/-git*}.xz
532                                                 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
533
534                         UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE/-git*}.xz ${DISTDIR}/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE}.xz"
535                 fi
536
537
538         fi
539
540         debug-print-kernel2-variables
541
542         handle_genpatches
543 }
544
545 # @FUNCTION: kernel_is
546 # @USAGE: <conditional version | version>
547 # @DESCRIPTION:
548 # user for comparing kernel versions
549 # or just identifying a version
550 # e.g kernel_is 2 4
551 # e.g kernel_is ge 4.8.11
552 # Note: duplicated in linux-info.eclass
553 kernel_is() {
554         # ALL of these should be set before we can safely continue this function.
555         # some of the sources have in the past had only one set.
556         local v n=0
557         for v in OKV KV_{MAJOR,MINOR,PATCH} ; do [[ -z ${!v} ]] && n=1 ; done
558         [[ $n -eq 1 ]] && detect_version
559         unset v n
560
561         # Now we can continue
562         local operator test value
563
564         case ${1#-} in
565           lt) operator="-lt"; shift;;
566           gt) operator="-gt"; shift;;
567           le) operator="-le"; shift;;
568           ge) operator="-ge"; shift;;
569           eq) operator="-eq"; shift;;
570            *) operator="-eq";;
571         esac
572         [[ $# -gt 3 ]] && die "Error in kernel-2_kernel_is(): too many parameters"
573
574         : $(( test = (KV_MAJOR << 16) + (KV_MINOR << 8) + KV_PATCH ))
575         : $(( value = (${1:-${KV_MAJOR}} << 16) + (${2:-${KV_MINOR}} << 8) + ${3:-${KV_PATCH}} ))
576         [ ${test} ${operator} ${value} ]
577 }
578
579 # @FUNCTION: kernel_is_2_4
580 # @USAGE:
581 # @DESCRIPTION:
582 # return true if kernel is version 2.4
583 kernel_is_2_4() {
584         kernel_is 2 4
585 }
586
587 # @FUNCTION: kernel_is_2_6
588 # @USAGE:
589 # @DESCRIPTION:
590 # return true if kernel is version 2.6
591 kernel_is_2_6() {
592         kernel_is 2 6 || kernel_is 2 5
593 }
594
595 # Capture the sources type and set DEPENDs
596 if [[ ${ETYPE} == sources ]]; then
597         DEPEND="!build? (
598                 sys-apps/sed
599                 >=sys-devel/binutils-2.11.90.0.31
600         )"
601         RDEPEND="!build? (
602                 dev-lang/perl
603                 sys-devel/bc
604                 sys-devel/make
605                 >=sys-libs/ncurses-5.2
606                 virtual/libelf
607         )"
608
609         SLOT="${PVR}"
610         DESCRIPTION="Sources based on the Linux Kernel."
611         IUSE="symlink build"
612
613         # Bug #266157, deblob for libre support
614         if [[ -z ${K_PREDEBLOBBED} ]] ; then
615                 # Bug #359865, force a call to detect_version if needed
616                 kernel_is ge 2 6 27 && \
617                         [[ -z "${K_DEBLOB_AVAILABLE}" ]] && \
618                                 kernel_is le 2 6 ${DEBLOB_MAX_VERSION} && \
619                                         K_DEBLOB_AVAILABLE=1
620                 if [[ ${K_DEBLOB_AVAILABLE} == "1" ]] ; then
621                         IUSE="${IUSE} deblob"
622
623                         # Reflect that kernels contain firmware blobs unless otherwise
624                         # stripped
625                         LICENSE="${LICENSE} !deblob? ( linux-firmware )"
626
627                         DEPEND+=" deblob? ( ${PYTHON_DEPS} )"
628
629                         if [[ -n KV_MINOR ]]; then
630                                 DEBLOB_PV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
631                         else
632                                 DEBLOB_PV="${KV_MAJOR}.${KV_PATCH}"
633                         fi
634
635                         if [[ ${KV_MAJOR} -ge 3 ]]; then
636                                 DEBLOB_PV="${KV_MAJOR}.${KV_MINOR}"
637                         fi
638
639                         # deblob svn tag, default is -gnu, to change, use K_DEBLOB_TAG in ebuild
640                         K_DEBLOB_TAG=${K_DEBLOB_TAG:--gnu}
641                         DEBLOB_A="deblob-${DEBLOB_PV}"
642                         DEBLOB_CHECK_A="deblob-check-${DEBLOB_PV}"
643                         DEBLOB_HOMEPAGE="https://www.fsfla.org/svn/fsfla/software/linux-libre/releases/tags/"
644                         DEBLOB_URI_PATH="${DEBLOB_PV}${K_DEBLOB_TAG}"
645                         DEBLOB_CHECK_URI="${DEBLOB_HOMEPAGE}/${DEBLOB_URI_PATH}/deblob-check -> ${DEBLOB_CHECK_A}"
646                         DEBLOB_URI="${DEBLOB_HOMEPAGE}/${DEBLOB_URI_PATH}/${DEBLOB_A}"
647                         HOMEPAGE="${HOMEPAGE} ${DEBLOB_HOMEPAGE}"
648
649                         KERNEL_URI="${KERNEL_URI}
650                                 deblob? (
651                                         ${DEBLOB_URI}
652                                         ${DEBLOB_CHECK_URI}
653                                 )"
654                 else
655                         # We have no way to deblob older kernels, so just mark them as
656                         # tainted with non-libre materials.
657                         LICENSE="${LICENSE} linux-firmware"
658                 fi
659         fi
660
661 elif [[ ${ETYPE} == headers ]]; then
662         DESCRIPTION="Linux system headers"
663         IUSE="headers-only"
664
665         # Since we should NOT honour KBUILD_OUTPUT in headers
666         # lets unset it here.
667         unset KBUILD_OUTPUT
668
669         SLOT="0"
670 fi
671
672 # Cross-compile support functions
673
674 # @FUNCTION: kernel_header_destdir
675 # @USAGE:
676 # @DESCRIPTION:
677 # return header destination directory
678 kernel_header_destdir() {
679         [[ ${CTARGET} == ${CHOST} ]] \
680                 && echo /usr/include \
681                 || echo /usr/${CTARGET}/usr/include
682 }
683
684 # @FUNCTION: cross_pre_c_headers
685 # @USAGE:
686 # @DESCRIPTION:
687 # set use if necessary for cross compile support
688 cross_pre_c_headers() {
689         use headers-only && [[ ${CHOST} != ${CTARGET} ]]
690 }
691
692 # @FUNCTION: env_setup_xmakeopts
693 # @USAGE:
694 # @DESCRIPTION:
695 # set the ARCH/CROSS_COMPILE when cross compiling
696
697 env_setup_xmakeopts() {
698         # Kernel ARCH != portage ARCH
699         export KARCH=$(tc-arch-kernel)
700
701         # When cross-compiling, we need to set the ARCH/CROSS_COMPILE
702         # variables properly or bad things happen !
703         xmakeopts="ARCH=${KARCH}"
704         if [[ ${CTARGET} != ${CHOST} ]] && ! cross_pre_c_headers ; then
705                 xmakeopts="${xmakeopts} CROSS_COMPILE=${CTARGET}-"
706         elif type -p ${CHOST}-ar > /dev/null ; then
707                 xmakeopts="${xmakeopts} CROSS_COMPILE=${CHOST}-"
708         fi
709         export xmakeopts
710 }
711
712 # @FUNCTION: unpack_2_4
713 # @USAGE:
714 # @DESCRIPTION:
715 # unpack and generate .config for 2.4 kernels
716
717 unpack_2_4() {
718         # this file is required for other things to build properly,
719         # so we autogenerate it
720         make -s mrproper ${xmakeopts} || die "make mrproper failed"
721         make -s symlinks ${xmakeopts} || die "make symlinks failed"
722         make -s include/linux/version.h ${xmakeopts} || die "make include/linux/version.h failed"
723         echo ">>> version.h compiled successfully."
724 }
725
726 # @FUNCTION: unpack_2_6
727 # @USAGE:
728 # @DESCRIPTION:
729 # unpack and generate .config for 2.6 kernels
730
731 unpack_2_6() {
732         # this file is required for other things to build properly, so we
733         # autogenerate it ... generate a .config to keep version.h build from
734         # spitting out an annoying warning
735         make -s mrproper ${xmakeopts} 2>/dev/null \
736                 || die "make mrproper failed"
737
738         # quick fix for bug #132152 which triggers when it cannot include linux
739         # headers (ie, we have not installed it yet)
740         if ! make -s defconfig ${xmakeopts} &>/dev/null 2>&1 ; then
741                 touch .config
742                 eerror "make defconfig failed."
743                 eerror "assuming you dont have any headers installed yet and continuing"
744         fi
745
746         make -s include/linux/version.h ${xmakeopts} 2>/dev/null \
747                 || die "make include/linux/version.h failed"
748         rm -f .config >/dev/null
749 }
750
751 # @FUNCTION: universal_unpack
752 # @USAGE:
753 # @DESCRIPTION:
754 # unpack kernel sources
755
756 universal_unpack() {
757         debug-print "Inside universal_unpack"
758
759         local OKV_ARRAY
760         IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
761
762         cd "${WORKDIR}"
763         if [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]]; then
764                 unpack linux-${KV_MAJOR}.${KV_MINOR}.tar.xz
765         else
766                 unpack linux-${OKV}.tar.xz
767         fi
768
769         if [[ -d "linux" ]]; then
770                 debug-print "Moving linux to linux-${KV_FULL}"
771                 mv linux linux-${KV_FULL} \
772                         || die "Unable to move source tree to ${KV_FULL}."
773         elif [[ "${OKV}" != "${KV_FULL}" ]]; then
774                 if [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]] &&
775                         [[ "${ETYPE}" = "sources" ]]; then
776                         debug-print "moving linux-${KV_MAJOR}.${KV_MINOR} to linux-${KV_FULL} "
777                         mv linux-${KV_MAJOR}.${KV_MINOR} linux-${KV_FULL} \
778                                 || die "Unable to move source tree to ${KV_FULL}."
779                 else
780                         debug-print "moving linux-${OKV} to linux-${KV_FULL} "
781                         mv linux-${OKV} linux-${KV_FULL} \
782                                 || die "Unable to move source tree to ${KV_FULL}."
783                 fi
784         elif [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]]; then
785                 mv linux-${KV_MAJOR}.${KV_MINOR} linux-${KV_FULL} \
786                         || die "Unable to move source tree to ${KV_FULL}."
787         fi
788         cd "${S}"
789
790         # remove all backup files
791         find . -iname "*~" -exec rm {} \; 2> /dev/null
792
793 }
794
795 # @FUNCTION: unpack_set_extraversion
796 # @USAGE:
797 # @DESCRIPTION:
798 # handle EXTRAVERSION
799
800 unpack_set_extraversion() {
801         cd "${S}"
802         sed -i -e "s:^\(EXTRAVERSION =\).*:\1 ${EXTRAVERSION}:" Makefile
803         cd "${OLDPWD}"
804 }
805
806 # @FUNCTION: unpack_fix_install_path
807 # @USAGE:
808 # @DESCRIPTION:
809 # Should be done after patches have been applied
810 # Otherwise patches that modify the same area of Makefile will fail
811
812 unpack_fix_install_path() {
813         cd "${S}"
814         sed     -i -e 's:#export\tINSTALL_PATH:export\tINSTALL_PATH:' Makefile
815 }
816
817 # Compile Functions
818
819 # @FUNCTION: compile_headers
820 # @USAGE:
821 # @DESCRIPTION:
822 # header compilation
823
824 compile_headers() {
825         env_setup_xmakeopts
826
827         # if we couldnt obtain HOSTCFLAGS from the Makefile,
828         # then set it to something sane
829         local HOSTCFLAGS=$(getfilevar HOSTCFLAGS "${S}"/Makefile)
830         HOSTCFLAGS=${HOSTCFLAGS:--Wall -Wstrict-prototypes -O2 -fomit-frame-pointer}
831
832         if kernel_is 2 4; then
833                 yes "" | make oldconfig ${xmakeopts}
834                 echo ">>> make oldconfig complete"
835                 make dep ${xmakeopts}
836         elif kernel_is 2 6; then
837                 # 2.6.18 introduces headers_install which means we dont need any
838                 # of this crap anymore :D
839                 kernel_is ge 2 6 18 && return 0
840
841                 # autoconf.h isnt generated unless it already exists. plus, we have
842                 # no guarantee that any headers are installed on the system...
843                 [[ -f ${EROOT}usr/include/linux/autoconf.h ]] \
844                         || touch include/linux/autoconf.h
845
846                 # if K_DEFCONFIG isn't set, force to "defconfig"
847                 # needed by mips
848                 if [[ -z ${K_DEFCONFIG} ]]; then
849                         if kernel_is ge 2 6 16 ; then
850                                 case ${CTARGET} in
851                                         powerpc64*)     K_DEFCONFIG="ppc64_defconfig";;
852                                         powerpc*)       K_DEFCONFIG="pmac32_defconfig";;
853                                         *)                      K_DEFCONFIG="defconfig";;
854                                 esac
855                         else
856                                 K_DEFCONFIG="defconfig"
857                         fi
858                 fi
859
860                 # if there arent any installed headers, then there also isnt an asm
861                 # symlink in /usr/include/, and make defconfig will fail, so we have
862                 # to force an include path with $S.
863                 HOSTCFLAGS="${HOSTCFLAGS} -I${S}/include/"
864                 ln -sf asm-${KARCH} "${S}"/include/asm || die
865                 cross_pre_c_headers && return 0
866
867                 make ${K_DEFCONFIG} HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "defconfig failed (${K_DEFCONFIG})"
868                 if compile_headers_tweak_config ; then
869                         yes "" | make oldconfig HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "2nd oldconfig failed"
870                 fi
871                 make prepare HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "prepare failed"
872                 make prepare-all HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "prepare failed"
873         fi
874 }
875
876 # @FUNCTION: compile_headers_tweak_config
877 # @USAGE:
878 # @DESCRIPTION:
879 # some targets can be very very picky, so let's finesse the
880 # .config based upon any info we may have
881
882 compile_headers_tweak_config() {
883         case ${CTARGET} in
884         sh*)
885                 sed -i '/CONFIG_CPU_SH/d' .config || die
886                 echo "CONFIG_CPU_SH${CTARGET:2:1}=y" >> .config
887                 return 0;;
888         esac
889
890         # no changes, so lets do nothing
891         return 1
892 }
893
894 # install functions
895
896 # @FUNCTION: install_universal
897 # @USAGE:
898 # @DESCRIPTION:
899 # Fix permissions in tarball
900
901 install_universal() {
902         cd "${WORKDIR}"
903         chown -R 0:0 * >& /dev/null
904         chmod -R a+r-w+X,u+w *
905         cd ${OLDPWD}
906 }
907
908 # @FUNCTION: install_headers
909 # @USAGE:
910 # @DESCRIPTION:
911 # Install headers
912
913 install_headers() {
914         local ddir=$(kernel_header_destdir)
915
916         # 2.6.18 introduces headers_install which means we dont need any
917         # of this crap anymore :D
918         if kernel_is ge 2 6 18 ; then
919                 env_setup_xmakeopts
920                 emake headers_install INSTALL_HDR_PATH="${ED}"${ddir}/.. ${xmakeopts} || die
921
922                 # let other packages install some of these headers
923                 rm -rf "${ED}"${ddir}/scsi || die #glibc/uclibc/etc...
924                 return 0
925         fi
926
927         # Do not use "linux/*" as that can cause problems with very long
928         # $S values where the cmdline to cp is too long
929         pushd "${S}" >/dev/null
930         dodir ${ddir}/linux
931         cp -pPR "${S}"/include/linux "${ED}"${ddir}/ || die
932         rm -rf "${ED}"${ddir}/linux/modules || die
933
934         dodir ${ddir}/asm
935         cp -pPR "${S}"/include/asm/* "${ED}"${ddir}/asm || die
936
937         if kernel_is 2 6 ; then
938                 dodir ${ddir}/asm-generic
939                 cp -pPR "${S}"/include/asm-generic/* "${ED}"${ddir}/asm-generic || die
940         fi
941
942         # clean up
943         find "${D}" -name '*.orig' -exec rm -f {} \;
944
945         popd >/dev/null
946 }
947
948 # @FUNCTION: install_sources
949 # @USAGE:
950 # @DESCRIPTION:
951 # Install sources
952
953 install_sources() {
954         local file
955
956         cd "${S}"
957         dodir /usr/src
958         echo ">>> Copying sources ..."
959
960         file="$(find ${WORKDIR} -iname "docs" -type d)"
961         if [[ -n ${file} ]]; then
962                 for file in $(find ${file} -type f); do
963                         echo "${file//*docs\/}" >> "${S}"/patches.txt
964                         echo "===================================================" >> "${S}"/patches.txt
965                         cat ${file} >> "${S}"/patches.txt
966                         echo "===================================================" >> "${S}"/patches.txt
967                         echo "" >> "${S}"/patches.txt
968                 done
969         fi
970
971         mv "${WORKDIR}"/linux* "${ED}"usr/src || die
972
973         if [[ -n "${UNIPATCH_DOCS}" ]] ; then
974                 for i in ${UNIPATCH_DOCS}; do
975                         dodoc "${T}"/${i}
976                 done
977         fi
978 }
979
980 # @FUNCTION: preinst_headers
981 # @USAGE:
982 # @DESCRIPTION:
983 # Headers preinst steps
984
985 preinst_headers() {
986         local ddir=$(kernel_header_destdir)
987         [[ -L ${EPREFIX}${ddir}/linux ]] && { rm "${EPREFIX}"${ddir}/linux || die; }
988         [[ -L ${EPREFIX}${ddir}/asm ]] && { rm "${EPREFIX}"${ddir}/asm || die; }
989 }
990
991 # @FUNCTION: postinst_sources
992 # @USAGE:
993 # @DESCRIPTION:
994 # Sources post installation function.
995 # see inline comments
996
997 postinst_sources() {
998         local MAKELINK=0
999
1000         # if we have USE=symlink, then force K_SYMLINK=1
1001         use symlink && K_SYMLINK=1
1002
1003         # We do support security on a deblobbed kernel, bug #555878.
1004         # If some particular kernel version doesn't have security
1005         # supported because of USE=deblob or otherwise, one can still
1006         # set K_SECURITY_UNSUPPORTED on a per ebuild basis.
1007         #[[ $K_DEBLOB_AVAILABLE == 1 ]] && \
1008         #       use deblob && \
1009         #       K_SECURITY_UNSUPPORTED=deblob
1010
1011         # if we are to forcably symlink, delete it if it already exists first.
1012         if [[ ${K_SYMLINK} > 0 ]]; then
1013                 [[ -h ${EROOT}usr/src/linux ]] && { rm "${EROOT}"usr/src/linux || die; }
1014                 MAKELINK=1
1015         fi
1016
1017         # if the link doesnt exist, lets create it
1018         [[ ! -h ${EROOT}usr/src/linux ]] && MAKELINK=1
1019
1020         if [[ ${MAKELINK} == 1 ]]; then
1021                 ln -sf linux-${KV_FULL} "${EROOT}"usr/src/linux || die
1022         fi
1023
1024         # Don't forget to make directory for sysfs
1025         [[ ! -d ${EROOT}sys ]] && kernel_is 2 6 && { mkdir "${EROOT}"sys || die ; }
1026
1027         echo
1028         elog "If you are upgrading from a previous kernel, you may be interested"
1029         elog "in the following document:"
1030         elog "  - General upgrade guide: https://wiki.gentoo.org/wiki/Kernel/Upgrade"
1031         echo
1032
1033         # if K_EXTRAEINFO is set then lets display it now
1034         if [[ -n ${K_EXTRAEINFO} ]]; then
1035                 echo ${K_EXTRAEINFO} | fmt |
1036                 while read -s ELINE; do einfo "${ELINE}"; done
1037         fi
1038
1039         # if K_EXTRAELOG is set then lets display it now
1040         if [[ -n ${K_EXTRAELOG} ]]; then
1041                 echo ${K_EXTRAELOG} | fmt |
1042                 while read -s ELINE; do elog "${ELINE}"; done
1043         fi
1044
1045         # if K_EXTRAEWARN is set then lets display it now
1046         if [[ -n ${K_EXTRAEWARN} ]]; then
1047                 echo ${K_EXTRAEWARN} | fmt |
1048                 while read -s ELINE; do ewarn "${ELINE}"; done
1049         fi
1050
1051         # optionally display security unsupported message
1052         #  Start with why
1053         if [[ -n ${K_SECURITY_UNSUPPORTED} ]]; then
1054                 ewarn "${PN} is UNSUPPORTED by Gentoo Security."
1055         fi
1056         #  And now the general message.
1057         if [[ -n ${K_SECURITY_UNSUPPORTED} ]]; then
1058                 ewarn "This means that it is likely to be vulnerable to recent security issues."
1059                 echo
1060                 ewarn "Upstream kernel developers recommend always running the latest "
1061                 ewarn "release of any current long term supported Linux kernel version."
1062                 ewarn "To see a list of these versions, their most current release and "
1063                 ewarn "long term support status, please go to https://www.kernel.org ."
1064                 echo
1065                 ewarn "For specific information on why this kernel is unsupported, please read:"
1066                 ewarn "https://wiki.gentoo.org/wiki/Project:Kernel_Security"
1067         fi
1068
1069         # warn sparc users that they need to do cross-compiling with >= 2.6.25(bug #214765)
1070         KV_MAJOR=$(ver_cut 1 ${OKV})
1071         KV_MINOR=$(ver_cut 2 ${OKV})
1072         KV_PATCH=$(ver_cut 3 ${OKV})
1073         if [[ "$(tc-arch)" = "sparc" ]]; then
1074                 if [[ $(gcc-major-version) -lt 4 && $(gcc-minor-version) -lt 4 ]]; then
1075                         if [[ ${KV_MAJOR} -ge 3 || ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} > 2.6.24 ]] ; then
1076                                 echo
1077                                 elog "NOTE: Since 2.6.25 the kernel Makefile has changed in a way that"
1078                                 elog "you now need to do"
1079                                 elog "  make CROSS_COMPILE=sparc64-unknown-linux-gnu-"
1080                                 elog "instead of just"
1081                                 elog "  make"
1082                                 elog "to compile the kernel. For more information please browse to"
1083                                 elog "https://bugs.gentoo.org/show_bug.cgi?id=214765"
1084                                 echo
1085                         fi
1086                 fi
1087         fi
1088 }
1089
1090 # pkg_setup functions
1091
1092 # @FUNCTION: setup_headers
1093 # @USAGE:
1094 # @DESCRIPTION:
1095 # Determine if ${PN} supports arch
1096
1097 setup_headers() {
1098         [[ -z ${H_SUPPORTEDARCH} ]] && H_SUPPORTEDARCH=${PN/-*/}
1099         for i in ${H_SUPPORTEDARCH}; do
1100                 [[ $(tc-arch) == "${i}" ]] && H_ACCEPT_ARCH="yes"
1101         done
1102
1103         if [[ ${H_ACCEPT_ARCH} != "yes" ]]; then
1104                 echo
1105                 eerror "This version of ${PN} does not support $(tc-arch)."
1106                 eerror "Please merge the appropriate sources, in most cases"
1107                 eerror "(but not all) this will be called $(tc-arch)-headers."
1108                 die "Package unsupported for $(tc-arch)"
1109         fi
1110 }
1111
1112 # @FUNCTION: unipatch
1113 # @USAGE: <list of patches to apply>
1114 # @DESCRIPTION:
1115 # Universal function that will apply patches to source
1116
1117 unipatch() {
1118         local i x y z extention PIPE_CMD UNIPATCH_DROP KPATCH_DIR PATCH_DEPTH ELINE
1119         local STRICT_COUNT PATCH_LEVEL myLC_ALL myLANG
1120
1121         # set to a standard locale to ensure sorts are ordered properly.
1122         myLC_ALL="${LC_ALL}"
1123         myLANG="${LANG}"
1124         LC_ALL="C"
1125         LANG=""
1126
1127         [ -z "${KPATCH_DIR}" ] && KPATCH_DIR="${WORKDIR}/patches/"
1128         [ ! -d ${KPATCH_DIR} ] && mkdir -p ${KPATCH_DIR}
1129
1130         # We're gonna need it when doing patches with a predefined patchlevel
1131         eshopts_push -s extglob
1132
1133         # This function will unpack all passed tarballs, add any passed patches,
1134         # and remove any passed patchnumbers
1135         # usage can be either via an env var or by params
1136         # although due to the nature we pass this within this eclass
1137         # it shall be by param only.
1138         # -z "${UNIPATCH_LIST}" ] && UNIPATCH_LIST="${@}"
1139         UNIPATCH_LIST="${@}"
1140
1141         #unpack any passed tarballs
1142         for i in ${UNIPATCH_LIST}; do
1143                 if echo ${i} | grep -qs -e "\.tar" -e "\.tbz" -e "\.tgz" ; then
1144                         if [ -n "${UNIPATCH_STRICTORDER}" ]; then
1145                                 unset z
1146                                 STRICT_COUNT=$((10#${STRICT_COUNT} + 1))
1147                                 for((y=0; y<$((6 - ${#STRICT_COUNT})); y++));
1148                                         do z="${z}0";
1149                                 done
1150                                 PATCH_ORDER="${z}${STRICT_COUNT}"
1151
1152                                 mkdir -p "${KPATCH_DIR}/${PATCH_ORDER}"
1153                                 pushd "${KPATCH_DIR}/${PATCH_ORDER}" >/dev/null
1154                                 unpack ${i##*/}
1155                                 popd >/dev/null
1156                         else
1157                                 pushd "${KPATCH_DIR}" >/dev/null
1158                                 unpack ${i##*/}
1159                                 popd >/dev/null
1160                         fi
1161
1162                         [[ ${i} == *:* ]] && echo ">>> Strict patch levels not currently supported for tarballed patchsets"
1163                 else
1164                         extention=${i/*./}
1165                         extention=${extention/:*/}
1166                         PIPE_CMD=""
1167                         case ${extention} in
1168                                      xz) PIPE_CMD="xz -dc";;
1169                                    lzma) PIPE_CMD="lzma -dc";;
1170                                     bz2) PIPE_CMD="bzip2 -dc";;
1171                                  patch*) PIPE_CMD="cat";;
1172                                    diff) PIPE_CMD="cat";;
1173                                  gz|Z|z) PIPE_CMD="gzip -dc";;
1174                                 ZIP|zip) PIPE_CMD="unzip -p";;
1175                                       *) UNIPATCH_DROP="${UNIPATCH_DROP} ${i/:*/}";;
1176                         esac
1177
1178                         PATCH_LEVEL=${i/*([^:])?(:)}
1179                         i=${i/:*/}
1180                         x=${i/*\//}
1181                         x=${x/\.${extention}/}
1182
1183                         if [ -n "${PIPE_CMD}" ]; then
1184                                 if [ ! -r "${i}" ]; then
1185                                         echo
1186                                         eerror "FATAL: unable to locate:"
1187                                         eerror "${i}"
1188                                         eerror "for read-only. The file either has incorrect permissions"
1189                                         eerror "or does not exist."
1190                                         die Unable to locate ${i}
1191                                 fi
1192
1193                                 if [ -n "${UNIPATCH_STRICTORDER}" ]; then
1194                                         unset z
1195                                         STRICT_COUNT=$((10#${STRICT_COUNT} + 1))
1196                                         for((y=0; y<$((6 - ${#STRICT_COUNT})); y++));
1197                                                 do z="${z}0";
1198                                         done
1199                                         PATCH_ORDER="${z}${STRICT_COUNT}"
1200
1201                                         mkdir -p ${KPATCH_DIR}/${PATCH_ORDER}/
1202                                         $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${PATCH_ORDER}/${x}.patch${PATCH_LEVEL}) || die "uncompressing patch failed"
1203                                 else
1204                                         $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${x}.patch${PATCH_LEVEL}) || die "uncompressing patch failed"
1205                                 fi
1206                         fi
1207                 fi
1208
1209                 # If experimental was not chosen by the user, drop experimental patches not in K_EXP_GENPATCHES_LIST.
1210                 if [[ "${i}" == *"genpatches-"*".experimental."* && -n ${K_EXP_GENPATCHES_PULL} ]] ; then
1211                         if [[ -z ${K_EXP_GENPATCHES_NOUSE} ]] && use experimental; then
1212                                 continue
1213                         fi
1214
1215                         local j
1216                         for j in ${KPATCH_DIR}/*/50*_*.patch*; do
1217                                 for k in ${K_EXP_GENPATCHES_LIST} ; do
1218                                         [[ "$(basename ${j})" == ${k}* ]] && continue 2
1219                                 done
1220                                 UNIPATCH_DROP+=" $(basename ${j})"
1221                         done
1222                 else
1223                         UNIPATCH_LIST_GENPATCHES+=" ${DISTDIR}/${tarball}"
1224                         debug-print "genpatches tarball: $tarball"
1225
1226                         # check gcc version < 4.9.X uses patch 5000 and = 4.9.X uses patch 5010
1227                         if [[ $(gcc-major-version) -eq 4 ]] && [[ $(gcc-minor-version) -ne 9 ]]; then
1228                                 # drop 5000_enable-additional-cpu-optimizations-for-gcc-4.9.patch
1229                                 if [[ $UNIPATCH_DROP != *"5010_enable-additional-cpu-optimizations-for-gcc-4.9.patch"* ]]; then
1230                                         UNIPATCH_DROP+=" 5010_enable-additional-cpu-optimizations-for-gcc-4.9.patch"
1231                                 fi
1232                         else
1233                                 if [[ $UNIPATCH_DROP != *"5000_enable-additional-cpu-optimizations-for-gcc.patch"* ]]; then
1234                                         #drop 5000_enable-additional-cpu-optimizations-for-gcc.patch
1235                                         UNIPATCH_DROP+=" 5000_enable-additional-cpu-optimizations-for-gcc.patch"
1236                                 fi
1237                         fi
1238                 fi
1239         done
1240
1241         #populate KPATCH_DIRS so we know where to look to remove the excludes
1242         x=${KPATCH_DIR}
1243         KPATCH_DIR=""
1244         for i in $(find ${x} -type d | sort -n); do
1245                 KPATCH_DIR="${KPATCH_DIR} ${i}"
1246         done
1247
1248         # do not apply fbcondecor patch to sparc/sparc64 as it breaks boot
1249         # bug #272676
1250         if [[ "$(tc-arch)" = "sparc" || "$(tc-arch)" = "sparc64" ]]; then
1251                 if [[ ${KV_MAJOR} -ge 3 || ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} > 2.6.28 ]]; then
1252                         if [[ ! -z ${K_WANT_GENPATCHES} ]] ; then
1253                                 UNIPATCH_DROP="${UNIPATCH_DROP} *_fbcondecor*.patch"
1254                                 echo
1255                                 ewarn "fbcondecor currently prevents sparc/sparc64 from booting"
1256                                 ewarn "for kernel versions >= 2.6.29. Removing fbcondecor patch."
1257                                 ewarn "See https://bugs.gentoo.org/show_bug.cgi?id=272676 for details"
1258                                 echo
1259                         fi
1260                 fi
1261         fi
1262
1263         #so now lets get rid of the patchno's we want to exclude
1264         UNIPATCH_DROP="${UNIPATCH_EXCLUDE} ${UNIPATCH_DROP}"
1265         for i in ${UNIPATCH_DROP}; do
1266                 ebegin "Excluding Patch #${i}"
1267                 for x in ${KPATCH_DIR}; do rm -f ${x}/${i}* 2>/dev/null; done
1268                 eend $?
1269         done
1270
1271         # and now, finally, we patch it :)
1272         for x in ${KPATCH_DIR}; do
1273                 for i in $(find ${x} -maxdepth 1 -iname "*.patch*" -or -iname "*.diff*" | sort -n); do
1274                         STDERR_T="${T}/${i/*\//}"
1275                         STDERR_T="${STDERR_T/.patch*/.err}"
1276
1277                         [ -z ${i/*.patch*/} ] && PATCH_DEPTH=${i/*.patch/}
1278                         #[ -z ${i/*.diff*/} ]  && PATCH_DEPTH=${i/*.diff/}
1279
1280                         if [ -z "${PATCH_DEPTH}" ]; then PATCH_DEPTH=0; fi
1281
1282                         ####################################################################
1283                         # IMPORTANT: This is temporary code to support Linux git 3.15_rc1! #
1284                         #                                                                  #
1285                         # The patch contains a removal of a symlink, followed by addition  #
1286                         # of a file with the same name as the symlink in the same          #
1287                         # location; this causes the dry-run to fail, filed bug #507656.    #
1288                         #                                                                  #
1289                         # https://bugs.gentoo.org/show_bug.cgi?id=507656                   #
1290                         ####################################################################
1291                         if [[ -n ${K_FROM_GIT} ]] ; then
1292                                 if [[ ${KV_MAJOR} -gt 3 || ( ${KV_MAJOR} -eq 3 && ${KV_PATCH} -gt 15 ) &&
1293                                         ${RELEASETYPE} == -rc ]] ; then
1294                                         ebegin "Applying ${i/*\//} (-p1)"
1295                                         if [ $(patch -p1 --no-backup-if-mismatch -f < ${i} >> ${STDERR_T}) "$?" -le 2 ]; then
1296                                                 eend 0
1297                                                 rm ${STDERR_T} || die
1298                                                 break
1299                                         else
1300                                                 eend 1
1301                                                 eerror "Failed to apply patch ${i/*\//}"
1302                                                 eerror "Please attach ${STDERR_T} to any bug you may post."
1303                                                 eshopts_pop
1304                                                 die "Failed to apply ${i/*\//} on patch depth 1."
1305                                         fi
1306                                 fi
1307                         fi
1308                         ####################################################################
1309
1310                         while [ ${PATCH_DEPTH} -lt 5 ]; do
1311                                 echo "Attempting Dry-run:" >> ${STDERR_T}
1312                                 echo "cmd: patch -p${PATCH_DEPTH} --no-backup-if-mismatch --dry-run -f < ${i}" >> ${STDERR_T}
1313                                 echo "=======================================================" >> ${STDERR_T}
1314                                 if [ $(patch -p${PATCH_DEPTH} --no-backup-if-mismatch --dry-run -f < ${i} >> ${STDERR_T}) $? -eq 0 ]; then
1315                                         ebegin "Applying ${i/*\//} (-p${PATCH_DEPTH})"
1316                                         echo "Attempting patch:" > ${STDERR_T}
1317                                         echo "cmd: patch -p${PATCH_DEPTH} --no-backup-if-mismatch -f < ${i}" >> ${STDERR_T}
1318                                         echo "=======================================================" >> ${STDERR_T}
1319                                         if [ $(patch -p${PATCH_DEPTH} --no-backup-if-mismatch -f < ${i} >> ${STDERR_T}) "$?" -eq 0 ]; then
1320                                                 eend 0
1321                                                 rm ${STDERR_T} || die
1322                                                 break
1323                                         else
1324                                                 eend 1
1325                                                 eerror "Failed to apply patch ${i/*\//}"
1326                                                 eerror "Please attach ${STDERR_T} to any bug you may post."
1327                                                 eshopts_pop
1328                                                 die "Failed to apply ${i/*\//} on patch depth ${PATCH_DEPTH}."
1329                                         fi
1330                                 else
1331                                         PATCH_DEPTH=$((${PATCH_DEPTH} + 1))
1332                                 fi
1333                         done
1334                         if [ ${PATCH_DEPTH} -eq 5 ]; then
1335                                 eerror "Failed to dry-run patch ${i/*\//}"
1336                                 eerror "Please attach ${STDERR_T} to any bug you may post."
1337                                 eshopts_pop
1338                                 die "Unable to dry-run patch on any patch depth lower than 5."
1339                         fi
1340                 done
1341         done
1342
1343         # When genpatches is used, we want to install 0000_README which documents
1344         # the patches that were used; such that the user can see them, bug #301478.
1345         if [[ ! -z ${K_WANT_GENPATCHES} ]] ; then
1346                 UNIPATCH_DOCS="${UNIPATCH_DOCS} 0000_README"
1347         fi
1348
1349         # When files listed in UNIPATCH_DOCS are found in KPATCH_DIR's, we copy it
1350         # to the temporary directory and remember them in UNIPATCH_DOCS to install
1351         # them during the install phase.
1352         local tmp
1353         for x in ${KPATCH_DIR}; do
1354                 for i in ${UNIPATCH_DOCS}; do
1355                         if [[ -f ${x}/${i} ]] ; then
1356                                 tmp="${tmp} ${i}"
1357                                 cp -f "${x}/${i}" "${T}"/ || die
1358                         fi
1359                 done
1360         done
1361         UNIPATCH_DOCS="${tmp}"
1362
1363         # clean up  KPATCH_DIR's - fixes bug #53610
1364         for x in ${KPATCH_DIR}; do rm -Rf ${x}; done
1365
1366         LC_ALL="${myLC_ALL}"
1367         LANG="${myLANG}"
1368         eshopts_pop
1369 }
1370
1371 # @FUNCTION: getfilevar
1372 # @USAGE: <variable> <configfile>
1373 # @DESCRIPTION:
1374 # pulled from linux-info
1375
1376 getfilevar() {
1377         local workingdir basefname basedname xarch=$(tc-arch-kernel)
1378
1379         if [[ -z ${1} ]] && [[ ! -f ${2} ]]; then
1380                 echo -e "\n"
1381                 eerror "getfilevar requires 2 variables, with the second a valid file."
1382                 eerror "   getfilevar <VARIABLE> <CONFIGFILE>"
1383         else
1384                 workingdir=${PWD}
1385                 basefname=$(basename ${2})
1386                 basedname=$(dirname ${2})
1387                 unset ARCH
1388
1389                 cd ${basedname}
1390                 echo -e "include ${basefname}\ne:\n\t@echo \$(${1})" | \
1391                         make ${BUILD_FIXES} -s -f - e 2>/dev/null
1392                 cd ${workingdir}
1393
1394                 ARCH=${xarch}
1395         fi
1396 }
1397
1398 # @FUNCTION: detect_arch
1399 # @USAGE:
1400 # @DESCRIPTION:
1401 # This function sets ARCH_URI and ARCH_PATCH
1402 # with the neccessary info for the arch sepecific compatibility
1403 # patchsets.
1404
1405 detect_arch() {
1406
1407         local ALL_ARCH LOOP_ARCH LOOP_ARCH_L COMPAT_URI i TC_ARCH_KERNEL
1408
1409         # COMPAT_URI is the contents of ${ARCH}_URI
1410         # ARCH_URI is the URI for all the ${ARCH}_URI patches
1411         # ARCH_PATCH is ARCH_URI broken into files for UNIPATCH
1412
1413         ARCH_URI=""
1414         ARCH_PATCH=""
1415         TC_ARCH_KERNEL=""
1416         ALL_ARCH="ALPHA AMD64 ARM HPPA IA64 M68K MIPS PPC PPC64 S390 SH SPARC X86"
1417
1418         for LOOP_ARCH in ${ALL_ARCH}; do
1419                 COMPAT_URI="${LOOP_ARCH}_URI"
1420                 COMPAT_URI="${!COMPAT_URI}"
1421
1422                 declare -l LOOP_ARCH_L=${LOOP_ARCH}
1423
1424                 [[ -n ${COMPAT_URI} ]] && \
1425                         ARCH_URI="${ARCH_URI} ${LOOP_ARCH_L}? ( ${COMPAT_URI} )"
1426
1427                 declare -u TC_ARCH_KERNEL=$(tc-arch-kernel)
1428                 if [[ ${LOOP_ARCH} == ${TC_ARCH_KERNEL} ]]; then
1429                         for i in ${COMPAT_URI}; do
1430                                 ARCH_PATCH="${ARCH_PATCH} ${DISTDIR}/${i/*\//}"
1431                         done
1432                 fi
1433
1434         done
1435 }
1436
1437 # @FUNCTION: headers___fix
1438 # @USAGE:
1439 # @DESCRIPTION:
1440 # Voodoo to partially fix broken upstream headers.
1441 # note: do not put inline/asm/volatile together (breaks "inline asm volatile")
1442
1443 headers___fix() {
1444         sed -i \
1445                 -e '/^\#define.*_TYPES_H/{:loop n; bloop}' \
1446                 -e 's:\<\([us]\(8\|16\|32\|64\)\)\>:__\1:g' \
1447                 -e "s/\([[:space:]]\)inline\([[:space:](]\)/\1__inline__\2/g" \
1448                 -e "s/\([[:space:]]\)asm\([[:space:](]\)/\1__asm__\2/g" \
1449                 -e "s/\([[:space:]]\)volatile\([[:space:](]\)/\1__volatile__\2/g" \
1450                 "$@"
1451 }
1452
1453 # @FUNCTION: kernel-2_src_unpack
1454 # @USAGE:
1455 # @DESCRIPTION:
1456 # unpack sources, handle genpatches, deblob
1457
1458 kernel-2_src_unpack() {
1459         universal_unpack
1460         debug-print "Doing unipatch"
1461
1462         # request UNIPATCH_LIST_GENPATCHES in phase since it calls 'use'
1463         handle_genpatches --set-unipatch-list
1464         [[ -n ${UNIPATCH_LIST} || -n ${UNIPATCH_LIST_DEFAULT} || -n ${UNIPATCH_LIST_GENPATCHES} ]] && \
1465                 unipatch "${UNIPATCH_LIST_DEFAULT} ${UNIPATCH_LIST_GENPATCHES} ${UNIPATCH_LIST}"
1466
1467         debug-print "Doing premake"
1468
1469         # allow ebuilds to massage the source tree after patching but before
1470         # we run misc `make` functions below
1471         [[ $(type -t kernel-2_hook_premake) == "function" ]] && kernel-2_hook_premake
1472
1473         debug-print "Doing unpack_set_extraversion"
1474
1475         [[ -z ${K_NOSETEXTRAVERSION} ]] && unpack_set_extraversion
1476         unpack_fix_install_path
1477
1478         # Setup xmakeopts and cd into sourcetree.
1479         env_setup_xmakeopts
1480         cd "${S}"
1481
1482         # We dont need a version.h for anything other than headers
1483         # at least, I should hope we dont. If this causes problems
1484         # take out the if/fi block and inform me please.
1485         # unpack_2_6 should now be 2.6.17 safe anyways
1486         if [[ ${ETYPE} == headers ]]; then
1487                 kernel_is 2 4 && unpack_2_4
1488                 kernel_is 2 6 && unpack_2_6
1489         fi
1490
1491         if [[ $K_DEBLOB_AVAILABLE == 1 ]] && use deblob ; then
1492                 cp "${DISTDIR}/${DEBLOB_A}" "${T}" || die "cp ${DEBLOB_A} failed"
1493                 cp "${DISTDIR}/${DEBLOB_CHECK_A}" "${T}/deblob-check" || die "cp ${DEBLOB_CHECK_A} failed"
1494                 chmod +x "${T}/${DEBLOB_A}" "${T}/deblob-check" || die "chmod deblob scripts failed"
1495         fi
1496
1497         # fix a problem on ppc where TOUT writes to /usr/src/linux breaking sandbox
1498         # only do this for kernel < 2.6.27 since this file does not exist in later
1499         # kernels
1500         if [[ -n ${KV_MINOR} &&  ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} < 2.6.27 ]] ; then
1501                 sed -i \
1502                         -e 's|TOUT      := .tmp_gas_check|TOUT  := $(T).tmp_gas_check|' \
1503                         "${S}"/arch/ppc/Makefile
1504         else
1505                 sed -i \
1506                         -e 's|TOUT      := .tmp_gas_check|TOUT  := $(T).tmp_gas_check|' \
1507                         "${S}"/arch/powerpc/Makefile
1508         fi
1509 }
1510
1511 # @FUNCTION: kernel-2_src_prepare
1512 # @USAGE:
1513 # @DESCRIPTION:
1514 # Apply any user patches
1515
1516 kernel-2_src_prepare() {
1517
1518         debug-print "Applying any user patches"
1519
1520         # apply any user patches
1521         case ${EAPI:-0} in
1522                 0|1|2|3|4|5) epatch_user ;;
1523                 6) eapply_user ;;
1524         esac
1525 }
1526
1527 # @FUNCTION: kernel-2_src_compile
1528 # @USAGE:
1529 # @DESCRIPTION:
1530 # conpile headers or run deblob script
1531
1532 kernel-2_src_compile() {
1533         cd "${S}"
1534         [[ ${ETYPE} == headers ]] && compile_headers
1535
1536         if [[ $K_DEBLOB_AVAILABLE == 1 ]] && use deblob ; then
1537                 echo ">>> Running deblob script ..."
1538                 python_setup
1539                 sh "${T}/${DEBLOB_A}" --force || die "Deblob script failed to run!!!"
1540         fi
1541 }
1542
1543 # @FUNCTION: kernel-2_src_test
1544 # @USAGE:
1545 # @DESCRIPTION:
1546 # if you leave it to the default src_test, it will run make to
1547 # find whether test/check targets are present; since "make test"
1548 # actually produces a few support files, they are installed even
1549 # though the package is binchecks-restricted.
1550 #
1551 # Avoid this altogether by making the function moot.
1552 kernel-2_src_test() { :; }
1553
1554 # @FUNCTION: kernel-2_pkg_preinst
1555 # @DESCRIPTION:
1556 # if ETYPE = headers, call preinst_headers
1557
1558 kernel-2_pkg_preinst() {
1559         [[ ${ETYPE} == headers ]] && preinst_headers
1560 }
1561
1562 # @FUNCTION: kernel-2_src_install
1563 # @USAGE:
1564 # @DESCRIPTION:
1565 # Install headers or sources dependant on ETYPE
1566
1567 kernel-2_src_install() {
1568         install_universal
1569         [[ ${ETYPE} == headers ]] && install_headers
1570         [[ ${ETYPE} == sources ]] && install_sources
1571 }
1572
1573 # @FUNCTION: kernel-2_pkg_postinst
1574 # @USAGE:
1575 # @DESCRIPTION:
1576 # call postinst_sources for ETYPE = sources
1577
1578 kernel-2_pkg_postinst() {
1579         [[ ${ETYPE} == sources ]] && postinst_sources
1580 }
1581
1582 # @FUNCTION: kernel-2_pkg_setup
1583 # @USAGE:
1584 # @DESCRIPTION:
1585 # check for supported kernel version, die if ETYPE is unknown, call setup_headers
1586 # if necessary
1587
1588 kernel-2_pkg_setup() {
1589         if kernel_is 2 4; then
1590                 if [[ $(gcc-major-version) -ge 4 ]] ; then
1591                         echo
1592                         ewarn "Be warned !! >=sys-devel/gcc-4.0.0 isn't supported with linux-2.4!"
1593                         ewarn "Either switch to another gcc-version (via gcc-config) or use a"
1594                         ewarn "newer kernel that supports gcc-4."
1595                         echo
1596                         ewarn "Also be aware that bugreports about gcc-4 not working"
1597                         ewarn "with linux-2.4 based ebuilds will be closed as INVALID!"
1598                         echo
1599                 fi
1600         fi
1601
1602         ABI="${KERNEL_ABI}"
1603         if [[ ${ETYPE} != sources ]] && [[ ${ETYPE} != headers ]]; then
1604                 eerror "Unknown ETYPE=\"${ETYPE}\", must be \"sources\" or \"headers\""
1605                 die "Unknown ETYPE=\"${ETYPE}\", must be \"sources\" or \"headers\""
1606         fi
1607
1608         [[ ${ETYPE} == headers ]] && setup_headers
1609         [[ ${ETYPE} == sources ]] && echo ">>> Preparing to unpack ..."
1610 }
1611
1612 # @FUNCTION: kernel-2_pkg_postrm
1613 # @USAGE:
1614 # @DESCRIPTION:
1615 # Notify the user that after a depclean, there may be sources
1616 # left behind that need to be manually cleaned
1617
1618 kernel-2_pkg_postrm() {
1619         # This warning only makes sense for kernel sources.
1620         [[ ${ETYPE} == headers ]] && return 0
1621
1622         # If there isn't anything left behind, then don't complain.
1623         [[ -e ${EROOT}usr/src/linux-${KV_FULL} ]] || return 0
1624         echo
1625         ewarn "Note: Even though you have successfully unmerged "
1626         ewarn "your kernel package, directories in kernel source location: "
1627         ewarn "${EROOT}usr/src/linux-${KV_FULL}"
1628         ewarn "with modified files will remain behind. By design, package managers"
1629         ewarn "will not remove these modified files and the directories they reside in."
1630         echo
1631         ewarn "For more detailed kernel removal instructions, please see: "
1632         ewarn "https://wiki.gentoo.org/wiki/Kernel/Removal"
1633         echo
1634 }