1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: kernel-2.eclass
6 # Gentoo Kernel project <kernel@gentoo.org>
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
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.
19 # @ECLASS-VARIABLE: K_USEPV
22 # When setting the EXTRAVERSION variable, it should
24 # this is useful for things like wolk. IE:
25 # EXTRAVERSION would be something like : -wolk-4.19-r1
27 # @ECLASS-VARIABLE: K_NOSETEXTRAVERSION
30 # if this is set then EXTRAVERSION will not be
31 # automatically set within the kernel Makefile
33 # @ECLASS-VARIABLE: K_NOUSENAME
36 # if this is set then EXTRAVERSION will not include the
37 # first part of ${PN} in EXTRAVERSION
39 # @ECLASS-VARIABLE: K_NOUSEPR
42 # if this is set then EXTRAVERSION will not include the
43 # anything based on ${PR}.
45 # @ECLASS-VARIABLE: K_PREPATCHED
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
53 # @ECLASS-VARIABLE: K_EXTRAEINFO
56 # this is a new-line seperated list of einfo displays in
57 # postinst and can be used to carry additional postinst
60 # @ECLASS-VARIABLE: K_EXTRAELOG
63 # same as K_EXTRAEINFO except using elog instead of einfo
65 # @ECLASS-VARIABLE: K_EXTRAEWARN
68 # same as K_EXTRAEINFO except using ewarn instead of einfo
70 # @ECLASS-VARIABLE: K_SYMLINK
73 # if this is set, then forcably create symlink anyway
75 # @ECLASS-VARIABLE: K_BASE_VER
78 # for git-sources, declare the base version this patch is
81 # @ECLASS-VARIABLE: K_DEFCONFIG
84 # Allow specifying a different defconfig target.
85 # If length zero, defaults to "defconfig".
87 # @ECLASS-VARIABLE: K_WANT_GENPATCHES
90 # Apply genpatches to kernel source. Provide any
91 # combination of "base", "extras" or "experimental".
93 # @ECLASS-VARIABLE: K_EXP_GENPATCHES_PULL
96 # If set, we pull "experimental" regardless of the USE FLAG
97 # but expect the ebuild maintainer to use K_EXP_GENPATCHES_LIST.
99 # @ECLASS-VARIABLE: K_EXP_GENPATCHES_NOUSE
102 # If set, no USE flag will be provided for "experimental";
103 # as a result the user cannot choose to apply those patches.
105 # @ECLASS-VARIABLE: K_EXP_GENPATCHES_LIST
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.
111 # @ECLASS-VARIABLE: K_FROM_GIT
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.
118 # @ECLASS-VARIABLE: K_GENPATCHES_VER
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
125 # @ECLASS-VARIABLE: K_SECURITY_UNSUPPORTED
128 # If set, this kernel is unsupported by Gentoo Security
129 # to the current eclass maintainer :)
131 # @ECLASS-VARIABLE: K_DEBLOB_AVAILABLE
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".
138 # @ECLASS-VARIABLE: K_DEBLOB_TAG
141 # This will be the version of deblob script. It's a upstream SVN tag
142 # such asw -gnu or -gnu1.
144 # @ECLASS-VARIABLE: K_PREDEBLOBBED
147 # This kernel was already deblobbed elsewhere.
148 # If false, either optional deblobbing will be available
149 # or the license will note the inclusion of linux-firmware code.
151 # @ECLASS-VARIABLE: K_LONGTERM
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
158 # @ECLASS-VARIABLE: H_SUPPORTEDARCH
161 # this should be a space separated list of ARCH's which
162 # can be supported by the headers ebuild
164 # @ECLASS-VARIABLE: UNIPATCH_LIST
167 # space delimetered list of patches to be applied to the kernel
169 # @ECLASS-VARIABLE: UNIPATCH_EXCLUDE
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
177 # @ECLASS-VARIABLE: UNIPATCH_DOCS
180 # space delimemeted list of docs to be installed to
183 # @ECLASS-VARIABLE: UNIPATCH_STRICTORDER
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.
193 PYTHON_COMPAT=( python{2_6,2_7} )
195 inherit eutils toolchain-funcs versionator multilib python-any-r1
198 EXPORT_FUNCTIONS src_{unpack,compile,install,test} \
199 pkg_{setup,preinst,postinst,postrm} ;;
201 EXPORT_FUNCTIONS src_{unpack,prepare,compile,install,test} \
202 pkg_{setup,preinst,postinst,postrm} ;;
203 *) die "${ECLASS}: EAPI ${EAPI} not supported" ;;
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#*-}"
211 export CTARGET=${CTARGET:-${CHOST}}
212 if [[ ${CTARGET} == ${CHOST} && ${CATEGORY/cross-} != ${CATEGORY} ]]; then
213 export CTARGET=${CATEGORY/cross-}
216 HOMEPAGE="https://www.kernel.org/ https://www.gentoo.org/ ${HOMEPAGE}"
217 : ${LICENSE:="GPL-2"}
219 has "${EAPI:-0}" 0 1 2 && ED=${D} EPREFIX= EROOT=${ROOT}
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}
226 # No need to run scanelf/strip on kernel sources/headers (bug #134453).
227 RESTRICT="binchecks strip"
229 # set LINUX_HOSTCFLAGS if not already set
230 : ${LINUX_HOSTCFLAGS:="-Wall -Wstrict-prototypes -Os -fomit-frame-pointer -I${S}/include"}
233 # @FUNCTION: debug-print-kernel2-variables
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.
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}"
248 # @FUNCTION: handle_genpatches
249 # @USAGE: [--set-unipatch-list]
251 # add genpatches to list of patches to apply if wanted
253 handle_genpatches() {
254 local tarball want_unipatch_list
255 [[ -z ${K_WANT_GENPATCHES} || -z ${K_GENPATCHES_VER} ]] && return 1
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
264 die "Usage: ${FUNCNAME} [--set-unipatch-list]"
268 debug-print "Inside handle_genpatches"
270 IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
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.
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"
282 tarball="genpatches-${KV_MAJOR}.${KV_PATCH}-${K_GENPATCHES_VER}.${i}.tar.xz"
285 tarball="genpatches-${OKV}-${K_GENPATCHES_VER}.${i}.tar.xz"
288 local use_cond_start="" use_cond_end=""
290 if [[ "${i}" == "experimental" && -z ${K_EXP_GENPATCHES_PULL} && -z ${K_EXP_GENPATCHES_NOUSE} ]] ; then
291 use_cond_start="experimental? ( "
294 if [[ -n ${want_unipatch_list} ]] && use experimental ; then
295 UNIPATCH_LIST_GENPATCHES+=" ${DISTDIR}/${tarball}"
296 debug-print "genpatches tarball: $tarball"
298 elif [[ -n ${want_unipatch_list} ]]; then
299 UNIPATCH_LIST_GENPATCHES+=" ${DISTDIR}/${tarball}"
300 debug-print "genpatches tarball: $tarball"
302 GENPATCHES_URI+=" ${use_cond_start}mirror://gentoo/${tarball}${use_cond_end}"
306 # @FUNCTION: detect_version
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)
315 # We've already run, so nothing to do here.
316 [[ -n ${KV_FULL} ]] && return 0
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:
324 OKV=${OKV/_beta/-test}
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)
332 IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
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/[-_]*}
343 KV_PATCH=$(get_version_component_range 3- ${OKV})
346 KV_PATCH=$(get_version_component_range 2 ${OKV})
347 KV_EXTRA=$(get_version_component_range 3- ${OKV})
348 KV_EXTRA=${KV_EXTRA/[-_]*}
351 debug-print "KV_EXTRA is ${KV_EXTRA}"
353 KV_PATCH=${KV_PATCH/[-_]*}
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} ";
362 for v in CKV OKV KV_{MAJOR,PATCH} ; do
363 [[ -z ${!v} ]] && n=1 && missing="${missing}${v} ";
368 eerror "Missing variables: ${missing}" && \
369 die "Failed to extract kernel version (try explicit CKV in ebuild)!"
372 # if [[ ${KV_MAJOR} -ge 3 ]]; then
373 if [[ ${#OKV_ARRAY[@]} -lt 3 ]]; then
374 KV_PATCH_ARR=(${KV_PATCH//\./ })
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"
380 [[ -n "${K_LONGTERM}" ]] &&
381 KERNEL_BASE_URI="${KERNEL_BASE_URI}/longterm/v${KV_MAJOR}.${KV_PATCH_ARR}"
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"
388 KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}"
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}"
396 debug-print "KERNEL_BASE_URI is ${KERNEL_BASE_URI}"
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"
404 KERNEL_URI="${KERNEL_URI} ${KERNEL_BASE_URI}/linux-${KV_MAJOR}.${KV_MINOR}.tar.xz"
406 KERNEL_URI="${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
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
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]}
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}"
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
444 [[ -z "${K_NOUSENAME}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*}"
445 [[ -n "${K_USEPV}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PV//_/-}"
446 [[ -n "${PR//r0}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PR}"
448 debug-print "2 EXTRAVERSION:${EXTRAVERSION}"
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
454 if [[ -n ${KV_EXTRA} ]]; then
455 if [[ -n ${KV_MINOR} ]]; then
456 OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
458 OKV="${KV_MAJOR}.${KV_PATCH}"
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"
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}
469 # we will set this for backwards compatibility.
470 S="${WORKDIR}"/linux-${KV_FULL}
473 # -rc-git pulls can be achieved by specifying CKV
475 # CKV="2.6.11_rc3_pre2"
477 # linux-2.6.10.tar.xz & patch-2.6.11-rc3.xz & patch-2.6.11-rc3-git2.xz
479 if [[ ${KV_MAJOR}${KV_MINOR} -eq 26 ]]; then
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"
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"
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"
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"
503 KV_PATCH_ARR=(${KV_PATCH//\./ })
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")
508 if [[ ${RELEASETYPE} == -rc ]] || [[ ${RELEASETYPE} == -pre ]]; then
510 OKV=${K_BASE_VER:-$OKV_DICT["${KV_MAJOR}"]}
512 # as of 12/5/2017, the rc patch is no longer offered as a compressed
513 # file, and no longer is it mirrored on kernel.org
514 if [[ ${KV_MAJOR} -ge 4 ]] && [[ ${KV_PATCH} -ge 12 ]]; then
515 KERNEL_URI="https://git.kernel.org/torvalds/p/v${KV_FULL}/v${OKV} -> patch-${KV_FULL}.patch
516 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
517 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV//_/-}.patch"
519 KERNEL_URI="${KERNEL_BASE_URI}/testing/patch-${CKV//_/-}.xz
520 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
521 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV//_/-}.xz"
525 if [[ ${RELEASETYPE} == -git ]]; then
526 KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${OKV}${RELEASE}.xz
527 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
528 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${OKV}${RELEASE}.xz"
531 if [[ ${RELEASETYPE} == -rc-git ]]; then
532 OKV=${K_BASE_VER:-$OKV_DICT["${KV_MAJOR}"]}
533 KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE}.xz
534 ${KERNEL_BASE_URI}/testing/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE/-git*}.xz
535 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
537 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE/-git*}.xz ${DISTDIR}/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE}.xz"
543 debug-print-kernel2-variables
548 # @FUNCTION: kernel_is
549 # @USAGE: <conditional version | version>
551 # user for comparing kernel versions
552 # or just identifying a version
554 # e.g kernel_is ge 4.8.11
555 # Note: duplicated in linux-info.eclass
557 # ALL of these should be set before we can safely continue this function.
558 # some of the sources have in the past had only one set.
560 for v in OKV KV_{MAJOR,MINOR,PATCH} ; do [[ -z ${!v} ]] && n=1 ; done
561 [[ $n -eq 1 ]] && detect_version
564 # Now we can continue
565 local operator test value
568 lt) operator="-lt"; shift;;
569 gt) operator="-gt"; shift;;
570 le) operator="-le"; shift;;
571 ge) operator="-ge"; shift;;
572 eq) operator="-eq"; shift;;
575 [[ $# -gt 3 ]] && die "Error in kernel-2_kernel_is(): too many parameters"
577 : $(( test = (KV_MAJOR << 16) + (KV_MINOR << 8) + KV_PATCH ))
578 : $(( value = (${1:-${KV_MAJOR}} << 16) + (${2:-${KV_MINOR}} << 8) + ${3:-${KV_PATCH}} ))
579 [ ${test} ${operator} ${value} ]
582 # @FUNCTION: kernel_is_2_4
585 # return true if kernel is version 2.4
590 # @FUNCTION: kernel_is_2_6
593 # return true if kernel is version 2.6
595 kernel_is 2 6 || kernel_is 2 5
598 # Capture the sources type and set DEPENDs
599 if [[ ${ETYPE} == sources ]]; then
602 >=sys-devel/binutils-2.11.90.0.31
605 >=sys-libs/ncurses-5.2
613 DESCRIPTION="Sources based on the Linux Kernel."
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} && \
623 if [[ ${K_DEBLOB_AVAILABLE} == "1" ]] ; then
624 IUSE="${IUSE} deblob"
626 # Reflect that kernels contain firmware blobs unless otherwise
628 LICENSE="${LICENSE} !deblob? ( linux-firmware )"
630 DEPEND+=" deblob? ( ${PYTHON_DEPS} )"
632 if [[ -n KV_MINOR ]]; then
633 DEBLOB_PV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
635 DEBLOB_PV="${KV_MAJOR}.${KV_PATCH}"
638 if [[ ${KV_MAJOR} -ge 3 ]]; then
639 DEBLOB_PV="${KV_MAJOR}.${KV_MINOR}"
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="http://www.fsfla.org/svn/fsfla/software/linux-libre/releases/tags"
647 DEBLOB_URI_PATH="${DEBLOB_PV}${K_DEBLOB_TAG}"
648 if ! has "${EAPI:-0}" 0 1 ; then
649 DEBLOB_CHECK_URI="${DEBLOB_HOMEPAGE}/${DEBLOB_URI_PATH}/deblob-check -> ${DEBLOB_CHECK_A}"
651 DEBLOB_CHECK_URI="mirror://gentoo/${DEBLOB_CHECK_A}"
654 DEBLOB_URI="${DEBLOB_HOMEPAGE}/${DEBLOB_URI_PATH}/${DEBLOB_A}"
655 HOMEPAGE="${HOMEPAGE} ${DEBLOB_HOMEPAGE}"
657 KERNEL_URI="${KERNEL_URI}
663 # We have no way to deblob older kernels, so just mark them as
664 # tainted with non-libre materials.
665 LICENSE="${LICENSE} linux-firmware"
669 elif [[ ${ETYPE} == headers ]]; then
670 DESCRIPTION="Linux system headers"
673 # Since we should NOT honour KBUILD_OUTPUT in headers
674 # lets unset it here.
680 # Cross-compile support functions
682 # @FUNCTION: kernel_header_destdir
685 # return header destination directory
686 kernel_header_destdir() {
687 [[ ${CTARGET} == ${CHOST} ]] \
688 && echo /usr/include \
689 || echo /usr/${CTARGET}/usr/include
692 # @FUNCTION: cross_pre_c_headers
695 # set use if necessary for cross compile support
696 cross_pre_c_headers() {
697 use headers-only && [[ ${CHOST} != ${CTARGET} ]]
700 # @FUNCTION: env_setup_xmakeopts
703 # set the ARCH/CROSS_COMPILE when cross compiling
705 env_setup_xmakeopts() {
706 # Kernel ARCH != portage ARCH
707 export KARCH=$(tc-arch-kernel)
709 # When cross-compiling, we need to set the ARCH/CROSS_COMPILE
710 # variables properly or bad things happen !
711 xmakeopts="ARCH=${KARCH}"
712 if [[ ${CTARGET} != ${CHOST} ]] && ! cross_pre_c_headers ; then
713 xmakeopts="${xmakeopts} CROSS_COMPILE=${CTARGET}-"
714 elif type -p ${CHOST}-ar > /dev/null ; then
715 xmakeopts="${xmakeopts} CROSS_COMPILE=${CHOST}-"
720 # @FUNCTION: unpack_2_4
723 # unpack and generate .config for 2.4 kernels
726 # this file is required for other things to build properly,
727 # so we autogenerate it
728 make -s mrproper ${xmakeopts} || die "make mrproper failed"
729 make -s symlinks ${xmakeopts} || die "make symlinks failed"
730 make -s include/linux/version.h ${xmakeopts} || die "make include/linux/version.h failed"
731 echo ">>> version.h compiled successfully."
734 # @FUNCTION: unpack_2_6
737 # unpack and generate .config for 2.6 kernels
740 # this file is required for other things to build properly, so we
741 # autogenerate it ... generate a .config to keep version.h build from
742 # spitting out an annoying warning
743 make -s mrproper ${xmakeopts} 2>/dev/null \
744 || die "make mrproper failed"
746 # quick fix for bug #132152 which triggers when it cannot include linux
747 # headers (ie, we have not installed it yet)
748 if ! make -s defconfig ${xmakeopts} &>/dev/null 2>&1 ; then
750 eerror "make defconfig failed."
751 eerror "assuming you dont have any headers installed yet and continuing"
755 make -s include/linux/version.h ${xmakeopts} 2>/dev/null \
756 || die "make include/linux/version.h failed"
757 rm -f .config >/dev/null
760 # @FUNCTION: universal_unpack
763 # unpack kernel sources
766 debug-print "Inside universal_unpack"
769 IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
772 if [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]]; then
773 unpack linux-${KV_MAJOR}.${KV_MINOR}.tar.xz
775 unpack linux-${OKV}.tar.xz
778 if [[ -d "linux" ]]; then
779 debug-print "Moving linux to linux-${KV_FULL}"
780 mv linux linux-${KV_FULL} \
781 || die "Unable to move source tree to ${KV_FULL}."
782 elif [[ "${OKV}" != "${KV_FULL}" ]]; then
783 if [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]] &&
784 [[ "${ETYPE}" = "sources" ]]; then
785 debug-print "moving linux-${KV_MAJOR}.${KV_MINOR} to linux-${KV_FULL} "
786 mv linux-${KV_MAJOR}.${KV_MINOR} linux-${KV_FULL} \
787 || die "Unable to move source tree to ${KV_FULL}."
789 debug-print "moving linux-${OKV} to linux-${KV_FULL} "
790 mv linux-${OKV} linux-${KV_FULL} \
791 || die "Unable to move source tree to ${KV_FULL}."
793 elif [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]]; then
794 mv linux-${KV_MAJOR}.${KV_MINOR} linux-${KV_FULL} \
795 || die "Unable to move source tree to ${KV_FULL}."
799 # remove all backup files
800 find . -iname "*~" -exec rm {} \; 2> /dev/null
804 # @FUNCTION: unpack_set_extraversion
807 # handle EXTRAVERSION
809 unpack_set_extraversion() {
811 sed -i -e "s:^\(EXTRAVERSION =\).*:\1 ${EXTRAVERSION}:" Makefile
815 # @FUNCTION: unpack_fix_install_path
818 # Should be done after patches have been applied
819 # Otherwise patches that modify the same area of Makefile will fail
821 unpack_fix_install_path() {
823 sed -i -e 's:#export\tINSTALL_PATH:export\tINSTALL_PATH:' Makefile
828 # @FUNCTION: compile_headers
836 # if we couldnt obtain HOSTCFLAGS from the Makefile,
837 # then set it to something sane
838 local HOSTCFLAGS=$(getfilevar HOSTCFLAGS "${S}"/Makefile)
839 HOSTCFLAGS=${HOSTCFLAGS:--Wall -Wstrict-prototypes -O2 -fomit-frame-pointer}
841 if kernel_is 2 4; then
842 yes "" | make oldconfig ${xmakeopts}
843 echo ">>> make oldconfig complete"
844 make dep ${xmakeopts}
845 elif kernel_is 2 6; then
846 # 2.6.18 introduces headers_install which means we dont need any
847 # of this crap anymore :D
848 kernel_is ge 2 6 18 && return 0
850 # autoconf.h isnt generated unless it already exists. plus, we have
851 # no guarantee that any headers are installed on the system...
852 [[ -f ${EROOT}usr/include/linux/autoconf.h ]] \
853 || touch include/linux/autoconf.h
855 # if K_DEFCONFIG isn't set, force to "defconfig"
857 if [[ -z ${K_DEFCONFIG} ]]; then
858 if kernel_is ge 2 6 16 ; then
860 powerpc64*) K_DEFCONFIG="ppc64_defconfig";;
861 powerpc*) K_DEFCONFIG="pmac32_defconfig";;
862 *) K_DEFCONFIG="defconfig";;
865 K_DEFCONFIG="defconfig"
869 # if there arent any installed headers, then there also isnt an asm
870 # symlink in /usr/include/, and make defconfig will fail, so we have
871 # to force an include path with $S.
872 HOSTCFLAGS="${HOSTCFLAGS} -I${S}/include/"
873 ln -sf asm-${KARCH} "${S}"/include/asm || die
874 cross_pre_c_headers && return 0
876 make ${K_DEFCONFIG} HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "defconfig failed (${K_DEFCONFIG})"
877 if compile_headers_tweak_config ; then
878 yes "" | make oldconfig HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "2nd oldconfig failed"
880 make prepare HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "prepare failed"
881 make prepare-all HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "prepare failed"
885 # @FUNCTION: compile_headers_tweak_config
888 # some targets can be very very picky, so let's finesse the
889 # .config based upon any info we may have
891 compile_headers_tweak_config() {
894 sed -i '/CONFIG_CPU_SH/d' .config || die
895 echo "CONFIG_CPU_SH${CTARGET:2:1}=y" >> .config
899 # no changes, so lets do nothing
905 # @FUNCTION: install_universal
908 # Fix permissions in tarball
910 install_universal() {
912 chown -R 0:0 * >& /dev/null
913 chmod -R a+r-w+X,u+w *
917 # @FUNCTION: install_headers
923 local ddir=$(kernel_header_destdir)
925 # 2.6.18 introduces headers_install which means we dont need any
926 # of this crap anymore :D
927 if kernel_is ge 2 6 18 ; then
929 emake headers_install INSTALL_HDR_PATH="${ED}"${ddir}/.. ${xmakeopts} || die
931 # let other packages install some of these headers
932 rm -rf "${ED}"${ddir}/scsi || die #glibc/uclibc/etc...
936 # Do not use "linux/*" as that can cause problems with very long
937 # $S values where the cmdline to cp is too long
938 pushd "${S}" >/dev/null
940 cp -pPR "${S}"/include/linux "${ED}"${ddir}/ || die
941 rm -rf "${ED}"${ddir}/linux/modules || die
944 cp -pPR "${S}"/include/asm/* "${ED}"${ddir}/asm || die
946 if kernel_is 2 6 ; then
947 dodir ${ddir}/asm-generic
948 cp -pPR "${S}"/include/asm-generic/* "${ED}"${ddir}/asm-generic || die
952 find "${D}" -name '*.orig' -exec rm -f {} \;
957 # @FUNCTION: install_sources
967 echo ">>> Copying sources ..."
969 file="$(find ${WORKDIR} -iname "docs" -type d)"
970 if [[ -n ${file} ]]; then
971 for file in $(find ${file} -type f); do
972 echo "${file//*docs\/}" >> "${S}"/patches.txt
973 echo "===================================================" >> "${S}"/patches.txt
974 cat ${file} >> "${S}"/patches.txt
975 echo "===================================================" >> "${S}"/patches.txt
976 echo "" >> "${S}"/patches.txt
980 mv "${WORKDIR}"/linux* "${ED}"usr/src || die
982 if [[ -n "${UNIPATCH_DOCS}" ]] ; then
983 for i in ${UNIPATCH_DOCS}; do
989 # @FUNCTION: preinst_headers
992 # Headers preinst steps
995 local ddir=$(kernel_header_destdir)
996 [[ -L ${EPREFIX}${ddir}/linux ]] && { rm "${EPREFIX}"${ddir}/linux || die; }
997 [[ -L ${EPREFIX}${ddir}/asm ]] && { rm "${EPREFIX}"${ddir}/asm || die; }
1000 # @FUNCTION: postinst_sources
1003 # Sources post installation function.
1004 # see inline comments
1006 postinst_sources() {
1009 # if we have USE=symlink, then force K_SYMLINK=1
1010 use symlink && K_SYMLINK=1
1012 # We do support security on a deblobbed kernel, bug #555878.
1013 # If some particular kernel version doesn't have security
1014 # supported because of USE=deblob or otherwise, one can still
1015 # set K_SECURITY_UNSUPPORTED on a per ebuild basis.
1016 #[[ $K_DEBLOB_AVAILABLE == 1 ]] && \
1018 # K_SECURITY_UNSUPPORTED=deblob
1020 # if we are to forcably symlink, delete it if it already exists first.
1021 if [[ ${K_SYMLINK} > 0 ]]; then
1022 [[ -h ${EROOT}usr/src/linux ]] && { rm "${EROOT}"usr/src/linux || die; }
1026 # if the link doesnt exist, lets create it
1027 [[ ! -h ${EROOT}usr/src/linux ]] && MAKELINK=1
1029 if [[ ${MAKELINK} == 1 ]]; then
1030 ln -sf linux-${KV_FULL} "${EROOT}"usr/src/linux || die
1033 # Don't forget to make directory for sysfs
1034 [[ ! -d ${EROOT}sys ]] && kernel_is 2 6 && { mkdir "${EROOT}"sys || die ; }
1037 elog "If you are upgrading from a previous kernel, you may be interested"
1038 elog "in the following document:"
1039 elog " - General upgrade guide: https://wiki.gentoo.org/wiki/Kernel/Upgrade"
1042 # if K_EXTRAEINFO is set then lets display it now
1043 if [[ -n ${K_EXTRAEINFO} ]]; then
1044 echo ${K_EXTRAEINFO} | fmt |
1045 while read -s ELINE; do einfo "${ELINE}"; done
1048 # if K_EXTRAELOG is set then lets display it now
1049 if [[ -n ${K_EXTRAELOG} ]]; then
1050 echo ${K_EXTRAELOG} | fmt |
1051 while read -s ELINE; do elog "${ELINE}"; done
1054 # if K_EXTRAEWARN is set then lets display it now
1055 if [[ -n ${K_EXTRAEWARN} ]]; then
1056 echo ${K_EXTRAEWARN} | fmt |
1057 while read -s ELINE; do ewarn "${ELINE}"; done
1060 # optionally display security unsupported message
1062 if [[ -n ${K_SECURITY_UNSUPPORTED} ]]; then
1063 ewarn "${PN} is UNSUPPORTED by Gentoo Security."
1065 # And now the general message.
1066 if [[ -n ${K_SECURITY_UNSUPPORTED} ]]; then
1067 ewarn "This means that it is likely to be vulnerable to recent security issues."
1069 ewarn "Upstream kernel developers recommend always running the latest "
1070 ewarn "release of any current long term supported Linux kernel version."
1071 ewarn "To see a list of these versions, their most current release and "
1072 ewarn "long term support status, please go to https://www.kernel.org ."
1074 ewarn "For specific information on why this kernel is unsupported, please read:"
1075 ewarn "https://wiki.gentoo.org/wiki/Project:Kernel_Security"
1078 # warn sparc users that they need to do cross-compiling with >= 2.6.25(bug #214765)
1079 KV_MAJOR=$(get_version_component_range 1 ${OKV})
1080 KV_MINOR=$(get_version_component_range 2 ${OKV})
1081 KV_PATCH=$(get_version_component_range 3 ${OKV})
1082 if [[ "$(tc-arch)" = "sparc" ]]; then
1083 if [[ $(gcc-major-version) -lt 4 && $(gcc-minor-version) -lt 4 ]]; then
1084 if [[ ${KV_MAJOR} -ge 3 || ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} > 2.6.24 ]] ; then
1086 elog "NOTE: Since 2.6.25 the kernel Makefile has changed in a way that"
1087 elog "you now need to do"
1088 elog " make CROSS_COMPILE=sparc64-unknown-linux-gnu-"
1089 elog "instead of just"
1091 elog "to compile the kernel. For more information please browse to"
1092 elog "https://bugs.gentoo.org/show_bug.cgi?id=214765"
1099 # pkg_setup functions
1101 # @FUNCTION: setup_headers
1104 # Determine if ${PN} supports arch
1107 [[ -z ${H_SUPPORTEDARCH} ]] && H_SUPPORTEDARCH=${PN/-*/}
1108 for i in ${H_SUPPORTEDARCH}; do
1109 [[ $(tc-arch) == "${i}" ]] && H_ACCEPT_ARCH="yes"
1112 if [[ ${H_ACCEPT_ARCH} != "yes" ]]; then
1114 eerror "This version of ${PN} does not support $(tc-arch)."
1115 eerror "Please merge the appropriate sources, in most cases"
1116 eerror "(but not all) this will be called $(tc-arch)-headers."
1117 die "Package unsupported for $(tc-arch)"
1121 # @FUNCTION: unipatch
1122 # @USAGE: <list of patches to apply>
1124 # Universal function that will apply patches to source
1127 local i x y z extention PIPE_CMD UNIPATCH_DROP KPATCH_DIR PATCH_DEPTH ELINE
1128 local STRICT_COUNT PATCH_LEVEL myLC_ALL myLANG
1130 # set to a standard locale to ensure sorts are ordered properly.
1131 myLC_ALL="${LC_ALL}"
1136 [ -z "${KPATCH_DIR}" ] && KPATCH_DIR="${WORKDIR}/patches/"
1137 [ ! -d ${KPATCH_DIR} ] && mkdir -p ${KPATCH_DIR}
1139 # We're gonna need it when doing patches with a predefined patchlevel
1140 eshopts_push -s extglob
1142 # This function will unpack all passed tarballs, add any passed patches,
1143 # and remove any passed patchnumbers
1144 # usage can be either via an env var or by params
1145 # although due to the nature we pass this within this eclass
1146 # it shall be by param only.
1147 # -z "${UNIPATCH_LIST}" ] && UNIPATCH_LIST="${@}"
1148 UNIPATCH_LIST="${@}"
1150 #unpack any passed tarballs
1151 for i in ${UNIPATCH_LIST}; do
1152 if echo ${i} | grep -qs -e "\.tar" -e "\.tbz" -e "\.tgz" ; then
1153 if [ -n "${UNIPATCH_STRICTORDER}" ]; then
1155 STRICT_COUNT=$((10#${STRICT_COUNT} + 1))
1156 for((y=0; y<$((6 - ${#STRICT_COUNT})); y++));
1159 PATCH_ORDER="${z}${STRICT_COUNT}"
1161 mkdir -p "${KPATCH_DIR}/${PATCH_ORDER}"
1162 pushd "${KPATCH_DIR}/${PATCH_ORDER}" >/dev/null
1166 pushd "${KPATCH_DIR}" >/dev/null
1171 [[ ${i} == *:* ]] && echo ">>> Strict patch levels not currently supported for tarballed patchsets"
1174 extention=${extention/:*/}
1176 case ${extention} in
1177 xz) PIPE_CMD="xz -dc";;
1178 lzma) PIPE_CMD="lzma -dc";;
1179 bz2) PIPE_CMD="bzip2 -dc";;
1180 patch*) PIPE_CMD="cat";;
1181 diff) PIPE_CMD="cat";;
1182 gz|Z|z) PIPE_CMD="gzip -dc";;
1183 ZIP|zip) PIPE_CMD="unzip -p";;
1184 *) UNIPATCH_DROP="${UNIPATCH_DROP} ${i/:*/}";;
1187 PATCH_LEVEL=${i/*([^:])?(:)}
1190 x=${x/\.${extention}/}
1192 if [ -n "${PIPE_CMD}" ]; then
1193 if [ ! -r "${i}" ]; then
1195 eerror "FATAL: unable to locate:"
1197 eerror "for read-only. The file either has incorrect permissions"
1198 eerror "or does not exist."
1199 die Unable to locate ${i}
1202 if [ -n "${UNIPATCH_STRICTORDER}" ]; then
1204 STRICT_COUNT=$((10#${STRICT_COUNT} + 1))
1205 for((y=0; y<$((6 - ${#STRICT_COUNT})); y++));
1208 PATCH_ORDER="${z}${STRICT_COUNT}"
1210 mkdir -p ${KPATCH_DIR}/${PATCH_ORDER}/
1211 $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${PATCH_ORDER}/${x}.patch${PATCH_LEVEL}) || die "uncompressing patch failed"
1213 $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${x}.patch${PATCH_LEVEL}) || die "uncompressing patch failed"
1218 # If experimental was not chosen by the user, drop experimental patches not in K_EXP_GENPATCHES_LIST.
1219 if [[ "${i}" == *"genpatches-"*".experimental."* && -n ${K_EXP_GENPATCHES_PULL} ]] ; then
1220 if [[ -z ${K_EXP_GENPATCHES_NOUSE} ]] && use experimental; then
1225 for j in ${KPATCH_DIR}/*/50*_*.patch*; do
1226 for k in ${K_EXP_GENPATCHES_LIST} ; do
1227 [[ "$(basename ${j})" == ${k}* ]] && continue 2
1229 UNIPATCH_DROP+=" $(basename ${j})"
1232 UNIPATCH_LIST_GENPATCHES+=" ${DISTDIR}/${tarball}"
1233 debug-print "genpatches tarball: $tarball"
1235 # check gcc version < 4.9.X uses patch 5000 and = 4.9.X uses patch 5010
1236 if [[ $(gcc-major-version) -eq 4 ]] && [[ $(gcc-minor-version) -ne 9 ]]; then
1237 # drop 5000_enable-additional-cpu-optimizations-for-gcc-4.9.patch
1238 if [[ $UNIPATCH_DROP != *"5010_enable-additional-cpu-optimizations-for-gcc-4.9.patch"* ]]; then
1239 UNIPATCH_DROP+=" 5010_enable-additional-cpu-optimizations-for-gcc-4.9.patch"
1242 if [[ $UNIPATCH_DROP != *"5000_enable-additional-cpu-optimizations-for-gcc.patch"* ]]; then
1243 #drop 5000_enable-additional-cpu-optimizations-for-gcc.patch
1244 UNIPATCH_DROP+=" 5000_enable-additional-cpu-optimizations-for-gcc.patch"
1250 #populate KPATCH_DIRS so we know where to look to remove the excludes
1253 for i in $(find ${x} -type d | sort -n); do
1254 KPATCH_DIR="${KPATCH_DIR} ${i}"
1257 # do not apply fbcondecor patch to sparc/sparc64 as it breaks boot
1259 if [[ "$(tc-arch)" = "sparc" || "$(tc-arch)" = "sparc64" ]]; then
1260 if [[ ${KV_MAJOR} -ge 3 || ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} > 2.6.28 ]]; then
1261 UNIPATCH_DROP="${UNIPATCH_DROP} *_fbcondecor-0.9.6.patch"
1263 ewarn "fbcondecor currently prevents sparc/sparc64 from booting"
1264 ewarn "for kernel versions >= 2.6.29. Removing fbcondecor patch."
1265 ewarn "See https://bugs.gentoo.org/show_bug.cgi?id=272676 for details"
1270 #so now lets get rid of the patchno's we want to exclude
1271 UNIPATCH_DROP="${UNIPATCH_EXCLUDE} ${UNIPATCH_DROP}"
1272 for i in ${UNIPATCH_DROP}; do
1273 ebegin "Excluding Patch #${i}"
1274 for x in ${KPATCH_DIR}; do rm -f ${x}/${i}* 2>/dev/null; done
1278 # and now, finally, we patch it :)
1279 for x in ${KPATCH_DIR}; do
1280 for i in $(find ${x} -maxdepth 1 -iname "*.patch*" -or -iname "*.diff*" | sort -n); do
1281 STDERR_T="${T}/${i/*\//}"
1282 STDERR_T="${STDERR_T/.patch*/.err}"
1284 [ -z ${i/*.patch*/} ] && PATCH_DEPTH=${i/*.patch/}
1285 #[ -z ${i/*.diff*/} ] && PATCH_DEPTH=${i/*.diff/}
1287 if [ -z "${PATCH_DEPTH}" ]; then PATCH_DEPTH=0; fi
1289 ####################################################################
1290 # IMPORTANT: This is temporary code to support Linux git 3.15_rc1! #
1292 # The patch contains a removal of a symlink, followed by addition #
1293 # of a file with the same name as the symlink in the same #
1294 # location; this causes the dry-run to fail, filed bug #507656. #
1296 # https://bugs.gentoo.org/show_bug.cgi?id=507656 #
1297 ####################################################################
1298 if [[ -n ${K_FROM_GIT} ]] ; then
1299 if [[ ${KV_MAJOR} -gt 3 || ( ${KV_MAJOR} -eq 3 && ${KV_PATCH} -gt 15 ) &&
1300 ${RELEASETYPE} == -rc ]] ; then
1301 ebegin "Applying ${i/*\//} (-p1)"
1302 if [ $(patch -p1 --no-backup-if-mismatch -f < ${i} >> ${STDERR_T}) "$?" -le 2 ]; then
1304 rm ${STDERR_T} || die
1308 eerror "Failed to apply patch ${i/*\//}"
1309 eerror "Please attach ${STDERR_T} to any bug you may post."
1311 die "Failed to apply ${i/*\//} on patch depth 1."
1315 ####################################################################
1317 while [ ${PATCH_DEPTH} -lt 5 ]; do
1318 echo "Attempting Dry-run:" >> ${STDERR_T}
1319 echo "cmd: patch -p${PATCH_DEPTH} --no-backup-if-mismatch --dry-run -f < ${i}" >> ${STDERR_T}
1320 echo "=======================================================" >> ${STDERR_T}
1321 if [ $(patch -p${PATCH_DEPTH} --no-backup-if-mismatch --dry-run -f < ${i} >> ${STDERR_T}) $? -eq 0 ]; then
1322 ebegin "Applying ${i/*\//} (-p${PATCH_DEPTH})"
1323 echo "Attempting patch:" > ${STDERR_T}
1324 echo "cmd: patch -p${PATCH_DEPTH} --no-backup-if-mismatch -f < ${i}" >> ${STDERR_T}
1325 echo "=======================================================" >> ${STDERR_T}
1326 if [ $(patch -p${PATCH_DEPTH} --no-backup-if-mismatch -f < ${i} >> ${STDERR_T}) "$?" -eq 0 ]; then
1328 rm ${STDERR_T} || die
1332 eerror "Failed to apply patch ${i/*\//}"
1333 eerror "Please attach ${STDERR_T} to any bug you may post."
1335 die "Failed to apply ${i/*\//} on patch depth ${PATCH_DEPTH}."
1338 PATCH_DEPTH=$((${PATCH_DEPTH} + 1))
1341 if [ ${PATCH_DEPTH} -eq 5 ]; then
1342 eerror "Failed to dry-run patch ${i/*\//}"
1343 eerror "Please attach ${STDERR_T} to any bug you may post."
1345 die "Unable to dry-run patch on any patch depth lower than 5."
1350 # When genpatches is used, we want to install 0000_README which documents
1351 # the patches that were used; such that the user can see them, bug #301478.
1352 if [[ ! -z ${K_WANT_GENPATCHES} ]] ; then
1353 UNIPATCH_DOCS="${UNIPATCH_DOCS} 0000_README"
1356 # When files listed in UNIPATCH_DOCS are found in KPATCH_DIR's, we copy it
1357 # to the temporary directory and remember them in UNIPATCH_DOCS to install
1358 # them during the install phase.
1360 for x in ${KPATCH_DIR}; do
1361 for i in ${UNIPATCH_DOCS}; do
1362 if [[ -f ${x}/${i} ]] ; then
1364 cp -f "${x}/${i}" "${T}"/ || die
1368 UNIPATCH_DOCS="${tmp}"
1370 # clean up KPATCH_DIR's - fixes bug #53610
1371 for x in ${KPATCH_DIR}; do rm -Rf ${x}; done
1373 LC_ALL="${myLC_ALL}"
1378 # @FUNCTION: getfilevar
1379 # @USAGE: <variable> <configfile>
1381 # pulled from linux-info
1384 local workingdir basefname basedname xarch=$(tc-arch-kernel)
1386 if [[ -z ${1} ]] && [[ ! -f ${2} ]]; then
1388 eerror "getfilevar requires 2 variables, with the second a valid file."
1389 eerror " getfilevar <VARIABLE> <CONFIGFILE>"
1392 basefname=$(basename ${2})
1393 basedname=$(dirname ${2})
1397 echo -e "include ${basefname}\ne:\n\t@echo \$(${1})" | \
1398 make ${BUILD_FIXES} -s -f - e 2>/dev/null
1405 # @FUNCTION: detect_arch
1408 # This function sets ARCH_URI and ARCH_PATCH
1409 # with the neccessary info for the arch sepecific compatibility
1414 local ALL_ARCH LOOP_ARCH LOOP_ARCH_L COMPAT_URI i TC_ARCH_KERNEL
1416 # COMPAT_URI is the contents of ${ARCH}_URI
1417 # ARCH_URI is the URI for all the ${ARCH}_URI patches
1418 # ARCH_PATCH is ARCH_URI broken into files for UNIPATCH
1423 ALL_ARCH="ALPHA AMD64 ARM HPPA IA64 M68K MIPS PPC PPC64 S390 SH SPARC X86"
1425 for LOOP_ARCH in ${ALL_ARCH}; do
1426 COMPAT_URI="${LOOP_ARCH}_URI"
1427 COMPAT_URI="${!COMPAT_URI}"
1429 declare -l LOOP_ARCH_L=${LOOP_ARCH}
1431 [[ -n ${COMPAT_URI} ]] && \
1432 ARCH_URI="${ARCH_URI} ${LOOP_ARCH_L}? ( ${COMPAT_URI} )"
1434 declare -u TC_ARCH_KERNEL=$(tc-arch-kernel)
1435 if [[ ${LOOP_ARCH} == ${TC_ARCH_KERNEL} ]]; then
1436 for i in ${COMPAT_URI}; do
1437 ARCH_PATCH="${ARCH_PATCH} ${DISTDIR}/${i/*\//}"
1444 # @FUNCTION: headers___fix
1447 # Voodoo to partially fix broken upstream headers.
1448 # note: do not put inline/asm/volatile together (breaks "inline asm volatile")
1452 -e '/^\#define.*_TYPES_H/{:loop n; bloop}' \
1453 -e 's:\<\([us]\(8\|16\|32\|64\)\)\>:__\1:g' \
1454 -e "s/\([[:space:]]\)inline\([[:space:](]\)/\1__inline__\2/g" \
1455 -e "s/\([[:space:]]\)asm\([[:space:](]\)/\1__asm__\2/g" \
1456 -e "s/\([[:space:]]\)volatile\([[:space:](]\)/\1__volatile__\2/g" \
1460 # @FUNCTION: kernel-2_src_unpack
1463 # unpack sources, handle genpatches, deblob
1465 kernel-2_src_unpack() {
1467 debug-print "Doing unipatch"
1469 # request UNIPATCH_LIST_GENPATCHES in phase since it calls 'use'
1470 handle_genpatches --set-unipatch-list
1471 [[ -n ${UNIPATCH_LIST} || -n ${UNIPATCH_LIST_DEFAULT} || -n ${UNIPATCH_LIST_GENPATCHES} ]] && \
1472 unipatch "${UNIPATCH_LIST_DEFAULT} ${UNIPATCH_LIST_GENPATCHES} ${UNIPATCH_LIST}"
1474 debug-print "Doing premake"
1476 # allow ebuilds to massage the source tree after patching but before
1477 # we run misc `make` functions below
1478 [[ $(type -t kernel-2_hook_premake) == "function" ]] && kernel-2_hook_premake
1481 0|1) kernel-2_src_prepare ;;
1484 debug-print "Doing unpack_set_extraversion"
1486 [[ -z ${K_NOSETEXTRAVERSION} ]] && unpack_set_extraversion
1487 unpack_fix_install_path
1489 # Setup xmakeopts and cd into sourcetree.
1493 # We dont need a version.h for anything other than headers
1494 # at least, I should hope we dont. If this causes problems
1495 # take out the if/fi block and inform me please.
1496 # unpack_2_6 should now be 2.6.17 safe anyways
1497 if [[ ${ETYPE} == headers ]]; then
1498 kernel_is 2 4 && unpack_2_4
1499 kernel_is 2 6 && unpack_2_6
1502 if [[ $K_DEBLOB_AVAILABLE == 1 ]] && use deblob ; then
1503 cp "${DISTDIR}/${DEBLOB_A}" "${T}" || die "cp ${DEBLOB_A} failed"
1504 cp "${DISTDIR}/${DEBLOB_CHECK_A}" "${T}/deblob-check" || die "cp ${DEBLOB_CHECK_A} failed"
1505 chmod +x "${T}/${DEBLOB_A}" "${T}/deblob-check" || die "chmod deblob scripts failed"
1508 # fix a problem on ppc where TOUT writes to /usr/src/linux breaking sandbox
1509 # only do this for kernel < 2.6.27 since this file does not exist in later
1511 if [[ -n ${KV_MINOR} && ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} < 2.6.27 ]] ; then
1513 -e 's|TOUT := .tmp_gas_check|TOUT := $(T).tmp_gas_check|' \
1514 "${S}"/arch/ppc/Makefile
1517 -e 's|TOUT := .tmp_gas_check|TOUT := $(T).tmp_gas_check|' \
1518 "${S}"/arch/powerpc/Makefile
1522 # @FUNCTION: kernel-2_src_prepare
1525 # Apply any user patches
1527 kernel-2_src_prepare() {
1529 debug-print "Applying any user patches"
1531 # apply any user patches
1533 0|1|2|3|4|5) epatch_user ;;
1538 # @FUNCTION: kernel-2_src_compile
1541 # conpile headers or run deblob script
1543 kernel-2_src_compile() {
1545 [[ ${ETYPE} == headers ]] && compile_headers
1547 if [[ $K_DEBLOB_AVAILABLE == 1 ]] && use deblob ; then
1548 echo ">>> Running deblob script ..."
1550 sh "${T}/${DEBLOB_A}" --force || die "Deblob script failed to run!!!"
1554 # @FUNCTION: kernel-2_src_test
1557 # if you leave it to the default src_test, it will run make to
1558 # find whether test/check targets are present; since "make test"
1559 # actually produces a few support files, they are installed even
1560 # though the package is binchecks-restricted.
1562 # Avoid this altogether by making the function moot.
1563 kernel-2_src_test() { :; }
1565 # @FUNCTION: kernel-2_pkg_preinst
1567 # if ETYPE = headers, call preinst_headers
1569 kernel-2_pkg_preinst() {
1570 [[ ${ETYPE} == headers ]] && preinst_headers
1573 # @FUNCTION: kernel-2_src_install
1576 # Install headers or sources dependant on ETYPE
1578 kernel-2_src_install() {
1580 [[ ${ETYPE} == headers ]] && install_headers
1581 [[ ${ETYPE} == sources ]] && install_sources
1584 # @FUNCTION: kernel-2_pkg_postinst
1587 # call postinst_sources for ETYPE = sources
1589 kernel-2_pkg_postinst() {
1590 [[ ${ETYPE} == sources ]] && postinst_sources
1593 # @FUNCTION: kernel-2_pkg_setup
1596 # check for supported kernel version, die if ETYPE is unknown, call setup_headers
1599 kernel-2_pkg_setup() {
1600 if kernel_is 2 4; then
1601 if [[ $(gcc-major-version) -ge 4 ]] ; then
1603 ewarn "Be warned !! >=sys-devel/gcc-4.0.0 isn't supported with linux-2.4!"
1604 ewarn "Either switch to another gcc-version (via gcc-config) or use a"
1605 ewarn "newer kernel that supports gcc-4."
1607 ewarn "Also be aware that bugreports about gcc-4 not working"
1608 ewarn "with linux-2.4 based ebuilds will be closed as INVALID!"
1615 if [[ ${ETYPE} != sources ]] && [[ ${ETYPE} != headers ]]; then
1616 eerror "Unknown ETYPE=\"${ETYPE}\", must be \"sources\" or \"headers\""
1617 die "Unknown ETYPE=\"${ETYPE}\", must be \"sources\" or \"headers\""
1620 [[ ${ETYPE} == headers ]] && setup_headers
1621 [[ ${ETYPE} == sources ]] && echo ">>> Preparing to unpack ..."
1624 # @FUNCTION: kernel-2_pkg_postrm
1627 # Notify the user that after a depclean, there may be sources
1628 # left behind that need to be manually cleaned
1630 kernel-2_pkg_postrm() {
1631 # This warning only makes sense for kernel sources.
1632 [[ ${ETYPE} == headers ]] && return 0
1634 # If there isn't anything left behind, then don't complain.
1635 [[ -e ${EROOT}usr/src/linux-${KV_FULL} ]] || return 0
1637 ewarn "Note: Even though you have successfully unmerged "
1638 ewarn "your kernel package, directories in kernel source location: "
1639 ewarn "${EROOT}usr/src/linux-${KV_FULL}"
1640 ewarn "with modified files will remain behind. By design, package managers"
1641 ewarn "will not remove these modified files and the directories they reside in."
1643 ewarn "For more detailed kernel removal instructions, please see: "
1644 ewarn "https://wiki.gentoo.org/wiki/Kernel/Removal"