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