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

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

  ViewVC Help
Powered by ViewVC 1.1.20