Gentoo Archives: gentoo-commits

From: "Anthony G. Basile" <blueness@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/hardened-dev:uclibc commit in: eclass/
Date: Thu, 12 Jan 2012 00:08:22
Message-Id: 0fbb85146952ee2ee107029abad5061cbf5a4076.blueness@gentoo
1 commit: 0fbb85146952ee2ee107029abad5061cbf5a4076
2 Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
3 AuthorDate: Thu Jan 12 00:08:06 2012 +0000
4 Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
5 CommitDate: Thu Jan 12 00:08:06 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/hardened-dev.git;a=commit;h=0fbb8514
7
8 eclass/kernel-2.eclass: removed PDEPEND on virtual/dev-manager
9
10 ---
11 eclass/kernel-2.eclass | 1229 ++++++++++++++++++++++++++++++++++++++++++++++++
12 1 files changed, 1229 insertions(+), 0 deletions(-)
13
14 diff --git a/eclass/kernel-2.eclass b/eclass/kernel-2.eclass
15 new file mode 100644
16 index 0000000..724a485
17 --- /dev/null
18 +++ b/eclass/kernel-2.eclass
19 @@ -0,0 +1,1229 @@
20 +# Copyright 1999-2011 Gentoo Foundation
21 +# Distributed under the terms of the GNU General Public License v2
22 +# $Header: /var/cvsroot/gentoo-x86/eclass/kernel-2.eclass,v 1.274 2011/12/28 13:38:05 psomas Exp $
23 +
24 +# Description: kernel.eclass rewrite for a clean base regarding the 2.6
25 +# series of kernel with back-compatibility for 2.4
26 +#
27 +# Original author: John Mylchreest <johnm@g.o>
28 +# Maintainer: kernel-misc@g.o
29 +#
30 +# Please direct your bugs to the current eclass maintainer :)
31 +
32 +# added functionality:
33 +# unipatch - a flexible, singular method to extract, add and remove patches.
34 +
35 +# A Couple of env vars are available to effect usage of this eclass
36 +# These are as follows:
37 +#
38 +# K_USEPV - When setting the EXTRAVERSION variable, it should
39 +# add PV to the end.
40 +# this is useful for thigns like wolk. IE:
41 +# EXTRAVERSION would be something like : -wolk-4.19-r1
42 +# K_NOSETEXTRAVERSION - if this is set then EXTRAVERSION will not be
43 +# automatically set within the kernel Makefile
44 +# K_NOUSENAME - if this is set then EXTRAVERSION will not include the
45 +# first part of ${PN} in EXTRAVERSION
46 +# K_NOUSEPR - if this is set then EXTRAVERSION will not include the
47 +# anything based on ${PR}.
48 +# K_PREPATCHED - if the patchset is prepatched (ie: mm-sources,
49 +# ck-sources, ac-sources) it will use PR (ie: -r5) as
50 +# the patchset version for
51 +# and not use it as a true package revision
52 +# K_EXTRAEINFO - this is a new-line seperated list of einfo displays in
53 +# postinst and can be used to carry additional postinst
54 +# messages
55 +# K_EXTRAELOG - same as K_EXTRAEINFO except using elog instead of einfo
56 +# K_EXTRAEWARN - same as K_EXTRAEINFO except using ewarn instead of einfo
57 +# K_SYMLINK - if this is set, then forcably create symlink anyway
58 +#
59 +# K_DEFCONFIG - Allow specifying a different defconfig target.
60 +# If length zero, defaults to "defconfig".
61 +# K_WANT_GENPATCHES - Apply genpatches to kernel source. Provide any
62 +# combination of "base" and "extras"
63 +# K_GENPATCHES_VER - The version of the genpatches tarball(s) to apply.
64 +# A value of "5" would apply genpatches-2.6.12-5 to
65 +# my-sources-2.6.12.ebuild
66 +# K_SECURITY_UNSUPPORTED- If set, this kernel is unsupported by Gentoo Security
67 +# K_DEBLOB_AVAILABLE - A value of "0" will disable all of the optional deblob
68 +# code. If empty, will be set to "1" if deblobbing is
69 +# possible. Test ONLY for "1".
70 +# K_PREDEBLOBBED - This kernel was already deblobbed elsewhere.
71 +# If false, either optional deblobbing will be available
72 +# or the license will note the inclusion of freedist
73 +# code.
74 +# K_LONGTERM - If set, the eclass will search for the kernel source
75 +# in the long term directories on the upstream servers
76 +# as the location has been changed by upstream
77 +# H_SUPPORTEDARCH - this should be a space separated list of ARCH's which
78 +# can be supported by the headers ebuild
79 +
80 +# UNIPATCH_LIST - space delimetered list of patches to be applied to the
81 +# kernel
82 +# UNIPATCH_EXCLUDE - an addition var to support exlusion based completely
83 +# on "<passedstring>*" and not "<passedno#>_*"
84 +# - this should _NOT_ be used from the ebuild as this is
85 +# reserved for end users passing excludes from the cli
86 +# UNIPATCH_DOCS - space delimemeted list of docs to be installed to
87 +# the doc dir
88 +# UNIPATCH_STRICTORDER - if this is set places patches into directories of
89 +# order, so they are applied in the order passed
90 +
91 +inherit eutils toolchain-funcs versionator multilib
92 +EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_test src_install pkg_preinst pkg_postinst pkg_postrm
93 +
94 +# Added by Daniel Ostrow <dostrow@g.o>
95 +# This is an ugly hack to get around an issue with a 32-bit userland on ppc64.
96 +# I will remove it when I come up with something more reasonable.
97 +[[ ${PROFILE_ARCH} == "ppc64" ]] && CHOST="powerpc64-${CHOST#*-}"
98 +
99 +export CTARGET=${CTARGET:-${CHOST}}
100 +if [[ ${CTARGET} == ${CHOST} && ${CATEGORY/cross-} != ${CATEGORY} ]]; then
101 + export CTARGET=${CATEGORY/cross-}
102 +fi
103 +
104 +HOMEPAGE="http://www.kernel.org/ http://www.gentoo.org/ ${HOMEPAGE}"
105 +: ${LICENSE:="GPL-2"}
106 +
107 +# This is the latest KV_PATCH of the deblob tool available from the
108 +# libre-sources upstream. If you bump this, you MUST regenerate the Manifests
109 +# for ALL kernel-2 consumer packages where deblob is available.
110 +: ${DEBLOB_MAX_VERSION:=38}
111 +
112 +# No need to run scanelf/strip on kernel sources/headers (bug #134453).
113 +RESTRICT="binchecks strip"
114 +
115 +# set LINUX_HOSTCFLAGS if not already set
116 +: ${LINUX_HOSTCFLAGS:="-Wall -Wstrict-prototypes -Os -fomit-frame-pointer -I${S}/include"}
117 +
118 +# debugging functions
119 +#==============================================================
120 +# this function exists only to help debug kernel-2.eclass
121 +# if you are adding new functionality in, put a call to it
122 +# at the start of src_unpack, or during SRC_URI/dep generation.
123 +debug-print-kernel2-variables() {
124 + for v in PVR CKV OKV KV KV_FULL KV_MAJOR KV_MINOR KV_PATCH RELEASETYPE \
125 + RELEASE UNIPATCH_LIST_DEFAULT UNIPATCH_LIST_GENPATCHES \
126 + UNIPATCH_LIST S KERNEL_URI K_WANT_GENPATCHES ; do
127 + debug-print "${v}: ${!v}"
128 + done
129 +}
130 +
131 +#Eclass functions only from here onwards ...
132 +#==============================================================
133 +handle_genpatches() {
134 + local tarball
135 + [[ -z ${K_WANT_GENPATCHES} || -z ${K_GENPATCHES_VER} ]] && return 1
136 +
137 + debug-print "Inside handle_genpatches"
138 + local OKV_ARRAY
139 + IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
140 +
141 + # for > 3.0 kernels, handle genpatches tarball name
142 + # genpatches for 3.0 and 3.0.1 might be named
143 + # genpatches-3.0-1.base.tar.bz2 and genpatches-3.0-2.base.tar.bz2
144 + # respectively. Handle this.
145 +
146 + for i in ${K_WANT_GENPATCHES} ; do
147 + if [[ ${KV_MAJOR} -ge 3 ]]; then
148 + if [[ ${#OKV_ARRAY[@]} -ge 3 ]]; then
149 + tarball="genpatches-${KV_MAJOR}.${KV_MINOR}-${K_GENPATCHES_VER}.${i}.tar.bz2"
150 + else
151 + tarball="genpatches-${KV_MAJOR}.${KV_PATCH}-${K_GENPATCHES_VER}.${i}.tar.bz2"
152 + fi
153 + else
154 + tarball="genpatches-${OKV}-${K_GENPATCHES_VER}.${i}.tar.bz2"
155 + fi
156 + debug-print "genpatches tarball: $tarball"
157 + GENPATCHES_URI="${GENPATCHES_URI} mirror://gentoo/${tarball}"
158 + UNIPATCH_LIST_GENPATCHES="${UNIPATCH_LIST_GENPATCHES} ${DISTDIR}/${tarball}"
159 + done
160 +}
161 +
162 +detect_version() {
163 + # this function will detect and set
164 + # - OKV: Original Kernel Version (2.6.0/2.6.0-test11)
165 + # - KV: Kernel Version (2.6.0-gentoo/2.6.0-test11-gentoo-r1)
166 + # - EXTRAVERSION: The additional version appended to OKV (-gentoo/-gentoo-r1)
167 +
168 + # We've already run, so nothing to do here.
169 + [[ -n ${KV_FULL} ]] && return 0
170 +
171 + # CKV is used as a comparison kernel version, which is used when
172 + # PV doesnt reflect the genuine kernel version.
173 + # this gets set to the portage style versioning. ie:
174 + # CKV=2.6.11_rc4
175 + CKV=${CKV:-${PV}}
176 + OKV=${OKV:-${CKV}}
177 + OKV=${OKV/_beta/-test}
178 + OKV=${OKV/_rc/-rc}
179 + OKV=${OKV/-r*}
180 + OKV=${OKV/_p*}
181 +
182 + KV_MAJOR=$(get_version_component_range 1 ${OKV})
183 + # handle if OKV is X.Y or X.Y.Z (e.g. 3.0 or 3.0.1)
184 + local OKV_ARRAY
185 + IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
186 +
187 + # if KV_MAJOR >= 3, then we have no more KV_MINOR
188 + #if [[ ${KV_MAJOR} -lt 3 ]]; then
189 + if [[ ${#OKV_ARRAY[@]} -ge 3 ]]; then
190 + KV_MINOR=$(get_version_component_range 2 ${OKV})
191 + KV_PATCH=$(get_version_component_range 3 ${OKV})
192 + if [[ ${KV_MAJOR}${KV_MINOR}${KV_PATCH} -ge 269 ]]; then
193 + KV_EXTRA=$(get_version_component_range 4- ${OKV})
194 + KV_EXTRA=${KV_EXTRA/[-_]*}
195 + else
196 + KV_PATCH=$(get_version_component_range 3- ${OKV})
197 + fi
198 + else
199 + KV_PATCH=$(get_version_component_range 2 ${OKV})
200 + KV_EXTRA=$(get_version_component_range 3- ${OKV})
201 + KV_EXTRA=${KV_EXTRA/[-_]*}
202 + fi
203 +
204 + debug-print "KV_EXTRA is ${KV_EXTRA}"
205 +
206 + KV_PATCH=${KV_PATCH/[-_]*}
207 +
208 + local v n=0 missing
209 + #if [[ ${KV_MAJOR} -lt 3 ]]; then
210 + if [[ ${#OKV_ARRAY[@]} -ge 3 ]]; then
211 + for v in CKV OKV KV_{MAJOR,MINOR,PATCH} ; do
212 + [[ -z ${!v} ]] && n=1 && missing="${missing}${v} ";
213 + done
214 + else
215 + for v in CKV OKV KV_{MAJOR,PATCH} ; do
216 + [[ -z ${!v} ]] && n=1 && missing="${missing}${v} ";
217 + done
218 + fi
219 +
220 + [[ $n -eq 1 ]] && \
221 + eerror "Missing variables: ${missing}" && \
222 + die "Failed to extract kernel version (try explicit CKV in ebuild)!"
223 + unset v n missing
224 +
225 +# if [[ ${KV_MAJOR} -ge 3 ]]; then
226 + if [[ ${#OKV_ARRAY[@]} -lt 3 ]]; then
227 + KV_PATCH_ARR=(${KV_PATCH//\./ })
228 +
229 + # at this point 080811, Linus is putting 3.1 kernels in 3.0 directory
230 + # revisit when 3.1 is released
231 + if [[ ${KV_PATCH} -gt 0 ]]; then
232 + KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.$((${KV_PATCH_ARR} - 1))"
233 + else
234 + KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_PATCH_ARR}"
235 + fi
236 + # KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_PATCH_ARR}"
237 + [[ -n "${K_LONGTERM}" ]] &&
238 + KERNEL_BASE_URI="${KERNEL_BASE_URI}/longterm/v${KV_MAJOR}.${KV_PATCH_ARR}"
239 + else
240 + #KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.0"
241 + #KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}"
242 + if [[ ${KV_MAJOR} -ge 3 ]]; then
243 + KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.x"
244 + else
245 + KERNEL_BASE_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}"
246 + fi
247 +
248 + [[ -n "${K_LONGTERM}" ]] &&
249 + #KERNEL_BASE_URI="${KERNEL_BASE_URI}/longterm"
250 + KERNEL_BASE_URI="${KERNEL_BASE_URI}/longterm/v${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
251 + fi
252 +
253 + debug-print "KERNEL_BASE_URI is ${KERNEL_BASE_URI}"
254 +
255 + if [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]]; then
256 + # handle non genpatch using sources correctly
257 + if [[ -z ${K_WANT_GENPATCHES} && -z ${K_GENPATCHES_VER} && ${KV_PATCH} -gt 0 ]]; then
258 + KERNEL_URI="${KERNEL_BASE_URI}/patch-${OKV}.bz2"
259 + UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV}.bz2"
260 + fi
261 + KERNEL_URI="${KERNEL_URI} ${KERNEL_BASE_URI}/linux-${KV_MAJOR}.${KV_MINOR}.tar.bz2"
262 + else
263 + KERNEL_URI="${KERNEL_BASE_URI}/linux-${OKV}.tar.bz2"
264 + fi
265 +
266 + RELEASE=${CKV/${OKV}}
267 + RELEASE=${RELEASE/_beta}
268 + RELEASE=${RELEASE/_rc/-rc}
269 + RELEASE=${RELEASE/_pre/-pre}
270 + # We cannot trivally call kernel_is here, because it calls us to detect the
271 + # version
272 + #kernel_is ge 2 6 && RELEASE=${RELEASE/-pre/-git}
273 + [ $(($KV_MAJOR * 1000 + ${KV_MINOR:-0})) -ge 2006 ] && RELEASE=${RELEASE/-pre/-git}
274 + RELEASETYPE=${RELEASE//[0-9]}
275 +
276 + # Now we know that RELEASE is the -rc/-git
277 + # and RELEASETYPE is the same but with its numerics stripped
278 + # we can work on better sorting EXTRAVERSION.
279 + # first of all, we add the release
280 + EXTRAVERSION="${RELEASE}"
281 + debug-print "0 EXTRAVERSION:${EXTRAVERSION}"
282 + [[ -n ${KV_EXTRA} ]] && [[ ${KV_MAJOR} -lt 3 ]] && EXTRAVERSION=".${KV_EXTRA}${EXTRAVERSION}"
283 +
284 + debug-print "1 EXTRAVERSION:${EXTRAVERSION}"
285 + if [[ -n "${K_NOUSEPR}" ]]; then
286 + # Don't add anything based on PR to EXTRAVERSION
287 + debug-print "1.0 EXTRAVERSION:${EXTRAVERSION}"
288 + elif [[ -n ${K_PREPATCHED} ]]; then
289 + debug-print "1.1 EXTRAVERSION:${EXTRAVERSION}"
290 + EXTRAVERSION="${EXTRAVERSION}-${PN/-*}${PR/r}"
291 + elif [[ "${ETYPE}" = "sources" ]]; then
292 + debug-print "1.2 EXTRAVERSION:${EXTRAVERSION}"
293 + # For some sources we want to use the PV in the extra version
294 + # This is because upstream releases with a completely different
295 + # versioning scheme.
296 + case ${PN/-*} in
297 + wolk) K_USEPV=1;;
298 + vserver) K_USEPV=1;;
299 + esac
300 +
301 + [[ -z "${K_NOUSENAME}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*}"
302 + [[ -n "${K_USEPV}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PV//_/-}"
303 + [[ -n "${PR//r0}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PR}"
304 + fi
305 + debug-print "2 EXTRAVERSION:${EXTRAVERSION}"
306 +
307 + # The only messing around which should actually effect this is for KV_EXTRA
308 + # since this has to limit OKV to MAJ.MIN.PAT and strip EXTRA off else
309 + # KV_FULL evaluates to MAJ.MIN.PAT.EXT.EXT after EXTRAVERSION
310 +
311 + if [[ -n ${KV_EXTRA} ]]; then
312 + if [[ -n ${KV_MINOR} ]]; then
313 + OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
314 + else
315 + OKV="${KV_MAJOR}.${KV_PATCH}"
316 + fi
317 + KERNEL_URI="${KERNEL_BASE_URI}/patch-${CKV}.bz2
318 + ${KERNEL_BASE_URI}/linux-${OKV}.tar.bz2"
319 + UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV}.bz2"
320 + fi
321 +
322 + # We need to set this using OKV, but we need to set it before we do any
323 + # messing around with OKV based on RELEASETYPE
324 + KV_FULL=${OKV}${EXTRAVERSION}
325 +
326 + # we will set this for backwards compatibility.
327 + S=${WORKDIR}/linux-${KV_FULL}
328 + KV=${KV_FULL}
329 +
330 + # -rc-git pulls can be achieved by specifying CKV
331 + # for example:
332 + # CKV="2.6.11_rc3_pre2"
333 + # will pull:
334 + # linux-2.6.10.tar.bz2 & patch-2.6.11-rc3.bz2 & patch-2.6.11-rc3-git2.bz2
335 +
336 + if [[ ${KV_MAJOR}${KV_MINOR} -eq 26 ]]; then
337 +
338 + if [[ ${RELEASETYPE} == -rc ]] || [[ ${RELEASETYPE} == -pre ]]; then
339 + OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))"
340 + KERNEL_URI="${KERNEL_BASE_URI}/testing/patch-${CKV//_/-}.bz2
341 + ${KERNEL_BASE_URI}/linux-${OKV}.tar.bz2"
342 + UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV//_/-}.bz2"
343 + fi
344 +
345 + if [[ ${RELEASETYPE} == -git ]]; then
346 + KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${OKV}${RELEASE}.bz2
347 + ${KERNEL_BASE_URI}/linux-${OKV}.tar.bz2"
348 + UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${OKV}${RELEASE}.bz2"
349 + fi
350 +
351 + if [[ ${RELEASETYPE} == -rc-git ]]; then
352 + OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))"
353 + KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2
354 + ${KERNEL_BASE_URI}/testing/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE/-git*}.bz2
355 + ${KERNEL_BASE_URI}/linux-${OKV}.tar.bz2"
356 +
357 + UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE/-git*}.bz2 ${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2"
358 + fi
359 + else
360 + if [[ ${RELEASETYPE} == -rc ]] || [[ ${RELEASETYPE} == -pre ]]; then
361 + if [[ ${KV_MAJOR}${KV_PATCH} -eq 30 ]]; then
362 + OKV="2.6.39"
363 + else
364 + KV_PATCH_ARR=(${KV_PATCH//\./ })
365 + OKV="${KV_MAJOR}.$((${KV_PATCH_ARR} - 1))"
366 + fi
367 + KERNEL_URI="${KERNEL_BASE_URI}/testing/patch-${CKV//_/-}.bz2
368 + ${KERNEL_BASE_URI}/testing/linux-${OKV}.tar.bz2"
369 + UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV//_/-}.bz2"
370 + fi
371 +
372 + if [[ ${RELEASETYPE} == -git ]]; then
373 + KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${OKV}${RELEASE}.bz2
374 + ${KERNEL_BASE_URI}/linux-${OKV}.tar.bz2"
375 + UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${OKV}${RELEASE}.bz2"
376 + fi
377 +
378 + if [[ ${RELEASETYPE} == -rc-git ]]; then
379 + if [[ ${KV_MAJOR}${KV_PATCH} -eq 30 ]]; then
380 + OKV="2.6.39"
381 + else
382 + KV_PATCH_ARR=(${KV_PATCH//\./ })
383 + OKV="${KV_MAJOR}.$((${KV_PATCH_ARR} - 1))"
384 + fi
385 + KERNEL_URI="${KERNEL_BASE_URI}/snapshots/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE}.bz2
386 + ${KERNEL_BASE_URI}/testing/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE/-git*}.bz2
387 + ${KERNEL_BASE_URI}/linux-${OKV}.tar.bz2"
388 +
389 + UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE/-git*}.bz2 ${DISTDIR}/patch-${KV_MAJOR}.${KV_PATCH}${RELEASE}.bz2"
390 + fi
391 +
392 +
393 + fi
394 +
395 +
396 + debug-print-kernel2-variables
397 +
398 + handle_genpatches
399 +}
400 +
401 +# Note: duplicated in linux-info.eclass
402 +kernel_is() {
403 + # ALL of these should be set before we can safely continue this function.
404 + # some of the sources have in the past had only one set.
405 + local v n=0
406 + for v in OKV KV_{MAJOR,MINOR,PATCH} ; do [[ -z ${!v} ]] && n=1 ; done
407 + [[ $n -eq 1 ]] && detect_version
408 + unset v n
409 +
410 + # Now we can continue
411 + local operator test value
412 +
413 + case ${1#-} in
414 + lt) operator="-lt"; shift;;
415 + gt) operator="-gt"; shift;;
416 + le) operator="-le"; shift;;
417 + ge) operator="-ge"; shift;;
418 + eq) operator="-eq"; shift;;
419 + *) operator="-eq";;
420 + esac
421 + [[ $# -gt 3 ]] && die "Error in kernel-2_kernel_is(): too many parameters"
422 +
423 + : $(( test = (KV_MAJOR << 16) + (KV_MINOR << 8) + KV_PATCH ))
424 + : $(( value = (${1:-${KV_MAJOR}} << 16) + (${2:-${KV_MINOR}} << 8) + ${3:-${KV_PATCH}} ))
425 + [ ${test} ${operator} ${value} ]
426 +}
427 +
428 +kernel_is_2_4() {
429 + kernel_is 2 4
430 +}
431 +
432 +kernel_is_2_6() {
433 + kernel_is 2 6 || kernel_is 2 5
434 +}
435 +
436 +# Capture the sources type and set DEPENDs
437 +if [[ ${ETYPE} == sources ]]; then
438 + DEPEND="!build? ( sys-apps/sed
439 + >=sys-devel/binutils-2.11.90.0.31 )"
440 + RDEPEND="!build? ( >=sys-libs/ncurses-5.2
441 + sys-devel/make )"
442 +
443 + SLOT="${PVR}"
444 + DESCRIPTION="Sources for the ${KV_MAJOR}.${KV_MINOR:-$KV_PATCH} linux kernel"
445 + IUSE="symlink build"
446 +
447 + # Bug #266157, deblob for libre support
448 + if [[ -z ${K_PREDEBLOBBED} ]] ; then
449 + # Bug #359865, force a call to detect_version if needed
450 + kernel_is ge 2 6 27 && \
451 + [[ -z "${K_DEBLOB_AVAILABLE}" ]] && \
452 + kernel_is le 2 6 ${DEBLOB_MAX_VERSION} && \
453 + K_DEBLOB_AVAILABLE=1
454 + if [[ ${K_DEBLOB_AVAILABLE} == "1" ]] ; then
455 + IUSE="${IUSE} deblob"
456 + # Reflect that kernels contain firmware blobs unless otherwise
457 + # stripped
458 + LICENSE="${LICENSE} !deblob? ( freedist )"
459 +
460 + if [[ -n KV_MINOR ]]; then
461 + DEBLOB_PV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
462 + else
463 + DEBLOB_PV="${KV_MAJOR}.${KV_PATCH}"
464 + fi
465 +
466 + if [[ ${KV_MAJOR} -ge 3 ]]; then
467 + DEBLOB_PV="${KV_MAJOR}.${KV_MINOR}"
468 + fi
469 +
470 + DEBLOB_A="deblob-${DEBLOB_PV}"
471 + DEBLOB_CHECK_A="deblob-check-${DEBLOB_PV}"
472 + DEBLOB_HOMEPAGE="http://www.fsfla.org/svnwiki/selibre/linux-libre/"
473 + DEBLOB_URI_PATH="download/releases/LATEST-${DEBLOB_PV}.N"
474 + if ! has "${EAPI:-0}" 0 1 ; then
475 + DEBLOB_CHECK_URI="${DEBLOB_HOMEPAGE}/${DEBLOB_URI_PATH}/deblob-check -> ${DEBLOB_CHECK_A}"
476 + else
477 + DEBLOB_CHECK_URI="mirror://gentoo/${DEBLOB_CHECK_A}"
478 + fi
479 + DEBLOB_URI="${DEBLOB_HOMEPAGE}/${DEBLOB_URI_PATH}/${DEBLOB_A}"
480 + HOMEPAGE="${HOMEPAGE} ${DEBLOB_HOMEPAGE}"
481 +
482 + KERNEL_URI="${KERNEL_URI}
483 + deblob? (
484 + ${DEBLOB_URI}
485 + ${DEBLOB_CHECK_URI}
486 + )"
487 + else
488 + # We have no way to deblob older kernels, so just mark them as
489 + # tainted with non-libre materials.
490 + LICENSE="${LICENSE} freedist"
491 + fi
492 + fi
493 +
494 +elif [[ ${ETYPE} == headers ]]; then
495 + DESCRIPTION="Linux system headers"
496 +
497 + # Since we should NOT honour KBUILD_OUTPUT in headers
498 + # lets unset it here.
499 + unset KBUILD_OUTPUT
500 +
501 + SLOT="0"
502 +else
503 + eerror "Unknown ETYPE=\"${ETYPE}\", must be \"sources\" or \"headers\""
504 + die "Unknown ETYPE=\"${ETYPE}\", must be \"sources\" or \"headers\""
505 +fi
506 +
507 +# Cross-compile support functions
508 +#==============================================================
509 +kernel_header_destdir() {
510 + [[ ${CTARGET} == ${CHOST} ]] \
511 + && echo /usr/include \
512 + || echo /usr/${CTARGET}/usr/include
513 +}
514 +
515 +cross_pre_c_headers() {
516 + use crosscompile_opts_headers-only && [[ ${CHOST} != ${CTARGET} ]]
517 +}
518 +
519 +env_setup_xmakeopts() {
520 + # Kernel ARCH != portage ARCH
521 + export KARCH=$(tc-arch-kernel)
522 +
523 + # When cross-compiling, we need to set the ARCH/CROSS_COMPILE
524 + # variables properly or bad things happen !
525 + xmakeopts="ARCH=${KARCH}"
526 + if [[ ${CTARGET} != ${CHOST} ]] && ! cross_pre_c_headers ; then
527 + xmakeopts="${xmakeopts} CROSS_COMPILE=${CTARGET}-"
528 + elif type -p ${CHOST}-ar > /dev/null ; then
529 + xmakeopts="${xmakeopts} CROSS_COMPILE=${CHOST}-"
530 + fi
531 + export xmakeopts
532 +}
533 +
534 +# Unpack functions
535 +#==============================================================
536 +unpack_2_4() {
537 + # this file is required for other things to build properly,
538 + # so we autogenerate it
539 + make -s mrproper ${xmakeopts} || die "make mrproper failed"
540 + make -s symlinks ${xmakeopts} || die "make symlinks failed"
541 + make -s include/linux/version.h ${xmakeopts} || die "make include/linux/version.h failed"
542 + echo ">>> version.h compiled successfully."
543 +}
544 +
545 +unpack_2_6() {
546 + # this file is required for other things to build properly, so we
547 + # autogenerate it ... generate a .config to keep version.h build from
548 + # spitting out an annoying warning
549 + make -s mrproper ${xmakeopts} 2>/dev/null \
550 + || die "make mrproper failed"
551 +
552 + # quick fix for bug #132152 which triggers when it cannot include linux
553 + # headers (ie, we have not installed it yet)
554 + if ! make -s defconfig ${xmakeopts} &>/dev/null 2>&1 ; then
555 + touch .config
556 + eerror "make defconfig failed."
557 + eerror "assuming you dont have any headers installed yet and continuing"
558 + epause 5
559 + fi
560 +
561 + make -s include/linux/version.h ${xmakeopts} 2>/dev/null \
562 + || die "make include/linux/version.h failed"
563 + rm -f .config >/dev/null
564 +}
565 +
566 +universal_unpack() {
567 + debug-print "Inside universal_unpack"
568 +
569 + local OKV_ARRAY
570 + IFS="." read -r -a OKV_ARRAY <<<"${OKV}"
571 +
572 + cd "${WORKDIR}"
573 + if [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]]; then
574 + unpack linux-${KV_MAJOR}.${KV_MINOR}.tar.bz2
575 + else
576 + unpack linux-${OKV}.tar.bz2
577 + fi
578 +
579 + if [[ -d "linux" ]]; then
580 + debug-print "Moving linux to linux-${KV_FULL}"
581 + mv linux linux-${KV_FULL} \
582 + || die "Unable to move source tree to ${KV_FULL}."
583 + elif [[ "${OKV}" != "${KV_FULL}" ]]; then
584 + if [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]] &&
585 + [[ "${ETYPE}" = "sources" ]]; then
586 + debug-print "moving linux-${KV_MAJOR}.${KV_MINOR} to linux-${KV_FULL} "
587 + mv linux-${KV_MAJOR}.${KV_MINOR} linux-${KV_FULL} \
588 + || die "Unable to move source tree to ${KV_FULL}."
589 + else
590 + debug-print "moving linux-${OKV} to linux-${KV_FULL} "
591 + mv linux-${OKV} linux-${KV_FULL} \
592 + || die "Unable to move source tree to ${KV_FULL}."
593 + fi
594 + elif [[ ${#OKV_ARRAY[@]} -ge 3 ]] && [[ ${KV_MAJOR} -ge 3 ]]; then
595 + mv linux-${KV_MAJOR}.${KV_MINOR} linux-${KV_FULL} \
596 + || die "Unable to move source tree to ${KV_FULL}."
597 + fi
598 + cd "${S}"
599 +
600 + # remove all backup files
601 + find . -iname "*~" -exec rm {} \; 2> /dev/null
602 +
603 + # fix a problem on ppc where TOUT writes to /usr/src/linux breaking sandbox
604 + # only do this for kernel < 2.6.27 since this file does not exist in later
605 + # kernels
606 + if [[ -n ${KV_MINOR} && ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} < 2.6.27 ]]
607 + then
608 + sed -i \
609 + -e 's|TOUT := .tmp_gas_check|TOUT := $(T).tmp_gas_check|' \
610 + "${S}"/arch/ppc/Makefile
611 + else
612 + sed -i \
613 + -e 's|TOUT := .tmp_gas_check|TOUT := $(T).tmp_gas_check|' \
614 + "${S}"/arch/powerpc/Makefile
615 + fi
616 +}
617 +
618 +unpack_set_extraversion() {
619 + cd "${S}"
620 + sed -i -e "s:^\(EXTRAVERSION =\).*:\1 ${EXTRAVERSION}:" Makefile
621 + cd "${OLDPWD}"
622 +}
623 +
624 +# Should be done after patches have been applied
625 +# Otherwise patches that modify the same area of Makefile will fail
626 +unpack_fix_install_path() {
627 + cd "${S}"
628 + sed -i -e 's:#export\tINSTALL_PATH:export\tINSTALL_PATH:' Makefile
629 +}
630 +
631 +# Compile Functions
632 +#==============================================================
633 +compile_headers() {
634 + env_setup_xmakeopts
635 +
636 + # if we couldnt obtain HOSTCFLAGS from the Makefile,
637 + # then set it to something sane
638 + local HOSTCFLAGS=$(getfilevar HOSTCFLAGS "${S}"/Makefile)
639 + HOSTCFLAGS=${HOSTCFLAGS:--Wall -Wstrict-prototypes -O2 -fomit-frame-pointer}
640 +
641 + if kernel_is 2 4; then
642 + yes "" | make oldconfig ${xmakeopts}
643 + echo ">>> make oldconfig complete"
644 + make dep ${xmakeopts}
645 + elif kernel_is 2 6; then
646 + # 2.6.18 introduces headers_install which means we dont need any
647 + # of this crap anymore :D
648 + kernel_is ge 2 6 18 && return 0
649 +
650 + # autoconf.h isnt generated unless it already exists. plus, we have
651 + # no guarantee that any headers are installed on the system...
652 + [[ -f ${ROOT}/usr/include/linux/autoconf.h ]] \
653 + || touch include/linux/autoconf.h
654 +
655 + # if K_DEFCONFIG isn't set, force to "defconfig"
656 + # needed by mips
657 + if [[ -z ${K_DEFCONFIG} ]]; then
658 + if [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]]; then
659 + case ${CTARGET} in
660 + powerpc64*) K_DEFCONFIG="ppc64_defconfig";;
661 + powerpc*) K_DEFCONFIG="pmac32_defconfig";;
662 + *) K_DEFCONFIG="defconfig";;
663 + esac
664 + else
665 + K_DEFCONFIG="defconfig"
666 + fi
667 + fi
668 +
669 + # if there arent any installed headers, then there also isnt an asm
670 + # symlink in /usr/include/, and make defconfig will fail, so we have
671 + # to force an include path with $S.
672 + HOSTCFLAGS="${HOSTCFLAGS} -I${S}/include/"
673 + ln -sf asm-${KARCH} "${S}"/include/asm
674 + cross_pre_c_headers && return 0
675 +
676 + make ${K_DEFCONFIG} HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "defconfig failed (${K_DEFCONFIG})"
677 + if compile_headers_tweak_config ; then
678 + yes "" | make oldconfig HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "2nd oldconfig failed"
679 + fi
680 + make prepare HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "prepare failed"
681 + make prepare-all HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "prepare failed"
682 + fi
683 +}
684 +
685 +compile_headers_tweak_config() {
686 + # some targets can be very very picky, so let's finesse the
687 + # .config based upon any info we may have
688 + case ${CTARGET} in
689 + sh*)
690 + sed -i '/CONFIG_CPU_SH/d' .config
691 + echo "CONFIG_CPU_SH${CTARGET:2:1}=y" >> .config
692 + return 0;;
693 + esac
694 +
695 + # no changes, so lets do nothing
696 + return 1
697 +}
698 +
699 +# install functions
700 +#==============================================================
701 +install_universal() {
702 + #fix silly permissions in tarball
703 + cd "${WORKDIR}"
704 + chown -R root:0 * >& /dev/null
705 + chmod -R a+r-w+X,u+w *
706 + cd ${OLDPWD}
707 +}
708 +
709 +install_headers() {
710 + local ddir=$(kernel_header_destdir)
711 +
712 + # 2.6.18 introduces headers_install which means we dont need any
713 + # of this crap anymore :D
714 + if kernel_is ge 2 6 18 ; then
715 + env_setup_xmakeopts
716 + emake headers_install INSTALL_HDR_PATH="${D}"/${ddir}/.. ${xmakeopts} || die
717 +
718 + # let other packages install some of these headers
719 + rm -rf "${D}"/${ddir}/sound #alsa-headers
720 + rm -rf "${D}"/${ddir}/scsi #glibc/uclibc/etc...
721 + return 0
722 + fi
723 +
724 + # Do not use "linux/*" as that can cause problems with very long
725 + # $S values where the cmdline to cp is too long
726 + pushd "${S}" >/dev/null
727 + dodir ${ddir}/linux
728 + cp -pPR "${S}"/include/linux "${D}"/${ddir}/ || die
729 + rm -rf "${D}"/${ddir}/linux/modules
730 +
731 + dodir ${ddir}/asm
732 + cp -pPR "${S}"/include/asm/* "${D}"/${ddir}/asm
733 +
734 + if kernel_is 2 6 ; then
735 + dodir ${ddir}/asm-generic
736 + cp -pPR "${S}"/include/asm-generic/* "${D}"/${ddir}/asm-generic
737 + fi
738 +
739 + # clean up
740 + find "${D}" -name '*.orig' -exec rm -f {} \;
741 +
742 + popd >/dev/null
743 +}
744 +
745 +install_sources() {
746 + local file
747 +
748 + cd "${S}"
749 + dodir /usr/src
750 + echo ">>> Copying sources ..."
751 +
752 + file="$(find ${WORKDIR} -iname "docs" -type d)"
753 + if [[ -n ${file} ]]; then
754 + for file in $(find ${file} -type f); do
755 + echo "${file//*docs\/}" >> "${S}"/patches.txt
756 + echo "===================================================" >> "${S}"/patches.txt
757 + cat ${file} >> "${S}"/patches.txt
758 + echo "===================================================" >> "${S}"/patches.txt
759 + echo "" >> "${S}"/patches.txt
760 + done
761 + fi
762 +
763 + if [[ ! -f ${S}/patches.txt ]]; then
764 + # patches.txt is empty so lets use our ChangeLog
765 + [[ -f ${FILESDIR}/../ChangeLog ]] && \
766 + echo "Please check the ebuild ChangeLog for more details." \
767 + > "${S}"/patches.txt
768 + fi
769 +
770 + mv ${WORKDIR}/linux* "${D}"/usr/src
771 +}
772 +
773 +# pkg_preinst functions
774 +#==============================================================
775 +preinst_headers() {
776 + local ddir=$(kernel_header_destdir)
777 + [[ -L ${ddir}/linux ]] && rm ${ddir}/linux
778 + [[ -L ${ddir}/asm ]] && rm ${ddir}/asm
779 +}
780 +
781 +# pkg_postinst functions
782 +#==============================================================
783 +postinst_sources() {
784 + local MAKELINK=0
785 +
786 + # if we have USE=symlink, then force K_SYMLINK=1
787 + use symlink && K_SYMLINK=1
788 +
789 + # if we're using a deblobbed kernel, it's not supported
790 + [[ $K_DEBLOB_AVAILABLE == 1 ]] && \
791 + use deblob && \
792 + K_SECURITY_UNSUPPORTED=deblob
793 +
794 + # if we are to forcably symlink, delete it if it already exists first.
795 + if [[ ${K_SYMLINK} > 0 ]]; then
796 + [[ -h ${ROOT}usr/src/linux ]] && rm ${ROOT}usr/src/linux
797 + MAKELINK=1
798 + fi
799 +
800 + # if the link doesnt exist, lets create it
801 + [[ ! -h ${ROOT}usr/src/linux ]] && MAKELINK=1
802 +
803 + if [[ ${MAKELINK} == 1 ]]; then
804 + cd "${ROOT}"usr/src
805 + ln -sf linux-${KV_FULL} linux
806 + cd ${OLDPWD}
807 + fi
808 +
809 + # Don't forget to make directory for sysfs
810 + [[ ! -d ${ROOT}sys ]] && kernel_is 2 6 && mkdir ${ROOT}sys
811 +
812 + echo
813 + elog "If you are upgrading from a previous kernel, you may be interested"
814 + elog "in the following document:"
815 + elog " - General upgrade guide: http://www.gentoo.org/doc/en/kernel-upgrade.xml"
816 + echo
817 +
818 + # if K_EXTRAEINFO is set then lets display it now
819 + if [[ -n ${K_EXTRAEINFO} ]]; then
820 + echo ${K_EXTRAEINFO} | fmt |
821 + while read -s ELINE; do einfo "${ELINE}"; done
822 + fi
823 +
824 + # if K_EXTRAELOG is set then lets display it now
825 + if [[ -n ${K_EXTRAELOG} ]]; then
826 + echo ${K_EXTRAELOG} | fmt |
827 + while read -s ELINE; do elog "${ELINE}"; done
828 + fi
829 +
830 + # if K_EXTRAEWARN is set then lets display it now
831 + if [[ -n ${K_EXTRAEWARN} ]]; then
832 + echo ${K_EXTRAEWARN} | fmt |
833 + while read -s ELINE; do ewarn "${ELINE}"; done
834 + fi
835 +
836 + # optionally display security unsupported message
837 + # Start with why
838 + if [[ ${K_SECURITY_UNSUPPORTED} = deblob ]]; then
839 + ewarn "Deblobbed kernels are UNSUPPORTED by Gentoo Security."
840 + elif [[ -n ${K_SECURITY_UNSUPPORTED} ]]; then
841 + ewarn "${PN} is UNSUPPORTED by Gentoo Security."
842 + fi
843 + # And now the general message.
844 + if [[ -n ${K_SECURITY_UNSUPPORTED} ]]; then
845 + ewarn "This means that it is likely to be vulnerable to recent security issues."
846 + ewarn "For specific information on why this kernel is unsupported, please read:"
847 + ewarn "http://www.gentoo.org/proj/en/security/kernel.xml"
848 + fi
849 +
850 + # warn sparc users that they need to do cross-compiling with >= 2.6.25(bug #214765)
851 + KV_MAJOR=$(get_version_component_range 1 ${OKV})
852 + KV_MINOR=$(get_version_component_range 2 ${OKV})
853 + KV_PATCH=$(get_version_component_range 3 ${OKV})
854 + if [[ "$(tc-arch)" = "sparc" ]]; then
855 + if [[ ${KV_MAJOR} -ge 3 || ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} > 2.6.24 ]]
856 + then
857 + echo
858 + elog "NOTE: Since 2.6.25 the kernel Makefile has changed in a way that"
859 + elog "you now need to do"
860 + elog " make CROSS_COMPILE=sparc64-unknown-linux-gnu-"
861 + elog "instead of just"
862 + elog " make"
863 + elog "to compile the kernel. For more information please browse to"
864 + elog "https://bugs.gentoo.org/show_bug.cgi?id=214765"
865 + echo
866 + fi
867 + fi
868 +}
869 +
870 +# pkg_setup functions
871 +#==============================================================
872 +setup_headers() {
873 + [[ -z ${H_SUPPORTEDARCH} ]] && H_SUPPORTEDARCH=${PN/-*/}
874 + for i in ${H_SUPPORTEDARCH}; do
875 + [[ $(tc-arch) == "${i}" ]] && H_ACCEPT_ARCH="yes"
876 + done
877 +
878 + if [[ ${H_ACCEPT_ARCH} != "yes" ]]; then
879 + echo
880 + eerror "This version of ${PN} does not support $(tc-arch)."
881 + eerror "Please merge the appropriate sources, in most cases"
882 + eerror "(but not all) this will be called $(tc-arch)-headers."
883 + die "Package unsupported for $(tc-arch)"
884 + fi
885 +}
886 +
887 +# unipatch
888 +#==============================================================
889 +unipatch() {
890 + local i x y z extention PIPE_CMD UNIPATCH_DROP KPATCH_DIR PATCH_DEPTH ELINE
891 + local STRICT_COUNT PATCH_LEVEL myLC_ALL myLANG
892 +
893 + # set to a standard locale to ensure sorts are ordered properly.
894 + myLC_ALL="${LC_ALL}"
895 + myLANG="${LANG}"
896 + LC_ALL="C"
897 + LANG=""
898 +
899 + [ -z "${KPATCH_DIR}" ] && KPATCH_DIR="${WORKDIR}/patches/"
900 + [ ! -d ${KPATCH_DIR} ] && mkdir -p ${KPATCH_DIR}
901 +
902 + # We're gonna need it when doing patches with a predefined patchlevel
903 + eshopts_push -s extglob
904 +
905 + # This function will unpack all passed tarballs, add any passed patches, and remove any passed patchnumbers
906 + # usage can be either via an env var or by params
907 + # although due to the nature we pass this within this eclass
908 + # it shall be by param only.
909 + # -z "${UNIPATCH_LIST}" ] && UNIPATCH_LIST="${@}"
910 + UNIPATCH_LIST="${@}"
911 +
912 + #unpack any passed tarballs
913 + for i in ${UNIPATCH_LIST}; do
914 + if echo ${i} | grep -qs -e "\.tar" -e "\.tbz" -e "\.tgz" ; then
915 + if [ -n "${UNIPATCH_STRICTORDER}" ]; then
916 + unset z
917 + STRICT_COUNT=$((10#${STRICT_COUNT} + 1))
918 + for((y=0; y<$((6 - ${#STRICT_COUNT})); y++));
919 + do z="${z}0";
920 + done
921 + PATCH_ORDER="${z}${STRICT_COUNT}"
922 +
923 + mkdir -p "${KPATCH_DIR}/${PATCH_ORDER}"
924 + pushd "${KPATCH_DIR}/${PATCH_ORDER}" >/dev/null
925 + unpack ${i##*/}
926 + popd >/dev/null
927 + else
928 + pushd "${KPATCH_DIR}" >/dev/null
929 + unpack ${i##*/}
930 + popd >/dev/null
931 + fi
932 +
933 + [[ ${i} == *:* ]] && echo ">>> Strict patch levels not currently supported for tarballed patchsets"
934 + else
935 + extention=${i/*./}
936 + extention=${extention/:*/}
937 + PIPE_CMD=""
938 + case ${extention} in
939 + xz) PIPE_CMD="xz -dc";;
940 + lzma) PIPE_CMD="lzma -dc";;
941 + bz2) PIPE_CMD="bzip2 -dc";;
942 + patch) PIPE_CMD="cat";;
943 + diff) PIPE_CMD="cat";;
944 + gz|Z|z) PIPE_CMD="gzip -dc";;
945 + ZIP|zip) PIPE_CMD="unzip -p";;
946 + *) UNIPATCH_DROP="${UNIPATCH_DROP} ${i/:*/}";;
947 + esac
948 +
949 + PATCH_LEVEL=${i/*([^:])?(:)}
950 + i=${i/:*/}
951 + x=${i/*\//}
952 + x=${x/\.${extention}/}
953 +
954 + if [ -n "${PIPE_CMD}" ]; then
955 + if [ ! -r "${i}" ]; then
956 + echo
957 + eerror "FATAL: unable to locate:"
958 + eerror "${i}"
959 + eerror "for read-only. The file either has incorrect permissions"
960 + eerror "or does not exist."
961 + die Unable to locate ${i}
962 + fi
963 +
964 + if [ -n "${UNIPATCH_STRICTORDER}" ]; then
965 + unset z
966 + STRICT_COUNT=$((10#${STRICT_COUNT} + 1))
967 + for((y=0; y<$((6 - ${#STRICT_COUNT})); y++));
968 + do z="${z}0";
969 + done
970 + PATCH_ORDER="${z}${STRICT_COUNT}"
971 +
972 + mkdir -p ${KPATCH_DIR}/${PATCH_ORDER}/
973 + $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${PATCH_ORDER}/${x}.patch${PATCH_LEVEL}) || die "uncompressing patch failed"
974 + else
975 + $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${x}.patch${PATCH_LEVEL}) || die "uncompressing patch failed"
976 + fi
977 + fi
978 + fi
979 + done
980 +
981 + #populate KPATCH_DIRS so we know where to look to remove the excludes
982 + x=${KPATCH_DIR}
983 + KPATCH_DIR=""
984 + for i in $(find ${x} -type d | sort -n); do
985 + KPATCH_DIR="${KPATCH_DIR} ${i}"
986 + done
987 +
988 + # do not apply fbcondecor patch to sparc/sparc64 as it breaks boot
989 + # bug #272676
990 + if [[ "$(tc-arch)" = "sparc" || "$(tc-arch)" = "sparc64" ]]; then
991 + if [[ ${KV_MAJOR} -ge 3 || ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} > 2.6.28 ]]; then
992 + UNIPATCH_DROP="${UNIPATCH_DROP} *_fbcondecor-0.9.6.patch"
993 + echo
994 + ewarn "fbcondecor currently prevents sparc/sparc64 from booting"
995 + ewarn "for kernel versions >= 2.6.29. Removing fbcondecor patch."
996 + ewarn "See https://bugs.gentoo.org/show_bug.cgi?id=272676 for details"
997 + echo
998 + fi
999 + fi
1000 +
1001 + #so now lets get rid of the patchno's we want to exclude
1002 + UNIPATCH_DROP="${UNIPATCH_EXCLUDE} ${UNIPATCH_DROP}"
1003 + for i in ${UNIPATCH_DROP}; do
1004 + ebegin "Excluding Patch #${i}"
1005 + for x in ${KPATCH_DIR}; do rm -f ${x}/${i}* 2>/dev/null; done
1006 + eend $?
1007 + done
1008 +
1009 + # and now, finally, we patch it :)
1010 + for x in ${KPATCH_DIR}; do
1011 + for i in $(find ${x} -maxdepth 1 -iname "*.patch*" -or -iname "*.diff*" | sort -n); do
1012 + STDERR_T="${T}/${i/*\//}"
1013 + STDERR_T="${STDERR_T/.patch*/.err}"
1014 +
1015 + [ -z ${i/*.patch*/} ] && PATCH_DEPTH=${i/*.patch/}
1016 + #[ -z ${i/*.diff*/} ] && PATCH_DEPTH=${i/*.diff/}
1017 +
1018 + if [ -z "${PATCH_DEPTH}" ]; then PATCH_DEPTH=0; fi
1019 +
1020 + ebegin "Applying ${i/*\//} (-p${PATCH_DEPTH}+)"
1021 + while [ ${PATCH_DEPTH} -lt 5 ]; do
1022 + echo "Attempting Dry-run:" >> ${STDERR_T}
1023 + echo "cmd: patch -p${PATCH_DEPTH} --no-backup-if-mismatch --dry-run -f < ${i}" >> ${STDERR_T}
1024 + echo "=======================================================" >> ${STDERR_T}
1025 + if [ $(patch -p${PATCH_DEPTH} --no-backup-if-mismatch --dry-run -f < ${i} >> ${STDERR_T}) $? -eq 0 ]; then
1026 + echo "Attempting patch:" > ${STDERR_T}
1027 + echo "cmd: patch -p${PATCH_DEPTH} --no-backup-if-mismatch -f < ${i}" >> ${STDERR_T}
1028 + echo "=======================================================" >> ${STDERR_T}
1029 + if [ $(patch -p${PATCH_DEPTH} --no-backup-if-mismatch -f < ${i} >> ${STDERR_T}) "$?" -eq 0 ]; then
1030 + eend 0
1031 + rm ${STDERR_T}
1032 + break
1033 + else
1034 + eend 1
1035 + eerror "Failed to apply patch ${i/*\//}"
1036 + eerror "Please attach ${STDERR_T} to any bug you may post."
1037 + eshopts_pop
1038 + die "Failed to apply ${i/*\//}"
1039 + fi
1040 + else
1041 + PATCH_DEPTH=$((${PATCH_DEPTH} + 1))
1042 + fi
1043 + done
1044 + if [ ${PATCH_DEPTH} -eq 5 ]; then
1045 + eend 1
1046 + eerror "Please attach ${STDERR_T} to any bug you may post."
1047 + eshopts_pop
1048 + die "Unable to dry-run patch."
1049 + fi
1050 + done
1051 + done
1052 +
1053 + # This is a quick, and kind of nasty hack to deal with UNIPATCH_DOCS which
1054 + # sit in KPATCH_DIR's. This is handled properly in the unipatch rewrite,
1055 + # which is why I'm not taking too much time over this.
1056 + local tmp
1057 + for i in ${UNIPATCH_DOCS}; do
1058 + tmp="${tmp} ${i//*\/}"
1059 + cp -f ${i} "${T}"/
1060 + done
1061 + UNIPATCH_DOCS="${tmp}"
1062 +
1063 + # clean up KPATCH_DIR's - fixes bug #53610
1064 + for x in ${KPATCH_DIR}; do rm -Rf ${x}; done
1065 +
1066 + LC_ALL="${myLC_ALL}"
1067 + LANG="${myLANG}"
1068 + eshopts_pop
1069 +}
1070 +
1071 +# getfilevar accepts 2 vars as follows:
1072 +# getfilevar <VARIABLE> <CONFIGFILE>
1073 +# pulled from linux-info
1074 +
1075 +getfilevar() {
1076 + local workingdir basefname basedname xarch=$(tc-arch-kernel)
1077 +
1078 + if [[ -z ${1} ]] && [[ ! -f ${2} ]]; then
1079 + echo -e "\n"
1080 + eerror "getfilevar requires 2 variables, with the second a valid file."
1081 + eerror " getfilevar <VARIABLE> <CONFIGFILE>"
1082 + else
1083 + workingdir=${PWD}
1084 + basefname=$(basename ${2})
1085 + basedname=$(dirname ${2})
1086 + unset ARCH
1087 +
1088 + cd ${basedname}
1089 + echo -e "include ${basefname}\ne:\n\t@echo \$(${1})" | \
1090 + make ${BUILD_FIXES} -s -f - e 2>/dev/null
1091 + cd ${workingdir}
1092 +
1093 + ARCH=${xarch}
1094 + fi
1095 +}
1096 +
1097 +detect_arch() {
1098 + # This function sets ARCH_URI and ARCH_PATCH
1099 + # with the neccessary info for the arch sepecific compatibility
1100 + # patchsets.
1101 +
1102 + local ALL_ARCH LOOP_ARCH COMPAT_URI i
1103 +
1104 + # COMPAT_URI is the contents of ${ARCH}_URI
1105 + # ARCH_URI is the URI for all the ${ARCH}_URI patches
1106 + # ARCH_PATCH is ARCH_URI broken into files for UNIPATCH
1107 +
1108 + ARCH_URI=""
1109 + ARCH_PATCH=""
1110 + ALL_ARCH="ALPHA AMD64 ARM HPPA IA64 M68K MIPS PPC PPC64 S390 SH SPARC X86"
1111 +
1112 + for LOOP_ARCH in ${ALL_ARCH}; do
1113 + COMPAT_URI="${LOOP_ARCH}_URI"
1114 + COMPAT_URI="${!COMPAT_URI}"
1115 +
1116 + [[ -n ${COMPAT_URI} ]] && \
1117 + ARCH_URI="${ARCH_URI} $(echo ${LOOP_ARCH} | tr '[:upper:]' '[:lower:]')? ( ${COMPAT_URI} )"
1118 +
1119 + if [[ ${LOOP_ARCH} == "$(echo $(tc-arch-kernel) | tr '[:lower:]' '[:upper:]')" ]]; then
1120 + for i in ${COMPAT_URI}; do
1121 + ARCH_PATCH="${ARCH_PATCH} ${DISTDIR}/${i/*\//}"
1122 + done
1123 + fi
1124 + done
1125 +}
1126 +
1127 +headers___fix() {
1128 + # Voodoo to partially fix broken upstream headers.
1129 + # note: do not put inline/asm/volatile together (breaks "inline asm volatile")
1130 + sed -i \
1131 + -e '/^\#define.*_TYPES_H/{:loop n; bloop}' \
1132 + -e 's:\<\([us]\(8\|16\|32\|64\)\)\>:__\1:g' \
1133 + -e "s/\([[:space:]]\)inline\([[:space:](]\)/\1__inline__\2/g" \
1134 + -e "s/\([[:space:]]\)asm\([[:space:](]\)/\1__asm__\2/g" \
1135 + -e "s/\([[:space:]]\)volatile\([[:space:](]\)/\1__volatile__\2/g" \
1136 + "$@"
1137 +}
1138 +
1139 +# common functions
1140 +#==============================================================
1141 +kernel-2_src_unpack() {
1142 + universal_unpack
1143 + debug-print "Doing unipatch"
1144 +
1145 + [[ -n ${UNIPATCH_LIST} || -n ${UNIPATCH_LIST_DEFAULT} || -n ${UNIPATCH_LIST_GENPATCHES} ]] && \
1146 + unipatch "${UNIPATCH_LIST_DEFAULT} ${UNIPATCH_LIST_GENPATCHES} ${UNIPATCH_LIST}"
1147 +
1148 + debug-print "Doing premake"
1149 +
1150 + # allow ebuilds to massage the source tree after patching but before
1151 + # we run misc `make` functions below
1152 + [[ $(type -t kernel-2_hook_premake) == "function" ]] && kernel-2_hook_premake
1153 +
1154 + debug-print "Doing epatch_user"
1155 + epatch_user
1156 +
1157 + debug-print "Doing unpack_set_extraversion"
1158 +
1159 + [[ -z ${K_NOSETEXTRAVERSION} ]] && unpack_set_extraversion
1160 + unpack_fix_install_path
1161 +
1162 + # Setup xmakeopts and cd into sourcetree.
1163 + env_setup_xmakeopts
1164 + cd "${S}"
1165 +
1166 + # We dont need a version.h for anything other than headers
1167 + # at least, I should hope we dont. If this causes problems
1168 + # take out the if/fi block and inform me please.
1169 + # unpack_2_6 should now be 2.6.17 safe anyways
1170 + if [[ ${ETYPE} == headers ]]; then
1171 + kernel_is 2 4 && unpack_2_4
1172 + kernel_is 2 6 && unpack_2_6
1173 + fi
1174 +
1175 + if [[ $K_DEBLOB_AVAILABLE == 1 ]] && use deblob ; then
1176 + cp "${DISTDIR}/${DEBLOB_A}" "${T}" || die "cp ${DEBLOB_A} failed"
1177 + cp "${DISTDIR}/${DEBLOB_CHECK_A}" "${T}/deblob-check" || die "cp ${DEBLOB_CHECK_A} failed"
1178 + chmod +x "${T}/${DEBLOB_A}" "${T}/deblob-check" || die "chmod deblob scripts failed"
1179 + fi
1180 +}
1181 +
1182 +kernel-2_src_compile() {
1183 + cd "${S}"
1184 + [[ ${ETYPE} == headers ]] && compile_headers
1185 +
1186 + if [[ $K_DEBLOB_AVAILABLE == 1 ]] && use deblob ; then
1187 + echo ">>> Running deblob script ..."
1188 + sh "${T}/${DEBLOB_A}" --force || \
1189 + die "Deblob script failed to run!!!"
1190 + fi
1191 +}
1192 +
1193 +# if you leave it to the default src_test, it will run make to
1194 +# find whether test/check targets are present; since "make test"
1195 +# actually produces a few support files, they are installed even
1196 +# though the package is binchecks-restricted.
1197 +#
1198 +# Avoid this altogether by making the function moot.
1199 +kernel-2_src_test() { :; }
1200 +
1201 +kernel-2_pkg_preinst() {
1202 + [[ ${ETYPE} == headers ]] && preinst_headers
1203 +}
1204 +
1205 +kernel-2_src_install() {
1206 + install_universal
1207 + [[ ${ETYPE} == headers ]] && install_headers
1208 + [[ ${ETYPE} == sources ]] && install_sources
1209 +}
1210 +
1211 +kernel-2_pkg_postinst() {
1212 + [[ ${ETYPE} == sources ]] && postinst_sources
1213 +}
1214 +
1215 +kernel-2_pkg_setup() {
1216 + if kernel_is 2 4; then
1217 + if [[ $(gcc-major-version) -ge 4 ]] ; then
1218 + echo
1219 + ewarn "Be warned !! >=sys-devel/gcc-4.0.0 isn't supported with linux-2.4!"
1220 + ewarn "Either switch to another gcc-version (via gcc-config) or use a"
1221 + ewarn "newer kernel that supports gcc-4."
1222 + echo
1223 + ewarn "Also be aware that bugreports about gcc-4 not working"
1224 + ewarn "with linux-2.4 based ebuilds will be closed as INVALID!"
1225 + echo
1226 + epause 10
1227 + fi
1228 + fi
1229 +
1230 + ABI="${KERNEL_ABI}"
1231 + [[ ${ETYPE} == headers ]] && setup_headers
1232 + [[ ${ETYPE} == sources ]] && echo ">>> Preparing to unpack ..."
1233 +}
1234 +
1235 +kernel-2_pkg_postrm() {
1236 + # This warning only makes sense for kernel sources.
1237 + [[ ${ETYPE} == headers ]] && return 0
1238 +
1239 + # If there isn't anything left behind, then don't complain.
1240 + [[ -e ${ROOT}usr/src/linux-${KV_FULL} ]] || return 0
1241 + echo
1242 + ewarn "Note: Even though you have successfully unmerged "
1243 + ewarn "your kernel package, directories in kernel source location: "
1244 + ewarn "${ROOT}usr/src/linux-${KV_FULL}"
1245 + ewarn "with modified files will remain behind. By design, package managers"
1246 + ewarn "will not remove these modified files and the directories they reside in."
1247 + echo
1248 +}