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

Contents of /eclass/kernel-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.76 - (show annotations) (download)
Wed Jan 12 05:07:24 2005 UTC (14 years, 5 months ago) by eradicator
Branch: MAIN
Changes since 1.75: +15 -2 lines
amd64 multilib header support.  Fixed missing ${D} in sparc header generation.

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

  ViewVC Help
Powered by ViewVC 1.1.20