/[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.230
1# Copyright 1999-2009 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.230 2010/04/26 07:26:06 robbat2 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# Original author: John Mylchreest <johnm@gentoo.org>
5# Copyright 2004 Gentoo Linux 9# Maintainer: kernel-misc@gentoo.org
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#
19# K_USEPV - When setting the EXTRAVERSION variable, it should
20# add PV to the end.
21# this is useful for thigns like wolk. IE:
22# EXTRAVERSION would be something like : -wolk-4.19-r1
16# K_NOSETEXTRAVERSION - if this is set then EXTRAVERSION will not be automatically set within the kernel Makefile 23# K_NOSETEXTRAVERSION - if this is set then EXTRAVERSION will not be
24# 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 25# 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 26# first part of ${PN} in EXTRAVERSION
27# K_NOUSEPR - if this is set then EXTRAVERSION will not include the
28# anything based on ${PR}.
29# K_PREPATCHED - if the patchset is prepatched (ie: mm-sources,
30# ck-sources, ac-sources) it will use PR (ie: -r5) as
31# the patchset version for
19# - and not use it as a true package revision 32# 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 33# K_EXTRAEINFO - this is a new-line seperated list of einfo displays in
34# postinst and can be used to carry additional postinst
35# messages
36# K_EXTRAELOG - same as K_EXTRAEINFO except using elog instead of einfo
21# K_EXTRAEWARN - same as K_EXTRAEINFO except ewarn's instead of einfo's 37# K_EXTRAEWARN - same as K_EXTRAEINFO except using ewarn instead of einfo
38# K_SYMLINK - if this is set, then forcably create symlink anyway
39#
40# K_DEFCONFIG - Allow specifying a different defconfig target.
41# If length zero, defaults to "defconfig".
42# K_WANT_GENPATCHES - Apply genpatches to kernel source. Provide any
43# combination of "base" and "extras"
44# K_GENPATCHES_VER - The version of the genpatches tarball(s) to apply.
45# A value of "5" would apply genpatches-2.6.12-5 to
46# my-sources-2.6.12.ebuild
47# K_SECURITY_UNSUPPORTED- If set, this kernel is unsupported by Gentoo Security
48# K_DEBLOB_AVAILABLE - A value of "0" will disable all of the optional deblob
49# code. If empty, will be set to "1" if deblobbing is
50# possible. Test ONLY for "1".
51# K_PREDEBLOBBED - This kernel was already deblobbed elsewhere.
52# If false, either optional deblobbing will be available
53# or the license will note the inclusion of freedist
54# code.
22 55
23# H_SUPPORTEDARCH - this should be a space separated list of ARCH's which can be supported by the headers ebuild 56# H_SUPPORTEDARCH - this should be a space separated list of ARCH's which
57# can be supported by the headers ebuild
24 58
25# UNIPATCH_LIST - space delimetered list of patches to be applied to the kernel 59# UNIPATCH_LIST - space delimetered list of patches to be applied to the
60# kernel
61# UNIPATCH_EXCLUDE - an addition var to support exlusion based completely
62# on "<passedstring>*" and not "<passedno#>_*"
63# - this should _NOT_ be used from the ebuild as this is
64# reserved for end users passing excludes from the cli
26# UNIPATCH_DOCS - space delimemeted list of docs to be installed to the doc dir 65# UNIPATCH_DOCS - space delimemeted list of docs to be installed to
66# the doc dir
67# UNIPATCH_STRICTORDER - if this is set places patches into directories of
68# order, so they are applied in the order passed
27 69
28ECLASS="kernel-2" 70inherit eutils toolchain-funcs versionator multilib
29EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_preinst pkg_postinst 71EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_preinst pkg_postinst
30 72
73# Added by Daniel Ostrow <dostrow@gentoo.org>
74# This is an ugly hack to get around an issue with a 32-bit userland on ppc64.
75# I will remove it when I come up with something more reasonable.
76[[ ${PROFILE_ARCH} == "ppc64" ]] && CHOST="powerpc64-${CHOST#*-}"
77
78export CTARGET=${CTARGET:-${CHOST}}
79if [[ ${CTARGET} == ${CHOST} && ${CATEGORY/cross-} != ${CATEGORY} ]]; then
80 export CTARGET=${CATEGORY/cross-}
81fi
82
31HOMEPAGE="http://www.kernel.org/ http://www.gentoo.org/" 83HOMEPAGE="http://www.kernel.org/ http://www.gentoo.org/ ${HOMEPAGE}"
84[[ -z ${LICENSE} ]] && \
32LICENSE="GPL-2" 85 LICENSE="GPL-2"
33IUSE="${IUSE} build"
34SLOT="${KV}"
35 86
87# No need to run scanelf/strip on kernel sources/headers (bug #134453).
88RESTRICT="binchecks strip"
89
90# set LINUX_HOSTCFLAGS if not already set
91[[ -z ${LINUX_HOSTCFLAGS} ]] && \
92 LINUX_HOSTCFLAGS="-Wall -Wstrict-prototypes -Os -fomit-frame-pointer -I${S}/include"
93
94# debugging functions
95#==============================================================
96# this function exists only to help debug kernel-2.eclass
97# if you are adding new functionality in, put a call to it
98# at the start of src_unpack, or during SRC_URI/dep generation.
99debug-print-kernel2-variables() {
100 for v in PVR CKV OKV KV KV_FULL KV_MAJOR KV_MINOR KV_PATCH RELEASETYPE \
101 RELEASE UNIPATCH_LIST_DEFAULT UNIPATCH_LIST_GENPATCHES \
102 UNIPATCH_LIST S KERNEL_URI ; do
103 debug-print "${v}: ${!v}"
104 done
105}
106
107#Eclass functions only from here onwards ...
108#==============================================================
109handle_genpatches() {
110 local tarball
111 [[ -z ${K_WANT_GENPATCHES} || -z ${K_GENPATCHES_VER} ]] && return 1
112
113 for i in ${K_WANT_GENPATCHES} ; do
114 tarball="genpatches-${OKV}-${K_GENPATCHES_VER}.${i}.tar.bz2"
115 GENPATCHES_URI="${GENPATCHES_URI} mirror://gentoo/${tarball}"
116 UNIPATCH_LIST_GENPATCHES="${UNIPATCH_LIST_GENPATCHES} ${DISTDIR}/${tarball}"
117 done
118}
119
120detect_version() {
121 # this function will detect and set
122 # - OKV: Original Kernel Version (2.6.0/2.6.0-test11)
123 # - KV: Kernel Version (2.6.0-gentoo/2.6.0-test11-gentoo-r1)
124 # - EXTRAVERSION: The additional version appended to OKV (-gentoo/-gentoo-r1)
125
126 if [[ -n ${KV_FULL} ]]; then
127 # we will set this for backwards compatibility.
128 KV=${KV_FULL}
129
130 # we know KV_FULL so lets stop here. but not without resetting S
131 S=${WORKDIR}/linux-${KV_FULL}
132 return
133 fi
134
135 # CKV is used as a comparison kernel version, which is used when
136 # PV doesnt reflect the genuine kernel version.
137 # this gets set to the portage style versioning. ie:
138 # CKV=2.6.11_rc4
139 CKV=${CKV:-${PV}}
140 OKV=${OKV:-${CKV}}
141 OKV=${OKV/_beta/-test}
142 OKV=${OKV/_rc/-rc}
143 OKV=${OKV/-r*}
144 OKV=${OKV/_p*}
145
146 KV_MAJOR=$(get_version_component_range 1 ${OKV})
147 KV_MINOR=$(get_version_component_range 2 ${OKV})
148 KV_PATCH=$(get_version_component_range 3 ${OKV})
149
150 if [[ ${KV_MAJOR}${KV_MINOR}${KV_PATCH} -ge 269 ]]; then
151 KV_EXTRA=$(get_version_component_range 4- ${OKV})
152 KV_EXTRA=${KV_EXTRA/[-_]*}
153 else
154 KV_PATCH=$(get_version_component_range 3- ${OKV})
155 fi
156 KV_PATCH=${KV_PATCH/[-_]*}
157
158 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
159
160 RELEASE=${CKV/${OKV}}
161 RELEASE=${RELEASE/_beta}
162 RELEASE=${RELEASE/_rc/-rc}
163 RELEASE=${RELEASE/_pre/-pre}
164 kernel_is ge 2 6 && RELEASE=${RELEASE/-pre/-git}
165 RELEASETYPE=${RELEASE//[0-9]}
166
167 # Now we know that RELEASE is the -rc/-git
168 # and RELEASETYPE is the same but with its numerics stripped
169 # we can work on better sorting EXTRAVERSION.
170 # first of all, we add the release
171 EXTRAVERSION="${RELEASE}"
172 debug-print "0 EXTRAVERSION:${EXTRAVERSION}"
173 [[ -n ${KV_EXTRA} ]] && EXTRAVERSION=".${KV_EXTRA}${EXTRAVERSION}"
174
175 debug-print "1 EXTRAVERSION:${EXTRAVERSION}"
176 if [[ -n "${K_NOUSEPR}" ]]; then
177 # Don't add anything based on PR to EXTRAVERSION
178 debug-print "1.0 EXTRAVERSION:${EXTRAVERSION}"
179 elif [[ -n ${K_PREPATCHED} ]]; then
180 debug-print "1.1 EXTRAVERSION:${EXTRAVERSION}"
181 EXTRAVERSION="${EXTRAVERSION}-${PN/-*}${PR/r}"
182 elif [[ "${ETYPE}" = "sources" ]]; then
183 debug-print "1.2 EXTRAVERSION:${EXTRAVERSION}"
184 # For some sources we want to use the PV in the extra version
185 # This is because upstream releases with a completely different
186 # versioning scheme.
187 case ${PN/-*} in
188 wolk) K_USEPV=1;;
189 vserver) K_USEPV=1;;
190 esac
191
192 [[ -z "${K_NOUSENAME}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*}"
193 [[ -n "${K_USEPV}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PV//_/-}"
194 [[ -n "${PR//r0}" ]] && EXTRAVERSION="${EXTRAVERSION}-${PR}"
195 fi
196 debug-print "2 EXTRAVERSION:${EXTRAVERSION}"
197
198 # The only messing around which should actually effect this is for KV_EXTRA
199 # since this has to limit OKV to MAJ.MIN.PAT and strip EXTRA off else
200 # KV_FULL evaluates to MAJ.MIN.PAT.EXT.EXT after EXTRAVERSION
201 if [[ -n ${KV_EXTRA} ]]; then
202 OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
203 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/patch-${CKV}.bz2
204 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}.tar.bz2"
205 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV}.bz2"
206 fi
207
208 # We need to set this using OKV, but we need to set it before we do any
209 # messing around with OKV based on RELEASETYPE
210 KV_FULL=${OKV}${EXTRAVERSION}
211
212 # we will set this for backwards compatibility.
213 S=${WORKDIR}/linux-${KV_FULL}
214 KV=${KV_FULL}
215
216 # -rc-git pulls can be achieved by specifying CKV
217 # for example:
218 # CKV="2.6.11_rc3_pre2"
219 # will pull:
220 # linux-2.6.10.tar.bz2 & patch-2.6.11-rc3.bz2 & patch-2.6.11-rc3-git2.bz2
221
222 if [[ ${RELEASETYPE} == -rc ]] || [[ ${RELEASETYPE} == -pre ]]; then
223 OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))"
224 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/testing/patch-${CKV//_/-}.bz2
225 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
226 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${CKV//_/-}.bz2"
227 fi
228
229 if [[ ${RELEASETYPE} == -git ]]; then
230 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${OKV}${RELEASE}.bz2
231 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
232 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${OKV}${RELEASE}.bz2"
233 fi
234
235 if [[ ${RELEASETYPE} == -rc-git ]]; then
236 OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))"
237 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2
238 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/testing/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE/-git*}.bz2
239 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
240 UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE/-git*}.bz2 ${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2"
241 fi
242
243 debug-print-kernel2-variables
244
245 handle_genpatches
246}
247
248kernel_is() {
249 # ALL of these should be set before we can safely continue this function.
250 # some of the sources have in the past had only one set.
251 local v n=0
252 for v in OKV KV_{MAJOR,MINOR,PATCH} ; do [[ -z ${!v} ]] && n=1 ; done
253 [[ $n -eq 1 ]] && detect_version
254 unset v n
255
256 # Now we can continue
257 local operator test value x=0 y=0 z=0
258
259 case ${1} in
260 lt) operator="-lt"; shift;;
261 gt) operator="-gt"; shift;;
262 le) operator="-le"; shift;;
263 ge) operator="-ge"; shift;;
264 eq) operator="-eq"; shift;;
265 *) operator="-eq";;
266 esac
267
268 for x in ${@}; do
269 for((y=0; y<$((3 - ${#x})); y++)); do value="${value}0"; done
270 value="${value}${x}"
271 z=$((${z} + 1))
272
273 case ${z} in
274 1) for((y=0; y<$((3 - ${#KV_MAJOR})); y++)); do test="${test}0"; done;
275 test="${test}${KV_MAJOR}";;
276 2) for((y=0; y<$((3 - ${#KV_MINOR})); y++)); do test="${test}0"; done;
277 test="${test}${KV_MINOR}";;
278 3) for((y=0; y<$((3 - ${#KV_PATCH})); y++)); do test="${test}0"; done;
279 test="${test}${KV_PATCH}";;
280 *) die "Error in kernel-2_kernel_is(): Too many parameters.";;
281 esac
282 done
283
284 [ ${test} ${operator} ${value} ] && return 0 || return 1
285}
286
287kernel_is_2_4() {
288 kernel_is 2 4
289}
290
291kernel_is_2_6() {
292 kernel_is 2 6 || kernel_is 2 5
293}
294
36# capture the sources type and set depends 295# Capture the sources type and set DEPENDs
37if [ "${ETYPE}" == "sources" ] 296if [[ ${ETYPE} == sources ]]; then
38then
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 297 DEPEND="!build? ( sys-apps/sed
41 >=sys-devel/binutils-2.11.90.0.31 )" 298 >=sys-devel/binutils-2.11.90.0.31 )"
42
43 RDEPEND="${DEPEND}
44 !build? ( >=sys-libs/ncurses-5.2 299 RDEPEND="!build? ( >=sys-libs/ncurses-5.2
45 dev-lang/perl
46 sys-apps/module-init-tools
47 sys-devel/make )" 300 sys-devel/make )"
301 PDEPEND="!build? ( virtual/dev-manager )"
48 302
49 PROVIDE="virtual/linux-sources virtual/alsa" 303 PROVIDE="virtual/linux-sources"
304 kernel_is gt 2 4 && PROVIDE="${PROVIDE} virtual/alsa"
50 305
306 SLOT="${PVR}"
307 DESCRIPTION="Sources for the ${KV_MAJOR}.${KV_MINOR} linux kernel"
308 IUSE="symlink build"
309
310 # Bug #266157, deblob for libre support
311 if [[ -z ${K_PREDEBLOBBED} ]] ; then
312 if kernel_is ge 2 6 27 && [[ -z ${K_DEBLOB_AVAILABLE} ]] ; then
313 IUSE="${IUSE} deblob"
314 # Reflect that kernels contain firmware blobs unless otherwise
315 # stripped
316 LICENSE="${LICENSE} !deblob? ( freedist )"
317
318 # This to to avoid us triggering some QA warnings
319 K_DEBLOB_AVAILABLE=1
320
321 DEBLOB_PV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
322 DEBLOB_A="deblob-${DEBLOB_PV}"
323 DEBLOB_HOMEPAGE="http://www.fsfla.org/svnwiki/selibre/linux-libre/"
324 HOMEPAGE="${HOMEPAGE} ${DEBLOB_HOMEPAGE}"
325
326 KERNEL_URI="${KERNEL_URI}
327 deblob? (
328 ${DEBLOB_HOMEPAGE}/download/releases/LATEST-${DEBLOB_PV}.N/${DEBLOB_A}
329 )"
330 else
331 # We have no way to deblob older kernels, so just mark them as
332 # tainted with non-libre materials.
333 LICENSE="${LICENSE} freedist"
334 fi
335 fi
336
51elif [ "${ETYPE}" == "headers" ] 337elif [[ ${ETYPE} == headers ]]; then
52then 338 DESCRIPTION="Linux system headers"
339
340 # Since we should NOT honour KBUILD_OUTPUT in headers
341 # lets unset it here.
342 unset KBUILD_OUTPUT
343
344 if [[ ${CTARGET} = ${CHOST} ]]; then
345 DEPEND="!virtual/os-headers"
53 PROVIDE="virtual/kernel virtual/os-headers" 346 PROVIDE="virtual/os-headers"
347 SLOT="0"
348 else
349 SLOT="${CTARGET}"
350 fi
54else 351else
55 eerror "Unknown ETYPE=\"${ETYPE}\", must be either \"sources\" or \"headers\"" 352 eerror "Unknown ETYPE=\"${ETYPE}\", must be \"sources\" or \"headers\""
56 die 353 die "Unknown ETYPE=\"${ETYPE}\", must be \"sources\" or \"headers\""
57fi 354fi
58 355
59# Grab kernel version from KV 356# Cross-compile support functions
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#============================================================== 357#==============================================================
71kernel_is_2_4() { 358kernel_header_destdir() {
72 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -eq 4 ] && return 0 || return 1 359 [[ ${CTARGET} == ${CHOST} ]] \
360 && echo /usr/include \
361 || echo /usr/${CTARGET}/usr/include
73} 362}
74 363
75kernel_is_2_6() { 364cross_pre_c_headers() {
76 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -eq 5 -o ${KV_MINOR} -eq 6 ] && return 0 || return 1 365 use crosscompile_opts_headers-only && [[ ${CHOST} != ${CTARGET} ]]
77} 366}
78 367
368env_setup_xmakeopts() {
369 # Kernel ARCH != portage ARCH
370 export KARCH=$(tc-arch-kernel)
371
372 # When cross-compiling, we need to set the ARCH/CROSS_COMPILE
373 # variables properly or bad things happen !
374 xmakeopts="ARCH=${KARCH}"
375 if [[ ${CTARGET} != ${CHOST} ]] && ! cross_pre_c_headers ; then
376 xmakeopts="${xmakeopts} CROSS_COMPILE=${CTARGET}-"
377 elif type -p ${CHOST}-ar > /dev/null ; then
378 xmakeopts="${xmakeopts} CROSS_COMPILE=${CHOST}-"
379 fi
380 export xmakeopts
381}
79 382
80# Unpack functions 383# Unpack functions
81#============================================================== 384#==============================================================
82unpack_2_4() { 385unpack_2_4() {
83 cd ${S}
84 # this file is required for other things to build properly, 386 # this file is required for other things to build properly,
85 # so we autogenerate it 387 # so we autogenerate it
86 make mrproper || die "make mrproper died" 388 make -s mrproper ${xmakeopts} || die "make mrproper failed"
389 make -s symlinks ${xmakeopts} || die "make symlinks failed"
87 make include/linux/version.h || die "make include/linux/version.h failed" 390 make -s include/linux/version.h ${xmakeopts} || die "make include/linux/version.h failed"
88 echo ">>> version.h compiled successfully." 391 echo ">>> version.h compiled successfully."
89} 392}
90 393
394unpack_2_6() {
395 # this file is required for other things to build properly, so we
396 # autogenerate it ... generate a .config to keep version.h build from
397 # spitting out an annoying warning
398 make -s mrproper ${xmakeopts} 2>/dev/null \
399 || die "make mrproper failed"
400
401 # quick fix for bug #132152 which triggers when it cannot include linux
402 # headers (ie, we have not installed it yet)
403 if ! make -s defconfig ${xmakeopts} &>/dev/null 2>&1 ; then
404 touch .config
405 eerror "make defconfig failed."
406 eerror "assuming you dont have any headers installed yet and continuing"
407 epause 5
408 fi
409
410 make -s include/linux/version.h ${xmakeopts} 2>/dev/null \
411 || die "make include/linux/version.h failed"
412 rm -f .config >/dev/null
413}
414
91universal_unpack() { 415universal_unpack() {
416 cd "${WORKDIR}"
417 unpack linux-${OKV}.tar.bz2
418 if [[ -d "linux" ]]; then
419 mv linux linux-${KV_FULL} \
420 || die "Unable to move source tree to ${KV_FULL}."
421 elif [[ "${OKV}" != "${KV_FULL}" ]]; then
422 mv linux-${OKV} linux-${KV_FULL} \
423 || die "Unable to move source tree to ${KV_FULL}."
424 fi
425 cd "${S}"
426
92 # remove all backup files 427 # remove all backup files
93 find . -iname "*~" -exec rm {} \; 2> /dev/null 428 find . -iname "*~" -exec rm {} \; 2> /dev/null
94 429
95 if [ -d "${S}/Documentation/DocBook" ] 430 # fix a problem on ppc where TOUT writes to /usr/src/linux breaking sandbox
431 # only do this for kernel < 2.6.27 since this file does not exist in later
432 # kernels
433 if [[ ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} < 2.6.27 ]]
96 then 434 then
97 cd ${S}/Documentation/DocBook 435 sed -i \
98 sed -e "s:db2:docbook2:g" Makefile > Makefile.new \ 436 -e 's|TOUT := .tmp_gas_check|TOUT := $(T).tmp_gas_check|' \
99 && mv Makefile.new Makefile 437 "${S}"/arch/ppc/Makefile
100 cd ${S} 438 else
439 sed -i \
440 -e 's|TOUT := .tmp_gas_check|TOUT := $(T).tmp_gas_check|' \
441 "${S}"/arch/powerpc/Makefile
101 fi 442 fi
102} 443}
103 444
104unpack_set_extraversion() { 445unpack_set_extraversion() {
105 # Gentoo Linux uses /boot, so fix 'make install' to work properly and fix EXTRAVERSION
106 cd ${S} 446 cd "${S}"
107 mv Makefile Makefile.orig 447 sed -i -e "s:^\(EXTRAVERSION =\).*:\1 ${EXTRAVERSION}:" Makefile
448 cd "${OLDPWD}"
449}
450
451# Should be done after patches have been applied
452# Otherwise patches that modify the same area of Makefile will fail
453unpack_fix_install_path() {
454 cd "${S}"
108 sed -e 's:#export\tINSTALL_PATH:export\tINSTALL_PATH:' \ 455 sed -i -e 's:#export\tINSTALL_PATH:export\tINSTALL_PATH:' Makefile
109 -e "s:^\(EXTRAVERSION =\).*:\1 ${EXTRAVERSION}:" \
110 Makefile.orig > Makefile
111 rm Makefile.orig
112} 456}
113 457
114# Compile Functions 458# Compile Functions
115#============================================================== 459#==============================================================
116compile_headers() { 460compile_headers() {
117 local MY_ARCH 461 env_setup_xmakeopts
118 462
119 MY_ARCH=${ARCH} 463 # if we couldnt obtain HOSTCFLAGS from the Makefile,
120 unset ${ARCH} 464 # then set it to something sane
465 local HOSTCFLAGS=$(getfilevar HOSTCFLAGS "${S}"/Makefile)
466 HOSTCFLAGS=${HOSTCFLAGS:--Wall -Wstrict-prototypes -O2 -fomit-frame-pointer}
467
468 if kernel_is 2 4; then
121 yes "" | make oldconfig 469 yes "" | make oldconfig ${xmakeopts}
122 echo ">>> make oldconfig complete" 470 echo ">>> make oldconfig complete"
123 ARCH=${MY_ARCH} 471 make dep ${xmakeopts}
472 elif kernel_is 2 6; then
473 # 2.6.18 introduces headers_install which means we dont need any
474 # of this crap anymore :D
475 kernel_is ge 2 6 18 && return 0
476
477 # autoconf.h isnt generated unless it already exists. plus, we have
478 # no guarantee that any headers are installed on the system...
479 [[ -f ${ROOT}/usr/include/linux/autoconf.h ]] \
480 || touch include/linux/autoconf.h
481
482 # if K_DEFCONFIG isn't set, force to "defconfig"
483 # needed by mips
484 if [[ -z ${K_DEFCONFIG} ]]; then
485 if [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]]; then
486 case ${CTARGET} in
487 powerpc64*) K_DEFCONFIG="ppc64_defconfig";;
488 powerpc*) K_DEFCONFIG="pmac32_defconfig";;
489 *) K_DEFCONFIG="defconfig";;
490 esac
491 else
492 K_DEFCONFIG="defconfig"
493 fi
494 fi
495
496 # if there arent any installed headers, then there also isnt an asm
497 # symlink in /usr/include/, and make defconfig will fail, so we have
498 # to force an include path with $S.
499 HOSTCFLAGS="${HOSTCFLAGS} -I${S}/include/"
500 ln -sf asm-${KARCH} "${S}"/include/asm
501 cross_pre_c_headers && return 0
502
503 make ${K_DEFCONFIG} HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "defconfig failed (${K_DEFCONFIG})"
504 if compile_headers_tweak_config ; then
505 yes "" | make oldconfig HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "2nd oldconfig failed"
506 fi
507 make prepare HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "prepare failed"
508 make prepare-all HOSTCFLAGS="${HOSTCFLAGS}" ${xmakeopts} || die "prepare failed"
509 fi
510}
511
512compile_headers_tweak_config() {
513 # some targets can be very very picky, so let's finesse the
514 # .config based upon any info we may have
515 case ${CTARGET} in
516 sh*)
517 sed -i '/CONFIG_CPU_SH/d' .config
518 echo "CONFIG_CPU_SH${CTARGET:2:1}=y" >> .config
519 return 0;;
520 esac
521
522 # no changes, so lets do nothing
523 return 1
124} 524}
125 525
126# install functions 526# install functions
127#============================================================== 527#==============================================================
128install_universal() { 528install_universal() {
129 #fix silly permissions in tarball 529 #fix silly permissions in tarball
130 cd ${WORKDIR} 530 cd "${WORKDIR}"
131 chown -R root:root * 531 chown -R root:0 * >& /dev/null
132 chmod -R a+r-w+X,u+w * 532 chmod -R a+r-w+X,u+w *
533 cd ${OLDPWD}
133} 534}
134 535
135install_headers() { 536install_headers() {
136 [ $(kernel_is_2_4) $? == 0 ] && unpack_2_4 537 local ddir=$(kernel_header_destdir)
137 [ $(kernel_is_2_6) $? == 0 ] && ln -sf ${S}/include/asm-${ARCH} ${S}/include/asm
138 538
539 # 2.6.18 introduces headers_install which means we dont need any
540 # of this crap anymore :D
541 if kernel_is ge 2 6 18 ; then
542 env_setup_xmakeopts
543 emake headers_install INSTALL_HDR_PATH="${D}"/${ddir}/.. ${xmakeopts} || die
544
545 # let other packages install some of these headers
546 rm -rf "${D}"/${ddir}/sound #alsa-headers
547 rm -rf "${D}"/${ddir}/scsi #glibc/uclibc/etc...
548 return 0
549 fi
550
551 # Do not use "linux/*" as that can cause problems with very long
552 # $S values where the cmdline to cp is too long
139 cd ${S} 553 cd "${S}"
140 dodir /usr/include/linux 554 dodir ${ddir}/linux
141 cp -ax ${S}/include/linux/* ${D}/usr/include/linux 555 cp -pPR "${S}"/include/linux "${D}"/${ddir}/ || die
142 rm -rf ${D}/usr/include/linux/modules 556 rm -rf "${D}"/${ddir}/linux/modules
143 dodir /usr/include/asm 557
144 cp -ax ${S}/include/asm/* ${D}/usr/include/asm 558 # Handle multilib headers and crap
145 559 local multi_dirs="" multi_defs=""
146 if [ $(kernel_is_2_6) $? == 0 ] 560 case $(tc-arch-kernel) in
147 then 561 sparc64)
148 dodir /usr/include/asm-generic 562 multi_dirs="sparc sparc64"
563 multi_defs="!__arch64__ __arch64__"
564 ;;
565 x86_64)
566 multi_dirs="i386 x86_64"
567 multi_defs="__i386__ __x86_64__"
568 ;;
569 ppc64)
570 multi_dirs="ppc ppc64"
571 multi_defs="!__powerpc64__ __powerpc64__"
572 ;;
573 s390x)
574 multi_dirs="s390 s390x"
575 multi_defs="!__s390x__ __s390x__"
576 ;;
577 arm)
578 dodir ${ddir}/asm
579 cp -pPR "${S}"/include/asm/* "${D}"/${ddir}/asm
580 [[ ! -e ${D}/${ddir}/asm/arch ]] && ln -sf arch-ebsa285 "${D}"/${ddir}/asm/arch
581 [[ ! -e ${D}/${ddir}/asm/proc ]] && ln -sf proc-armv "${D}"/${ddir}/asm/proc
582 ;;
583 powerpc)
584 dodir ${ddir}/asm
585 cp -pPR "${S}"/include/asm/* "${D}"/${ddir}/asm
586 if [[ -e "${S}"/include/asm-ppc ]] ; then
587 dodir ${ddir}/asm-ppc
588 cp -pPR "${S}"/include/asm-ppc/* "${D}"/${ddir}/asm-ppc
589 fi
590 ;;
591 *)
592 dodir ${ddir}/asm
593 cp -pPR "${S}"/include/asm/* "${D}"/${ddir}/asm
594 ;;
595 esac
596 if [[ -n ${multi_dirs} ]] ; then
597 local d ml_inc=""
598 for d in ${multi_dirs} ; do
599 dodir ${ddir}/asm-${d}
600 cp -pPR "${S}"/include/asm-${d}/* "${D}"/${ddir}/asm-${d}/ || die "cp asm-${d} failed"
601
602 ml_inc="${ml_inc} ${multi_defs%% *}:${ddir}/asm-${d}"
603 multi_defs=${multi_defs#* }
604 done
605 create_ml_includes ${ddir}/asm ${ml_inc}
606 fi
607
608 if kernel_is 2 6; then
609 dodir ${ddir}/asm-generic
149 cp -ax ${S}/include/asm-generic/* ${D}/usr/include/asm-generic 610 cp -pPR "${S}"/include/asm-generic/* "${D}"/${ddir}/asm-generic
150 fi 611 fi
612
613 # clean up
614 find "${D}" -name '*.orig' -exec rm -f {} \;
615
616 cd ${OLDPWD}
151} 617}
152 618
153install_sources() { 619install_sources() {
154 local doc 620 local file
155 local docs
156 621
157 cd ${S} 622 cd "${S}"
158 dodir /usr/src 623 dodir /usr/src
159 echo ">>> Copying sources..." 624 echo ">>> Copying sources ..."
160 if [ -d "${WORKDIR}/${KV}/docs/" ] 625
161 then 626 file="$(find ${WORKDIR} -iname "docs" -type d)"
162 for file in $(ls -1 ${WORKDIR}/${KV}/docs/) 627 if [[ -n ${file} ]]; then
163 do 628 for file in $(find ${file} -type f); do
164 echo "XX_${file}*" >> ${S}/patches.txt 629 echo "${file//*docs\/}" >> "${S}"/patches.txt
165 cat ${WORKDIR}/${KV}/docs/${file} >> ${S}/patches.txt 630 echo "===================================================" >> "${S}"/patches.txt
631 cat ${file} >> "${S}"/patches.txt
632 echo "===================================================" >> "${S}"/patches.txt
166 echo "" >> ${S}/patches.txt 633 echo "" >> "${S}"/patches.txt
167 done 634 done
168 fi 635 fi
169 636
170 if [ ! -f ${S}/patches.txt ] 637 if [[ ! -f ${S}/patches.txt ]]; then
171 then
172 # patches.txt is empty so lets use our ChangeLog 638 # 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 639 [[ -f ${FILESDIR}/../ChangeLog ]] && \
640 echo "Please check the ebuild ChangeLog for more details." \
641 > "${S}"/patches.txt
174 fi 642 fi
175 643
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 644 mv ${WORKDIR}/linux* "${D}"/usr/src
186} 645}
187 646
188# pkg_preinst functions 647# pkg_preinst functions
189#============================================================== 648#==============================================================
190preinst_headers() { 649preinst_headers() {
191 [ -L ${ROOT}usr/include/linux ] && rm ${ROOT}usr/include/linux 650 local ddir=$(kernel_header_destdir)
192 [ -L ${ROOT}usr/include/asm ] && rm ${ROOT}usr/include/asm 651 [[ -L ${ddir}/linux ]] && rm ${ddir}/linux
652 [[ -L ${ddir}/asm ]] && rm ${ddir}/asm
193} 653}
194 654
195# pkg_postinst functions 655# pkg_postinst functions
196#============================================================== 656#==============================================================
197postinst_sources() { 657postinst_sources() {
658 local MAKELINK=0
659
660 # if we have USE=symlink, then force K_SYMLINK=1
661 use symlink && K_SYMLINK=1
662
663 # if we're using a deblobbed kernel, it's not supported
664 [[ $K_DEBLOB_AVAILABLE == 1 ]] && \
665 use deblob && \
666 K_SECURITY_UNSUPPORTED=1
667
668 # if we are to forcably symlink, delete it if it already exists first.
669 if [[ ${K_SYMLINK} > 0 ]]; then
670 [[ -h ${ROOT}usr/src/linux ]] && rm ${ROOT}usr/src/linux
671 MAKELINK=1
672 fi
673
674 # if the link doesnt exist, lets create it
198 if [ ! -h ${ROOT}usr/src/linux ] 675 [[ ! -h ${ROOT}usr/src/linux ]] && MAKELINK=1
676
677 if [[ ${MAKELINK} == 1 ]]; then
678 cd "${ROOT}"usr/src
679 ln -sf linux-${KV_FULL} linux
680 cd ${OLDPWD}
681 fi
682
683 # Don't forget to make directory for sysfs
684 [[ ! -d ${ROOT}sys ]] && kernel_is 2 6 && mkdir ${ROOT}sys
685
686 echo
687 elog "If you are upgrading from a previous kernel, you may be interested"
688 elog "in the following document:"
689 elog " - General upgrade guide: http://www.gentoo.org/doc/en/kernel-upgrade.xml"
690 echo
691
692 # if K_EXTRAEINFO is set then lets display it now
693 if [[ -n ${K_EXTRAEINFO} ]]; then
694 echo ${K_EXTRAEINFO} | fmt |
695 while read -s ELINE; do einfo "${ELINE}"; done
696 fi
697
698 # if K_EXTRAELOG is set then lets display it now
699 if [[ -n ${K_EXTRAELOG} ]]; then
700 echo ${K_EXTRAELOG} | fmt |
701 while read -s ELINE; do elog "${ELINE}"; done
702 fi
703
704 # if K_EXTRAEWARN is set then lets display it now
705 if [[ -n ${K_EXTRAEWARN} ]]; then
706 echo ${K_EXTRAEWARN} | fmt |
707 while read -s ELINE; do ewarn "${ELINE}"; done
708 fi
709
710 # optionally display security unsupported message
711 if [[ -n ${K_SECURITY_UNSUPPORTED} ]]; then
712 echo
713 ewarn "${PN} is UNSUPPORTED by Gentoo Security."
714 ewarn "This means that it is likely to be vulnerable to recent security issues."
715 ewarn "For specific information on why this kernel is unsupported, please read:"
716 ewarn "http://www.gentoo.org/proj/en/security/kernel.xml"
717 fi
718
719 # warn sparc users that they need to do cross-compiling with >= 2.6.25(bug #214765)
720 KV_MAJOR=$(get_version_component_range 1 ${OKV})
721 KV_MINOR=$(get_version_component_range 2 ${OKV})
722 KV_PATCH=$(get_version_component_range 3 ${OKV})
723 if [[ "$(tc-arch)" = "sparc" ]] \
724 && [[ ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} > 2.6.24 ]]
199 then 725 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 726 echo
225 fi 727 elog "NOTE: Since 2.6.25 the kernel Makefile has changed in a way that"
226 728 elog "you now need to do"
227 # if K_EXTRAEWARN is set then lets display it now 729 elog " make CROSS_COMPILE=sparc64-unknown-linux-gnu-"
228 if [ -n "${K_EXTRAEWARN}" ] 730 elog "instead of just"
229 then 731 elog " make"
230 echo ${K_EXTRAEWARN} | fmt | 732 elog "to compile the kernel. For more information please browse to"
231 while read -s ELINE 733 elog "https://bugs.gentoo.org/show_bug.cgi?id=214765"
232 do
233 ewarn "${ELINE}"
234 done
235
236 echo 734 echo
237 fi 735 fi
238} 736}
239 737
240postinst_headers() { 738postinst_headers() {
241 echo
242 einfo "Kernel headers are usually only used when recompiling glibc." 739 elog "Kernel headers are usually only used when recompiling your system libc, as"
243 einfo "Following the installation of newer headers it is advised that" 740 elog "such, following the installation of newer headers, it is advised that you"
244 einfo "you re-merge glibc as follows:" 741 elog "re-merge your system libc."
245 einfo "# emerge glibc"
246 einfo "Failure to do so will cause glibc to not make use of newer" 742 elog "Failure to do so will cause your system libc to not make use of newer"
247 einfo "features present in the updated kernelheaders." 743 elog "features present in the updated kernel headers."
248 echo
249} 744}
250 745
251# pkg_setup functions 746# pkg_setup functions
252#============================================================== 747#==============================================================
253setup_headers() { 748setup_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/-*/}" 749 [[ -z ${H_SUPPORTEDARCH} ]] && H_SUPPORTEDARCH=${PN/-*/}
258 for i in ${H_SUPPORTEDARCH} 750 for i in ${H_SUPPORTEDARCH}; do
259 do
260 [ "${ARCH}" == "${i}" ] && H_ACCEPT_ARCH="yes" 751 [[ $(tc-arch) == "${i}" ]] && H_ACCEPT_ARCH="yes"
261 done 752 done
262 753
263 if [ "${H_ACCEPT_ARCH}" != "yes" ] 754 if [[ ${H_ACCEPT_ARCH} != "yes" ]]; then
264 then
265 echo 755 echo
266 eerror "This version of ${PN} does not support ${ARCH}." 756 eerror "This version of ${PN} does not support $(tc-arch)."
267 eerror "Please merge the appropriate sources, in most cases" 757 eerror "Please merge the appropriate sources, in most cases"
268 eerror "this will be ${ARCH}-headers." 758 eerror "(but not all) this will be called $(tc-arch)-headers."
269 die "incorrect headers" 759 die "Package unsupported for $(tc-arch)"
270 fi 760 fi
271} 761}
272 762
273# unipatch 763# unipatch
274#============================================================== 764#==============================================================
275unipatch() { 765unipatch() {
276 local i 766 local i x y z extention PIPE_CMD UNIPATCH_DROP KPATCH_DIR PATCH_DEPTH ELINE
277 local x 767 local STRICT_COUNT PATCH_LEVEL myLC_ALL myLANG extglob_bak
278 local extention 768
279 local PIPE_CMD 769 # set to a standard locale to ensure sorts are ordered properly.
280 local UNIPATCH_EXCLUDE 770 myLC_ALL="${LC_ALL}"
281 local KPATCH_DIR 771 myLANG="${LANG}"
282 local PATCH_DEPTH 772 LC_ALL="C"
283 local ELINE 773 LANG=""
284 774
285 [ -z "${KPATCH_DIR}" ] && KPATCH_DIR="${WORKDIR}/patches/" 775 [ -z "${KPATCH_DIR}" ] && KPATCH_DIR="${WORKDIR}/patches/"
286 [ ! -d ${KPATCH_DIR} ] && mkdir -p ${KPATCH_DIR} 776 [ ! -d ${KPATCH_DIR} ] && mkdir -p ${KPATCH_DIR}
287 777
778 # We're gonna need it when doing patches with a predefined patchlevel
779 extglob_bak=$(shopt -p extglob)
780 shopt -s extglob
781
288 # This function will unpack all passed tarballs, add any passed patches, and remove any passed patchnumbers 782 # 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 783 # usage can be either via an env var or by params
784 # although due to the nature we pass this within this eclass
785 # it shall be by param only.
290 [ -z "${UNIPATCH_LIST}" ] && UNIPATCH_LIST="${@}" 786 # -z "${UNIPATCH_LIST}" ] && UNIPATCH_LIST="${@}"
787 UNIPATCH_LIST="${@}"
291 788
292 #unpack any passed tarballs 789 #unpack any passed tarballs
293 for i in ${UNIPATCH_LIST} 790 for i in ${UNIPATCH_LIST}; do
294 do
295 if [ -n "$(echo ${i} | grep -e "\.tar" -e "\.tbz" -e "\.tgz")" ] 791 if echo ${i} | grep -qs -e "\.tar" -e "\.tbz" -e "\.tgz" ; then
296 then 792 if [ -n "${UNIPATCH_STRICTORDER}" ]; then
793 unset z
794 STRICT_COUNT=$((10#${STRICT_COUNT} + 1))
795 for((y=0; y<$((6 - ${#STRICT_COUNT})); y++));
796 do z="${z}0";
797 done
798 PATCH_ORDER="${z}${STRICT_COUNT}"
799
800 mkdir -p "${KPATCH_DIR}/${PATCH_ORDER}"
801 pushd "${KPATCH_DIR}/${PATCH_ORDER}" >/dev/null
802 unpack ${i##*/}
803 popd >/dev/null
804 else
805 pushd "${KPATCH_DIR}" >/dev/null
806 unpack ${i##*/}
807 popd >/dev/null
808 fi
809
810 [[ ${i} == *:* ]] && echo ">>> Strict patch levels not currently supported for tarballed patchsets"
811 else
297 extention=${i/*./} 812 extention=${i/*./}
813 extention=${extention/:*/}
814 PIPE_CMD=""
298 case ${extention} in 815 case ${extention} in
299 tbz2) PIPE_CMD="tar -xvjf";; 816 bz2) PIPE_CMD="bzip2 -dc";;
300 bz2) PIPE_CMD="tar -xvjf";; 817 patch) PIPE_CMD="cat";;
301 tgz) PIPE_CMD="tar -xvzf";; 818 diff) PIPE_CMD="cat";;
302 gz) PIPE_CMD="tar -xvzf";; 819 gz|Z|z) PIPE_CMD="gzip -dc";;
303 *) eerror "Unrecognized tarball compression" 820 ZIP|zip) PIPE_CMD="unzip -p";;
304 die "Unrecognized tarball compression";; 821 *) UNIPATCH_DROP="${UNIPATCH_DROP} ${i/:*/}";;
305 esac 822 esac
306 823
307 ${PIPE_CMD} ${i} -C ${KPATCH_DIR} 1>/dev/null 824 PATCH_LEVEL=${i/*([^:])?(:)}
308 if [ $? == 0 ] 825 i=${i/:*/}
309 then 826 x=${i/*\//}
310 einfo "${i/*\//} unpacked" 827 x=${x/\.${extention}/}
828
829 if [ -n "${PIPE_CMD}" ]; then
830 if [ ! -r "${i}" ]; then
831 echo
832 eerror "FATAL: unable to locate:"
833 eerror "${i}"
834 eerror "for read-only. The file either has incorrect permissions"
835 eerror "or does not exist."
836 die Unable to locate ${i}
837 fi
838
839 if [ -n "${UNIPATCH_STRICTORDER}" ]; then
840 unset z
841 STRICT_COUNT=$((10#${STRICT_COUNT} + 1))
842 for((y=0; y<$((6 - ${#STRICT_COUNT})); y++));
843 do z="${z}0";
844 done
845 PATCH_ORDER="${z}${STRICT_COUNT}"
846
847 mkdir -p ${KPATCH_DIR}/${PATCH_ORDER}/
848 $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${PATCH_ORDER}/${x}.patch${PATCH_LEVEL})
311 else 849 else
312 eerror "Failed to unpack ${i}" 850 $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${x}.patch${PATCH_LEVEL})
313 die "unable to unpack patch tarball" 851 fi
314 fi 852 fi
315
316 UNIPATCH_LIST="${UNIPATCH_LIST/${i}/}"
317 fi 853 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 854 done
337 855
338 #populate KPATCH_DIRS so we know where to look to remove the excludes 856 #populate KPATCH_DIRS so we know where to look to remove the excludes
339 x=${KPATCH_DIR} 857 x=${KPATCH_DIR}
340 KPATCH_DIR="" 858 KPATCH_DIR=""
341 for i in $(find ${x} -type d) 859 for i in $(find ${x} -type d | sort -n); do
342 do
343 KPATCH_DIR="${KPATCH_DIR} ${i}" 860 KPATCH_DIR="${KPATCH_DIR} ${i}"
344 done 861 done
345 862
863 # do not apply fbcondecor patch to sparc/sparc64 as it breaks boot
864 # bug #272676
865 if [[ "$(tc-arch)" = "sparc" || "$(tc-arch)" = "sparc64" ]]; then
866 if [[ ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} > 2.6.28 ]]; then
867 UNIPATCH_DROP="${UNIPATCH_DROP} *_fbcondecor-0.9.6.patch"
868 echo
869 ewarn "fbcondecor currently prevents sparc/sparc64 from booting"
870 ewarn "for kernel versions >= 2.6.29. Removing fbcondecor patch."
871 ewarn "See https://bugs.gentoo.org/show_bug.cgi?id=272676 for details"
872 echo
873 fi
874 fi
875
346 #so now lets get rid of the patchno's we want to exclude 876 #so now lets get rid of the patchno's we want to exclude
877 UNIPATCH_DROP="${UNIPATCH_EXCLUDE} ${UNIPATCH_DROP}"
347 for i in ${UNIPATCH_EXCLUDE} 878 for i in ${UNIPATCH_DROP}; do
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}" 879 ebegin "Excluding Patch #${i}"
355 einfo "From: ${x/${WORKDIR}/}" 880 for x in ${KPATCH_DIR}; do rm -f ${x}/${i}* 2>/dev/null; done
356 fi 881 eend $?
357 done
358 done 882 done
359 883
360 # and now, finally, we patch it :) 884 # and now, finally, we patch it :)
361 for x in ${KPATCH_DIR} 885 for x in ${KPATCH_DIR}; do
362 do
363 for i in $(find ${x} -maxdepth 1 -iname "*.patch" -or -iname "*.diff" | sort -u) 886 for i in $(find ${x} -maxdepth 1 -iname "*.patch*" -or -iname "*.diff*" | sort -n); do
364 do 887 STDERR_T="${T}/${i/*\//}"
888 STDERR_T="${STDERR_T/.patch*/.err}"
365 889
890 [ -z ${i/*.patch*/} ] && PATCH_DEPTH=${i/*.patch/}
891 #[ -z ${i/*.diff*/} ] && PATCH_DEPTH=${i/*.diff/}
366 892
367 PATCH_DEPTH=0 893 if [ -z "${PATCH_DEPTH}" ]; then PATCH_DEPTH=0; fi
894
368 ebegin "Applying ${i/*\//}" 895 ebegin "Applying ${i/*\//} (-p${PATCH_DEPTH}+)"
369 while [ ${PATCH_DEPTH} -lt 5 ] 896 while [ ${PATCH_DEPTH} -lt 5 ]; do
370 do 897 echo "Attempting Dry-run:" >> ${STDERR_T}
371 if (patch -p${PATCH_DEPTH} --dry-run -f < ${i} >/dev/null) 898 echo "cmd: patch -p${PATCH_DEPTH} --no-backup-if-mismatch --dry-run -f < ${i}" >> ${STDERR_T}
372 then 899 echo "=======================================================" >> ${STDERR_T}
373 $(patch -p${PATCH_DEPTH} -f < ${i} >/dev/null) 900 if [ $(patch -p${PATCH_DEPTH} --no-backup-if-mismatch --dry-run -f < ${i} >> ${STDERR_T}) $? -eq 0 ]; then
374 if [ "$?" -eq 0 ] 901 echo "Attempting patch:" > ${STDERR_T}
375 then 902 echo "cmd: patch -p${PATCH_DEPTH} --no-backup-if-mismatch -f < ${i}" >> ${STDERR_T}
903 echo "=======================================================" >> ${STDERR_T}
904 if [ $(patch -p${PATCH_DEPTH} --no-backup-if-mismatch -f < ${i} >> ${STDERR_T}) "$?" -eq 0 ]; then
376 eend 0 905 eend 0
906 rm ${STDERR_T}
377 break 907 break
378 else 908 else
379 eend 1 909 eend 1
380 eerror "Failed to apply patch ${i/*\//}" 910 eerror "Failed to apply patch ${i/*\//}"
911 eerror "Please attach ${STDERR_T} to any bug you may post."
381 die "Failed to apply ${i/*\//}" 912 die "Failed to apply ${i/*\//}"
382 fi 913 fi
383 else 914 else
384 PATCH_DEPTH=$((${PATCH_DEPTH} + 1)) 915 PATCH_DEPTH=$((${PATCH_DEPTH} + 1))
385 fi 916 fi
386 done 917 done
387 if [ ${PATCH_DEPTH} -eq 5 ] 918 if [ ${PATCH_DEPTH} -eq 5 ]; then
388 then
389 eend 1 919 eend 1
920 eerror "Please attach ${STDERR_T} to any bug you may post."
390 die "Unable to dry-run patch." 921 die "Unable to dry-run patch."
391 fi 922 fi
392
393
394 done 923 done
395 done 924 done
396}
397 925
398# custom functions 926 # This is a quick, and kind of nasty hack to deal with UNIPATCH_DOCS which
927 # sit in KPATCH_DIR's. This is handled properly in the unipatch rewrite,
928 # which is why I'm not taking too much time over this.
929 local tmp
930 for i in ${UNIPATCH_DOCS}; do
931 tmp="${tmp} ${i//*\/}"
932 cp -f ${i} "${T}"/
933 done
934 UNIPATCH_DOCS="${tmp}"
935
936 # clean up KPATCH_DIR's - fixes bug #53610
937 for x in ${KPATCH_DIR}; do rm -Rf ${x}; done
938
939 LC_ALL="${myLC_ALL}"
940 LANG="${myLANG}"
941 eval ${extglob_bak}
942}
943
944# getfilevar accepts 2 vars as follows:
945# getfilevar <VARIABLE> <CONFIGFILE>
946# pulled from linux-info
947
948getfilevar() {
949 local workingdir basefname basedname xarch=$(tc-arch-kernel)
950
951 if [[ -z ${1} ]] && [[ ! -f ${2} ]]; then
952 echo -e "\n"
953 eerror "getfilevar requires 2 variables, with the second a valid file."
954 eerror " getfilevar <VARIABLE> <CONFIGFILE>"
955 else
956 workingdir=${PWD}
957 basefname=$(basename ${2})
958 basedname=$(dirname ${2})
959 unset ARCH
960
961 cd ${basedname}
962 echo -e "include ${basefname}\ne:\n\t@echo \$(${1})" | \
963 make ${BUILD_FIXES} -s -f - e 2>/dev/null
964 cd ${workingdir}
965
966 ARCH=${xarch}
967 fi
968}
969
970detect_arch() {
971 # This function sets ARCH_URI and ARCH_PATCH
972 # with the neccessary info for the arch sepecific compatibility
973 # patchsets.
974
975 local ALL_ARCH LOOP_ARCH COMPAT_URI i
976
977 # COMPAT_URI is the contents of ${ARCH}_URI
978 # ARCH_URI is the URI for all the ${ARCH}_URI patches
979 # ARCH_PATCH is ARCH_URI broken into files for UNIPATCH
980
981 ARCH_URI=""
982 ARCH_PATCH=""
983 ALL_ARCH="ALPHA AMD64 ARM HPPA IA64 M68K MIPS PPC PPC64 S390 SH SPARC X86"
984
985 for LOOP_ARCH in ${ALL_ARCH}; do
986 COMPAT_URI="${LOOP_ARCH}_URI"
987 COMPAT_URI="${!COMPAT_URI}"
988
989 [[ -n ${COMPAT_URI} ]] && \
990 ARCH_URI="${ARCH_URI} $(echo ${LOOP_ARCH} | tr '[:upper:]' '[:lower:]')? ( ${COMPAT_URI} )"
991
992 if [[ ${LOOP_ARCH} == "$(echo $(tc-arch-kernel) | tr '[:lower:]' '[:upper:]')" ]]; then
993 for i in ${COMPAT_URI}; do
994 ARCH_PATCH="${ARCH_PATCH} ${DISTDIR}/${i/*\//}"
995 done
996 fi
997 done
998}
999
1000# sparc nastiness
399#============================================================== 1001#==============================================================
400detect_version() { 1002# This script generates the files in /usr/include/asm for sparc systems
401 # this function will detect and set 1003# during installation of sys-kernel/linux-headers.
402 # - OKV: Original Kernel Version (2.6.0/2.6.0-test11) 1004# Will no longer be needed when full 64 bit support is used on sparc64
403 # - KV: Kernel Version (2.6.0-gentoo/2.6.0-test11-gentoo-r1) 1005# systems.
404 # - EXTRAVERSION: The additional version appended to OKV (-gentoo/-gentoo-r1) 1006#
405 1007# Shamefully ripped from Debian
406 OKV=${PV/_beta/-test} 1008# ----------------------------------------------------------------------
407 OKV=${OKV/_rc/-rc} 1009
408 OKV=${OKV/_pre*/} 1010# Idea borrowed from RedHat's kernel package
409 OKV=${OKV/-r*/} 1011
410 1012# This is gonna get replaced by something in multilib.eclass soon...
411 KV_MAJOR=$(echo ${OKV} | cut -d. -f1) 1013# --eradicator
412 KV_MINOR=$(echo ${OKV} | cut -d. -f2) 1014generate_sparc_asm() {
413 KV_PATCH=$(echo ${OKV} | cut -d. -f3) 1015 local name
414 KV_PATCH=${KV_PATCH/[-_]*/} 1016
415 1017 cd $1 || die
416 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2" 1018 mkdir asm
417 1019
418 RELEASE=${PV/${OKV}/} 1020 for h in `( ls asm-sparc; ls asm-sparc64 ) | grep '\.h$' | sort -u`; do
419 RELEASE=${RELEASE/_beta/} 1021 name="$(echo $h | tr a-z. A-Z_)"
420 RELEASE=${RELEASE/_rc/-rc} 1022 # common header
421 RELEASE=${RELEASE/_pre/-bk} 1023 echo "/* All asm/ files are generated and point to the corresponding
422 RELEASETYPE=${RELEASE//[0-9]/} 1024 * file in asm-sparc or asm-sparc64.
423 1025 */
424 EXTRAVERSION="${RELEASE}" 1026
425 1027#ifndef __SPARCSTUB__${name}__
426 if [ -n "${K_PREPATCHED}" ] 1028#define __SPARCSTUB__${name}__
427 then 1029" > asm/${h}
428 KV="${OKV}-${PN/-*/}${PR/r/}" 1030
1031 # common for sparc and sparc64
1032 if [ -f asm-sparc/$h -a -f asm-sparc64/$h ]; then
1033 echo "#ifdef __arch64__
1034#include <asm-sparc64/$h>
1035#else
1036#include <asm-sparc/$h>
1037#endif
1038" >> asm/${h}
1039
1040 # sparc only
1041 elif [ -f asm-sparc/$h ]; then
1042echo "#ifndef __arch64__
1043#include <asm-sparc/$h>
1044#endif
1045" >> asm/${h}
1046
1047 # sparc64 only
429 else 1048 else
430 [ -z "${K_NOUSENAME}" ] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*/}" 1049echo "#ifdef __arch64__
431 [ ! "${PR}" == "r0" ] && EXTRAVERSION="${EXTRAVERSION}-${PR}" 1050#include <asm-sparc64/$h>
432 1051#endif
433 KV=${OKV}${EXTRAVERSION} 1052" >> asm/${h}
434 fi 1053 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 1054
1055 # common footer
1056 echo "#endif /* !__SPARCSTUB__${name}__ */" >> asm/${h}
1057 done
1058 return 0
1059}
1060
1061headers___fix() {
1062 # Voodoo to partially fix broken upstream headers.
1063 # note: do not put inline/asm/volatile together (breaks "inline asm volatile")
1064 sed -i \
1065 -e '/^\#define.*_TYPES_H/{:loop n; bloop}' \
1066 -e 's:\<\([us]\(8\|16\|32\|64\)\)\>:__\1:g' \
1067 -e "s/\([[:space:]]\)inline\([[:space:](]\)/\1__inline__\2/g" \
1068 -e "s/\([[:space:]]\)asm\([[:space:](]\)/\1__asm__\2/g" \
1069 -e "s/\([[:space:]]\)volatile\([[:space:](]\)/\1__volatile__\2/g" \
1070 "$@"
1071}
472 1072
473# common functions 1073# common functions
474#============================================================== 1074#==============================================================
475src_unpack() { 1075kernel-2_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 1076 universal_unpack
487 [ -n "${UNIPATCH_LIST}" ] && unipatch ${UNIPATCH_LIST} 1077 debug-print "Doing unipatch"
1078
1079 [[ -n ${UNIPATCH_LIST} || -n ${UNIPATCH_LIST_DEFAULT} || -n ${UNIPATCH_LIST_GENPATCHES} ]] && \
1080 unipatch "${UNIPATCH_LIST_DEFAULT} ${UNIPATCH_LIST_GENPATCHES} ${UNIPATCH_LIST}"
1081
1082 debug-print "Doing premake"
1083
1084 # allow ebuilds to massage the source tree after patching but before
1085 # we run misc `make` functions below
1086 [[ $(type -t kernel-2_hook_premake) == "function" ]] && kernel-2_hook_premake
1087
1088 debug-print "Doing epatch_user"
1089 epatch_user
1090
1091 debug-print "Doing unpack_set_extraversion"
1092
488 [ -z "${K_NOSETEXTRAVERSION}" ] && unpack_set_extraversion 1093 [[ -z ${K_NOSETEXTRAVERSION} ]] && unpack_set_extraversion
1094 unpack_fix_install_path
489 1095
490 [ $(kernel_is_2_4) $? == 0 ] && unpack_2_4 1096 # Setup xmakeopts and cd into sourcetree.
491} 1097 env_setup_xmakeopts
1098 cd "${S}"
492 1099
1100 # We dont need a version.h for anything other than headers
1101 # at least, I should hope we dont. If this causes problems
1102 # take out the if/fi block and inform me please.
1103 # unpack_2_6 should now be 2.6.17 safe anyways
1104 if [[ ${ETYPE} == headers ]]; then
1105 kernel_is 2 4 && unpack_2_4
1106 kernel_is 2 6 && unpack_2_6
1107 fi
1108
1109 if [[ $K_DEBLOB_AVAILABLE == 1 ]] && use deblob ; then
1110 cp "${DISTDIR}/${DEBLOB_A}" "${T}"
1111 chmod +x "${T}/${DEBLOB_A}"
1112 fi
1113}
1114
493src_compile() { 1115kernel-2_src_compile() {
1116 cd "${S}"
494 [ "${ETYPE}" == "headers" ] && compile_headers 1117 [[ ${ETYPE} == headers ]] && compile_headers
495}
496 1118
1119 if [[ $K_DEBLOB_AVAILABLE == 1 ]] && use deblob ; then
1120 echo ">>> Running deblob script ..."
1121 sh "${T}/${DEBLOB_A}" --force || \
1122 die "Deblob script failed to run!!!"
1123 fi
1124}
1125
497pkg_preinst() { 1126kernel-2_pkg_preinst() {
498 [ "${ETYPE}" == "headers" ] && preinst_headers 1127 [[ ${ETYPE} == headers ]] && preinst_headers
499} 1128}
500 1129
501src_install() { 1130kernel-2_src_install() {
502 install_universal 1131 install_universal
503 [ "${ETYPE}" == "headers" ] && install_headers 1132 [[ ${ETYPE} == headers ]] && install_headers
504 [ "${ETYPE}" == "sources" ] && install_sources 1133 [[ ${ETYPE} == sources ]] && install_sources
505} 1134}
506 1135
507pkg_postinst() { 1136kernel-2_pkg_postinst() {
508 [ "${ETYPE}" == "headers" ] && postinst_headers 1137 [[ ${ETYPE} == headers ]] && postinst_headers
509 [ "${ETYPE}" == "sources" ] && postinst_sources 1138 [[ ${ETYPE} == sources ]] && postinst_sources
510} 1139}
511 1140
512pkg_setup() { 1141kernel-2_pkg_setup() {
1142 if kernel_is 2 4; then
1143 if [ "$( gcc-major-version )" -eq "4" ] ; then
1144 echo
1145 ewarn "Be warned !! >=sys-devel/gcc-4.0.0 isn't supported with linux-2.4!"
1146 ewarn "Either switch to another gcc-version (via gcc-config) or use a"
1147 ewarn "newer kernel that supports gcc-4."
1148 echo
1149 ewarn "Also be aware that bugreports about gcc-4 not working"
1150 ewarn "with linux-2.4 based ebuilds will be closed as INVALID!"
1151 echo
1152 epause 10
1153 fi
1154 fi
1155
1156 ABI="${KERNEL_ABI}"
513 [ "${ETYPE}" == "headers" ] && setup_headers 1157 [[ ${ETYPE} == headers ]] && setup_headers
1158 [[ ${ETYPE} == sources ]] && echo ">>> Preparing to unpack ..."
514} 1159}

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

  ViewVC Help
Powered by ViewVC 1.1.20