/[gentoo-x86]/eclass/kernel-2.eclass
Gentoo

Contents of /eclass/kernel-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.203 - (show annotations) (download)
Wed Apr 25 18:22:37 2007 UTC (12 years, 2 months ago) by robbat2
Branch: MAIN
Changes since 1.202: +14 -5 lines
Use MY_DATADIR instead of DATADIR, as DATADIR breaks when the environment already contains it, per bug #174755.

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

  ViewVC Help
Powered by ViewVC 1.1.20