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

Diff of /eclass/kernel-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 Revision 1.12
1# kernel.eclass rewrite for a clean base regarding the 2.6 series of kernel 1# kernel.eclass rewrite for a clean base regarding the 2.6 series of kernel
2# with back-compatibility for 2.4 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
3 9
4# added functionality: 10# added functionality:
5# unipatch - a flexible, singular method to extract, add and remove patches. 11# unipatch - a flexible, singular method to extract, add and remove patches.
6 12
7# A Couple of env vars are available to effect usage of this eclass 13# A Couple of env vars are available to effect usage of this eclass
8# These are as follows: 14# These are as follows:
9# 15#
10# K_NOSETEXTRAVERSION - if this is set then EXTRAVERSION will not be automatically set within the kernel Makefile 16# K_NOSETEXTRAVERSION - if this is set then EXTRAVERSION will not be automatically set within the kernel Makefile
11# K_NOUSENAME - if this is set then EXTRAVERSION will not include the first part of ${PN} in EXTRAVERSION 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
12# UNIPATCH_LIST - space delimetered list of patches to be applied to the kernel 25# UNIPATCH_LIST - space delimetered list of patches to be applied to the kernel
13# UNIPATCH_DOCS - space delimemeted list of docs to be installed to the doc dir 26# UNIPATCH_DOCS - space delimemeted list of docs to be installed to the doc dir
14 27
15ECLASS="kernel-2" 28ECLASS="kernel-2"
16EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_preinst pkg_postinst 29EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_preinst pkg_postinst
28 >=sys-devel/binutils-2.11.90.0.31 )" 41 >=sys-devel/binutils-2.11.90.0.31 )"
29 42
30 RDEPEND="${DEPEND} 43 RDEPEND="${DEPEND}
31 !build? ( >=sys-libs/ncurses-5.2 44 !build? ( >=sys-libs/ncurses-5.2
32 dev-lang/perl 45 dev-lang/perl
33 virtual/modutils 46 sys-apps/module-init-tools
34 sys-devel/make )" 47 sys-devel/make )"
35 48
36 PROVIDE="virtual/linux-sources virtual/alsa" 49 PROVIDE="virtual/linux-sources virtual/alsa"
37 50
38elif [ "${ETYPE}" == "headers" ] 51elif [ "${ETYPE}" == "headers" ]
39then 52then
40 PROVIDE="virtual/kernel virtual/os-headers" 53 PROVIDE="virtual/kernel virtual/os-headers"
119 chmod -R a+r-w+X,u+w * 132 chmod -R a+r-w+X,u+w *
120} 133}
121 134
122install_headers() { 135install_headers() {
123 [ $(kernel_is_2_4) $? == 0 ] && unpack_2_4 136 [ $(kernel_is_2_4) $? == 0 ] && unpack_2_4
137 [ $(kernel_is_2_6) $? == 0 ] && ln -sf ${S}/include/asm-${ARCH} ${S}/include/asm
124 138
125 cd ${S} 139 cd ${S}
126 dodir /usr/include/linux 140 dodir /usr/include/linux
127 cp -ax ${S}/include/linux/* ${D}/usr/include/linux 141 cp -ax ${S}/include/linux/* ${D}/usr/include/linux
128 rm -rf ${D}/usr/include/linux/modules 142 rm -rf ${D}/usr/include/linux/modules
129 dodir /usr/include/asm 143 dodir /usr/include/asm
130 cp -ax ${S}/include/asm/* ${D}/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
131} 151}
132 152
133install_sources() { 153install_sources() {
134 local doc 154 local doc
135 local docs 155 local docs
136 156
137 cd ${S} 157 cd ${S}
138 dodir /usr/src 158 dodir /usr/src
139 echo ">>> Copying sources..." 159 echo ">>> Copying sources..."
140 if [ -d "${WORKDIR}/${KV}/docs/" ] 160 if [ -d "${WORKDIR}/${KV}/docs/" ]
141 then 161 then
142 for file in $(ls -1 ${WORKDIR}/${KV}/docs/) 162 for file in $(ls -1 ${WORKDIR}/${KV}/docs/)
143 do
144 echo "XX_${file}*" >> ${S}/patches.txt
145 cat ${WORKDIR}/${KV}/docs/${file} >> ${S}/patches.txt
146 echo "" >> ${S}/patches.txt
147 done
148 fi
149
150 if [ ! -f ${S}/patches.txt ]
151 then
152 # patches.txt is empty so lets use our ChangeLog
153 [ -f ${FILESDIR}/../ChangeLog ] && echo "Please check the ebuild ChangeLog for more details." > ${S}/patches.txt
154 fi
155
156 for doc in ${UNIPATCH_DOCS}
157 do 163 do
158 [ -f ${doc} ] && docs="${docs} ${doc}" 164 echo "XX_${file}*" >> ${S}/patches.txt
165 cat ${WORKDIR}/${KV}/docs/${file} >> ${S}/patches.txt
166 echo "" >> ${S}/patches.txt
159 done 167 done
168 fi
160 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
161 if [ -f ${S}/patches.txt ]; then 181 if [ -f ${S}/patches.txt ]; then
162 docs="${docs} ${S}/patches.txt" 182 docs="${docs} ${S}/patches.txt"
163 fi 183 fi
164 dodoc ${docs} 184 dodoc ${docs}
165 mv ${WORKDIR}/linux* ${D}/usr/src 185 mv ${WORKDIR}/linux* ${D}/usr/src
166} 186}
167 187
168# pkg_preinst functions 188# pkg_preinst functions
169#============================================================== 189#==============================================================
170preinst_headers() { 190preinst_headers() {
171 [ -L ${ROOT}usr/include/linux ] && rm ${ROOT}usr/include/linux 191 [ -L ${ROOT}usr/include/linux ] && rm ${ROOT}usr/include/linux
172 [ -L ${ROOT}usr/include/asm ] && rm ${ROOT}usr/include/asm 192 [ -L ${ROOT}usr/include/asm ] && rm ${ROOT}usr/include/asm
173} 193}
174 194
175# pkg_postinst functions 195# pkg_postinst functions
176#============================================================== 196#==============================================================
177postinst_sources() { 197postinst_sources() {
189 einfo "created (X.Y is the first 2 parts of your new kernel version)" 209 einfo "created (X.Y is the first 2 parts of your new kernel version)"
190 echo 210 echo
191 einfo "For example, this kernel will require:" 211 einfo "For example, this kernel will require:"
192 einfo "/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}" 212 einfo "/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}"
193 echo 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
240postinst_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#==============================================================
253setup_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
194} 271}
195 272
196# unipatch 273# unipatch
197#============================================================== 274#==============================================================
198unipatch() { 275unipatch() {
201 local extention 278 local extention
202 local PIPE_CMD 279 local PIPE_CMD
203 local UNIPATCH_EXCLUDE 280 local UNIPATCH_EXCLUDE
204 local KPATCH_DIR 281 local KPATCH_DIR
205 local PATCH_DEPTH 282 local PATCH_DEPTH
283 local ELINE
206 284
207 [ -z "${KPATCH_DIR}" ] && KPATCH_DIR="${WORKDIR}/patches/" 285 [ -z "${KPATCH_DIR}" ] && KPATCH_DIR="${WORKDIR}/patches/"
208 [ ! -d ${KPATCH_DIR} ] && mkdir -p ${KPATCH_DIR} 286 [ ! -d ${KPATCH_DIR} ] && mkdir -p ${KPATCH_DIR}
209 287
210 # This function will unpack all passed tarballs, add any passed patches, and remove any passed patchnumbers 288 # This function will unpack all passed tarballs, add any passed patches, and remove any passed patchnumbers
212 [ -z "${UNIPATCH_LIST}" ] && UNIPATCH_LIST="${@}" 290 [ -z "${UNIPATCH_LIST}" ] && UNIPATCH_LIST="${@}"
213 291
214 #unpack any passed tarballs 292 #unpack any passed tarballs
215 for i in ${UNIPATCH_LIST} 293 for i in ${UNIPATCH_LIST}
216 do 294 do
217 if [ -n "$(echo ${i} | grep -e ".tar" -e ".tbz" -e ".tgz")" ] 295 if [ -n "$(echo ${i} | grep -e "\.tar" -e "\.tbz" -e "\.tgz")" ]
218 then 296 then
219 extention=${i/*./} 297 extention=${i/*./}
220 case ${extention} in 298 case ${extention} in
221 tbz2) PIPE_CMD="tar -xvjf";; 299 tbz2) PIPE_CMD="tar -xvjf";;
222 bz2) PIPE_CMD="tar -xvjf";; 300 bz2) PIPE_CMD="tar -xvjf";;
245 extention=${i/*./} 323 extention=${i/*./}
246 PIPE_CMD="" 324 PIPE_CMD=""
247 case ${extention} in 325 case ${extention} in
248 bz2) PIPE_CMD="bzip2 -dc";; 326 bz2) PIPE_CMD="bzip2 -dc";;
249 patch) PIPE_CMD="cat";; 327 patch) PIPE_CMD="cat";;
328 diff) PIPE_CMD="cat";;
250 gz|Z|z) PIPE_CMD="gzip -dc";; 329 gz|Z|z) PIPE_CMD="gzip -dc";;
251 ZIP|zip) PIPE_CMD="unzip -p";; 330 ZIP|zip) PIPE_CMD="unzip -p";;
252 *) UNIPATCH_EXCLUDE="${UNIPATCH_EXCLUDE} ${i}";; 331 *) UNIPATCH_EXCLUDE="${UNIPATCH_EXCLUDE} ${i}";;
253 esac 332 esac
333 x=${i/*\//}
334 x=${x/\.${extention}/}
254 [ -n "${PIPE_CMD}" ] && ${PIPE_CMD} ${i} > ${KPATCH_DIR}/${i/*\//}.patch 335 [ -n "${PIPE_CMD}" ] && ${PIPE_CMD} ${i} > ${KPATCH_DIR}/${x}.patch
255 done 336 done
256 337
257 #populate KPATCH_DIRS so we know where to look to remove the excludes 338 #populate KPATCH_DIRS so we know where to look to remove the excludes
258 x=${KPATCH_DIR} 339 x=${KPATCH_DIR}
259 KPATCH_DIR="" 340 KPATCH_DIR=""
277 done 358 done
278 359
279 # and now, finally, we patch it :) 360 # and now, finally, we patch it :)
280 for x in ${KPATCH_DIR} 361 for x in ${KPATCH_DIR}
281 do 362 do
282 for i in $(find ${x} -maxdepth 1 -iname "*.patch" | sort -u) 363 for i in $(find ${x} -maxdepth 1 -iname "*.patch" -or -iname "*.diff" | sort -u)
283 do 364 do
284 365
285 366
286 PATCH_DEPTH=0 367 PATCH_DEPTH=0
287 ebegin "Applying ${i/*\//}" 368 ebegin "Applying ${i/*\//}"
339 RELEASE=${RELEASE/_rc/-rc} 420 RELEASE=${RELEASE/_rc/-rc}
340 RELEASE=${RELEASE/_pre/-bk} 421 RELEASE=${RELEASE/_pre/-bk}
341 RELEASETYPE=${RELEASE//[0-9]/} 422 RELEASETYPE=${RELEASE//[0-9]/}
342 423
343 EXTRAVERSION="${RELEASE}" 424 EXTRAVERSION="${RELEASE}"
425
426 if [ -n "${K_PREPATCHED}" ]
427 then
428 KV="${OKV}-${PN/-*/}${PR/r/}"
429 else
344 [ -z "${K_NOUSENAME}" ] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*/}" 430 [ -z "${K_NOUSENAME}" ] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*/}"
345 [ ! "${PR}" == "r0" ] && EXTRAVERSION="${EXTRAVERSION}-${PR}" 431 [ ! "${PR}" == "r0" ] && EXTRAVERSION="${EXTRAVERSION}-${PR}"
346 432
347 KV=${OKV}${EXTRAVERSION} 433 KV=${OKV}${EXTRAVERSION}
434 fi
348 435
349 # -rcXX-bkXX pulls are *IMPOSSIBLE* to support within the portage naming convention 436 # -rcXX-bkXX pulls are *IMPOSSIBLE* to support within the portage naming convention
350 # these cannot be supported, but the code here can handle it up until this point 437 # these cannot be supported, but the code here can handle it up until this point
351 # and theoretically thereafter. 438 # and theoretically thereafter.
352 439
354 then 441 then
355 OKV="${KV_MAJOR}.${KV_MINOR}.$([ $((${KV_PATCH} - 1)) -lt 0 ] && echo ${KV_PATCH} || echo $((${KV_PATCH} - 1)))" 442 OKV="${KV_MAJOR}.${KV_MINOR}.$([ $((${KV_PATCH} - 1)) -lt 0 ] && echo ${KV_PATCH} || echo $((${KV_PATCH} - 1)))"
356 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/testing/patch-${PV//_/-}.bz2 443 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/testing/patch-${PV//_/-}.bz2
357 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2" 444 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
358 UNIPATCH_LIST="${DISTDIR}/patch-${PV//_/-}.bz2 ${UNIPATCH_LIST}" 445 UNIPATCH_LIST="${DISTDIR}/patch-${PV//_/-}.bz2 ${UNIPATCH_LIST}"
359 KV=${PV/[-_]*/}${EXTRAVERSION} 446 [ -n "${K_PREPATCHED}" ] && KV="${PV/[-_]*/}${EXTRAVERSION}-${PN/-*/}${PR/r/}" || KV=${PV/[-_]*/}${EXTRAVERSION}
360 fi 447 fi
361 448
362 if [ "${RELEASETYPE}" == "-bk" ] 449 if [ "${RELEASETYPE}" == "-bk" ]
363 then 450 then
364 OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}" 451 OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
365 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 452 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2
366 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2" 453 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
367 UNIPATCH_LIST="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 ${UNIPATCH_LIST}" 454 UNIPATCH_LIST="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 ${UNIPATCH_LIST}"
368 KV=${PV/[-_]*/}${EXTRAVERSION} 455 [ -n "${K_PREPATCHED}" ] && KV="${PV/[-_]*/}${EXTRAVERSION}-${PN/-*/}${PR/r/}" || KV=${PV/[-_]*/}${EXTRAVERSION}
369 fi 456 fi
370 457
371 if [ "${RELEASETYPE}" == "-rc-bk" ] 458 if [ "${RELEASETYPE}" == "-rc-bk" ]
372 then 459 then
373 OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))-${RELEASE/-bk*}" 460 OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))-${RELEASE/-bk*}"
374 EXTRAVERSION="$([ -n "${RELEASE}" ] && echo ${RELEASE/*-bk/-bk})$([ -n "${K_USENAME}" ] && echo -${PN/-*/})$([ ! "${PR}" == "r0" ] && echo -${PR})" 461 EXTRAVERSION="$([ -n "${RELEASE}" ] && echo ${RELEASE/*-bk/-bk})$([ -n "${K_USENAME}" ] && echo -${PN/-*/})$([ ! "${PR}" == "r0" ] && echo -${PR})"
375 462
376 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 463 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2
377 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2" 464 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
378 UNIPATCH_LIST="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 ${UNIPATCH_LIST}" 465 UNIPATCH_LIST="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 ${UNIPATCH_LIST}"
379 KV=${PV/[-_]*/}${EXTRAVERSION} 466 [ -n "${K_PREPATCHED}" ] && KV="${PV/[-_]*/}${EXTRAVERSION}-${PN/-*/}${PR/r/}" || KV=${PV/[-_]*/}${EXTRAVERSION}
380 fi 467 fi
468
469 S=${WORKDIR}/linux-${KV}
381} 470}
382 471
383 472
384# common functions 473# common functions
385#============================================================== 474#==============================================================
386src_unpack() { 475src_unpack() {
387 [ -z "${OKV}" ] && OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}" 476 [ -z "${OKV}" ] && OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
388 477
389 cd ${WORKDIR} 478 cd ${WORKDIR}
390 unpack linux-${OKV}.tar.bz2 479 unpack linux-${OKV}.tar.bz2
480 if [ "${OKV}" != "${KV}" ]
481 then
391 mv linux-${OKV} linux-${KV} || die "Unable to move source tree to ${KV}." 482 mv linux-${OKV} linux-${KV} || die "Unable to move source tree to ${KV}."
483 fi
392 cd ${S} 484 cd ${S}
393 485
394 universal_unpack 486 universal_unpack
395 [ -n "${UNIPATCH_LIST}" ] && unipatch ${UNIPATCH_LIST} 487 [ -n "${UNIPATCH_LIST}" ] && unipatch ${UNIPATCH_LIST}
396 [ -z "${K_NOSETEXTRAVERSION}" ] && unpack_set_extraversion 488 [ -z "${K_NOSETEXTRAVERSION}" ] && unpack_set_extraversion
411 [ "${ETYPE}" == "headers" ] && install_headers 503 [ "${ETYPE}" == "headers" ] && install_headers
412 [ "${ETYPE}" == "sources" ] && install_sources 504 [ "${ETYPE}" == "sources" ] && install_sources
413} 505}
414 506
415pkg_postinst() { 507pkg_postinst() {
508 [ "${ETYPE}" == "headers" ] && postinst_headers
416 [ "${ETYPE}" == "sources" ] && postinst_sources 509 [ "${ETYPE}" == "sources" ] && postinst_sources
417} 510}
511
512pkg_setup() {
513 [ "${ETYPE}" == "headers" ] && setup_headers
514}

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.12

  ViewVC Help
Powered by ViewVC 1.1.20