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

Contents of /eclass/kernel-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (show annotations) (download)
Fri Jan 23 18:08:48 2004 UTC (15 years, 8 months ago) by johnm
Branch: MAIN
Changes since 1.12: +11 -2 lines
minor fix in pkg_setup to ensure it gets a return code, this appears to be an old portage bug as the newer versions of portage work fine. this will only happen when merging outside of ones profile. fixes bug #39139

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 EXTRAVERSION
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
32 ECLASS="kernel-2"
33 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_preinst pkg_postinst
34
35 HOMEPAGE="http://www.kernel.org/ http://www.gentoo.org/"
36 LICENSE="GPL-2"
37 IUSE="${IUSE} build"
38 SLOT="${KV}"
39
40 # capture the sources type and set depends
41 if [ "${ETYPE}" == "sources" ]
42 then
43 #console-tools is needed to solve the loadkeys fiasco; binutils version needed to avoid Athlon/PIII/SSE assembler bugs.
44 DEPEND="!build? ( sys-apps/sed
45 >=sys-devel/binutils-2.11.90.0.31 )"
46
47 RDEPEND="${DEPEND}
48 !build? ( >=sys-libs/ncurses-5.2
49 dev-lang/perl
50 sys-apps/module-init-tools
51 sys-devel/make )"
52
53 PROVIDE="virtual/linux-sources virtual/alsa"
54
55 elif [ "${ETYPE}" == "headers" ]
56 then
57 PROVIDE="virtual/kernel virtual/os-headers"
58 else
59 eerror "Unknown ETYPE=\"${ETYPE}\", must be either \"sources\" or \"headers\""
60 die
61 fi
62
63 # Grab kernel version from KV
64 KV_MAJOR=$(echo ${KV} | cut -d. -f1)
65 KV_MINOR=$(echo ${KV} | cut -d. -f2)
66 KV_PATCH=$(echo ${KV} | cut -d. -f3)
67 KV_PATCH=${KV_PATCH/[-_]*/}
68
69 # set LINUX_HOSTCFLAGS if not already set
70 [ -z "$LINUX_HOSTCFLAGS" ] && LINUX_HOSTCFLAGS="-Wall -Wstrict-prototypes -Os -fomit-frame-pointer -I${S}/include"
71
72
73 #eclass functions only from here onwards.
74 #==============================================================
75 kernel_is_2_4() {
76 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -eq 4 ] && return 0 || return 1
77 }
78
79 kernel_is_2_6() {
80 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -eq 5 -o ${KV_MINOR} -eq 6 ] && return 0 || return 1
81 }
82
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 [ $(kernel_is_2_6) $? == 0 ] && ln -sf ${S}/include/asm-${ARCH} ${S}/include/asm
142
143
144 cd ${S}
145 dodir /usr/include/linux
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
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 ${PIPE_CMD} ${i} -C ${KPATCH_DIR} 1>/dev/null
314 if [ $? == 0 ]
315 then
316 einfo "${i/*\//} unpacked"
317 else
318 eerror "Failed to unpack ${i}"
319 die "unable to unpack patch tarball"
320 fi
321
322 UNIPATCH_LIST="${UNIPATCH_LIST/${i}/}"
323 fi
324 done
325
326 #so now everything is unpacked, lets work out whats to be dropped and whats to be included.
327 for i in ${UNIPATCH_LIST}
328 do
329 extention=${i/*./}
330 PIPE_CMD=""
331 case ${extention} in
332 bz2) PIPE_CMD="bzip2 -dc";;
333 patch) PIPE_CMD="cat";;
334 diff) PIPE_CMD="cat";;
335 gz|Z|z) PIPE_CMD="gzip -dc";;
336 ZIP|zip) PIPE_CMD="unzip -p";;
337 *) UNIPATCH_EXCLUDE="${UNIPATCH_EXCLUDE} ${i}";;
338 esac
339 x=${i/*\//}
340 x=${x/\.${extention}/}
341 [ -n "${PIPE_CMD}" ] && ${PIPE_CMD} ${i} > ${KPATCH_DIR}/${x}.patch
342 done
343
344 #populate KPATCH_DIRS so we know where to look to remove the excludes
345 x=${KPATCH_DIR}
346 KPATCH_DIR=""
347 for i in $(find ${x} -type d)
348 do
349 KPATCH_DIR="${KPATCH_DIR} ${i}"
350 done
351
352 #so now lets get rid of the patchno's we want to exclude
353 for i in ${UNIPATCH_EXCLUDE}
354 do
355 for x in ${KPATCH_DIR}
356 do
357 rm ${x}/${i}_* 2>/dev/null
358 if [ $? == 0 ]
359 then
360 einfo "Excluding Patch #${i}"
361 einfo "From: ${x/${WORKDIR}/}"
362 fi
363 done
364 done
365
366 # and now, finally, we patch it :)
367 for x in ${KPATCH_DIR}
368 do
369 for i in $(find ${x} -maxdepth 1 -iname "*.patch" -or -iname "*.diff" | sort -u)
370 do
371
372
373 PATCH_DEPTH=0
374 ebegin "Applying ${i/*\//}"
375 while [ ${PATCH_DEPTH} -lt 5 ]
376 do
377 if (patch -p${PATCH_DEPTH} --dry-run -f < ${i} >/dev/null)
378 then
379 $(patch -p${PATCH_DEPTH} -f < ${i} >/dev/null)
380 if [ "$?" -eq 0 ]
381 then
382 eend 0
383 break
384 else
385 eend 1
386 eerror "Failed to apply patch ${i/*\//}"
387 die "Failed to apply ${i/*\//}"
388 fi
389 else
390 PATCH_DEPTH=$((${PATCH_DEPTH} + 1))
391 fi
392 done
393 if [ ${PATCH_DEPTH} -eq 5 ]
394 then
395 eend 1
396 die "Unable to dry-run patch."
397 fi
398
399
400 done
401 done
402 }
403
404 # custom functions
405 #==============================================================
406 detect_version() {
407 # this function will detect and set
408 # - OKV: Original Kernel Version (2.6.0/2.6.0-test11)
409 # - KV: Kernel Version (2.6.0-gentoo/2.6.0-test11-gentoo-r1)
410 # - EXTRAVERSION: The additional version appended to OKV (-gentoo/-gentoo-r1)
411
412 OKV=${PV/_beta/-test}
413 OKV=${OKV/_rc/-rc}
414 OKV=${OKV/_pre*/}
415 OKV=${OKV/-r*/}
416
417 KV_MAJOR=$(echo ${OKV} | cut -d. -f1)
418 KV_MINOR=$(echo ${OKV} | cut -d. -f2)
419 KV_PATCH=$(echo ${OKV} | cut -d. -f3)
420 KV_PATCH=${KV_PATCH/[-_]*/}
421
422 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
423
424 RELEASE=${PV/${OKV}/}
425 RELEASE=${RELEASE/_beta/}
426 RELEASE=${RELEASE/_rc/-rc}
427 RELEASE=${RELEASE/_pre/-bk}
428 RELEASETYPE=${RELEASE//[0-9]/}
429
430 EXTRAVERSION="${RELEASE}"
431
432 if [ -n "${K_PREPATCHED}" ]
433 then
434 KV="${OKV}-${PN/-*/}${PR/r/}"
435 else
436 [ -z "${K_NOUSENAME}" ] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*/}"
437 [ ! "${PR}" == "r0" ] && EXTRAVERSION="${EXTRAVERSION}-${PR}"
438
439 KV=${OKV}${EXTRAVERSION}
440 fi
441
442 # -rcXX-bkXX pulls are *IMPOSSIBLE* to support within the portage naming convention
443 # these cannot be supported, but the code here can handle it up until this point
444 # and theoretically thereafter.
445
446 if [ "${RELEASETYPE}" == "-rc" ]
447 then
448 OKV="${KV_MAJOR}.${KV_MINOR}.$([ $((${KV_PATCH} - 1)) -lt 0 ] && echo ${KV_PATCH} || echo $((${KV_PATCH} - 1)))"
449 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/testing/patch-${PV//_/-}.bz2
450 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
451 UNIPATCH_LIST="${DISTDIR}/patch-${PV//_/-}.bz2 ${UNIPATCH_LIST}"
452 [ -n "${K_PREPATCHED}" ] && KV="${PV/[-_]*/}${EXTRAVERSION}-${PN/-*/}${PR/r/}" || KV=${PV/[-_]*/}${EXTRAVERSION}
453 fi
454
455 if [ "${RELEASETYPE}" == "-bk" ]
456 then
457 OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
458 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2
459 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
460 UNIPATCH_LIST="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 ${UNIPATCH_LIST}"
461 [ -n "${K_PREPATCHED}" ] && KV="${PV/[-_]*/}${EXTRAVERSION}-${PN/-*/}${PR/r/}" || KV=${PV/[-_]*/}${EXTRAVERSION}
462 fi
463
464 if [ "${RELEASETYPE}" == "-rc-bk" ]
465 then
466 OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))-${RELEASE/-bk*}"
467 EXTRAVERSION="$([ -n "${RELEASE}" ] && echo ${RELEASE/*-bk/-bk})$([ -n "${K_USENAME}" ] && echo -${PN/-*/})$([ ! "${PR}" == "r0" ] && echo -${PR})"
468
469 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2
470 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
471 UNIPATCH_LIST="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 ${UNIPATCH_LIST}"
472 [ -n "${K_PREPATCHED}" ] && KV="${PV/[-_]*/}${EXTRAVERSION}-${PN/-*/}${PR/r/}" || KV=${PV/[-_]*/}${EXTRAVERSION}
473 fi
474
475 S=${WORKDIR}/linux-${KV}
476 }
477
478
479 # common functions
480 #==============================================================
481 src_unpack() {
482 [ -z "${OKV}" ] && OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
483
484 cd ${WORKDIR}
485 unpack linux-${OKV}.tar.bz2
486 if [ "${OKV}" != "${KV}" ]
487 then
488 mv linux-${OKV} linux-${KV} || die "Unable to move source tree to ${KV}."
489 fi
490 cd ${S}
491
492 universal_unpack
493 [ -n "${UNIPATCH_LIST}" ] && unipatch ${UNIPATCH_LIST}
494 [ -z "${K_NOSETEXTRAVERSION}" ] && unpack_set_extraversion
495
496 [ $(kernel_is_2_4) $? == 0 ] && unpack_2_4
497 }
498
499 src_compile() {
500 [ "${ETYPE}" == "headers" ] && compile_headers
501 }
502
503 pkg_preinst() {
504 [ "${ETYPE}" == "headers" ] && preinst_headers
505 }
506
507 src_install() {
508 install_universal
509 [ "${ETYPE}" == "headers" ] && install_headers
510 [ "${ETYPE}" == "sources" ] && install_sources
511 }
512
513 pkg_postinst() {
514 [ "${ETYPE}" == "headers" ] && postinst_headers
515 [ "${ETYPE}" == "sources" ] && postinst_sources
516 }
517
518 pkg_setup() {
519 [ "${ETYPE}" == "headers" ] && setup_headers
520
521 # this is to fix some weird portage bug? in stable versions of portage.
522 [ "${ETYPE}" == "sources" ] && echo ">>> Preparing to unpack..."
523 }

  ViewVC Help
Powered by ViewVC 1.1.20