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