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

Contents of /eclass/kernel-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (show annotations) (download)
Sun Jan 25 21:58:26 2004 UTC (15 years, 5 months ago) by johnm
Branch: MAIN
Changes since 1.18: +6 -4 lines
adding support for UNIPATCH_EXCLUDE as well as exclusion within UNIPATCH_LIST

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_EXCLUDE - an addition var to support exlusion based completely on "<passedstring>*" and not "<passedno#>_*"
31 # UNIPATCH_DOCS - space delimemeted list of docs to be installed to the doc dir
32 # UNIPATCH_STRICTORDER - if this is set places patches into directories of order, so they are applied in the order passed
33
34 ECLASS="kernel-2"
35 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_preinst pkg_postinst
36
37 HOMEPAGE="http://www.kernel.org/ http://www.gentoo.org/"
38 LICENSE="GPL-2"
39 IUSE="${IUSE} build"
40 SLOT="${KV}"
41
42 # Grab kernel version from KV
43 KV_MAJOR=$(echo ${KV} | cut -d. -f1)
44 KV_MINOR=$(echo ${KV} | cut -d. -f2)
45 KV_PATCH=$(echo ${KV} | cut -d. -f3)
46 KV_PATCH=${KV_PATCH/[-_]*/}
47
48 # set LINUX_HOSTCFLAGS if not already set
49 [ -z "$LINUX_HOSTCFLAGS" ] && LINUX_HOSTCFLAGS="-Wall -Wstrict-prototypes -Os -fomit-frame-pointer -I${S}/include"
50
51
52 #eclass functions only from here onwards.
53 #==============================================================
54 kernel_is_2_4() {
55 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -eq 4 ] && return 0 || return 1
56 }
57
58 kernel_is_2_6() {
59 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -eq 5 -o ${KV_MINOR} -eq 6 ] && return 0 || return 1
60 }
61
62 # capture the sources type and set depends
63 if [ "${ETYPE}" == "sources" ]
64 then
65 #console-tools is needed to solve the loadkeys fiasco; binutils version needed to avoid Athlon/PIII/SSE assembler bugs.
66 DEPEND="!build? ( sys-apps/sed
67 >=sys-devel/binutils-2.11.90.0.31 )"
68
69 RDEPEND="${DEPEND}
70 !build? ( >=sys-libs/ncurses-5.2
71 dev-lang/perl
72 sys-apps/module-init-tools
73 sys-devel/make )"
74
75 [ $(kernel_is_2_4) $? == 0 ] && PROVIDE="virtual/linux-sources" || PROVIDE="virtual/linux-sources virtual/alsa"
76
77 elif [ "${ETYPE}" == "headers" ]
78 then
79 PROVIDE="virtual/kernel virtual/os-headers"
80 else
81 eerror "Unknown ETYPE=\"${ETYPE}\", must be either \"sources\" or \"headers\""
82 die
83 fi
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_DROP
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_DROP="${UNIPATCH_DROP} ${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 UNIPATCH_DROP="${UNIPATCH_EXCLUDE} ${UNIPATCH_DROP}"
371 for i in ${UNIPATCH_DROP}
372 do
373 for x in ${KPATCH_DIR}
374 do
375 rm ${x}/${i}* 2>/dev/null
376 if [ $? == 0 ]
377 then
378 einfo "Excluding Patch #${i}"
379 einfo "From: ${x/${WORKDIR}/}"
380 fi
381 done
382 done
383
384 # and now, finally, we patch it :)
385 for x in ${KPATCH_DIR}
386 do
387 for i in $(find ${x} -maxdepth 1 -iname "*.patch" -or -iname "*.diff" | sort -u)
388 do
389 PATCH_DEPTH=0
390 ebegin "Applying ${i/*\//}"
391 while [ ${PATCH_DEPTH} -lt 5 ]
392 do
393 if (patch -p${PATCH_DEPTH} --dry-run -f < ${i} >/dev/null)
394 then
395 $(patch -p${PATCH_DEPTH} -f < ${i} >/dev/null)
396 if [ "$?" -eq 0 ]
397 then
398 eend 0
399 break
400 else
401 eend 1
402 eerror "Failed to apply patch ${i/*\//}"
403 die "Failed to apply ${i/*\//}"
404 fi
405 else
406 PATCH_DEPTH=$((${PATCH_DEPTH} + 1))
407 fi
408 done
409 if [ ${PATCH_DEPTH} -eq 5 ]
410 then
411 eend 1
412 die "Unable to dry-run patch."
413 fi
414
415
416 done
417 done
418 }
419
420 # custom functions
421 #==============================================================
422 detect_version() {
423 # this function will detect and set
424 # - OKV: Original Kernel Version (2.6.0/2.6.0-test11)
425 # - KV: Kernel Version (2.6.0-gentoo/2.6.0-test11-gentoo-r1)
426 # - EXTRAVERSION: The additional version appended to OKV (-gentoo/-gentoo-r1)
427
428 OKV=${PV/_beta/-test}
429 OKV=${OKV/_rc/-rc}
430 OKV=${OKV/_pre*/}
431 OKV=${OKV/-r*/}
432
433 KV_MAJOR=$(echo ${OKV} | cut -d. -f1)
434 KV_MINOR=$(echo ${OKV} | cut -d. -f2)
435 KV_PATCH=$(echo ${OKV} | cut -d. -f3)
436 KV_PATCH=${KV_PATCH/[-_]*/}
437
438 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
439
440 RELEASE=${PV/${OKV}/}
441 RELEASE=${RELEASE/_beta/}
442 RELEASE=${RELEASE/_rc/-rc}
443 RELEASE=${RELEASE/_pre/-bk}
444 RELEASETYPE=${RELEASE//[0-9]/}
445
446 EXTRAVERSION="${RELEASE}"
447
448 if [ -n "${K_PREPATCHED}" ]
449 then
450 KV="${OKV}-${PN/-*/}${PR/r/}"
451 else
452 [ -z "${K_NOUSENAME}" ] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*/}"
453 [ ! "${PR}" == "r0" ] && EXTRAVERSION="${EXTRAVERSION}-${PR}"
454
455 KV=${OKV}${EXTRAVERSION}
456 fi
457
458 # -rcXX-bkXX pulls are *IMPOSSIBLE* to support within the portage naming convention
459 # these cannot be supported, but the code here can handle it up until this point
460 # and theoretically thereafter.
461
462 if [ "${RELEASETYPE}" == "-rc" ]
463 then
464 OKV="${KV_MAJOR}.${KV_MINOR}.$([ $((${KV_PATCH} - 1)) -lt 0 ] && echo ${KV_PATCH} || echo $((${KV_PATCH} - 1)))"
465 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/testing/patch-${PV//_/-}.bz2
466 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
467 UNIPATCH_LIST="${DISTDIR}/patch-${PV//_/-}.bz2 ${UNIPATCH_LIST}"
468 [ -n "${K_PREPATCHED}" ] && KV="${PV/[-_]*/}${EXTRAVERSION}-${PN/-*/}${PR/r/}" || KV=${PV/[-_]*/}${EXTRAVERSION}
469 fi
470
471 if [ "${RELEASETYPE}" == "-bk" ]
472 then
473 OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
474 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2
475 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
476 UNIPATCH_LIST="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 ${UNIPATCH_LIST}"
477 [ -n "${K_PREPATCHED}" ] && KV="${PV/[-_]*/}${EXTRAVERSION}-${PN/-*/}${PR/r/}" || KV=${PV/[-_]*/}${EXTRAVERSION}
478 fi
479
480 if [ "${RELEASETYPE}" == "-rc-bk" ]
481 then
482 OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))-${RELEASE/-bk*}"
483 EXTRAVERSION="$([ -n "${RELEASE}" ] && echo ${RELEASE/*-bk/-bk})$([ -n "${K_USENAME}" ] && echo -${PN/-*/})$([ ! "${PR}" == "r0" ] && echo -${PR})"
484
485 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2
486 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
487 UNIPATCH_LIST="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 ${UNIPATCH_LIST}"
488 [ -n "${K_PREPATCHED}" ] && KV="${PV/[-_]*/}${EXTRAVERSION}-${PN/-*/}${PR/r/}" || KV=${PV/[-_]*/}${EXTRAVERSION}
489 fi
490
491 S=${WORKDIR}/linux-${KV}
492 }
493
494
495 # common functions
496 #==============================================================
497 src_unpack() {
498 [ -z "${OKV}" ] && OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
499
500 cd ${WORKDIR}
501 unpack linux-${OKV}.tar.bz2
502 if [ "${OKV}" != "${KV}" ]
503 then
504 mv linux-${OKV} linux-${KV} || die "Unable to move source tree to ${KV}."
505 fi
506 cd ${S}
507
508 universal_unpack
509 [ -n "${UNIPATCH_LIST}" ] && unipatch ${UNIPATCH_LIST}
510 [ -z "${K_NOSETEXTRAVERSION}" ] && unpack_set_extraversion
511
512 [ $(kernel_is_2_4) $? == 0 ] && unpack_2_4
513 }
514
515 src_compile() {
516 [ "${ETYPE}" == "headers" ] && compile_headers
517 }
518
519 pkg_preinst() {
520 [ "${ETYPE}" == "headers" ] && preinst_headers
521 }
522
523 src_install() {
524 install_universal
525 [ "${ETYPE}" == "headers" ] && install_headers
526 [ "${ETYPE}" == "sources" ] && install_sources
527 }
528
529 pkg_postinst() {
530 [ "${ETYPE}" == "headers" ] && postinst_headers
531 [ "${ETYPE}" == "sources" ] && postinst_sources
532 }
533
534 pkg_setup() {
535 [ "${ETYPE}" == "headers" ] && setup_headers
536
537 # this is to fix some weird portage bug? in stable versions of portage.
538 [ "${ETYPE}" == "sources" ] && echo ">>> Preparing to unpack..."
539 }

  ViewVC Help
Powered by ViewVC 1.1.20