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

Contents of /eclass/kernel-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (show annotations) (download)
Fri Jan 23 21:43:47 2004 UTC (15 years, 4 months ago) by johnm
Branch: MAIN
Changes since 1.17: +21 -22 lines
minor fix in alsa virtual code

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

  ViewVC Help
Powered by ViewVC 1.1.20