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

Contents of /eclass/kernel-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations) (download)
Thu Jan 22 23:45:03 2004 UTC (15 years, 4 months ago) by johnm
Branch: MAIN
Changes since 1.11: +81 -34 lines
update to potentially patch all header issues (perhaps excluding sparc) and minor fix to detect_version and K_PREPATCHED for rc and bk pulls

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

  ViewVC Help
Powered by ViewVC 1.1.20