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

Contents of /eclass/kernel-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations) (download)
Thu Jan 15 18:04:16 2004 UTC (15 years, 5 months ago) by johnm
Branch: MAIN
Changes since 1.5: +1 -1 lines
cause it to pull module-init-tools instead of virtual/modutils, this fixes the dependancy issue of 2.6 sources, and is back compatible with 2.4 sources

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
213 # unipatch
214 #==============================================================
215 unipatch() {
216 local i
217 local x
218 local extention
219 local PIPE_CMD
220 local UNIPATCH_EXCLUDE
221 local KPATCH_DIR
222 local PATCH_DEPTH
223 local ELINE
224
225 [ -z "${KPATCH_DIR}" ] && KPATCH_DIR="${WORKDIR}/patches/"
226 [ ! -d ${KPATCH_DIR} ] && mkdir -p ${KPATCH_DIR}
227
228 # This function will unpack all passed tarballs, add any passed patches, and remove any passed patchnumbers
229 # usage can be either via an env var or by params
230 [ -z "${UNIPATCH_LIST}" ] && UNIPATCH_LIST="${@}"
231
232 #unpack any passed tarballs
233 for i in ${UNIPATCH_LIST}
234 do
235 if [ -n "$(echo ${i} | grep -e ".tar" -e ".tbz" -e ".tgz")" ]
236 then
237 extention=${i/*./}
238 case ${extention} in
239 tbz2) PIPE_CMD="tar -xvjf";;
240 bz2) PIPE_CMD="tar -xvjf";;
241 tgz) PIPE_CMD="tar -xvzf";;
242 gz) PIPE_CMD="tar -xvzf";;
243 *) eerror "Unrecognized tarball compression"
244 die "Unrecognized tarball compression";;
245 esac
246
247 ${PIPE_CMD} ${i} -C ${KPATCH_DIR} 1>/dev/null
248 if [ $? == 0 ]
249 then
250 einfo "${i/*\//} unpacked"
251 else
252 eerror "Failed to unpack ${i}"
253 die "unable to unpack patch tarball"
254 fi
255
256 UNIPATCH_LIST="${UNIPATCH_LIST/${i}/}"
257 fi
258 done
259
260 #so now everything is unpacked, lets work out whats to be dropped and whats to be included.
261 for i in ${UNIPATCH_LIST}
262 do
263 extention=${i/*./}
264 PIPE_CMD=""
265 case ${extention} in
266 bz2) PIPE_CMD="bzip2 -dc";;
267 patch) PIPE_CMD="cat";;
268 gz|Z|z) PIPE_CMD="gzip -dc";;
269 ZIP|zip) PIPE_CMD="unzip -p";;
270 *) UNIPATCH_EXCLUDE="${UNIPATCH_EXCLUDE} ${i}";;
271 esac
272 [ -n "${PIPE_CMD}" ] && ${PIPE_CMD} ${i} > ${KPATCH_DIR}/${i/*\//}.patch
273 done
274
275 #populate KPATCH_DIRS so we know where to look to remove the excludes
276 x=${KPATCH_DIR}
277 KPATCH_DIR=""
278 for i in $(find ${x} -type d)
279 do
280 KPATCH_DIR="${KPATCH_DIR} ${i}"
281 done
282
283 #so now lets get rid of the patchno's we want to exclude
284 for i in ${UNIPATCH_EXCLUDE}
285 do
286 for x in ${KPATCH_DIR}
287 do
288 rm ${x}/${i}_* 2>/dev/null
289 if [ $? == 0 ]
290 then
291 einfo "Excluding Patch #${i}"
292 einfo "From: ${x/${WORKDIR}/}"
293 fi
294 done
295 done
296
297 # and now, finally, we patch it :)
298 for x in ${KPATCH_DIR}
299 do
300 for i in $(find ${x} -maxdepth 1 -iname "*.patch" | sort -u)
301 do
302
303
304 PATCH_DEPTH=0
305 ebegin "Applying ${i/*\//}"
306 while [ ${PATCH_DEPTH} -lt 5 ]
307 do
308 if (patch -p${PATCH_DEPTH} --dry-run -f < ${i} >/dev/null)
309 then
310 $(patch -p${PATCH_DEPTH} -f < ${i} >/dev/null)
311 if [ "$?" -eq 0 ]
312 then
313 eend 0
314 break
315 else
316 eend 1
317 eerror "Failed to apply patch ${i/*\//}"
318 die "Failed to apply ${i/*\//}"
319 fi
320 else
321 PATCH_DEPTH=$((${PATCH_DEPTH} + 1))
322 fi
323 done
324 if [ ${PATCH_DEPTH} -eq 5 ]
325 then
326 eend 1
327 die "Unable to dry-run patch."
328 fi
329
330
331 done
332 done
333 }
334
335 # custom functions
336 #==============================================================
337 detect_version() {
338 # this function will detect and set
339 # - OKV: Original Kernel Version (2.6.0/2.6.0-test11)
340 # - KV: Kernel Version (2.6.0-gentoo/2.6.0-test11-gentoo-r1)
341 # - EXTRAVERSION: The additional version appended to OKV (-gentoo/-gentoo-r1)
342
343 OKV=${PV/_beta/-test}
344 OKV=${OKV/_rc/-rc}
345 OKV=${OKV/_pre*/}
346 OKV=${OKV/-r*/}
347
348 KV_MAJOR=$(echo ${OKV} | cut -d. -f1)
349 KV_MINOR=$(echo ${OKV} | cut -d. -f2)
350 KV_PATCH=$(echo ${OKV} | cut -d. -f3)
351 KV_PATCH=${KV_PATCH/[-_]*/}
352
353 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
354
355 RELEASE=${PV/${OKV}/}
356 RELEASE=${RELEASE/_beta/}
357 RELEASE=${RELEASE/_rc/-rc}
358 RELEASE=${RELEASE/_pre/-bk}
359 RELEASETYPE=${RELEASE//[0-9]/}
360
361 EXTRAVERSION="${RELEASE}"
362 [ -z "${K_NOUSENAME}" ] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*/}"
363 [ ! "${PR}" == "r0" ] && EXTRAVERSION="${EXTRAVERSION}-${PR}"
364
365 KV=${OKV}${EXTRAVERSION}
366
367 # -rcXX-bkXX pulls are *IMPOSSIBLE* to support within the portage naming convention
368 # these cannot be supported, but the code here can handle it up until this point
369 # and theoretically thereafter.
370
371 if [ "${RELEASETYPE}" == "-rc" ]
372 then
373 OKV="${KV_MAJOR}.${KV_MINOR}.$([ $((${KV_PATCH} - 1)) -lt 0 ] && echo ${KV_PATCH} || echo $((${KV_PATCH} - 1)))"
374 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/testing/patch-${PV//_/-}.bz2
375 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
376 UNIPATCH_LIST="${DISTDIR}/patch-${PV//_/-}.bz2 ${UNIPATCH_LIST}"
377 KV=${PV/[-_]*/}${EXTRAVERSION}
378 fi
379
380 if [ "${RELEASETYPE}" == "-bk" ]
381 then
382 OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
383 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2
384 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
385 UNIPATCH_LIST="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 ${UNIPATCH_LIST}"
386 KV=${PV/[-_]*/}${EXTRAVERSION}
387 fi
388
389 if [ "${RELEASETYPE}" == "-rc-bk" ]
390 then
391 OKV="${KV_MAJOR}.${KV_MINOR}.$((${KV_PATCH} - 1))-${RELEASE/-bk*}"
392 EXTRAVERSION="$([ -n "${RELEASE}" ] && echo ${RELEASE/*-bk/-bk})$([ -n "${K_USENAME}" ] && echo -${PN/-*/})$([ ! "${PR}" == "r0" ] && echo -${PR})"
393
394 KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/snapshots/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2
395 mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
396 UNIPATCH_LIST="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2 ${UNIPATCH_LIST}"
397 KV=${PV/[-_]*/}${EXTRAVERSION}
398 fi
399
400 S=${WORKDIR}/linux-${KV}
401 }
402
403
404 # common functions
405 #==============================================================
406 src_unpack() {
407 [ -z "${OKV}" ] && OKV="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
408
409 cd ${WORKDIR}
410 unpack linux-${OKV}.tar.bz2
411 if [ "${OKV}" != "${KV}" ]
412 then
413 mv linux-${OKV} linux-${KV} || die "Unable to move source tree to ${KV}."
414 fi
415 cd ${S}
416
417 universal_unpack
418 [ -n "${UNIPATCH_LIST}" ] && unipatch ${UNIPATCH_LIST}
419 [ -z "${K_NOSETEXTRAVERSION}" ] && unpack_set_extraversion
420
421 [ $(kernel_is_2_4) $? == 0 ] && unpack_2_4
422 }
423
424 src_compile() {
425 [ "${ETYPE}" == "headers" ] && compile_headers
426 }
427
428 pkg_preinst() {
429 [ "${ETYPE}" == "headers" ] && preinst_headers
430 }
431
432 src_install() {
433 install_universal
434 [ "${ETYPE}" == "headers" ] && install_headers
435 [ "${ETYPE}" == "sources" ] && install_sources
436 }
437
438 pkg_postinst() {
439 [ "${ETYPE}" == "sources" ] && postinst_sources
440 }

  ViewVC Help
Powered by ViewVC 1.1.20