/[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.12 Revision 1.69
1# Copyright 1999-2004 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/kernel-2.eclass,v 1.69 2005/01/06 13:58:15 johnm Exp $
4
1# kernel.eclass rewrite for a clean base regarding the 2.6 series of kernel 5# Description: kernel.eclass rewrite for a clean base regarding the 2.6
2# with back-compatibility for 2.4 6# series of kernel with back-compatibility for 2.4
3# 7#
4# Author: John Mylchreest <johnm@gentoo.org> 8# Maintainer: John Mylchreest <johnm@gentoo.org>
5# Copyright 2004 Gentoo Linux 9# Copyright 2004 Gentoo Linux
6# 10#
7# Please direct your bugs to the current eclass maintainer :) 11# Please direct your bugs to the current eclass maintainer :)
8# thatll be: johnm
9 12
10# added functionality: 13# added functionality:
11# unipatch - a flexible, singular method to extract, add and remove patches. 14# unipatch - a flexible, singular method to extract, add and remove patches.
12 15
13# A Couple of env vars are available to effect usage of this eclass 16# A Couple of env vars are available to effect usage of this eclass
14# These are as follows: 17# These are as follows:
15# 18#
16# K_NOSETEXTRAVERSION - if this is set then EXTRAVERSION will not be automatically set within the kernel Makefile 19# K_NOSETEXTRAVERSION - if this is set then EXTRAVERSION will not be
20# 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 21# K_NOUSENAME - if this is set then EXTRAVERSION will not include the
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 22# first part of ${PN} in EXTRAVERSION
23# K_PREPATCHED - if the patchset is prepatched (ie: mm-sources,
24# ck-sources, ac-sources) it will use PR (ie: -r5) as
25# the patchset version for
19# - and not use it as a true package revision 26# - 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 27# K_EXTRAEINFO - this is a new-line seperated list of einfo displays in
28# postinst and can be used to carry additional postinst
29# messages
21# K_EXTRAEWARN - same as K_EXTRAEINFO except ewarn's instead of einfo's 30# K_EXTRAEWARN - same as K_EXTRAEINFO except ewarn's instead of einfo's
22 31
23# H_SUPPORTEDARCH - this should be a space separated list of ARCH's which can be supported by the headers ebuild 32# H_SUPPORTEDARCH - this should be a space separated list of ARCH's which
33# can be supported by the headers ebuild
24 34
25# UNIPATCH_LIST - space delimetered list of patches to be applied to the kernel 35# UNIPATCH_LIST - space delimetered list of patches to be applied to the
36# kernel
37# UNIPATCH_EXCLUDE - an addition var to support exlusion based completely
38# on "<passedstring>*" and not "<passedno#>_*"
39# - this should _NOT_ be used from the ebuild as this is
40# reserved for end users passing excludes from the cli
26# UNIPATCH_DOCS - space delimemeted list of docs to be installed to the doc dir 41# UNIPATCH_DOCS - space delimemeted list of docs to be installed to
42# the doc dir
43# UNIPATCH_STRICTORDER - if this is set places patches into directories of
44# order, so they are applied in the order passed
27 45
28ECLASS="kernel-2" 46ECLASS="kernel-2"
47INHERITED="$INHERITED $ECLASS"
29EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_preinst pkg_postinst 48EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_preinst pkg_postinst
30 49
50export CTARGET="${CTARGET:-${CHOST}}"
51
31HOMEPAGE="http://www.kernel.org/ http://www.gentoo.org/" 52HOMEPAGE="http://www.kernel.org/ http://www.gentoo.org/"
32LICENSE="GPL-2" 53LICENSE="GPL-2"
33IUSE="${IUSE} build" 54IUSE="${IUSE} build doc"
34SLOT="${KV}" 55SLOT="${PVR}"
35 56
57# set LINUX_HOSTCFLAGS if not already set
58[ -z "$LINUX_HOSTCFLAGS" ] && LINUX_HOSTCFLAGS="-Wall -Wstrict-prototypes -Os -fomit-frame-pointer -I${S}/include"
59
60#Eclass functions only from here onwards ...
61#==============================================================
62kernel_is() {
63 # And lets add a sanity check
64 [ -z "${KV_FULL}" ] && return 1
65
66 local RESULT operator test value
67 RESULT=0
68
69 operator="="
70 if [ "${1}" == "lt" ]
71 then
72 operator="-lt"
73 shift
74 elif [ "${1}" == "gt" ]
75 then
76 operator="-gt"
77 shift
78 elif [ "${1}" == "le" ]
79 then
80 operator="-le"
81 shift
82 elif [ "${1}" == "ge" ]
83 then
84 operator="-ge"
85 shift
86 fi
87
88 if [ -n "${1}" ]
89 then
90 value="${value}${1}"
91 test="${test}${KV_MAJOR}"
92 fi
93 if [ -n "${2}" ]
94 then
95 value="${value}${2}"
96 test="${test}${KV_MINOR}"
97 fi
98 if [ -n "${3}" ]
99 then
100 value="${value}${3}"
101 test="${test}${KV_PATCH}"
102 fi
103
104 [ ${test} ${operator} ${value} ] && return 0 || return 1
105}
106
107
108kernel_is_2_4() {
109 kernel_is 2 4
110 return $?
111}
112
113kernel_is_2_6() {
114 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -eq 5 -o ${KV_MINOR} -eq 6 ] && \
115 return 0 || return 1
116}
117
118kernel_header_destdir() {
119 [ "${CTARGET}" = "${CHOST}" ] \
120 && echo /usr/include \
121 || echo /usr/${CTARGET}/include
122}
123
36# capture the sources type and set depends 124# Capture the sources type and set DEPENDs
37if [ "${ETYPE}" == "sources" ] 125if [ "${ETYPE}" == "sources" ]
38then 126then
39 #console-tools is needed to solve the loadkeys fiasco; binutils version needed to avoid Athlon/PIII/SSE assembler bugs. 127 # binutils version needed to avoid Athlon/PIII/SSE assembler bugs.
40 DEPEND="!build? ( sys-apps/sed 128 DEPEND="!build? ( sys-apps/sed
41 >=sys-devel/binutils-2.11.90.0.31 )" 129 >=sys-devel/binutils-2.11.90.0.31 )
130 doc? ( !arm? ( !s390? ( app-text/docbook-sgml-utils ) ) )"
42 131
43 RDEPEND="${DEPEND} 132 RDEPEND="${DEPEND}
44 !build? ( >=sys-libs/ncurses-5.2 133 !build? ( >=sys-libs/ncurses-5.2
45 dev-lang/perl 134 dev-lang/perl
46 sys-apps/module-init-tools 135 sys-apps/module-init-tools
47 sys-devel/make )" 136 sys-devel/make )"
48 137
138 [ $(kernel_is_2_4) $? == 0 ] && PROVIDE="virtual/linux-sources" \
49 PROVIDE="virtual/linux-sources virtual/alsa" 139 || PROVIDE="virtual/linux-sources virtual/alsa"
50 140
51elif [ "${ETYPE}" == "headers" ] 141elif [ "${ETYPE}" == "headers" ]
52then 142then
53 PROVIDE="virtual/kernel virtual/os-headers" 143 PROVIDE="virtual/kernel virtual/os-headers"
54else 144else
55 eerror "Unknown ETYPE=\"${ETYPE}\", must be either \"sources\" or \"headers\"" 145 eerror "Unknown ETYPE=\"${ETYPE}\", must be \"sources\" or \"headers\""
56 die 146 die
57fi 147fi
58 148
59# Grab kernel version from KV
60KV_MAJOR=$(echo ${KV} | cut -d. -f1)
61KV_MINOR=$(echo ${KV} | cut -d. -f2)
62KV_PATCH=$(echo ${KV} | cut -d. -f3)
63KV_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#==============================================================
71kernel_is_2_4() {
72 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -eq 4 ] && return 0 || return 1
73}
74
75kernel_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 149# Unpack functions
81#============================================================== 150#==============================================================
82unpack_2_4() { 151unpack_2_4() {
83 cd ${S} 152 cd ${S}
84 # this file is required for other things to build properly, 153 # this file is required for other things to build properly,
85 # so we autogenerate it 154 # so we autogenerate it
86 make mrproper || die "make mrproper died" 155 make mrproper || die "make mrproper died"
87 make include/linux/version.h || die "make include/linux/version.h failed" 156 make include/linux/version.h || die "make include/linux/version.h failed"
88 echo ">>> version.h compiled successfully." 157 echo ">>> version.h compiled successfully."
89} 158}
90 159
91universal_unpack() { 160universal_unpack() {
161 [ -z "${OKV}" ] && OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
162
163 cd ${WORKDIR}
164 unpack linux-${OKV}.tar.bz2
165 if [ "${OKV}" != "${KV_FULL}" ]
166 then
167 mv linux-${OKV} linux-${KV_FULL} \
168 || die "Unable to move source tree to ${KV_FULL}."
169 fi
170 cd ${S}
171
172 # change incorrect install path
173 sed -ie 's:#export\tINSTALL_PATH:export\tINSTALL_PATH:' Makefile
174
92 # remove all backup files 175 # remove all backup files
93 find . -iname "*~" -exec rm {} \; 2> /dev/null 176 find . -iname "*~" -exec rm {} \; 2> /dev/null
94 177
95 if [ -d "${S}/Documentation/DocBook" ] 178 if [ -d "${S}/Documentation/DocBook" ]
96 then 179 then
97 cd ${S}/Documentation/DocBook 180 cd ${S}/Documentation/DocBook
98 sed -e "s:db2:docbook2:g" Makefile > Makefile.new \ 181 sed -e "s:db2:docbook2:g" Makefile > Makefile.new \
99 && mv Makefile.new Makefile 182 && mv Makefile.new Makefile
100 cd ${S} 183 cd ${S}
101 fi 184 fi
185 # fix a problem on ppc
186 use ppc && \
187 sed -ie 's|TOUT := .tmp_gas_check|TOUT := $(T).tmp_gas_check|' \
188 ${S}/arch/ppc/Makefile
102} 189}
103 190
104unpack_set_extraversion() { 191unpack_set_extraversion() {
105 # Gentoo Linux uses /boot, so fix 'make install' to work properly and fix EXTRAVERSION
106 cd ${S} 192 cd ${S}
107 mv Makefile Makefile.orig
108 sed -e 's:#export\tINSTALL_PATH:export\tINSTALL_PATH:' \
109 -e "s:^\(EXTRAVERSION =\).*:\1 ${EXTRAVERSION}:" \ 193 sed -ie "s:^\(EXTRAVERSION =\).*:\1 ${EXTRAVERSION}:" Makefile
110 Makefile.orig > Makefile
111 rm Makefile.orig
112} 194}
113 195
114# Compile Functions 196# Compile Functions
115#============================================================== 197#==============================================================
116compile_headers() { 198compile_headers() {
117 local MY_ARCH 199 local MY_ARCH
118 200
119 MY_ARCH=${ARCH} 201 MY_ARCH=${ARCH}
120 unset ${ARCH} 202 unset ${ARCH}
121 yes "" | make oldconfig 203 yes "" | make oldconfig
122 echo ">>> make oldconfig complete" 204 echo ">>> make oldconfig complete"
123 ARCH=${MY_ARCH} 205 ARCH=${MY_ARCH}
206}
207
208compile_manpages() {
209 local MY_ARCH
210
211 einfo "Making manpages ..."
212 MY_ARCH=${ARCH}
213 unset ARCH
214 make mandocs
215 ARCH=${MY_ARCH}
124} 216}
125 217
126# install functions 218# install functions
127#============================================================== 219#==============================================================
128install_universal() { 220install_universal() {
132 chmod -R a+r-w+X,u+w * 224 chmod -R a+r-w+X,u+w *
133} 225}
134 226
135install_headers() { 227install_headers() {
136 [ $(kernel_is_2_4) $? == 0 ] && unpack_2_4 228 [ $(kernel_is_2_4) $? == 0 ] && unpack_2_4
137 [ $(kernel_is_2_6) $? == 0 ] && ln -sf ${S}/include/asm-${ARCH} ${S}/include/asm
138 229
230 local ddir=$(kernel_header_destdir)
139 cd ${S} 231 cd ${S}
140 dodir /usr/include/linux 232 dodir ${ddir}/linux
233 ln -sf ${S}/include/asm-${ARCH} ${S}/include/asm
141 cp -ax ${S}/include/linux/* ${D}/usr/include/linux 234 cp -ax ${S}/include/linux/* ${D}/${ddir}/linux
142 rm -rf ${D}/usr/include/linux/modules 235 rm -rf ${D}/${ddir}/linux/modules
143 dodir /usr/include/asm 236
237 dodir ${ddir}/asm
144 cp -ax ${S}/include/asm/* ${D}/usr/include/asm 238 cp -ax ${S}/include/asm/* ${D}/${ddir}/asm
145 239
146 if [ $(kernel_is_2_6) $? == 0 ] 240 if [ $(kernel_is_2_6) $? == 0 ]
147 then 241 then
148 dodir /usr/include/asm-generic 242 dodir ${ddir}/asm-generic
149 cp -ax ${S}/include/asm-generic/* ${D}/usr/include/asm-generic 243 cp -ax ${S}/include/asm-generic/* ${D}/${ddir}/asm-generic
150 fi 244 fi
151} 245}
152 246
153install_sources() { 247install_sources() {
154 local doc 248 local doc
155 local docs 249 local docs
250 local file
156 251
157 cd ${S} 252 cd ${S}
158 dodir /usr/src 253 dodir /usr/src
159 echo ">>> Copying sources..." 254 echo ">>> Copying sources ..."
160 if [ -d "${WORKDIR}/${KV}/docs/" ] 255 file="$(find ${WORKDIR} -iname "docs" -type d)"
256 if [ -n "${file}" ]
161 then 257 then
162 for file in $(ls -1 ${WORKDIR}/${KV}/docs/) 258 for file in $(find ${file} -type f)
163 do 259 do
164 echo "XX_${file}*" >> ${S}/patches.txt 260 echo "${file/*docs\//}" >> ${S}/patches.txt
261 echo "===================================================" >> ${S}/patches.txt
165 cat ${WORKDIR}/${KV}/docs/${file} >> ${S}/patches.txt 262 cat ${file} >> ${S}/patches.txt
263 echo "===================================================" >> ${S}/patches.txt
166 echo "" >> ${S}/patches.txt 264 echo "" >> ${S}/patches.txt
167 done 265 done
168 fi 266 fi
169 267
170 if [ ! -f ${S}/patches.txt ] 268 if [ ! -f ${S}/patches.txt ]
179 done 277 done
180 278
181 if [ -f ${S}/patches.txt ]; then 279 if [ -f ${S}/patches.txt ]; then
182 docs="${docs} ${S}/patches.txt" 280 docs="${docs} ${S}/patches.txt"
183 fi 281 fi
282
283 if use doc && ! use arm && ! use s390; then
284 install_manpages
285 fi
286
184 dodoc ${docs} 287 dodoc ${docs}
185 mv ${WORKDIR}/linux* ${D}/usr/src 288 mv ${WORKDIR}/linux* ${D}/usr/src
186} 289}
187 290
291install_manpages() {
292 local MY_ARCH
293
294 ebegin "Installing manpages"
295 MY_ARCH=${ARCH}
296 unset ARCH
297 sed -ie "s#/usr/local/man#${D}/usr/man#g" scripts/makeman
298 make installmandocs
299 eend $?
300 sed -ie "s#${D}/usr/man#/usr/local/man#g" scripts/makeman
301 ARCH=${MY_ARCH}
302}
303
188# pkg_preinst functions 304# pkg_preinst functions
189#============================================================== 305#==============================================================
190preinst_headers() { 306preinst_headers() {
191 [ -L ${ROOT}usr/include/linux ] && rm ${ROOT}usr/include/linux 307 local ddir=$(kernel_header_destdir)
192 [ -L ${ROOT}usr/include/asm ] && rm ${ROOT}usr/include/asm 308 [[ -L ${ROOT}${ddir}/linux ]] && rm "${ROOT}"${ddir}/linux
309 [[ -L ${ROOT}${ddir}/asm ]] && rm "${ROOT}"${ddir}/asm
193} 310}
194 311
195# pkg_postinst functions 312# pkg_postinst functions
196#============================================================== 313#==============================================================
197postinst_sources() { 314postinst_sources() {
198 if [ ! -h ${ROOT}usr/src/linux ] 315 if [ ! -h ${ROOT}usr/src/linux ]
199 then 316 then
200 ln -sf ${ROOT}usr/src/linux-${KV} ${ROOT}usr/src/linux 317 ln -sf ${ROOT}usr/src/linux-${KV_FULL} ${ROOT}usr/src/linux
201 fi 318 fi
202 319
203 # Don't forget to make directory for sysfs 320 # Don't forget to make directory for sysfs
204 [ ! -d "${ROOT}/sys" -a $(kernel_is_2_6) $? == 0 ] && mkdir /sys 321 [ ! -d "${ROOT}/sys" -a $(kernel_is_2_6) $? == 0 ] && mkdir /sys
205 322
209 einfo "created (X.Y is the first 2 parts of your new kernel version)" 326 einfo "created (X.Y is the first 2 parts of your new kernel version)"
210 echo 327 echo
211 einfo "For example, this kernel will require:" 328 einfo "For example, this kernel will require:"
212 einfo "/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}" 329 einfo "/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}"
213 echo 330 echo
214 331
215 # if K_EXTRAEINFO is set then lets display it now 332 # if K_EXTRAEINFO is set then lets display it now
216 if [ -n "${K_EXTRAEINFO}" ] 333 if [ -n "${K_EXTRAEINFO}" ]
217 then 334 then
218 echo ${K_EXTRAEINFO} | fmt | 335 echo ${K_EXTRAEINFO} | fmt |
219 while read -s ELINE 336 while read -s ELINE
220 do 337 do
221 einfo "${ELINE}" 338 einfo "${ELINE}"
222 done 339 done
223 340
341 echo
342 fi
343
344 # Show policy version, if this kernel has SELinux ...
345 local secfile
346 secfile="${ROOT}usr/src/linux-${KV_FULL}/security/selinux/include/security.h"
347 if use selinux && [ -f "$secfile" ]
348 then
349 local polver=$(awk '/POLICYDB_VERSION /{print $3}' $secfile)
350 einfo "The SELinux policy version of this kernel is $polver."
224 echo 351 echo
225 fi 352 fi
226 353
227 # if K_EXTRAEWARN is set then lets display it now 354 # if K_EXTRAEWARN is set then lets display it now
228 if [ -n "${K_EXTRAEWARN}" ] 355 if [ -n "${K_EXTRAEWARN}" ]
249} 376}
250 377
251# pkg_setup functions 378# pkg_setup functions
252#============================================================== 379#==============================================================
253setup_headers() { 380setup_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/) 381 ARCH=$(uname -m | sed -e s/[i].86/i386/ -e s/x86/i386/ -e s/sun4u/sparc64/ \
382 -e s/arm.*/arm/ -e s/sa110/arm/ -e s/amd64/x86_64/)
255 [ "$ARCH" == "sparc" -a "$PROFILE_ARCH" == "sparc64" ] && ARCH="sparc64" 383 [ "$ARCH" == "sparc" -a "$PROFILE_ARCH" == "sparc64" ] && ARCH="sparc64"
256 384 [ "$ARCH" == "sparc" -a "$PROFILE_ARCH" == "sparc64-multilib" ] && ARCH="sparc64"
385
257 [ -z "${H_SUPPORTEDARCH}" ] && H_SUPPORTEDARCH="${PN/-*/}" 386 [ -z "${H_SUPPORTEDARCH}" ] && H_SUPPORTEDARCH="${PN/-*/}"
258 for i in ${H_SUPPORTEDARCH} 387 for i in ${H_SUPPORTEDARCH}
259 do 388 do
260 [ "${ARCH}" == "${i}" ] && H_ACCEPT_ARCH="yes" 389 [ "${ARCH}" == "${i}" ] && H_ACCEPT_ARCH="yes"
261 done 390 done
262 391
263 if [ "${H_ACCEPT_ARCH}" != "yes" ] 392 if [ "${H_ACCEPT_ARCH}" != "yes" ]
264 then 393 then
265 echo 394 echo
266 eerror "This version of ${PN} does not support ${ARCH}." 395 eerror "This version of ${PN} does not support ${ARCH}."
267 eerror "Please merge the appropriate sources, in most cases" 396 eerror "Please merge the appropriate sources, in most cases"
275unipatch() { 404unipatch() {
276 local i 405 local i
277 local x 406 local x
278 local extention 407 local extention
279 local PIPE_CMD 408 local PIPE_CMD
280 local UNIPATCH_EXCLUDE 409 local UNIPATCH_DROP
281 local KPATCH_DIR 410 local KPATCH_DIR
282 local PATCH_DEPTH 411 local PATCH_DEPTH
283 local ELINE 412 local ELINE
413 local STRICT_COUNT
414 local PATCH_LEVEL
284 415
285 [ -z "${KPATCH_DIR}" ] && KPATCH_DIR="${WORKDIR}/patches/" 416 [ -z "${KPATCH_DIR}" ] && KPATCH_DIR="${WORKDIR}/patches/"
286 [ ! -d ${KPATCH_DIR} ] && mkdir -p ${KPATCH_DIR} 417 [ ! -d ${KPATCH_DIR} ] && mkdir -p ${KPATCH_DIR}
287 418
419 # We're gonna need it when doing patches with a predefined patchlevel
420 shopt -s extglob
421
288 # This function will unpack all passed tarballs, add any passed patches, and remove any passed patchnumbers 422 # 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 423 # usage can be either via an env var or by params
424 # although due to the nature we pass this within this eclass
425 # it shall be by param only.
290 [ -z "${UNIPATCH_LIST}" ] && UNIPATCH_LIST="${@}" 426 # -z "${UNIPATCH_LIST}" ] && UNIPATCH_LIST="${@}"
427 UNIPATCH_LIST="${@}"
291 428
292 #unpack any passed tarballs 429 #unpack any passed tarballs
293 for i in ${UNIPATCH_LIST} 430 for i in ${UNIPATCH_LIST}
294 do 431 do
295 if [ -n "$(echo ${i} | grep -e "\.tar" -e "\.tbz" -e "\.tgz")" ] 432 if [ -n "$(echo ${i} | grep -e "\.tar" -e "\.tbz" -e "\.tgz")" ]
296 then 433 then
297 extention=${i/*./} 434 extention=${i/*./}
435 extention=${extention/:*/}
298 case ${extention} in 436 case ${extention} in
299 tbz2) PIPE_CMD="tar -xvjf";; 437 tbz2) PIPE_CMD="tar -xvjf";;
300 bz2) PIPE_CMD="tar -xvjf";; 438 bz2) PIPE_CMD="tar -xvjf";;
301 tgz) PIPE_CMD="tar -xvzf";; 439 tgz) PIPE_CMD="tar -xvzf";;
302 gz) PIPE_CMD="tar -xvzf";; 440 gz) PIPE_CMD="tar -xvzf";;
303 *) eerror "Unrecognized tarball compression" 441 *) eerror "Unrecognized tarball compression"
304 die "Unrecognized tarball compression";; 442 die "Unrecognized tarball compression";;
305 esac 443 esac
306 444
445 if [ -n "${UNIPATCH_STRICTORDER}" ]
446 then
447 STRICT_COUNT=$((${STRICT_COUNT} + 1))
448 mkdir -p ${KPATCH_DIR}/${STRICT_COUNT}/
449 ${PIPE_CMD} ${i/:*/} -C ${KPATCH_DIR}/${STRICT_COUNT}/ 1>/dev/null
450 else
307 ${PIPE_CMD} ${i} -C ${KPATCH_DIR} 1>/dev/null 451 ${PIPE_CMD} ${i/:*/} -C ${KPATCH_DIR} 1>/dev/null
452 fi
453
308 if [ $? == 0 ] 454 if [ $? == 0 ]
309 then 455 then
310 einfo "${i/*\//} unpacked" 456 einfo "${i/*\//} unpacked"
457 [ -n "$(echo ${i} | grep ':')" ] && echo ">>> Strict patch levels not currently supported for tarballed patchsets"
311 else 458 else
312 eerror "Failed to unpack ${i}" 459 eerror "Failed to unpack ${i/:*/}"
313 die "unable to unpack patch tarball" 460 die "unable to unpack patch tarball"
314 fi 461 fi
462 else
463 extention=${i/*./}
464 extention=${extention/:*/}
465 PIPE_CMD=""
466 case ${extention} in
467 bz2) PIPE_CMD="bzip2 -dc";;
468 patch) PIPE_CMD="cat";;
469 diff) PIPE_CMD="cat";;
470 gz|Z|z) PIPE_CMD="gzip -dc";;
471 ZIP|zip) PIPE_CMD="unzip -p";;
472 *) UNIPATCH_DROP="${UNIPATCH_DROP} ${i/:*/}";;
473 esac
315 474
316 UNIPATCH_LIST="${UNIPATCH_LIST/${i}/}" 475 PATCH_LEVEL=${i/*([^:])?(:)}
476 i=${i/:*/}
477 x=${i/*\//}
478 x=${x/\.${extention}/}
479
480 if [ -n "${PIPE_CMD}" ]
481 then
482 if [ ! -r "${i}" ]
483 then
484 echo
485 eerror "FATAL: unable to locate:"
486 eerror "${i}"
487 eerror "for read-only. The file either has incorrect permissions"
488 eerror "or does not exist."
489 die Unable to locate ${i}
490 fi
491
492 if [ -n "${UNIPATCH_STRICTORDER}" ]
493 then
494 STRICT_COUNT=$((${STRICT_COUNT} + 1))
495 mkdir -p ${KPATCH_DIR}/${STRICT_COUNT}/
496 $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${STRICT_COUNT}/${x}.patch${PATCH_LEVEL})
497 else
498 $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${x}.patch${PATCH_LEVEL})
499 fi
500 fi
317 fi 501 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 502 done
337 503
338 #populate KPATCH_DIRS so we know where to look to remove the excludes 504 #populate KPATCH_DIRS so we know where to look to remove the excludes
339 x=${KPATCH_DIR} 505 x=${KPATCH_DIR}
340 KPATCH_DIR="" 506 KPATCH_DIR=""
507 LC_ALL="C"
341 for i in $(find ${x} -type d) 508 for i in $(find ${x} -type d | sort -n)
342 do 509 do
343 KPATCH_DIR="${KPATCH_DIR} ${i}" 510 KPATCH_DIR="${KPATCH_DIR} ${i}"
344 done 511 done
345 512
346 #so now lets get rid of the patchno's we want to exclude 513 #so now lets get rid of the patchno's we want to exclude
514 UNIPATCH_DROP="${UNIPATCH_EXCLUDE} ${UNIPATCH_DROP}"
347 for i in ${UNIPATCH_EXCLUDE} 515 for i in ${UNIPATCH_DROP}
348 do 516 do
517 ebegin "Excluding Patch #${i}"
349 for x in ${KPATCH_DIR} 518 for x in ${KPATCH_DIR}
350 do 519 do
351 rm ${x}/${i}_* 2>/dev/null 520 rm -f ${x}/${i}* 2>/dev/null
352 if [ $? == 0 ]
353 then
354 einfo "Excluding Patch #${i}"
355 einfo "From: ${x/${WORKDIR}/}"
356 fi
357 done 521 done
522 eend $?
358 done 523 done
359 524
360 # and now, finally, we patch it :) 525 # and now, finally, we patch it :)
361 for x in ${KPATCH_DIR} 526 for x in ${KPATCH_DIR}
362 do 527 do
363 for i in $(find ${x} -maxdepth 1 -iname "*.patch" -or -iname "*.diff" | sort -u) 528 for i in $(find ${x} -maxdepth 1 -iname "*.patch*" -or -iname "*.diff*" | sort -n)
364 do 529 do
530 STDERR_T="${T}/${i/*\//}"
531 STDERR_T="${STDERR_T/.patch*/.err}"
365 532
533 [ -z ${i/*.patch*/} ] && PATCH_DEPTH=${i/*.patch/}
534 [ -z ${i/*.diff*/} ] && PATCH_DEPTH=${i/*.diff/}
366 535
536 if [ -z "${PATCH_DEPTH}" ]; then
367 PATCH_DEPTH=0 537 PATCH_DEPTH=0
538 fi
539
368 ebegin "Applying ${i/*\//}" 540 ebegin "Applying ${i/*\//} (-p${PATCH_DEPTH}+)"
369 while [ ${PATCH_DEPTH} -lt 5 ] 541 while [ ${PATCH_DEPTH} -lt 5 ]
370 do 542 do
371 if (patch -p${PATCH_DEPTH} --dry-run -f < ${i} >/dev/null) 543 echo "Attempting Dry-run:" >> ${STDERR_T}
544 echo "cmd: patch -p${PATCH_DEPTH} --dry-run -f < ${i}" >> ${STDERR_T}
545 echo "=======================================================" >> ${STDERR_T}
546 if [ $(patch -p${PATCH_DEPTH} --dry-run -f < ${i} >> ${STDERR_T}) $? -eq 0 ]
372 then 547 then
373 $(patch -p${PATCH_DEPTH} -f < ${i} >/dev/null) 548 echo "Attempting patch:" > ${STDERR_T}
374 if [ "$?" -eq 0 ] 549 echo "cmd: patch -p${PATCH_DEPTH} -f < ${i}" >> ${STDERR_T}
550 echo "=======================================================" >> ${STDERR_T}
551 if [ $(patch -p${PATCH_DEPTH} -f < ${i} >> ${STDERR_T}) "$?" -eq 0 ]
375 then 552 then
376 eend 0 553 eend 0
554 rm ${STDERR_T}
377 break 555 break
378 else 556 else
379 eend 1 557 eend 1
380 eerror "Failed to apply patch ${i/*\//}" 558 eerror "Failed to apply patch ${i/*\//}"
559 eerror "Please attach ${STDERR_T} to any bug you may post."
381 die "Failed to apply ${i/*\//}" 560 die "Failed to apply ${i/*\//}"
382 fi 561 fi
383 else 562 else
384 PATCH_DEPTH=$((${PATCH_DEPTH} + 1)) 563 PATCH_DEPTH=$((${PATCH_DEPTH} + 1))
385 fi 564 fi
386 done 565 done
387 if [ ${PATCH_DEPTH} -eq 5 ] 566 if [ ${PATCH_DEPTH} -eq 5 ]
388 then 567 then
389 eend 1 568 eend 1
569 eerror "Please attach ${STDERR_T} to any bug you may post."
390 die "Unable to dry-run patch." 570 die "Unable to dry-run patch."
391 fi 571 fi
392
393
394 done 572 done
395 done 573 done
574
575 # clean up KPATCH_DIR's - fixes bug #53610
576 for x in ${KPATCH_DIR}
577 do
578 rm -Rf ${x}
579 done
580 unset LC_ALL
396} 581}
397 582
398# custom functions 583# custom functions
399#============================================================== 584#==============================================================
400detect_version() { 585detect_version() {
401 # this function will detect and set 586 # this function will detect and set
402 # - OKV: Original Kernel Version (2.6.0/2.6.0-test11) 587 # - 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) 588 # - KV: Kernel Version (2.6.0-gentoo/2.6.0-test11-gentoo-r1)
404 # - EXTRAVERSION: The additional version appended to OKV (-gentoo/-gentoo-r1) 589 # - EXTRAVERSION: The additional version appended to OKV (-gentoo/-gentoo-r1)
405 590
591 if [ -n "${KV_FULL}" ] ;
592 then
593 # we will set this for backwards compatibility.
594 KV=${KV_FULL}
595
596 # we know KV_FULL so lets stop here. but not without resetting S
597 S=${WORKDIR}/linux-${KV_FULL}
598 return
599 fi
600
406 OKV=${PV/_beta/-test} 601 OKV=${PV/_beta/-test}
407 OKV=${OKV/_rc/-rc} 602 OKV=${OKV/_rc/-rc}
408 OKV=${OKV/_pre*/} 603 OKV=${OKV/_p*/}
409 OKV=${OKV/-r*/} 604 OKV=${OKV/-r*/}
410 605
411 KV_MAJOR=$(echo ${OKV} | cut -d. -f1) 606 KV_MAJOR=$(echo ${OKV} | cut -d. -f1)
412 KV_MINOR=$(echo ${OKV} | cut -d. -f2) 607 KV_MINOR=$(echo ${OKV} | cut -d. -f2)
413 KV_PATCH=$(echo ${OKV} | cut -d. -f3) 608 KV_PATCH=$(echo ${OKV} | cut -d. -f3-)
414 KV_PATCH=${KV_PATCH/[-_]*/} 609 KV_PATCH=${KV_PATCH/[-_]*/}
415 610
416 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2" 611 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
417 612
418 RELEASE=${PV/${OKV}/} 613 RELEASE=${PV/${OKV}/}
419 RELEASE=${RELEASE/_beta/} 614 RELEASE=${RELEASE/_beta/}
420 RELEASE=${RELEASE/_rc/-rc} 615 RELEASE=${RELEASE/_rc/-rc}
616 if [ $(kernel_is_2_4) $? == 0 ]
617 then
618 RELEASE=${RELEASE/_pre/-pre}
619 else
421 RELEASE=${RELEASE/_pre/-bk} 620 RELEASE=${RELEASE/_pre/-bk}
621 fi
422 RELEASETYPE=${RELEASE//[0-9]/} 622 RELEASETYPE=${RELEASE//[0-9]/}
423
424 EXTRAVERSION="${RELEASE}" 623 EXTRAVERSION="${RELEASE}"
425 624
426 if [ -n "${K_PREPATCHED}" ] 625 if [ -n "${K_PREPATCHED}" ]
427 then 626 then
428 KV="${OKV}-${PN/-*/}${PR/r/}" 627 EXTRAVERSION="${EXTRAVERSION}-${PN/-*/}${PR/r/}"
429 else 628 else
430 [ -z "${K_NOUSENAME}" ] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*/}" 629 [ -z "${K_NOUSENAME}" ] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*/}"
431 [ ! "${PR}" == "r0" ] && EXTRAVERSION="${EXTRAVERSION}-${PR}" 630 [ "${PR}" != "r0" ] && EXTRAVERSION="${EXTRAVERSION}-${PR}"
432 631 fi
632
433 KV=${OKV}${EXTRAVERSION} 633 KV_FULL=${OKV}${EXTRAVERSION}
434 fi 634
435
436 # -rcXX-bkXX pulls are *IMPOSSIBLE* to support within the portage naming convention 635 # -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 636 # these cannot be supported, but the code here can handle it up until this point
438 # and theoretically thereafter. 637 # and theoretically thereafter.
439 638
440 if [ "${RELEASETYPE}" == "-rc" ] 639 if [ "${RELEASETYPE}" == "-rc" -o "${RELEASETYPE}" == "-pre" ]
441 then 640 then
442 OKV="${KV_MAJOR}.${KV_MINOR}.$([ $((${KV_PATCH} - 1)) -lt 0 ] && echo ${KV_PATCH} || echo $((${KV_PATCH} - 1)))" 641 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 642 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" 643 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
445 UNIPATCH_LIST="${DISTDIR}/patch-${PV//_/-}.bz2 ${UNIPATCH_LIST}" 644 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${PV//_/-}.bz2"
446 [ -n "${K_PREPATCHED}" ] && KV="${PV/[-_]*/}${EXTRAVERSION}-${PN/-*/}${PR/r/}" || KV=${PV/[-_]*/}${EXTRAVERSION} 645 KV_FULL=${PV/[-_]*/}${EXTRAVERSION}
447 fi 646 fi
448 647
449 if [ "${RELEASETYPE}" == "-bk" ] 648 if [ "${RELEASETYPE}" == "-bk" ]
450 then 649 then
451 OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}" 650 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 651 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" 652 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}" 653 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2"
455 [ -n "${K_PREPATCHED}" ] && KV="${PV/[-_]*/}${EXTRAVERSION}-${PN/-*/}${PR/r/}" || KV=${PV/[-_]*/}${EXTRAVERSION} 654 KV_FULL=${PV/[-_]*/}${EXTRAVERSION}
456 fi 655 fi
457 656
458 if [ "${RELEASETYPE}" == "-rc-bk" ] 657 if [ "${RELEASETYPE}" == "-rc-bk" ]
459 then 658 then
460 OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))-${RELEASE/-bk*}" 659 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})" 660 EXTRAVERSION="$([ -n "${RELEASE}" ] && echo ${RELEASE/*-bk/-bk})$([ -n "${K_USENAME}" ] && echo -${PN/-*/})$([ ! "${PR}" == "r0" ] && echo -${PR})"
462 661
463 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 662 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" 663 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}" 664 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2"
466 [ -n "${K_PREPATCHED}" ] && KV="${PV/[-_]*/}${EXTRAVERSION}-${PN/-*/}${PR/r/}" || KV=${PV/[-_]*/}${EXTRAVERSION} 665 KV_FULL=${PV/[-_]*/}${EXTRAVERSION}
467 fi 666 fi
468 667
469 S=${WORKDIR}/linux-${KV} 668 S=${WORKDIR}/linux-${KV_FULL}
669 # we will set this for backwards compatibility.
670 KV=${KV_FULL}
671}
672
673detect_arch() {
674 # This function sets ARCH_URI and ARCH_PATCH
675 # with the neccessary info for the arch sepecific compatibility
676 # patchsets.
677
678 local ALL_ARCH
679 local LOOP_ARCH
680 local COMPAT_URI
681 local i
682
683 # COMPAT_URI is the contents of ${ARCH}_URI
684 # ARCH_URI is the URI for all the ${ARCH}_URI patches
685 # ARCH_PATCH is ARCH_URI broken into files for UNIPATCH
686
687 ARCH_URI=""
688 ARCH_PATCH=""
689 ALL_ARCH="X86 PPC PPC64 SPARC MIPS ALPHA ARM HPPA AMD64 IA64 X86OBSD S390"
690
691 for LOOP_ARCH in ${ALL_ARCH}
692 do
693 COMPAT_URI="${LOOP_ARCH}_URI"
694 COMPAT_URI="${!COMPAT_URI}"
695
696 [ -n "${COMPAT_URI}" ] && \
697 ARCH_URI="${ARCH_URI} $(echo ${LOOP_ARCH} | tr '[:upper:]' '[:lower:]')? ( ${COMPAT_URI} )"
698
699 if [ "${LOOP_ARCH}" == "$(echo ${ARCH} | tr '[:lower:]' '[:upper:]')" ]
700 then
701 for i in ${COMPAT_URI}
702 do
703 ARCH_PATCH="${ARCH_PATCH} ${DISTDIR}/${i/*\//}"
704 done
705 fi
706 done
470} 707}
471 708
472 709
473# common functions 710# common functions
474#============================================================== 711#==============================================================
475src_unpack() { 712kernel-2_src_unpack() {
476 [ -z "${OKV}" ] && OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}" 713 detect_version
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 714 universal_unpack
487 [ -n "${UNIPATCH_LIST}" ] && unipatch ${UNIPATCH_LIST} 715
716 [ -n "${UNIPATCH_LIST}" -o -n "${UNIPATCH_LIST_DEFAULT}" ] && \
717 unipatch "${UNIPATCH_LIST_DEFAULT} ${UNIPATCH_LIST}"
718
488 [ -z "${K_NOSETEXTRAVERSION}" ] && unpack_set_extraversion 719 [ -z "${K_NOSETEXTRAVERSION}" ] && \
720 unpack_set_extraversion
489 721
490 [ $(kernel_is_2_4) $? == 0 ] && unpack_2_4 722 kernel_is 2 4 && unpack_2_4
491} 723}
492 724
493src_compile() { 725kernel-2_src_compile() {
494 [ "${ETYPE}" == "headers" ] && compile_headers 726 [ "${ETYPE}" == "headers" ] && compile_headers
727 [ "${ETYPE}" == "sources" ] && \
728 use doc && ! use arm && ! use s390 && compile_manpages
495} 729}
496 730
497pkg_preinst() { 731kernel-2_pkg_preinst() {
498 [ "${ETYPE}" == "headers" ] && preinst_headers 732 [ "${ETYPE}" == "headers" ] && preinst_headers
499} 733}
500 734
501src_install() { 735kernel-2_src_install() {
502 install_universal 736 install_universal
503 [ "${ETYPE}" == "headers" ] && install_headers 737 [ "${ETYPE}" == "headers" ] && install_headers
504 [ "${ETYPE}" == "sources" ] && install_sources 738 [ "${ETYPE}" == "sources" ] && install_sources
505} 739}
506 740
507pkg_postinst() { 741kernel-2_pkg_postinst() {
508 [ "${ETYPE}" == "headers" ] && postinst_headers 742 [ "${ETYPE}" == "headers" ] && postinst_headers
509 [ "${ETYPE}" == "sources" ] && postinst_sources 743 [ "${ETYPE}" == "sources" ] && postinst_sources
510} 744}
511 745
512pkg_setup() { 746kernel-2_pkg_setup() {
513 [ "${ETYPE}" == "headers" ] && setup_headers 747 [ "${ETYPE}" == "headers" ] && setup_headers
748
749 # This is to fix some weird portage bug? in stable versions of portage.
750 [ "${ETYPE}" == "sources" ] && echo ">>> Preparing to unpack ..."
514} 751}
752
753

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

  ViewVC Help
Powered by ViewVC 1.1.20