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

Contents of /eclass/kernel-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Fri Jan 16 22:23:52 2004 UTC (15 years, 5 months ago) by iggy
Branch: MAIN
Changes since 1.6: +11 -1 lines
added K_EXTRAEWARN like K_EXTRAEINFO

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

  ViewVC Help
Powered by ViewVC 1.1.20