Magellan Linux

Annotation of /branches/magellan-next/include/kernel.sminc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9311 - (hide annotations) (download)
Fri Nov 25 22:54:56 2011 UTC (12 years, 11 months ago) by niro
File size: 12198 byte(s)
-added file
1 niro 9311 # kernel global smage functions
2     # $Id$
3    
4     # needed extra vars:
5     # ${KERNEL_TYPE}: needed, 'sources', 'headers' or 'image'
6     # ${BRANCH}: needed, style branch of the kernel
7     # ${KERNEL_CONFIG}: optional, needed if you want to override the default
8     # searchpath ${SOURCEDIR}/${PNAME}/config-${PVER}-${BRANCH}-${PBUILD}
9     #
10     # ${PSUBVER}: optional, only needed for 2.6.x.x naming scheme
11     # ${EXTRAVERSION}: optinal, extra version for the kernel name
12     # default setting is ${PSUBVER}-${BRANCH}-${PBUILD}
13     # ${KERNEL_IMAGE_PATH}: override the default KERNEL_IMAGE_PATH (to build xen images for e.g.)
14    
15     sminclude mtools
16    
17     # remove me when all distris support this:
18     if [[ ${USE_KERNEL_ARCH_EXTENSION} = true ]]
19     then
20     KERNEL_ARCH_EXTENSION="-${ARCH}"
21     else
22     KERNEL_ARCH_EXTENSION=""
23     fi
24    
25     # some sane defaults
26     : ${PCATEGORIE="sys-kernel"}
27     : ${HOMEPAGE="http://magellan-linux.de/"}
28     : ${SRCFILE="linux-${PVER/${PSUBVER}/}.tar.bz2"}
29     : ${SRCDIR="${BUILDDIR}/linux-${PVER}-${BRANCH}-${PBUILD}"}
30    
31     case ${KERNEL_TYPE} in
32     image|sources)
33     if [[ -z ${SRC_URI[*]} ]]
34     then
35     SRC_URI=(
36     http://www.kernel.org/pub/linux/kernel/v$(echo ${PVER} | cut -d. -f1-2)/${SRCFILE}
37     http://ftp.uni-erlangen.de/pub/Linux/MIRROR.kernel/v$(echo ${PVER} | cut -d. -f1-2)/${SRCFILE}
38     mirror://kernel-${BRANCH}/${SRCFILE}
39     mirror://kernel-${BRANCH}/config-${PVER}-${BRANCH}-${PBUILD}-i686
40     mirror://kernel-${BRANCH}/config-${PVER}-${BRANCH}-${PBUILD}-x86_64
41     )
42     fi
43     ;;
44    
45     headers)
46     if [[ -z ${SRC_URI[*]} ]]
47     then
48     SRC_URI=(
49     http://www.kernel.org/pub/linux/kernel/v$(echo ${PVER} | cut -d. -f1-2)/${SRCFILE}
50     http://ftp.uni-erlangen.de/pub/Linux/MIRROR.kernel/v$(echo ${PVER} | cut -d. -f1-2)/${SRCFILE}
51     mirror://kernel-${BRANCH}/${SRCFILE}
52     )
53     fi
54     ;;
55     esac
56    
57     case ${KERNEL_TYPE} in
58     image)
59     : ${PROVIDE="virtual/kernel"}
60     : ${DEPEND=">= sys-apps/module-init-tools-3.2
61     >= sys-fs/udev-115
62     >= sys-apps/mkinitrd-5.0.8
63     >= virtual/initscripts"}
64     : ${DESCRIPTION="Kernel image of the '${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}' kernel."}
65     ;;
66    
67     sources)
68     : ${PROVIDE="virtual/kernel-sources"}
69     : ${DESCRIPTION="Kernel sources of the '${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}' kernel."}
70     ;;
71    
72     headers)
73     : ${PROVIDE="virtual/kernel-headers"}
74     : ${DESCRIPTION="Sanitized kernel headers for libc."}
75     ;;
76     esac
77    
78     EXTRAVERSION="${PSUBVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}"
79     KERNEL_CONFIG="${SOURCEDIR}/${PNAME}/config-${PVER}-${BRANCH}-${PBUILD}-${ARCH}"
80    
81     # special vars for mage file only
82     KPVER="${PVER}"
83     KPBUILD="${PBUILD}"
84     KBRANCH="${BRANCH}"
85     SPECIAL_VARS="${SPECIAL_VARS} KPVER KPBUILD KBRANCH"
86    
87     kernel_src_prepare()
88     {
89     munpack ${SRCFILE} || die
90     mv ${BUILDDIR}/linux-${PVER/${PSUBVER}/} ${SRCDIR} || die
91    
92     # fix permissions
93     chown -R 0:0 ${SRCDIR} || die
94     chmod -R a+r-w+X,u+w ${SRCDIR} || die
95    
96     cd ${SRCDIR}
97    
98     # fixes INSTALL_PATH to /boot and EXTRAVERSION
99     sed -i -e 's:#export\tINSTALL_PATH:export\tINSTALL_PATH:' \
100     -e "s:^\(EXTRAVERSION =\).*:\1 ${EXTRAVERSION}:" Makefile || die
101     }
102    
103     kernel_src_compile()
104     {
105     cd ${SRCDIR}
106    
107     make mrproper || die
108    
109     if [[ ${KERNEL_TYPE} = sources ]] || [[ ${KERNEL_TYPE} = image ]]
110     then
111     # inject our kernel config
112     cp ${KERNEL_CONFIG} ${SRCDIR}/.config || die
113     make ARCH=${ARCH/i*86/x86} oldconfig || die
114     fi
115    
116     case ${KERNEL_TYPE} in
117     image)
118     mmake ARCH=${ARCH/i*86/x86} || die
119     ;;
120    
121     headers)
122     make ARCH=${ARCH/i*86/x86} headers_check || die
123     ;;
124    
125     sources)
126     make clean || die
127    
128     # needed to compile other programs like iptables
129     make ARCH=${ARCH/i*86/x86} prepare || die
130     # needed to cover >=2.6.14 builds
131     # but deprecated with >=2.6.21, prepare cover all targets there
132     local kver=$(echo ${PVER} | sed "s:\.::g")
133     # honor >=3.0.x; add one zero
134     if [[ ${PVER%%.*} -gt 2 ]]
135     then
136     kver="${kver}0"
137     fi
138     if [[ ${kver} < 2621 ]]
139     then
140     make ARCH=${ARCH/i*86/x86} prepare-all || die
141     fi
142     make ARCH=${ARCH/i*86/x86} scripts || die
143    
144     # at least alsa-drivers needs this one ...
145     touch include/linux/autoconf.h || die
146     ;;
147     esac
148     }
149    
150     kernel_image_src_install()
151     {
152     cd ${SRCDIR}
153    
154     # needed directories
155     minstalldir /boot || die
156    
157     # install modules
158     make ARCH=${ARCH/i*86/x86} INSTALL_MOD_PATH=${BINDIR} modules_install || die
159    
160     # install kernelimage
161     if [[ -z ${KERNEL_IMAGE_PATH} ]]
162     then
163     local my_arch="${ARCH}"
164     [[ ${my_arch} = i*86 ]] && my_arch=i386
165     minstallfile arch/${my_arch}/boot/bzImage \
166     /boot/kernel-${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION} \
167     || die
168     else
169     minstallfile ${KERNEL_IMAGE_PATH} \
170     /boot/kernel-${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION} \
171     || die
172     fi
173    
174     # install System.map
175     minstallfile System.map \
176     /boot/System.map-${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION} \
177     || die
178    
179     # install Module.symvers in boot and /usr/src
180     minstallfile Module.symvers \
181     /boot/Module.symvers-${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION} \
182     || die
183     minstalldir /usr/src/linux-${PVER}-${BRANCH}-${PBUILD} || die
184     minstallfile Module.symvers \
185     /usr/src/linux-${PVER}-${BRANCH}-${PBUILD} \
186     || die
187    
188     # install kernel description
189     echo "
190     KRNVER=${BRANCH}-${PVER}-${ARCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}
191     KRNLIB=${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}
192     KRNIMG=kernel-${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}
193     KRNINITRD=
194     " > ${BINDIR}/boot/kernelversion || die
195    
196     # install kernel-config from srcdir
197     minstallfile .config \
198     /boot/config-${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION} \
199     || die
200    
201     # fix build symlink
202     if [ -L ${BINDIR}/lib/modules/${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}/build ]
203     then
204     echo "fixing build symlink"
205     rm ${BINDIR}/lib/modules/${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}/build || die
206     mlink /usr/src/linux-${PVER}-${BRANCH}-${PBUILD} \
207     /lib/modules/${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}/build \
208     || die
209     fi
210    
211     # and fixing source symlink
212     if [ -L ${BINDIR}/lib/modules/${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}/source ]
213     then
214     echo "fixing source symlink"
215     rm ${BINDIR}/lib/modules/${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}/source || die
216     mlink /usr/src/linux-${PVER}-${BRANCH}-${PBUILD} \
217     /lib/modules/${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}/source \
218     || die
219     fi
220     }
221    
222     kernel_headers_src_install()
223     {
224     cd ${SRCDIR}
225     make ARCH=${ARCH/i*86/x86} INSTALL_HDR_PATH=${BINDIR}/usr headers_install || die
226     }
227    
228     kernel_sources_src_install()
229     {
230     cd ${BUILDDIR}
231    
232     echo "Creating linux-${PVER}-${BRANCH}-${PBUILD} sources tarball ... "
233     tar cvjf ${BUILDDIR}/linux-${PVER}-${BRANCH}-${PBUILD}.tar.bz2 $(basename ${SRCDIR}) || die
234    
235     echo "Moving linux-${PVER}-${BRANCH}-${PBUILD} tarball to \${BINDIR}/usr/src ... "
236     minstalldir /usr/src || die
237     mv ${BUILDDIR}/linux-${PVER}-${BRANCH}-${PBUILD}.tar.bz2 ${BINDIR}/usr/src || die
238     }
239    
240     # installs module-sources path/to/SRCDIR to MODDIR/MODNAME
241     # kernel_external_modules_install path/to/SRCDIR DESTDIRNAME
242     kernel_external_modules_install()
243     {
244     cd ${BUILDDIR}
245    
246     local modsrc="$1"
247     local moddest="$2"
248     local moddir="${BUILDDIR}/kernel-modules-${PVER}-${BRANCH}-${PBUILD}"
249    
250     echo "Installing ${modsrc} to ${moddir}/${moddest} ..."
251     install -d ${moddir} || die
252     mv ${modsrc} ${moddir}/${moddest} || die
253     }
254    
255     kernel_external_modules_tarball()
256     {
257     cd ${BUILDDIR}
258    
259     echo "Creating kernel-modules-${PVER}-${BRANCH}-${PBUILD} sources tarball ... "
260     tar cvjf ${BUILDDIR}/kernel-modules-${PVER}-${BRANCH}-${PBUILD}.tar.bz2 \
261     kernel-modules-${PVER}-${BRANCH}-${PBUILD} || die
262    
263     echo "Moving kernel-modules-${PVER}-${BRANCH}-${PBUILD} tarball to \${BINDIR}/usr/src ... "
264     minstalldir /usr/src || die
265     mv ${BUILDDIR}/kernel-modules-${PVER}-${BRANCH}-${PBUILD}.tar.bz2 ${BINDIR}/usr/src || die
266     }
267    
268     kernel_src_install()
269     {
270     case ${KERNEL_TYPE} in
271     image)
272     kernel_image_src_install || die
273     ;;
274    
275     headers)
276     kernel_headers_src_install || die
277     ;;
278    
279     sources)
280     kernel_sources_src_install || die
281     ;;
282     esac
283     }
284    
285     kernel_major_version()
286     {
287     local ksrc="$@"
288     local kv
289    
290     if [[ -z ${ksrc} ]]
291     then
292     kv="$(uname -r|cut -d. -f1-2)"
293     else
294     local version
295     local patchlevel
296    
297     # get version from makefile
298     version=$(grep "^VERSION[[:space:]]*=[[:space:]]*[[:digit:]]" ${ksrc}/Makefile | sed "s/^.*=[[:space:]]*\([[:digit:]]\+\)/\1/g")
299     # get patchlevel from makefile
300     patchlevel=$(grep "^PATCHLEVEL[[:space:]]*=[[:space:]]*[[:digit:]]" ${ksrc}/Makefile | sed "s/^.*=[[:space:]]*\([[:digit:]]\+\)/\1/g")
301     # kernelversion
302     kv="${version}.${patchlevel}"
303     fi
304    
305     echo "${kv}"
306     }
307    
308     mod_suffix()
309     {
310     local ksrc="$@"
311     local mod_suffix
312     local kmv
313    
314     kmv=$(kernel_major_version ${ksrc})
315     if [[ ${kmv//.} -ge 26 ]]
316     then
317     mod_suffix="ko"
318     else
319     mod_suffix="o"
320     fi
321    
322     echo ${mod_suffix}
323     }
324    
325     kernel_image_preinstall()
326     {
327     if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
328     then
329     mount /boot &> /dev/null
330     fi
331     }
332    
333     kernel_image_preremove()
334     {
335     if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
336     then
337     mount /boot &> /dev/null
338     fi
339     }
340    
341     kernel_image_postremove()
342     {
343     if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
344     then
345     # remove old image entry from grub
346     new-kernel-pkg -v --rminitrd --remove ${KPVER}-${KBRANCH}-${KPBUILD}
347     fi
348     }
349    
350     kernel_image_postinstall()
351     {
352     [ ! -d ${MROOT}/sys ] && install -d ${MROOT}/sys
353    
354     # fixes a small glitch in <=mage-0.3.6-r15 with symlinks
355     [ -f ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD} ] && \
356     rm ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD}
357    
358     [ -x ${MROOT}/sbin/depmod ] &&
359     ${MROOT}/sbin/depmod -ae \
360     -F /boot/System.map-${KPVER}-${KBRANCH}-${KPBUILD} \
361     ${KPVER}-${KBRANCH}-${KPBUILD}
362    
363     # do not run this if ${MROOT} is set !
364     if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
365     then
366     new-kernel-pkg -v --mkinitrd --make-default --install ${KPVER}-${KBRANCH}-${KPBUILD}
367     fi
368    
369     # symlink actual kernel to /boot/vmlinuz etc...
370     ln -snf kernel-${KPVER}-${KBRANCH}-${KPBUILD} ${MROOT}/boot/vmlinuz
371     ln -snf System.map-${KPVER}-${KBRANCH}-${KPBUILD} ${MROOT}/boot/System.map
372     ln -snf config-${KPVER}-${KBRANCH}-${KPBUILD} ${MROOT}/boot/config
373     [[ -f ${MROOT}/boot/initrd-${KPVER}-${KBRANCH}-${KPBUILD}.img ]] &&
374     ln -snf initrd-${KPVER}-${KBRANCH}-${KPBUILD}.img ${MROOT}/boot/initrd
375     }
376    
377     kernel_sources_postinstall()
378     {
379     # check for linux-VERSION/include as the kernel-image installs
380     # the file Modules.symver in the linux-VERSION directory
381     if [ ! -d ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD}/include ]
382     then
383     echo "Unpacking linux-${KPVER}-${KBRANCH}-${KPBUILD} source tarball ... "
384     tar xvjf ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD}.tar.bz2 -C ${MROOT}/usr/src
385     fi
386    
387     if [ ! -d ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} ] &&
388     [ -f ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD}.tar.bz2 ]
389     then
390     echo "Unpacking kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} source tarball ... "
391     tar xvjf ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD}.tar.bz2 -C ${MROOT}/usr/src
392     fi
393    
394     # if not exist create linux symlink
395     if [ ! -h ${MROOT}/usr/src/linux ]
396     then
397     echo "Creating linux -> linux-${KPVER}-${KBRANCH}-${KPBUILD} symlink ... "
398     [ ! -d ${MROOT}/usr/src ] && install ${MROOT}/usr/src
399     ln -snf ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD} \
400     ${MROOT}/usr/src/linux || die
401     fi
402    
403     # if not exist create kernel-modules symlink
404     if [ ! -h ${MROOT}/usr/src/kernel-modules ] &&
405     [ -d ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} ]
406     then
407     echo "Creating kernel-modules -> kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} symlink ... "
408     [ ! -d ${MROOT}/usr/src ] && install ${MROOT}/usr/src
409     ln -snf ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} \
410     ${MROOT}/usr/src/kernel-modules || die
411     fi
412     }
413    
414     export_inherits kernel src_prepare src_compile src_install
415    
416     # export pre/postinstall functions depending on KERNEL_TYPE
417     case ${KERNEL_TYPE} in
418     image)
419     export_inherits kernel_image preinstall preremove postinstall postremove
420     SPECIAL_FUNCTIONS="${SPECIAL_FUNCTIONS} kernel_image_preinstall kernel_image_preremove kernel_image_postinstall kernel_image_postremove"
421     ;;
422     sources)
423     export_inherits kernel_sources postinstall
424     SPECIAL_FUNCTIONS="${SPECIAL_FUNCTIONS} kernel_sources_postinstall"
425     ;;
426     esac