Magellan Linux

Annotation of /smage/trunk/include/kernel.sminc

Parent Directory Parent Directory | Revision Log Revision Log


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