Magellan Linux

Contents of /smage/branches/alx07x-unstable/include/kernel.sminc

Parent Directory Parent Directory | Revision Log Revision Log


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