1 # Copyright 1999-2019 Gentoo Authors
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 # @SUPPORTED_EAPIS: 2 3 4 5 6
12 # @BLURB: Eclass for kernel packages
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.
20 # @ECLASS-VARIABLE: K_USEPV
23 # When setting the EXTRAVERSION variable, it should
25 # this is useful for things like wolk. IE:
26 # EXTRAVERSION would be something like : -wolk-4.19-r1
28 # @ECLASS-VARIABLE: K_NOSETEXTRAVERSION
31 # if this is set then EXTRAVERSION will not be
32 # automatically set within the kernel Makefile
34 # @ECLASS-VARIABLE: K_NOUSENAME
37 # if this is set then EXTRAVERSION will not include the
38 # first part of ${PN} in EXTRAVERSION
40 # @ECLASS-VARIABLE: K_NOUSEPR
43 # if this is set then EXTRAVERSION will not include the
44 # anything based on ${PR}.
46 # @ECLASS-VARIABLE: K_PREPATCHED
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
54 # @ECLASS-VARIABLE: K_EXTRAEINFO
57 # this is a new-line seperated list of einfo displays in
58 # postinst and can be used to carry additional postinst
61 # @ECLASS-VARIABLE: K_EXTRAELOG
64 # same as K_EXTRAEINFO except using elog instead of einfo
66 # @ECLASS-VARIABLE: K_EXTRAEWARN
69 # same as K_EXTRAEINFO except using ewarn instead of einfo
71 # @ECLASS-VARIABLE: K_SYMLINK
74 # if this is set, then forcably create symlink anyway
76 # @ECLASS-VARIABLE: K_BASE_VER
79 # for git-sources, declare the base version this patch is
82 # @ECLASS-VARIABLE: K_DEFCONFIG
85 # Allow specifying a different defconfig target.
86 # If length zero, defaults to "defconfig".
88 # @ECLASS-VARIABLE: K_WANT_GENPATCHES
91 # Apply genpatches to kernel source. Provide any
92 # combination of "base", "extras" or "experimental".
94 # @ECLASS-VARIABLE: K_EXP_GENPATCHES_PULL
97 # If set, we pull "experimental" regardless of the USE FLAG
98 # but expect the ebuild maintainer to use K_EXP_GENPATCHES_LIST.
100 # @ECLASS-VARIABLE: K_EXP_GENPATCHES_NOUSE
103 # If set, no USE flag will be provided for "experimental";
104 # as a result the user cannot choose to apply those patches.
106 # @ECLASS-VARIABLE: K_EXP_GENPATCHES_LIST
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.
112 # @ECLASS-VARIABLE: K_FROM_GIT
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.
119 # @ECLASS-VARIABLE: K_GENPATCHES_VER
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
126 # @ECLASS-VARIABLE: K_SECURITY_UNSUPPORTED
129 # If set, this kernel is unsupported by Gentoo Security
130 # to the current eclass maintainer :)
132 # @ECLASS-VARIABLE: K_DEBLOB_AVAILABLE
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".
139 # @ECLASS-VARIABLE: K_DEBLOB_TAG
142 # This will be the version of deblob script. It's a upstream SVN tag
143 # such asw -gnu or -gnu1.
145 # @ECLASS-VARIABLE: K_PREDEBLOBBED
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.
152 # @ECLASS-VARIABLE: K_LONGTERM
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
159 # @ECLASS-VARIABLE: H_SUPPORTEDARCH
162 # this should be a space separated list of ARCH's which
163 # can be supported by the headers ebuild
165 # @ECLASS-VARIABLE: UNIPATCH_LIST
168 # space delimetered list of patches to be applied to the kernel
170 # @ECLASS-VARIABLE: UNIPATCH_EXCLUDE
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
178 # @ECLASS-VARIABLE: UNIPATCH_DOCS
181 # space delimemeted list of docs to be installed to
184 # @ECLASS-VARIABLE: UNIPATCH_STRICTORDER
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.
194 inherit toolchain-funcs
195 [[ ${EAPI:-0} == [012345] ]] && inherit epatch
196 [[ ${EAPI:-0} == [0123456] ]] && inherit estack eapi7-ver
199 EXPORT_FUNCTIONS src_{unpack,prepare,compile,install,test} \
200 pkg_{setup,preinst,postinst,postrm} ;;
201 *) die "${ECLASS}: EAPI ${EAPI} not supported" ;;
204 # Added by Daniel Ostrow <dostrow@gentoo.org>
205 # This is an ugly hack to get around an issue with a 32-bit userland on ppc64.
206 # I will remove it when I come up with something more reasonable.
207 [[ ${PROFILE_ARCH} == "ppc64" ]] && CHOST="powerpc64-${CHOST#*-}"
209 export CTARGET=${CTARGET:-${CHOST}}
210 if [[ ${CTARGET} == ${CHOST} && ${CATEGORY/cross-} != ${CATEGORY} ]]; then
211 export CTARGET=${CATEGORY/cross-}
214 HOMEPAGE="https://www.kernel.org/ https://wiki.gentoo.org/wiki/Kernel ${HOMEPAGE}"
215 : ${LICENSE:="GPL-2"}
217 # This is the latest KV_PATCH of the deblob tool available from the
218 # libre-sources upstream. If you bump this, you MUST regenerate the Manifests
219 # for ALL kernel-2 consumer packages where deblob is available.
220 : ${DEBLOB_MAX_VERSION:=38}
222 # No need to run scanelf/strip on kernel sources/headers (bug #134453).
223 RESTRICT="binchecks strip"
225 # set LINUX_HOSTCFLAGS if not already set
226 : ${LINUX_HOSTCFLAGS:="-Wall -Wstrict-prototypes -Os -fomit-frame-pointer -I${S}/include"}
229 # @FUNCTION: debug-print-kernel2-variables
232 # this function exists only to help debug kernel-2.eclass
233 # if you are adding new functionality in, put a call to it
234 # at the start of src_unpack, or during SRC_URI/dep generation.
236 debug-print-kernel2-variables() {
237 for v in PVR CKV OKV KV KV_FULL KV_MAJOR KV_MINOR KV_PATCH RELEASETYPE \
238 RELEASE UNIPATCH_LIST_DEFAULT UNIPATCH_LIST_GENPATCHES \
239 UNIPATCH_LIST S KERNEL_URI K_WANT_GENPATCHES ; do
240 debug-print "${v}: ${!v}"
244 # @FUNCTION: handle_genpatches
245 # @USAGE: [--set-unipatch-list]
247 # add genpatches to list of patches to apply if wanted
249 handle_genpatches() {
250 local tarball want_unipatch_list
251 [[ -z ${K_WANT_GENPATCHES} || -z ${K_GENPATCHES_VER} ]] && return 1
253 if [[ -n ${1} ]]; then
254 # set UNIPATCH_LIST_GENPATCHES only on explicit request
255 # since that requires 'use' call which can be used only in phase
256 # functions, while the function is also called in global scope
257 if [[ ${1} == --set-unipatch-list ]]; then
260 die "Usage: ${FUNCNAME} [--set-unipatch-list]"
264 debug-print "Inside handle_genpatches"
266 IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
268 # for > 3.0 kernels, handle genpatches tarball name
269 # genpatches for 3.0 and 3.0.1 might be named
270 # genpatches-3.0-1.base.tar.xz and genpatches-3.0-2.base.tar.xz
271 # respectively. Handle this.
273 for i in ${K_WANT_GENPATCHES} ; do
274 if [[ ${KV_MAJOR} -ge 3 ]]; then
275 if [[ ${#OKV_ARRAY[@]} -ge 3 ]]; then
276 tarball="genpatches-${KV_MAJOR}.${KV_MINOR}-${K_GENPATCHES_VER}.${i}.tar.xz"
278 tarball="genpatches-${KV_MAJOR}.${KV_PATCH}-${K_GENPATCHES_VER}.${i}.tar.xz"
281 tarball="genpatches-${OKV}-${K_GENPATCHES_VER}.${i}.tar.xz"
284 local use_cond_start="" use_cond_end=""
286 if [[ "${i}" == "experimental" && -z ${K_EXP_GENPATCHES_PULL} && -z ${K_EXP_GENPATCHES_NOUSE} ]] ; then
287 use_cond_start="experimental? ( "
290 if [[ -n ${want_unipatch_list} ]] && use experimental ; then
291 UNIPATCH_LIST_GENPATCHES+=" ${DISTDIR}/${tarball}"
292 debug-print "genpatches tarball: $tarball"
294 elif [[ -n ${want_unipatch_list} ]]; then
295 UNIPATCH_LIST_GENPATCHES+=" ${DISTDIR}/${tarball}"
296 debug-print "genpatches tarball: $tarball"
298 GENPATCHES_URI+=" ${use_cond_start}$(echo https://dev.gentoo.org/~{alicef,mpagano,whissi}/dist/genpatches/${tarball})${use_cond_end}"
302 # @FUNCTION: detect_version
305 # this function will detect and set
306 # - OKV: Original Kernel Version (2.6.0/2.6.0-test11)
307 # - KV: Kernel Version (2.6.0-gentoo/2.6.0-test11-gentoo-r1)
308 # - EXTRAVERSION: The additional version appended to OKV (-gentoo/-gentoo-r1)
311 # We've already run, so nothing to do here.
312 [[ -n ${KV_FULL} ]] && return 0
314 # CKV is used as a comparison kernel version, which is used when
315 # PV doesnt reflect the genuine kernel version.
316 # this gets set to the portage style versioning. ie:
320 OKV=${OKV/_beta/-test}
325 KV_MAJOR=$(ver_cut 1 ${OKV})
326 # handle if OKV is X.Y or X.Y.Z (e.g. 3.0 or 3.0.1)
328 IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
330 # if KV_MAJOR >= 3, then we have no more KV_MINOR
331 #if [[ ${KV_MAJOR} -lt 3 ]]; then
332 if [[ ${#OKV_ARRAY[@]} -ge 3 ]]; then
333 KV_MINOR=$(ver_cut 2 ${OKV})
334 KV_PATCH=$(ver_cut 3 ${OKV})
335 if [[ ${KV_MAJOR}${KV_MINOR}${KV_PATCH} -ge 269 ]]; then
336 KV_EXTRA=$(ver_cut 4- ${OKV})
337 KV_EXTRA=${KV_EXTRA/[-_]*}
339 KV_PATCH=$(ver_cut 3- ${OKV})
342 KV_PATCH=$(ver_cut 2 ${OKV})
343 KV_EXTRA=$(ver_cut 3- ${OKV})
344 KV_EXTRA=${KV_EXTRA/[-_]*}
347 debug-print "KV_EXTRA is ${KV_EXTRA}"
349 KV_PATCH=${KV_PATCH/[-_]*}
352 #if [[ ${KV_MAJOR} -lt 3 ]]; then
353 if [[ ${#OKV_ARRAY[@]} -ge 3 ]]; then
354 for v in CKV OKV KV_{MAJOR,MINOR,PATCH} ; do
355 [[ -z ${!v} ]] && n=1 && missing="${missing}${v} ";
358 for v in CKV OKV KV_{MAJOR,PATCH} ; do
359 [[ -z ${!v} ]] && n=1 && missing="${missing}${v} ";
364 eerror "Missing variables: ${missing}" && \
365 die "Failed to extract kernel version (try explicit CKV in ebuild)!"
368 # if [[ ${KV_MAJOR} -ge 3 ]]; then
369 if [[ ${#OKV_ARRAY[@]} -lt 3 ]]; then
370 KV_PATCH_ARR=(${KV_PATCH//\./ })
372 # at this point 031412, Linus is putting all 3.x kernels in a
373 # 3.x directory, may need to revisit when 4.x is released
374 KERNEL_BASE_URI="https://www.kernel.org/pub/linux/kernel/v${KV_MAJOR}.x"
376 [[ -n "${K_LONGTERM}" ]] &&
377 KERNEL_BASE_URI="${KERNEL_BASE_URI}/longterm/v${KV_MAJOR}.${KV_PATCH_ARR}"
379 #KERNEL_BASE_URI="https://www.kernel.org/pub/linux/kernel/v${KV_MAJOR}.0"
380 #KERNEL_BASE_URI="https://www.kernel.org/pub/linux/kernel/v${KV_MAJOR}.${KV_MINOR}"
381 if [[ ${KV_MAJOR} -ge 3 ]]; then
382 KERNEL_BASE_URI="https://www.kernel.org/pub/linux/kernel/v${KV_MAJOR}.x"
384 KERNEL_BASE_URI="https://www.kernel.org/pub/linux/kernel/v${KV_MAJOR}.${KV_MINOR}"
387 [[ -n "${K_LONGTERM}" ]] &&
388 #KERNEL_BASE_URI="${KERNEL_BASE_URI}/longterm"
389 KERNEL_BASE_URI="${KERNEL_BASE_URI}/longterm/v${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
392 debug-print "KERNEL_BASE_URI is ${KERNEL_BASE_URI}"
394 if [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]]; then
395 # handle non genpatch using sources correctly
396 if [[ -z ${K_WANT_GENPATCHES} && -z ${K_GENPATCHES_VER} && ${KV_PATCH} -gt 0 ]]; then
397 KERNEL_URI="${KERNEL_BASE_URI}/patch-${OKV}.xz"
398 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV}.xz"
400 KERNEL_URI="${KERNEL_URI} ${KERNEL_BASE_URI}/linux-${KV_MAJOR}.${KV_MINOR}.tar.xz"
402 KERNEL_URI="${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
405 RELEASE=${CKV/${OKV}}
406 RELEASE=${RELEASE/_beta}
407 RELEASE=${RELEASE/_rc/-rc}
408 RELEASE=${RELEASE/_pre/-pre}
409 # We cannot trivally call kernel_is here, because it calls us to detect the
411 #kernel_is ge 2 6 && RELEASE=${RELEASE/-pre/-git}
412 [ $(($KV_MAJOR * 1000 + ${KV_MINOR:-0})) -ge 2006 ] && RELEASE=${RELEASE/-pre/-git}
413 RELEASETYPE=${RELEASE//[0-9]}
415 # Now we know that RELEASE is the -rc/-git
416 # and RELEASETYPE is the same but with its numerics stripped
417 # we can work on better sorting EXTRAVERSION.
418 # first of all, we add the release
419 EXTRAVERSION="${RELEASE}"
420 debug-print "0 EXTRAVERSION:${EXTRAVERSION}"
421 [[ -n ${KV_EXTRA} ]] && [[ ${KV_MAJOR} -lt 3 ]] && EXTRAVERSION=".${KV_EXTRA}${EXTRAVERSION}"
423 debug-print "1 EXTRAVERSION:${EXTRAVERSION}"
424 if [[ -n "${K_NOUSEPR}" ]]; then
425 # Don't add anything based on PR to EXTRAVERSION
426 debug-print "1.0 EXTRAVERSION:${EXTRAVERSION}"
427 elif [[ -n ${K_PREPATCHED} ]]; then
428 debug-print "1.1 EXTRAVERSION:${EXTRAVERSION}"
429 EXTRAVERSION="${EXTRAVERSION}-${PN/-*}${PR/r}"
430 elif [[ "${ETYPE}" = "sources" ]]; then
431 debug-print "1.2 EXTRAVERSION:${EXTRAVERSION}"
432 # For some sources we want to use the PV in the extra version
433 # This is because upstream releases with a completely different
440 [[ -z "${K_NOUSENAME}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*}"
441 [[ -n "${K_USEPV}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PV//_/-}"
442 [[ -n "${PR//r0}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PR}"
444 debug-print "2 EXTRAVERSION:${EXTRAVERSION}"
446 # The only messing around which should actually effect this is for KV_EXTRA
447 # since this has to limit OKV to MAJ.MIN.PAT and strip EXTRA off else
448 # KV_FULL evaluates to MAJ.MIN.PAT.EXT.EXT after EXTRAVERSION
450 if [[ -n ${KV_EXTRA} ]]; then
451 if [[ -n ${KV_MINOR} ]]; then
452 OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
454 OKV="${KV_MAJOR}.${KV_PATCH}"
456 KERNEL_URI="${KERNEL_BASE_URI}/patch-${CKV}.xz
457 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
458 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV}.xz"
461 # We need to set this using OKV, but we need to set it before we do any
462 # messing around with OKV based on RELEASETYPE
463 KV_FULL=${OKV}${EXTRAVERSION}
465 # we will set this for backwards compatibility.
466 S="${WORKDIR}"/linux-${KV_FULL}
469 # -rc-git pulls can be achieved by specifying CKV
471 # CKV="2.6.11_rc3_pre2"
473 # linux-2.6.10.tar.xz & patch-2.6.11-rc3.xz & patch-2.6.11-rc3-git2.xz
475 if [[ ${KV_MAJOR}${KV_MINOR} -eq 26 ]]; then
477 if [[ ${RELEASETYPE} == -rc ]] || [[ ${RELEASETYPE} == -pre ]]; then
478 OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))"
479 KERNEL_URI="${KERNEL_BASE_URI}/testing/patch-${CKV//_/-}.xz
480 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
481 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV//_/-}.xz"
484 if [[ ${RELEASETYPE} == -git ]]; then
485 KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${OKV}${RELEASE}.xz
486 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
487 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${OKV}${RELEASE}.xz"
490 if [[ ${RELEASETYPE} == -rc-git ]]; then
491 OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))"
492 KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.xz
493 ${KERNEL_BASE_URI}/testing/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE/-git*}.xz
494 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
496 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 KV_PATCH_ARR=(${KV_PATCH//\./ })
501 # the different majorminor versions have different patch start versions
502 OKV_DICT=(["2"]="${KV_MAJOR}.$((${KV_PATCH_ARR} - 1))" ["3"]="2.6.39" ["4"]="3.19")
504 if [[ ${RELEASETYPE} == -rc ]] || [[ ${RELEASETYPE} == -pre ]]; then
506 OKV=${K_BASE_VER:-$OKV_DICT["${KV_MAJOR}"]}
508 # as of 12/5/2017, the rc patch is no longer offered as a compressed
509 # file, and no longer is it mirrored on kernel.org
510 if ver_test "${KV_MAJOR}.${KV_PATCH}" -ge "4.12"; then
511 KERNEL_URI="https://git.kernel.org/torvalds/p/v${KV_FULL}/v${OKV} -> patch-${KV_FULL}.patch
512 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
513 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV//_/-}.patch"
515 KERNEL_URI="${KERNEL_BASE_URI}/testing/patch-${CKV//_/-}.xz
516 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
517 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV//_/-}.xz"
521 if [[ ${RELEASETYPE} == -git ]]; then
522 KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${OKV}${RELEASE}.xz
523 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
524 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${OKV}${RELEASE}.xz"
527 if [[ ${RELEASETYPE} == -rc-git ]]; then
528 OKV=${K_BASE_VER:-$OKV_DICT["${KV_MAJOR}"]}
529 KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE}.xz
530 ${KERNEL_BASE_URI}/testing/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE/-git*}.xz
531 ${KERNEL_BASE_URI}/linux-${OKV}.tar.xz"
533 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE/-git*}.xz ${DISTDIR}/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE}.xz"
539 debug-print-kernel2-variables
544 # @FUNCTION: kernel_is
545 # @USAGE: <conditional version | version>
547 # user for comparing kernel versions
548 # or just identifying a version
550 # e.g kernel_is ge 4.8.11
551 # Note: duplicated in linux-info.eclass
553 # ALL of these should be set before we can safely continue this function.
554 # some of the sources have in the past had only one set.
556 for v in OKV KV_{MAJOR,MINOR,PATCH} ; do [[ -z ${!v} ]] && n=1 ; done
557 [[ $n -eq 1 ]] && detect_version
560 # Now we can continue
561 local operator test value
564 lt) operator="-lt"; shift;;
565 gt) operator="-gt"; shift;;
566 le) operator="-le"; shift;;
567 ge) operator="-ge"; shift;;
568 eq) operator="-eq"; shift;;
571 [[ $# -gt 3 ]] && die "Error in kernel-2_kernel_is(): too many parameters"
573 : $(( test = (KV_MAJOR << 16) + (KV_MINOR << 8) + KV_PATCH ))
574 : $(( value = (${1:-${KV_MAJOR}} << 16) + (${2:-${KV_MINOR}} << 8) + ${3:-${KV_PATCH}} ))
575 [ ${test} ${operator} ${value} ]
578 # @FUNCTION: kernel_is_2_4
581 # return true if kernel is version 2.4
586 # @FUNCTION: kernel_is_2_6
589 # return true if kernel is version 2.6
591 kernel_is 2 6 || kernel_is 2 5
594 # Capture the sources type and set DEPENDs
595 if [[ ${ETYPE} == sources ]]; then
598 >=sys-devel/binutils-2.11.90.0.31
606 >=sys-libs/ncurses-5.2
611 DESCRIPTION="Sources based on the Linux Kernel."
614 # Bug #266157, deblob for libre support
615 if [[ -z ${K_PREDEBLOBBED} ]] ; then
616 # Bug #359865, force a call to detect_version if needed
617 kernel_is ge 2 6 27 && \
618 [[ -z "${K_DEBLOB_AVAILABLE}" ]] && \
619 kernel_is le 2 6 ${DEBLOB_MAX_VERSION} && \
621 if [[ ${K_DEBLOB_AVAILABLE} == "1" ]] ; then
622 PYTHON_COMPAT=( python2_7 )
624 inherit python-any-r1
626 IUSE="${IUSE} deblob"
628 # Reflect that kernels contain firmware blobs unless otherwise
629 # stripped. Starting with version 4.14, the whole firmware
630 # tree has been dropped from the kernel.
631 kernel_is lt 4 14 && LICENSE+=" !deblob? ( linux-firmware )"
633 DEPEND+=" deblob? ( ${PYTHON_DEPS} )"
635 if [[ -n KV_MINOR ]]; then
636 DEBLOB_PV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
638 DEBLOB_PV="${KV_MAJOR}.${KV_PATCH}"
641 if [[ ${KV_MAJOR} -ge 3 ]]; then
642 DEBLOB_PV="${KV_MAJOR}.${KV_MINOR}"
645 # deblob svn tag, default is -gnu, to change, use K_DEBLOB_TAG in ebuild
646 K_DEBLOB_TAG=${K_DEBLOB_TAG:--gnu}
647 DEBLOB_A="deblob-${DEBLOB_PV}"
648 DEBLOB_CHECK_A="deblob-check-${DEBLOB_PV}"
649 DEBLOB_HOMEPAGE="https://www.fsfla.org/svn/fsfla/software/linux-libre/releases/tags/"
650 DEBLOB_URI_PATH="${DEBLOB_PV}${K_DEBLOB_TAG}"
651 DEBLOB_CHECK_URI="${DEBLOB_HOMEPAGE}/${DEBLOB_URI_PATH}/deblob-check -> ${DEBLOB_CHECK_A}"
652 DEBLOB_URI="${DEBLOB_HOMEPAGE}/${DEBLOB_URI_PATH}/${DEBLOB_A}"
653 HOMEPAGE="${HOMEPAGE} ${DEBLOB_HOMEPAGE}"
655 KERNEL_URI="${KERNEL_URI}
660 elif kernel_is lt 4 14; then
661 # Deblobbing is not available, so just mark kernels older
662 # than 4.14 as tainted with non-libre materials.
663 LICENSE+=" linux-firmware"
667 elif [[ ${ETYPE} == headers ]]; then
668 DESCRIPTION="Linux system headers"
671 # Since we should NOT honour KBUILD_OUTPUT in headers
672 # lets unset it here.
678 # Cross-compile support functions
680 # @FUNCTION: kernel_header_destdir
683 # return header destination directory
684 kernel_header_destdir() {
685 [[ ${CTARGET} == ${CHOST} ]] \
686 && echo /usr/include \
687 || echo /usr/${CTARGET}/usr/include
690 # @FUNCTION: cross_pre_c_headers
693 # set use if necessary for cross compile support
694 cross_pre_c_headers() {
695 use headers-only && [[ ${CHOST} != ${CTARGET} ]]
698 # @FUNCTION: env_setup_xmakeopts
701 # set the ARCH/CROSS_COMPILE when cross compiling
703 env_setup_xmakeopts() {
704 # Kernel ARCH != portage ARCH
705 export KARCH=$(tc-arch-kernel)
707 # When cross-compiling, we need to set the ARCH/CROSS_COMPILE
708 # variables properly or bad things happen !
709 xmakeopts="ARCH=${KARCH}"
710 if [[ ${CTARGET} != ${CHOST} ]] && ! cross_pre_c_headers ; then
711 xmakeopts="${xmakeopts} CROSS_COMPILE=${CTARGET}-"
712 elif type -p ${CHOST}-ar > /dev/null ; then
713 xmakeopts="${xmakeopts} CROSS_COMPILE=${CHOST}-"
718 # @FUNCTION: unpack_2_4
721 # unpack and generate .config for 2.4 kernels
724 # this file is required for other things to build properly,
725 # so we autogenerate it
726 make -s mrproper ${xmakeopts} || die "make mrproper failed"
727 make -s symlinks ${xmakeopts} || die "make symlinks failed"
728 make -s include/linux/version.h ${xmakeopts} || die "make include/linux/version.h failed"
729 echo ">>> version.h compiled successfully."
732 # @FUNCTION: unpack_2_6
735 # unpack and generate .config for 2.6 kernels
738 # this file is required for other things to build properly, so we
739 # autogenerate it ... generate a .config to keep version.h build from
740 # spitting out an annoying warning
741 make -s mrproper ${xmakeopts} 2>/dev/null \
742 || die "make mrproper failed"
744 # quick fix for bug #132152 which triggers when it cannot include linux
745 # headers (ie, we have not installed it yet)
746 if ! make -s defconfig ${xmakeopts} &>/dev/null 2>&1 ; then
748 eerror "make defconfig failed."
749 eerror "assuming you dont have any headers installed yet and continuing"
752 make -s include/linux/version.h ${xmakeopts} 2>/dev/null \
753 || die "make include/linux/version.h failed"
754 rm -f .config >/dev/null
757 # @FUNCTION: universal_unpack
760 # unpack kernel sources
763 debug-print "Inside universal_unpack"
766 IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
769 if [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]]; then
770 unpack linux-${KV_MAJOR}.${KV_MINOR}.tar.xz
772 unpack linux-${OKV}.tar.xz
775 if [[ -d "linux" ]]; then
776 debug-print "Moving linux to linux-${KV_FULL}"
777 mv linux linux-${KV_FULL} \
778 || die "Unable to move source tree to ${KV_FULL}."
779 elif [[ "${OKV}" != "${KV_FULL}" ]]; then
780 if [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]] &&
781 [[ "${ETYPE}" = "sources" ]]; then
782 debug-print "moving linux-${KV_MAJOR}.${KV_MINOR} to linux-${KV_FULL} "
783 mv linux-${KV_MAJOR}.${KV_MINOR} linux-${KV_FULL} \
784 || die "Unable to move source tree to ${KV_FULL}."
786 debug-print "moving linux-${OKV} to linux-${KV_FULL} "
787 mv linux-${OKV} linux-${KV_FULL} \
788 || die "Unable to move source tree to ${KV_FULL}."
790 elif [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]]; then
791 mv linux-${KV_MAJOR}.${KV_MINOR} linux-${KV_FULL} \
792 || die "Unable to move source tree to ${KV_FULL}."
796 # remove all backup files
797 find . -iname "*~" -exec rm {} \; 2> /dev/null
801 # @FUNCTION: unpack_set_extraversion
804 # handle EXTRAVERSION
806 unpack_set_extraversion() {
808 sed -i -e "s:^\(EXTRAVERSION =\).*:\1 ${EXTRAVERSION}:" Makefile
812 # @FUNCTION: unpack_fix_install_path
815 # Should be done after patches have been applied
816 # Otherwise patches that modify the same area of Makefile will fail
818 unpack_fix_install_path() {
820 sed -i -e 's:#export\tINSTALL_PATH:export\tINSTALL_PATH:' Makefile
825 # @FUNCTION: compile_headers
833 # if we couldnt obtain HOSTCFLAGS from the Makefile,
834 # then set it to something sane
835 local HOSTCFLAGS=$(getfilevar HOSTCFLAGS "${S}"/Makefile)
836 HOSTCFLAGS=${HOSTCFLAGS:--Wall -Wstrict-prototypes -O2 -fomit-frame-pointer}
838 if kernel_is 2 4; then
839 yes "" | make oldconfig ${xmakeopts}
840 echo ">>> make oldconfig complete"
841 make dep ${xmakeopts}
842 elif kernel_is 2 6; then
843 # 2.6.18 introduces headers_install which means we dont need any
844 # of this crap anymore :D
845 kernel_is ge 2 6 18 && return 0
847 # autoconf.h isnt generated unless it already exists. plus, we have
848 # no guarantee that any headers are installed on the system...
849 [[ -f ${EROOT}usr/include/linux/autoconf.h ]] \
850 || touch include/linux/autoconf.h
852 # if K_DEFCONFIG isn't set, force to "defconfig"
854 if [[ -z ${K_DEFCONFIG} ]]; then
855 if kernel_is ge 2 6 16 ; then
857 powerpc64*) K_DEFCONFIG="ppc64_defconfig";;
858 powerpc*) K_DEFCONFIG="pmac32_defconfig";;
859 *) K_DEFCONFIG="defconfig";;
862 K_DEFCONFIG="defconfig"
866 # if there arent any installed headers, then there also isnt an asm
867 # symlink in /usr/include/, and make defconfig will fail, so we have
868 # to force an include path with $S.
869 HOSTCFLAGS="${HOSTCFLAGS} -I${S}/include/"
870 ln -sf asm-${KARCH} "${S}"/include/asm || die
871 cross_pre_c_headers && return 0
873 make ${K_DEFCONFIG} HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "defconfig failed (${K_DEFCONFIG})"
874 if compile_headers_tweak_config ; then
875 yes "" | make oldconfig HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "2nd oldconfig failed"
877 make prepare HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "prepare failed"
878 make prepare-all HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "prepare failed"
882 # @FUNCTION: compile_headers_tweak_config
885 # some targets can be very very picky, so let's finesse the
886 # .config based upon any info we may have
888 compile_headers_tweak_config() {
891 sed -i '/CONFIG_CPU_SH/d' .config || die
892 echo "CONFIG_CPU_SH${CTARGET:2:1}=y" >> .config
896 # no changes, so lets do nothing
902 # @FUNCTION: install_universal
905 # Fix permissions in tarball
907 install_universal() {
909 chown -R 0:0 * >& /dev/null
910 chmod -R a+r-w+X,u+w *
914 # @FUNCTION: install_headers
920 local ddir=$(kernel_header_destdir)
922 # 2.6.18 introduces headers_install which means we dont need any
923 # of this crap anymore :D
924 if kernel_is ge 2 6 18 ; then
926 emake headers_install INSTALL_HDR_PATH="${ED}"${ddir}/.. ${xmakeopts} || die
928 # let other packages install some of these headers
929 rm -rf "${ED}"${ddir}/scsi || die #glibc/uclibc/etc...
933 # Do not use "linux/*" as that can cause problems with very long
934 # $S values where the cmdline to cp is too long
935 pushd "${S}" >/dev/null
937 cp -pPR "${S}"/include/linux "${ED}"${ddir}/ || die
938 rm -rf "${ED}"${ddir}/linux/modules || die
941 cp -pPR "${S}"/include/asm/* "${ED}"${ddir}/asm || die
943 if kernel_is 2 6 ; then
944 dodir ${ddir}/asm-generic
945 cp -pPR "${S}"/include/asm-generic/* "${ED}"${ddir}/asm-generic || die
949 find "${D}" -name '*.orig' -exec rm -f {} \;
954 # @FUNCTION: install_sources
964 echo ">>> Copying sources ..."
966 file="$(find ${WORKDIR} -iname "docs" -type d)"
967 if [[ -n ${file} ]]; then
968 for file in $(find ${file} -type f); do
969 echo "${file//*docs\/}" >> "${S}"/patches.txt
970 echo "===================================================" >> "${S}"/patches.txt
971 cat ${file} >> "${S}"/patches.txt
972 echo "===================================================" >> "${S}"/patches.txt
973 echo "" >> "${S}"/patches.txt
977 mv "${WORKDIR}"/linux* "${ED}"usr/src || die
979 if [[ -n "${UNIPATCH_DOCS}" ]] ; then
980 for i in ${UNIPATCH_DOCS}; do
986 # @FUNCTION: preinst_headers
989 # Headers preinst steps
992 local ddir=$(kernel_header_destdir)
993 [[ -L ${EPREFIX}${ddir}/linux ]] && { rm "${EPREFIX}"${ddir}/linux || die; }
994 [[ -L ${EPREFIX}${ddir}/asm ]] && { rm "${EPREFIX}"${ddir}/asm || die; }
997 # @FUNCTION: postinst_sources
1000 # Sources post installation function.
1001 # see inline comments
1003 postinst_sources() {
1006 # if we have USE=symlink, then force K_SYMLINK=1
1007 use symlink && K_SYMLINK=1
1009 # We do support security on a deblobbed kernel, bug #555878.
1010 # If some particular kernel version doesn't have security
1011 # supported because of USE=deblob or otherwise, one can still
1012 # set K_SECURITY_UNSUPPORTED on a per ebuild basis.
1013 #[[ $K_DEBLOB_AVAILABLE == 1 ]] && \
1015 # K_SECURITY_UNSUPPORTED=deblob
1017 # if we are to forcably symlink, delete it if it already exists first.
1018 if [[ ${K_SYMLINK} > 0 ]]; then
1019 [[ -h ${EROOT}usr/src/linux ]] && { rm "${EROOT}"usr/src/linux || die; }
1023 # if the link doesnt exist, lets create it
1024 [[ ! -h ${EROOT}usr/src/linux ]] && MAKELINK=1
1026 if [[ ${MAKELINK} == 1 ]]; then
1027 ln -sf linux-${KV_FULL} "${EROOT}"usr/src/linux || die
1030 # Don't forget to make directory for sysfs
1031 [[ ! -d ${EROOT}sys ]] && kernel_is 2 6 && { mkdir "${EROOT}"sys || die ; }
1034 elog "If you are upgrading from a previous kernel, you may be interested"
1035 elog "in the following document:"
1036 elog " - General upgrade guide: https://wiki.gentoo.org/wiki/Kernel/Upgrade"
1039 # if K_EXTRAEINFO is set then lets display it now
1040 if [[ -n ${K_EXTRAEINFO} ]]; then
1041 echo ${K_EXTRAEINFO} | fmt |
1042 while read -s ELINE; do einfo "${ELINE}"; done
1045 # if K_EXTRAELOG is set then lets display it now
1046 if [[ -n ${K_EXTRAELOG} ]]; then
1047 echo ${K_EXTRAELOG} | fmt |
1048 while read -s ELINE; do elog "${ELINE}"; done
1051 # if K_EXTRAEWARN is set then lets display it now
1052 if [[ -n ${K_EXTRAEWARN} ]]; then
1053 echo ${K_EXTRAEWARN} | fmt |
1054 while read -s ELINE; do ewarn "${ELINE}"; done
1057 # optionally display security unsupported message
1059 if [[ -n ${K_SECURITY_UNSUPPORTED} ]]; then
1060 ewarn "${PN} is UNSUPPORTED by Gentoo Security."
1062 # And now the general message.
1063 if [[ -n ${K_SECURITY_UNSUPPORTED} ]]; then
1064 ewarn "This means that it is likely to be vulnerable to recent security issues."
1066 ewarn "Upstream kernel developers recommend always running the latest "
1067 ewarn "release of any current long term supported Linux kernel version."
1068 ewarn "To see a list of these versions, their most current release and "
1069 ewarn "long term support status, please go to https://www.kernel.org ."
1071 ewarn "For specific information on why this kernel is unsupported, please read:"
1072 ewarn "https://wiki.gentoo.org/wiki/Project:Kernel_Security"
1075 # warn sparc users that they need to do cross-compiling with >= 2.6.25(bug #214765)
1076 KV_MAJOR=$(ver_cut 1 ${OKV})
1077 KV_MINOR=$(ver_cut 2 ${OKV})
1078 KV_PATCH=$(ver_cut 3 ${OKV})
1079 if [[ "$(tc-arch)" = "sparc" ]]; then
1080 if [[ $(gcc-major-version) -lt 4 && $(gcc-minor-version) -lt 4 ]]; then
1081 if [[ ${KV_MAJOR} -ge 3 || ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} > 2.6.24 ]] ; then
1083 elog "NOTE: Since 2.6.25 the kernel Makefile has changed in a way that"
1084 elog "you now need to do"
1085 elog " make CROSS_COMPILE=sparc64-unknown-linux-gnu-"
1086 elog "instead of just"
1088 elog "to compile the kernel. For more information please browse to"
1089 elog "https://bugs.gentoo.org/show_bug.cgi?id=214765"
1096 # pkg_setup functions
1098 # @FUNCTION: setup_headers
1101 # Determine if ${PN} supports arch
1104 [[ -z ${H_SUPPORTEDARCH} ]] && H_SUPPORTEDARCH=${PN/-*/}
1105 for i in ${H_SUPPORTEDARCH}; do
1106 [[ $(tc-arch) == "${i}" ]] && H_ACCEPT_ARCH="yes"
1109 if [[ ${H_ACCEPT_ARCH} != "yes" ]]; then
1111 eerror "This version of ${PN} does not support $(tc-arch)."
1112 eerror "Please merge the appropriate sources, in most cases"
1113 eerror "(but not all) this will be called $(tc-arch)-headers."
1114 die "Package unsupported for $(tc-arch)"
1118 # @FUNCTION: unipatch
1119 # @USAGE: <list of patches to apply>
1121 # Universal function that will apply patches to source
1124 local i x y z extention PIPE_CMD UNIPATCH_DROP KPATCH_DIR PATCH_DEPTH ELINE
1125 local STRICT_COUNT PATCH_LEVEL myLC_ALL myLANG
1127 # set to a standard locale to ensure sorts are ordered properly.
1128 myLC_ALL="${LC_ALL}"
1133 [ -z "${KPATCH_DIR}" ] && KPATCH_DIR="${WORKDIR}/patches/"
1134 [ ! -d ${KPATCH_DIR} ] && mkdir -p ${KPATCH_DIR}
1136 # We're gonna need it when doing patches with a predefined patchlevel
1137 eshopts_push -s extglob
1139 # This function will unpack all passed tarballs, add any passed patches,
1140 # and remove any passed patchnumbers
1141 # usage can be either via an env var or by params
1142 # although due to the nature we pass this within this eclass
1143 # it shall be by param only.
1144 # -z "${UNIPATCH_LIST}" ] && UNIPATCH_LIST="${@}"
1145 UNIPATCH_LIST="${@}"
1147 #unpack any passed tarballs
1148 for i in ${UNIPATCH_LIST}; do
1149 if echo ${i} | grep -qs -e "\.tar" -e "\.tbz" -e "\.tgz" ; then
1150 if [ -n "${UNIPATCH_STRICTORDER}" ]; then
1152 STRICT_COUNT=$((10#${STRICT_COUNT} + 1))
1153 for((y=0; y<$((6 - ${#STRICT_COUNT})); y++));
1156 PATCH_ORDER="${z}${STRICT_COUNT}"
1158 mkdir -p "${KPATCH_DIR}/${PATCH_ORDER}"
1159 pushd "${KPATCH_DIR}/${PATCH_ORDER}" >/dev/null
1163 pushd "${KPATCH_DIR}" >/dev/null
1168 [[ ${i} == *:* ]] && echo ">>> Strict patch levels not currently supported for tarballed patchsets"
1171 extention=${extention/:*/}
1173 case ${extention} in
1174 xz) PIPE_CMD="xz -dc";;
1175 lzma) PIPE_CMD="lzma -dc";;
1176 bz2) PIPE_CMD="bzip2 -dc";;
1177 patch*) PIPE_CMD="cat";;
1178 diff) PIPE_CMD="cat";;
1179 gz|Z|z) PIPE_CMD="gzip -dc";;
1180 ZIP|zip) PIPE_CMD="unzip -p";;
1181 *) UNIPATCH_DROP="${UNIPATCH_DROP} ${i/:*/}";;
1184 PATCH_LEVEL=${i/*([^:])?(:)}
1187 x=${x/\.${extention}/}
1189 if [ -n "${PIPE_CMD}" ]; then
1190 if [ ! -r "${i}" ]; then
1192 eerror "FATAL: unable to locate:"
1194 eerror "for read-only. The file either has incorrect permissions"
1195 eerror "or does not exist."
1196 die Unable to locate ${i}
1199 if [ -n "${UNIPATCH_STRICTORDER}" ]; then
1201 STRICT_COUNT=$((10#${STRICT_COUNT} + 1))
1202 for((y=0; y<$((6 - ${#STRICT_COUNT})); y++));
1205 PATCH_ORDER="${z}${STRICT_COUNT}"
1207 mkdir -p ${KPATCH_DIR}/${PATCH_ORDER}/
1208 $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${PATCH_ORDER}/${x}.patch${PATCH_LEVEL}) || die "uncompressing patch failed"
1210 $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${x}.patch${PATCH_LEVEL}) || die "uncompressing patch failed"
1215 # If experimental was not chosen by the user, drop experimental patches not in K_EXP_GENPATCHES_LIST.
1216 if [[ "${i}" == *"genpatches-"*".experimental."* && -n ${K_EXP_GENPATCHES_PULL} ]] ; then
1217 if [[ -z ${K_EXP_GENPATCHES_NOUSE} ]] && use experimental; then
1222 for j in ${KPATCH_DIR}/*/50*_*.patch*; do
1223 for k in ${K_EXP_GENPATCHES_LIST} ; do
1224 [[ "$(basename ${j})" == ${k}* ]] && continue 2
1226 UNIPATCH_DROP+=" $(basename ${j})"
1229 UNIPATCH_LIST_GENPATCHES+=" ${DISTDIR}/${tarball}"
1230 debug-print "genpatches tarball: $tarball"
1232 local GCC_MAJOR_VER=$(gcc-major-version)
1233 local GCC_MINOR_VER=$(gcc-minor-version)
1235 # optimization patch for gcc < 8.X and kernel > 4.13
1236 if kernel_is ge 4 13 ; then
1237 if [[ ${GCC_MAJOR_VER} -lt 8 ]] && [[ ${GCC_MAJOR_VER} -gt 4 ]]; then
1238 UNIPATCH_DROP+=" 5011_enable-cpu-optimizations-for-gcc8.patch"
1239 UNIPATCH_DROP+=" 5012_enable-cpu-optimizations-for-gcc91.patch"
1240 # optimization patch for gcc >= 8 and kernel ge 4.13
1241 elif [[ "${GCC_MAJOR_VER}" -eq 8 ]]; then
1242 # support old kernels for a period. For now, remove as all gcc versions required are masked
1243 UNIPATCH_DROP+=" 5010_enable-additional-cpu-optimizations-for-gcc.patch"
1244 UNIPATCH_DROP+=" 5010_enable-additional-cpu-optimizations-for-gcc-4.9.patch"
1245 UNIPATCH_DROP+=" 5012_enable-cpu-optimizations-for-gcc91.patch"
1246 elif [[ "${GCC_MAJOR_VER}" -eq 9 ]] && [[ ${GCC_MINOR_VER} -ge 1 ]]; then
1247 UNIPATCH_DROP+=" 5010_enable-additional-cpu-optimizations-for-gcc.patch"
1248 UNIPATCH_DROP+=" 5010_enable-additional-cpu-optimizations-for-gcc-4.9.patch"
1249 UNIPATCH_DROP+=" 5011_enable-cpu-optimizations-for-gcc8.patch"
1251 UNIPATCH_DROP+=" 5010_enable-additional-cpu-optimizations-for-gcc.patch"
1252 UNIPATCH_DROP+=" 5010_enable-additional-cpu-optimizations-for-gcc-4.9.patch"
1253 UNIPATCH_DROP+=" 5011_enable-cpu-optimizations-for-gcc8.patch"
1254 UNIPATCH_DROP+=" 5012_enable-cpu-optimizations-for-gcc91.patch"
1257 UNIPATCH_DROP+=" 5010_enable-additional-cpu-optimizations-for-gcc.patch"
1258 UNIPATCH_DROP+=" 5010_enable-additional-cpu-optimizations-for-gcc-4.9.patch"
1259 UNIPATCH_DROP+=" 5011_enable-cpu-optimizations-for-gcc8.patch"
1260 UNIPATCH_DROP+=" 5012_enable-cpu-optimizations-for-gcc91.patch"
1265 #populate KPATCH_DIRS so we know where to look to remove the excludes
1268 for i in $(find ${x} -type d | sort -n); do
1269 KPATCH_DIR="${KPATCH_DIR} ${i}"
1272 # do not apply fbcondecor patch to sparc/sparc64 as it breaks boot
1274 if [[ "$(tc-arch)" = "sparc" || "$(tc-arch)" = "sparc64" ]]; then
1275 if [[ ${KV_MAJOR} -ge 3 || ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} > 2.6.28 ]]; then
1276 if [[ ! -z ${K_WANT_GENPATCHES} ]] ; then
1277 UNIPATCH_DROP="${UNIPATCH_DROP} *_fbcondecor*.patch"
1279 ewarn "fbcondecor currently prevents sparc/sparc64 from booting"
1280 ewarn "for kernel versions >= 2.6.29. Removing fbcondecor patch."
1281 ewarn "See https://bugs.gentoo.org/show_bug.cgi?id=272676 for details"
1287 #so now lets get rid of the patchno's we want to exclude
1288 UNIPATCH_DROP="${UNIPATCH_EXCLUDE} ${UNIPATCH_DROP}"
1289 for i in ${UNIPATCH_DROP}; do
1290 ebegin "Excluding Patch #${i}"
1291 for x in ${KPATCH_DIR}; do rm -f ${x}/${i}* 2>/dev/null; done
1295 # and now, finally, we patch it :)
1296 for x in ${KPATCH_DIR}; do
1297 for i in $(find ${x} -maxdepth 1 -iname "*.patch*" -or -iname "*.diff*" | sort -n); do
1298 STDERR_T="${T}/${i/*\//}"
1299 STDERR_T="${STDERR_T/.patch*/.err}"
1301 [ -z ${i/*.patch*/} ] && PATCH_DEPTH=${i/*.patch/}
1302 #[ -z ${i/*.diff*/} ] && PATCH_DEPTH=${i/*.diff/}
1304 if [ -z "${PATCH_DEPTH}" ]; then PATCH_DEPTH=0; fi
1306 ####################################################################
1307 # IMPORTANT: This is temporary code to support Linux git 3.15_rc1! #
1309 # The patch contains a removal of a symlink, followed by addition #
1310 # of a file with the same name as the symlink in the same #
1311 # location; this causes the dry-run to fail, filed bug #507656. #
1313 # https://bugs.gentoo.org/show_bug.cgi?id=507656 #
1314 ####################################################################
1315 if [[ -n ${K_FROM_GIT} ]] ; then
1316 if [[ ${KV_MAJOR} -gt 3 || ( ${KV_MAJOR} -eq 3 && ${KV_PATCH} -gt 15 ) &&
1317 ${RELEASETYPE} == -rc ]] ; then
1318 ebegin "Applying ${i/*\//} (-p1)"
1319 if [ $(patch -p1 --no-backup-if-mismatch -f < ${i} >> ${STDERR_T}) "$?" -le 2 ]; then
1321 rm ${STDERR_T} || die
1325 eerror "Failed to apply patch ${i/*\//}"
1326 eerror "Please attach ${STDERR_T} to any bug you may post."
1328 die "Failed to apply ${i/*\//} on patch depth 1."
1332 ####################################################################
1334 while [ ${PATCH_DEPTH} -lt 5 ]; do
1335 echo "Attempting Dry-run:" >> ${STDERR_T}
1336 echo "cmd: patch -p${PATCH_DEPTH} --no-backup-if-mismatch --dry-run -f < ${i}" >> ${STDERR_T}
1337 echo "=======================================================" >> ${STDERR_T}
1338 if [ $(patch -p${PATCH_DEPTH} --no-backup-if-mismatch --dry-run -f < ${i} >> ${STDERR_T}) $? -eq 0 ]; then
1339 ebegin "Applying ${i/*\//} (-p${PATCH_DEPTH})"
1340 echo "Attempting patch:" > ${STDERR_T}
1341 echo "cmd: patch -p${PATCH_DEPTH} --no-backup-if-mismatch -f < ${i}" >> ${STDERR_T}
1342 echo "=======================================================" >> ${STDERR_T}
1343 if [ $(patch -p${PATCH_DEPTH} --no-backup-if-mismatch -f < ${i} >> ${STDERR_T}) "$?" -eq 0 ]; then
1345 rm ${STDERR_T} || die
1349 eerror "Failed to apply patch ${i/*\//}"
1350 eerror "Please attach ${STDERR_T} to any bug you may post."
1352 die "Failed to apply ${i/*\//} on patch depth ${PATCH_DEPTH}."
1355 PATCH_DEPTH=$((${PATCH_DEPTH} + 1))
1358 if [ ${PATCH_DEPTH} -eq 5 ]; then
1359 eerror "Failed to dry-run patch ${i/*\//}"
1360 eerror "Please attach ${STDERR_T} to any bug you may post."
1362 die "Unable to dry-run patch on any patch depth lower than 5."
1367 # When genpatches is used, we want to install 0000_README which documents
1368 # the patches that were used; such that the user can see them, bug #301478.
1369 if [[ ! -z ${K_WANT_GENPATCHES} ]] ; then
1370 UNIPATCH_DOCS="${UNIPATCH_DOCS} 0000_README"
1373 # When files listed in UNIPATCH_DOCS are found in KPATCH_DIR's, we copy it
1374 # to the temporary directory and remember them in UNIPATCH_DOCS to install
1375 # them during the install phase.
1377 for x in ${KPATCH_DIR}; do
1378 for i in ${UNIPATCH_DOCS}; do
1379 if [[ -f ${x}/${i} ]] ; then
1381 cp -f "${x}/${i}" "${T}"/ || die
1385 UNIPATCH_DOCS="${tmp}"
1387 # clean up KPATCH_DIR's - fixes bug #53610
1388 for x in ${KPATCH_DIR}; do rm -Rf ${x}; done
1390 LC_ALL="${myLC_ALL}"
1395 # @FUNCTION: getfilevar
1396 # @USAGE: <variable> <configfile>
1398 # pulled from linux-info
1401 local workingdir basefname basedname xarch=$(tc-arch-kernel)
1403 if [[ -z ${1} ]] && [[ ! -f ${2} ]]; then
1405 eerror "getfilevar requires 2 variables, with the second a valid file."
1406 eerror " getfilevar <VARIABLE> <CONFIGFILE>"
1409 basefname=$(basename ${2})
1410 basedname=$(dirname ${2})
1414 echo -e "include ${basefname}\ne:\n\t@echo \$(${1})" | \
1415 make ${BUILD_FIXES} -s -f - e 2>/dev/null
1422 # @FUNCTION: detect_arch
1425 # This function sets ARCH_URI and ARCH_PATCH
1426 # with the neccessary info for the arch sepecific compatibility
1431 local ALL_ARCH LOOP_ARCH LOOP_ARCH_L COMPAT_URI i TC_ARCH_KERNEL
1433 # COMPAT_URI is the contents of ${ARCH}_URI
1434 # ARCH_URI is the URI for all the ${ARCH}_URI patches
1435 # ARCH_PATCH is ARCH_URI broken into files for UNIPATCH
1440 ALL_ARCH="ALPHA AMD64 ARM HPPA IA64 M68K MIPS PPC PPC64 S390 SH SPARC X86"
1442 for LOOP_ARCH in ${ALL_ARCH}; do
1443 COMPAT_URI="${LOOP_ARCH}_URI"
1444 COMPAT_URI="${!COMPAT_URI}"
1446 declare -l LOOP_ARCH_L=${LOOP_ARCH}
1448 [[ -n ${COMPAT_URI} ]] && \
1449 ARCH_URI="${ARCH_URI} ${LOOP_ARCH_L}? ( ${COMPAT_URI} )"
1451 declare -u TC_ARCH_KERNEL=$(tc-arch-kernel)
1452 if [[ ${LOOP_ARCH} == ${TC_ARCH_KERNEL} ]]; then
1453 for i in ${COMPAT_URI}; do
1454 ARCH_PATCH="${ARCH_PATCH} ${DISTDIR}/${i/*\//}"
1461 # @FUNCTION: headers___fix
1464 # Voodoo to partially fix broken upstream headers.
1465 # note: do not put inline/asm/volatile together (breaks "inline asm volatile")
1469 -e '/^\#define.*_TYPES_H/{:loop n; bloop}' \
1470 -e 's:\<\([us]\(8\|16\|32\|64\)\)\>:__\1:g' \
1471 -e "s/\([[:space:]]\)inline\([[:space:](]\)/\1__inline__\2/g" \
1472 -e "s/\([[:space:]]\)asm\([[:space:](]\)/\1__asm__\2/g" \
1473 -e "s/\([[:space:]]\)volatile\([[:space:](]\)/\1__volatile__\2/g" \
1477 # @FUNCTION: kernel-2_src_unpack
1480 # unpack sources, handle genpatches, deblob
1482 kernel-2_src_unpack() {
1484 debug-print "Doing unipatch"
1486 # request UNIPATCH_LIST_GENPATCHES in phase since it calls 'use'
1487 handle_genpatches --set-unipatch-list
1488 [[ -n ${UNIPATCH_LIST} || -n ${UNIPATCH_LIST_DEFAULT} || -n ${UNIPATCH_LIST_GENPATCHES} ]] && \
1489 unipatch "${UNIPATCH_LIST_DEFAULT} ${UNIPATCH_LIST_GENPATCHES} ${UNIPATCH_LIST}"
1491 debug-print "Doing premake"
1493 # allow ebuilds to massage the source tree after patching but before
1494 # we run misc `make` functions below
1495 [[ $(type -t kernel-2_hook_premake) == "function" ]] && kernel-2_hook_premake
1497 debug-print "Doing unpack_set_extraversion"
1499 [[ -z ${K_NOSETEXTRAVERSION} ]] && unpack_set_extraversion
1500 unpack_fix_install_path
1502 # Setup xmakeopts and cd into sourcetree.
1506 # We dont need a version.h for anything other than headers
1507 # at least, I should hope we dont. If this causes problems
1508 # take out the if/fi block and inform me please.
1509 # unpack_2_6 should now be 2.6.17 safe anyways
1510 if [[ ${ETYPE} == headers ]]; then
1511 kernel_is 2 4 && unpack_2_4
1512 kernel_is 2 6 && unpack_2_6
1515 if [[ $K_DEBLOB_AVAILABLE == 1 ]] && use deblob ; then
1516 cp "${DISTDIR}/${DEBLOB_A}" "${T}" || die "cp ${DEBLOB_A} failed"
1517 cp "${DISTDIR}/${DEBLOB_CHECK_A}" "${T}/deblob-check" || die "cp ${DEBLOB_CHECK_A} failed"
1518 chmod +x "${T}/${DEBLOB_A}" "${T}/deblob-check" || die "chmod deblob scripts failed"
1521 # fix a problem on ppc where TOUT writes to /usr/src/linux breaking sandbox
1522 # only do this for kernel < 2.6.27 since this file does not exist in later
1524 if [[ -n ${KV_MINOR} && ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} < 2.6.27 ]] ; then
1526 -e 's|TOUT := .tmp_gas_check|TOUT := $(T).tmp_gas_check|' \
1527 "${S}"/arch/ppc/Makefile
1530 -e 's|TOUT := .tmp_gas_check|TOUT := $(T).tmp_gas_check|' \
1531 "${S}"/arch/powerpc/Makefile
1535 # @FUNCTION: kernel-2_src_prepare
1538 # Apply any user patches
1540 kernel-2_src_prepare() {
1542 debug-print "Applying any user patches"
1544 # apply any user patches
1546 0|1|2|3|4|5) epatch_user ;;
1551 # @FUNCTION: kernel-2_src_compile
1554 # conpile headers or run deblob script
1556 kernel-2_src_compile() {
1558 [[ ${ETYPE} == headers ]] && compile_headers
1560 if [[ $K_DEBLOB_AVAILABLE == 1 ]] && use deblob ; then
1561 echo ">>> Running deblob script ..."
1563 sh "${T}/${DEBLOB_A}" --force || die "Deblob script failed to run!!!"
1567 # @FUNCTION: kernel-2_src_test
1570 # if you leave it to the default src_test, it will run make to
1571 # find whether test/check targets are present; since "make test"
1572 # actually produces a few support files, they are installed even
1573 # though the package is binchecks-restricted.
1575 # Avoid this altogether by making the function moot.
1576 kernel-2_src_test() { :; }
1578 # @FUNCTION: kernel-2_pkg_preinst
1580 # if ETYPE = headers, call preinst_headers
1582 kernel-2_pkg_preinst() {
1583 [[ ${ETYPE} == headers ]] && preinst_headers
1586 # @FUNCTION: kernel-2_src_install
1589 # Install headers or sources dependant on ETYPE
1591 kernel-2_src_install() {
1593 [[ ${ETYPE} == headers ]] && install_headers
1594 [[ ${ETYPE} == sources ]] && install_sources
1597 # @FUNCTION: kernel-2_pkg_postinst
1600 # call postinst_sources for ETYPE = sources
1602 kernel-2_pkg_postinst() {
1603 [[ ${ETYPE} == sources ]] && postinst_sources
1606 # @FUNCTION: kernel-2_pkg_setup
1609 # check for supported kernel version, die if ETYPE is unknown, call setup_headers
1612 kernel-2_pkg_setup() {
1613 if kernel_is 2 4; then
1614 if [[ $(gcc-major-version) -ge 4 ]] ; then
1616 ewarn "Be warned !! >=sys-devel/gcc-4.0.0 isn't supported with linux-2.4!"
1617 ewarn "Either switch to another gcc-version (via gcc-config) or use a"
1618 ewarn "newer kernel that supports gcc-4."
1620 ewarn "Also be aware that bugreports about gcc-4 not working"
1621 ewarn "with linux-2.4 based ebuilds will be closed as INVALID!"
1627 if [[ ${ETYPE} != sources ]] && [[ ${ETYPE} != headers ]]; then
1628 eerror "Unknown ETYPE=\"${ETYPE}\", must be \"sources\" or \"headers\""
1629 die "Unknown ETYPE=\"${ETYPE}\", must be \"sources\" or \"headers\""
1632 [[ ${ETYPE} == headers ]] && setup_headers
1633 [[ ${ETYPE} == sources ]] && echo ">>> Preparing to unpack ..."
1636 # @FUNCTION: kernel-2_pkg_postrm
1639 # Notify the user that after a depclean, there may be sources
1640 # left behind that need to be manually cleaned
1642 kernel-2_pkg_postrm() {
1643 # This warning only makes sense for kernel sources.
1644 [[ ${ETYPE} == headers ]] && return 0
1646 # If there isn't anything left behind, then don't complain.
1647 [[ -e ${EROOT}usr/src/linux-${KV_FULL} ]] || return 0
1649 ewarn "Note: Even though you have successfully unmerged "
1650 ewarn "your kernel package, directories in kernel source location: "
1651 ewarn "${EROOT}usr/src/linux-${KV_FULL}"
1652 ewarn "with modified files will remain behind. By design, package managers"
1653 ewarn "will not remove these modified files and the directories they reside in."
1655 ewarn "For more detailed kernel removal instructions, please see: "
1656 ewarn "https://wiki.gentoo.org/wiki/Kernel/Removal"