Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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