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