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

Contents of /eclass/kernel-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Sat Jan 17 00:08:12 2004 UTC (15 years, 5 months ago) by johnm
Branch: MAIN
Changes since 1.8: +1 -1 lines
updated to force the check for the existance of . in tarball grep. solves bug #38410

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

  ViewVC Help
Powered by ViewVC 1.1.20