Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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