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

Contents of /eclass/kernel-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (show annotations) (download)
Mon Jan 26 17:46:57 2004 UTC (15 years, 4 months ago) by johnm
Branch: MAIN
Changes since 1.22: +2 -2 lines
just a tiny tiny little whitespace fix

1 # Copyright 1999-2004 Gentoo Technologies, Inc.
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /home/cvsroot/gentoo-x86/eclass/kernel-2.eclass,v 1.22 2004/01/26 15:30:59 lu_zero Exp $
4
5 # kernel.eclass rewrite for a clean base regarding the 2.6 series of kernel
6 # with back-compatibility for 2.4
7 #
8 # Author: John Mylchreest <johnm@gentoo.org>
9 # Copyright 2004 Gentoo Linux
10 #
11 # Please direct your bugs to the current eclass maintainer :)
12 # thatll be: johnm
13
14 # added functionality:
15 # unipatch - a flexible, singular method to extract, add and remove patches.
16
17 # A Couple of env vars are available to effect usage of this eclass
18 # These are as follows:
19 #
20 # K_NOSETEXTRAVERSION - if this is set then EXTRAVERSION will not be automatically set within the kernel Makefile
21 # K_NOUSENAME - if this is set then EXTRAVERSION will not include the first part of ${PN} in EXTRAVERSION
22 # K_PREPATCHED - if the patchset is prepatched (ie: mm-sources, ck-sources, ac-sources) it will use PR (ie: -r5) as the patchset version for
23 # - and not use it as a true package revision
24 # K_EXTRAEINFO - this is a new-line seperated list of einfo displays in postinst and can be used to carry additional postinst messages
25 # K_EXTRAEWARN - same as K_EXTRAEINFO except ewarn's instead of einfo's
26
27 # H_SUPPORTEDARCH - this should be a space separated list of ARCH's which can be supported by the headers ebuild
28
29 # UNIPATCH_LIST - space delimetered list of patches to be applied to the kernel
30 # UNIPATCH_EXCLUDE - an addition var to support exlusion based completely on "<passedstring>*" and not "<passedno#>_*"
31 # - this should _NOT_ be used from the ebuild as this is reserved for end users passing excludes from the cli
32 # UNIPATCH_DOCS - space delimemeted list of docs to be installed to the doc dir
33 # UNIPATCH_STRICTORDER - if this is set places patches into directories of order, so they are applied in the order passed
34
35 ECLASS="kernel-2"
36 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_preinst pkg_postinst
37
38 HOMEPAGE="http://www.kernel.org/ http://www.gentoo.org/"
39 LICENSE="GPL-2"
40 IUSE="${IUSE} build"
41 SLOT="${KV}"
42
43 # Grab kernel version from KV
44 KV_MAJOR=$(echo ${KV} | cut -d. -f1)
45 KV_MINOR=$(echo ${KV} | cut -d. -f2)
46 KV_PATCH=$(echo ${KV} | cut -d. -f3)
47 KV_PATCH=${KV_PATCH/[-_]*/}
48
49 # set LINUX_HOSTCFLAGS if not already set
50 [ -z "$LINUX_HOSTCFLAGS" ] && LINUX_HOSTCFLAGS="-Wall -Wstrict-prototypes -Os -fomit-frame-pointer -I${S}/include"
51
52
53 #eclass functions only from here onwards.
54 #==============================================================
55 kernel_is_2_4() {
56 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -eq 4 ] && return 0 || return 1
57 }
58
59 kernel_is_2_6() {
60 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -eq 5 -o ${KV_MINOR} -eq 6 ] && return 0 || return 1
61 }
62
63 # capture the sources type and set depends
64 if [ "${ETYPE}" == "sources" ]
65 then
66 #console-tools is needed to solve the loadkeys fiasco; binutils version needed to avoid Athlon/PIII/SSE assembler bugs.
67 DEPEND="!build? ( sys-apps/sed
68 >=sys-devel/binutils-2.11.90.0.31 )"
69
70 RDEPEND="${DEPEND}
71 !build? ( >=sys-libs/ncurses-5.2
72 dev-lang/perl
73 sys-apps/module-init-tools
74 sys-devel/make )"
75
76 [ $(kernel_is_2_4) $? == 0 ] && PROVIDE="virtual/linux-sources" || PROVIDE="virtual/linux-sources virtual/alsa"
77
78 elif [ "${ETYPE}" == "headers" ]
79 then
80 PROVIDE="virtual/kernel virtual/os-headers"
81 else
82 eerror "Unknown ETYPE=\"${ETYPE}\", must be either \"sources\" or \"headers\""
83 die
84 fi
85
86 # Unpack functions
87 #==============================================================
88 unpack_2_4() {
89 cd ${S}
90 # this file is required for other things to build properly,
91 # so we autogenerate it
92 make mrproper || die "make mrproper died"
93 make include/linux/version.h || die "make include/linux/version.h failed"
94 echo ">>> version.h compiled successfully."
95 }
96
97 universal_unpack() {
98 # remove all backup files
99 find . -iname "*~" -exec rm {} \; 2> /dev/null
100
101 if [ -d "${S}/Documentation/DocBook" ]
102 then
103 cd ${S}/Documentation/DocBook
104 sed -e "s:db2:docbook2:g" Makefile > Makefile.new \
105 && mv Makefile.new Makefile
106 cd ${S}
107 fi
108 }
109
110 unpack_set_extraversion() {
111 # Gentoo Linux uses /boot, so fix 'make install' to work properly and fix EXTRAVERSION
112 cd ${S}
113 mv Makefile Makefile.orig
114 sed -e 's:#export\tINSTALL_PATH:export\tINSTALL_PATH:' \
115 -e "s:^\(EXTRAVERSION =\).*:\1 ${EXTRAVERSION}:" \
116 Makefile.orig > Makefile
117 rm Makefile.orig
118 }
119
120 # Compile Functions
121 #==============================================================
122 compile_headers() {
123 local MY_ARCH
124
125 MY_ARCH=${ARCH}
126 unset ${ARCH}
127 yes "" | make oldconfig
128 echo ">>> make oldconfig complete"
129 ARCH=${MY_ARCH}
130 }
131
132 # install functions
133 #==============================================================
134 install_universal() {
135 #fix silly permissions in tarball
136 cd ${WORKDIR}
137 chown -R root:root *
138 chmod -R a+r-w+X,u+w *
139 }
140
141 install_headers() {
142 [ $(kernel_is_2_4) $? == 0 ] && unpack_2_4
143
144 cd ${S}
145 dodir /usr/include/linux
146 ln -sf ${S}/include/asm-${ARCH} ${S}/include/asm
147 cp -ax ${S}/include/linux/* ${D}/usr/include/linux
148 rm -rf ${D}/usr/include/linux/modules
149
150 dodir /usr/include/asm
151 cp -ax ${S}/include/asm/* ${D}/usr/include/asm
152
153 if [ $(kernel_is_2_6) $? == 0 ]
154 then
155 dodir /usr/include/asm-generic
156 cp -ax ${S}/include/asm-generic/* ${D}/usr/include/asm-generic
157 fi
158 }
159
160 install_sources() {
161 local doc
162 local docs
163
164 cd ${S}
165 dodir /usr/src
166 echo ">>> Copying sources..."
167 if [ -d "${WORKDIR}/${KV}/docs/" ]
168 then
169 for file in $(ls -1 ${WORKDIR}/${KV}/docs/)
170 do
171 echo "XX_${file}*" >> ${S}/patches.txt
172 cat ${WORKDIR}/${KV}/docs/${file} >> ${S}/patches.txt
173 echo "" >> ${S}/patches.txt
174 done
175 fi
176
177 if [ ! -f ${S}/patches.txt ]
178 then
179 # patches.txt is empty so lets use our ChangeLog
180 [ -f ${FILESDIR}/../ChangeLog ] && echo "Please check the ebuild ChangeLog for more details." > ${S}/patches.txt
181 fi
182
183 for doc in ${UNIPATCH_DOCS}
184 do
185 [ -f ${doc} ] && docs="${docs} ${doc}"
186 done
187
188 if [ -f ${S}/patches.txt ]; then
189 docs="${docs} ${S}/patches.txt"
190 fi
191 dodoc ${docs}
192 mv ${WORKDIR}/linux* ${D}/usr/src
193 }
194
195 # pkg_preinst functions
196 #==============================================================
197 preinst_headers() {
198 [ -L ${ROOT}usr/include/linux ] && rm ${ROOT}usr/include/linux
199 [ -L ${ROOT}usr/include/asm ] && rm ${ROOT}usr/include/asm
200 }
201
202 # pkg_postinst functions
203 #==============================================================
204 postinst_sources() {
205 if [ ! -h ${ROOT}usr/src/linux ]
206 then
207 ln -sf ${ROOT}usr/src/linux-${KV} ${ROOT}usr/src/linux
208 fi
209
210 # Don't forget to make directory for sysfs
211 [ ! -d "${ROOT}/sys" -a $(kernel_is_2_6) $? == 0 ] && mkdir /sys
212
213 echo
214 einfo "After installing a new kernel of any version, it is important"
215 einfo "that you have the appropriate /etc/modules.autoload.d/kernel-X.Y"
216 einfo "created (X.Y is the first 2 parts of your new kernel version)"
217 echo
218 einfo "For example, this kernel will require:"
219 einfo "/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}"
220 echo
221
222 # if K_EXTRAEINFO is set then lets display it now
223 if [ -n "${K_EXTRAEINFO}" ]
224 then
225 echo ${K_EXTRAEINFO} | fmt |
226 while read -s ELINE
227 do
228 einfo "${ELINE}"
229 done
230
231 echo
232 fi
233
234 # if K_EXTRAEWARN is set then lets display it now
235 if [ -n "${K_EXTRAEWARN}" ]
236 then
237 echo ${K_EXTRAEWARN} | fmt |
238 while read -s ELINE
239 do
240 ewarn "${ELINE}"
241 done
242
243 echo
244 fi
245 }
246
247 postinst_headers() {
248 echo
249 einfo "Kernel headers are usually only used when recompiling glibc."
250 einfo "Following the installation of newer headers it is advised that"
251 einfo "you re-merge glibc as follows:"
252 einfo "# emerge glibc"
253 einfo "Failure to do so will cause glibc to not make use of newer"
254 einfo "features present in the updated kernelheaders."
255 echo
256 }
257
258 # pkg_setup functions
259 #==============================================================
260 setup_headers() {
261 ARCH=$(uname -m | sed -e s/[i].86/i386/ -e s/x86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/amd64/x86_64/)
262 [ "$ARCH" == "sparc" -a "$PROFILE_ARCH" == "sparc64" ] && ARCH="sparc64"
263
264 [ -z "${H_SUPPORTEDARCH}" ] && H_SUPPORTEDARCH="${PN/-*/}"
265 for i in ${H_SUPPORTEDARCH}
266 do
267 [ "${ARCH}" == "${i}" ] && H_ACCEPT_ARCH="yes"
268 done
269
270 if [ "${H_ACCEPT_ARCH}" != "yes" ]
271 then
272 echo
273 eerror "This version of ${PN} does not support ${ARCH}."
274 eerror "Please merge the appropriate sources, in most cases"
275 eerror "this will be ${ARCH}-headers."
276 die "incorrect headers"
277 fi
278 }
279
280 # unipatch
281 #==============================================================
282 unipatch() {
283 local i
284 local x
285 local extention
286 local PIPE_CMD
287 local UNIPATCH_DROP
288 local KPATCH_DIR
289 local PATCH_DEPTH
290 local ELINE
291 local STRICT_COUNT
292
293 [ -z "${KPATCH_DIR}" ] && KPATCH_DIR="${WORKDIR}/patches/"
294 [ ! -d ${KPATCH_DIR} ] && mkdir -p ${KPATCH_DIR}
295
296 # This function will unpack all passed tarballs, add any passed patches, and remove any passed patchnumbers
297 # usage can be either via an env var or by params
298 [ -z "${UNIPATCH_LIST}" ] && UNIPATCH_LIST="${@}"
299
300 #unpack any passed tarballs
301 for i in ${UNIPATCH_LIST}
302 do
303 if [ -n "$(echo ${i} | grep -e "\.tar" -e "\.tbz" -e "\.tgz")" ]
304 then
305 extention=${i/*./}
306 case ${extention} in
307 tbz2) PIPE_CMD="tar -xvjf";;
308 bz2) PIPE_CMD="tar -xvjf";;
309 tgz) PIPE_CMD="tar -xvzf";;
310 gz) PIPE_CMD="tar -xvzf";;
311 *) eerror "Unrecognized tarball compression"
312 die "Unrecognized tarball compression";;
313 esac
314
315 if [ -n "${UNIPATCH_STRICTORDER}" ]
316 then
317 STRICT_COUNT=$((${STRICT_COUNT} + 1))
318 mkdir -p ${KPATCH_DIR}/${STRICT_COUNT}/
319 ${PIPE_CMD} ${i} -C ${KPATCH_DIR}/${STRICT_COUNT}/ 1>/dev/null
320 else
321 ${PIPE_CMD} ${i} -C ${KPATCH_DIR} 1>/dev/null
322 fi
323
324 if [ $? == 0 ]
325 then
326 einfo "${i/*\//} unpacked"
327 else
328 eerror "Failed to unpack ${i}"
329 die "unable to unpack patch tarball"
330 fi
331
332 UNIPATCH_LIST="${UNIPATCH_LIST/${i}/}"
333 fi
334 done
335
336 #so now everything is unpacked, lets work out whats to be dropped and whats to be included.
337 for i in ${UNIPATCH_LIST}
338 do
339 extention=${i/*./}
340 PIPE_CMD=""
341 case ${extention} in
342 bz2) PIPE_CMD="bzip2 -dc";;
343 patch) PIPE_CMD="cat";;
344 diff) PIPE_CMD="cat";;
345 gz|Z|z) PIPE_CMD="gzip -dc";;
346 ZIP|zip) PIPE_CMD="unzip -p";;
347 *) UNIPATCH_DROP="${UNIPATCH_DROP} ${i}";;
348 esac
349 x=${i/*\//}
350 x=${x/\.${extention}/}
351
352 if [ -n "${UNIPATCH_STRICTORDER}" -a -n "${PIPE_CMD}" ]
353 then
354 STRICT_COUNT=$((${STRICT_COUNT} + 1))
355 mkdir -p ${KPATCH_DIR}/${STRICT_COUNT}/
356 $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${STRICT_COUNT}/${x}.patch)
357 else
358 $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${x}.patch)
359 fi
360 done
361
362 #populate KPATCH_DIRS so we know where to look to remove the excludes
363 x=${KPATCH_DIR}
364 KPATCH_DIR=""
365 for i in $(find ${x} -type d)
366 do
367 KPATCH_DIR="${KPATCH_DIR} ${i}"
368 done
369
370 #so now lets get rid of the patchno's we want to exclude
371 UNIPATCH_DROP="${UNIPATCH_EXCLUDE} ${UNIPATCH_DROP}"
372 for i in ${UNIPATCH_DROP}
373 do
374 for x in ${KPATCH_DIR}
375 do
376 rm ${x}/${i}* 2>/dev/null
377 if [ $? == 0 ]
378 then
379 einfo "Excluding Patch #${i}"
380 einfo "From: ${x/${WORKDIR}/}"
381 fi
382 done
383 done
384
385 # and now, finally, we patch it :)
386 for x in ${KPATCH_DIR}
387 do
388 for i in $(find ${x} -maxdepth 1 -iname "*.patch" -or -iname "*.diff" | sort -u)
389 do
390 PATCH_DEPTH=0
391 ebegin "Applying ${i/*\//}"
392 while [ ${PATCH_DEPTH} -lt 5 ]
393 do
394 if (patch -p${PATCH_DEPTH} --dry-run -f < ${i} >/dev/null)
395 then
396 $(patch -p${PATCH_DEPTH} -f < ${i} >/dev/null)
397 if [ "$?" -eq 0 ]
398 then
399 eend 0
400 break
401 else
402 eend 1
403 eerror "Failed to apply patch ${i/*\//}"
404 die "Failed to apply ${i/*\//}"
405 fi
406 else
407 PATCH_DEPTH=$((${PATCH_DEPTH} + 1))
408 fi
409 done
410 if [ ${PATCH_DEPTH} -eq 5 ]
411 then
412 eend 1
413 die "Unable to dry-run patch."
414 fi
415
416
417 done
418 done
419 }
420
421 # custom functions
422 #==============================================================
423 detect_version() {
424 # this function will detect and set
425 # - OKV: Original Kernel Version (2.6.0/2.6.0-test11)
426 # - KV: Kernel Version (2.6.0-gentoo/2.6.0-test11-gentoo-r1)
427 # - EXTRAVERSION: The additional version appended to OKV (-gentoo/-gentoo-r1)
428
429 OKV=${PV/_beta/-test}
430 OKV=${OKV/_rc/-rc}
431 OKV=${OKV/_pre*/}
432 OKV=${OKV/-r*/}
433
434 KV_MAJOR=$(echo ${OKV} | cut -d. -f1)
435 KV_MINOR=$(echo ${OKV} | cut -d. -f2)
436 KV_PATCH=$(echo ${OKV} | cut -d. -f3)
437 KV_PATCH=${KV_PATCH/[-_]*/}
438
439 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
440
441 RELEASE=${PV/${OKV}/}
442 RELEASE=${RELEASE/_beta/}
443 RELEASE=${RELEASE/_rc/-rc}
444 RELEASE=${RELEASE/_pre/-bk}
445 RELEASETYPE=${RELEASE//[0-9]/}
446
447 EXTRAVERSION="${RELEASE}"
448
449 if [ -n "${K_PREPATCHED}" ]
450 then
451 EXTRAVERSION="${EXTRAVERSION}-${PN/-*/}${PR/r/}"
452 else
453 [ -z "${K_NOUSENAME}" ] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*/}"
454 [ "${PR}" != "r0" ] && EXTRAVERSION="${EXTRAVERSION}-${PR}"
455 fi
456
457 KV=${OKV}${EXTRAVERSION}
458
459 # -rcXX-bkXX pulls are *IMPOSSIBLE* to support within the portage naming convention
460 # these cannot be supported, but the code here can handle it up until this point
461 # and theoretically thereafter.
462
463 if [ "${RELEASETYPE}" == "-rc" ]
464 then
465 OKV="${KV_MAJOR}.${KV_MINOR}.$([ $((${KV_PATCH} - 1)) -lt 0 ] && echo ${KV_PATCH} || echo $((${KV_PATCH} - 1)))"
466 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/testing/patch-${PV//_/-}.bz2
467 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
468 UNIPATCH_LIST="${DISTDIR}/patch-${PV//_/-}.bz2 ${UNIPATCH_LIST}"
469 KV=${PV/[-_]*/}${EXTRAVERSION}
470 fi
471
472 if [ "${RELEASETYPE}" == "-bk" ]
473 then
474 OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
475 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2
476 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
477 UNIPATCH_LIST="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 ${UNIPATCH_LIST}"
478 KV=${PV/[-_]*/}${EXTRAVERSION}
479 fi
480
481 if [ "${RELEASETYPE}" == "-rc-bk" ]
482 then
483 OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))-${RELEASE/-bk*}"
484 EXTRAVERSION="$([ -n "${RELEASE}" ] && echo ${RELEASE/*-bk/-bk})$([ -n "${K_USENAME}" ] && echo -${PN/-*/})$([ ! "${PR}" == "r0" ] && echo -${PR})"
485
486 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2
487 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
488 UNIPATCH_LIST="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 ${UNIPATCH_LIST}"
489 KV=${PV/[-_]*/}${EXTRAVERSION}
490 fi
491
492 S=${WORKDIR}/linux-${KV}
493 }
494
495
496 # common functions
497 #==============================================================
498 src_unpack() {
499 [ -z "${OKV}" ] && OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
500
501 cd ${WORKDIR}
502 unpack linux-${OKV}.tar.bz2
503 if [ "${OKV}" != "${KV}" ]
504 then
505 mv linux-${OKV} linux-${KV} || die "Unable to move source tree to ${KV}."
506 fi
507 cd ${S}
508
509 universal_unpack
510 [ -n "${UNIPATCH_LIST}" ] && unipatch ${UNIPATCH_LIST}
511 [ -z "${K_NOSETEXTRAVERSION}" ] && unpack_set_extraversion
512
513 [ $(kernel_is_2_4) $? == 0 ] && unpack_2_4
514 }
515
516 src_compile() {
517 [ "${ETYPE}" == "headers" ] && compile_headers
518 }
519
520 pkg_preinst() {
521 [ "${ETYPE}" == "headers" ] && preinst_headers
522 }
523
524 src_install() {
525 install_universal
526 [ "${ETYPE}" == "headers" ] && install_headers
527 [ "${ETYPE}" == "sources" ] && install_sources
528 }
529
530 pkg_postinst() {
531 [ "${ETYPE}" == "headers" ] && postinst_headers
532 [ "${ETYPE}" == "sources" ] && postinst_sources
533 }
534
535 pkg_setup() {
536 [ "${ETYPE}" == "headers" ] && setup_headers
537
538 # this is to fix some weird portage bug? in stable versions of portage.
539 [ "${ETYPE}" == "sources" ] && echo ">>> Preparing to unpack..."
540 }

  ViewVC Help
Powered by ViewVC 1.1.20