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

Contents of /eclass/kernel-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.161 - (show annotations) (download)
Tue Feb 28 02:56:47 2006 UTC (13 years, 3 months ago) by vapier
Branch: MAIN
Changes since 1.160: +2 -3 lines
move EXPORT_FUNCTIONS definition to one line to make it easier to grep/parse

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

  ViewVC Help
Powered by ViewVC 1.1.20