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

Contents of /eclass/kernel-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20