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

Contents of /eclass/kernel-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.93 - (show annotations) (download)
Tue Feb 8 19:41:42 2005 UTC (14 years, 4 months ago) by johnm
Branch: MAIN
Changes since 1.92: +148 -205 lines
Pretty large cleanup, kernel_is rewrite and detect_version refactor

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

  ViewVC Help
Powered by ViewVC 1.1.20