Magellan Linux

Annotation of /smage/branches/alx-0_6_0/include/kernel26.sminc

Parent Directory Parent Directory | Revision Log Revision Log


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