Contents of /smage/trunk/include/kernel.sminc
Parent Directory | Revision Log
Revision 2938 -
(show annotations)
(download)
Tue Sep 6 18:52:10 2011 UTC (13 years, 2 months ago) by niro
File size: 10834 byte(s)
Tue Sep 6 18:52:10 2011 UTC (13 years, 2 months ago) by niro
File size: 10834 byte(s)
-honor 3.x naming scheme -use virtual/initscript in dependencies -fixed SRC_URI (kernel26 -> kernel)
1 | # kernel 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 | # 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%%.*}/${SRCFILE} |
31 | mirror://kernel-${BRANCH}/${SRCFILE} |
32 | mirror://kernel-${BRANCH}/config-${PVER}-${BRANCH}-${PBUILD}-i686 |
33 | mirror://kernel-${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 | >= virtual/initscripts"} |
40 | |
41 | : ${PROVIDE="virtual/kernel"} |
42 | |
43 | EXTRAVERSION="${PSUBVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}" |
44 | KERNEL_CONFIG="${SOURCEDIR}/${PNAME}/config-${PVER}-${BRANCH}-${PBUILD}-${ARCH}" |
45 | |
46 | # 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 | kernel_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 | kernel_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 | make ARCH=${ARCH/i*86/x86} oldconfig || die |
77 | |
78 | case ${KERNEL_TYPE} in |
79 | image) |
80 | mmake ARCH=${ARCH/i*86/x86} || die |
81 | ;; |
82 | |
83 | sources) |
84 | make clean || die |
85 | |
86 | # needed to compile other programs like iptables |
87 | make ARCH=${ARCH/i*86/x86} prepare || die |
88 | # needed to cover >=2.6.14 builds |
89 | # but deprecated with >=2.6.21, prepare cover all targets there |
90 | local kver=$(echo ${PVER} | sed "s:\.::g") |
91 | # honor >=3.0.x; add one zero |
92 | if [[ ${PVER%%.*} -gt 2 ]] |
93 | then |
94 | kver="${kver}0" |
95 | fi |
96 | if [[ ${kver} < 2621 ]] |
97 | then |
98 | make ARCH=${ARCH/i*86/x86} prepare-all || die |
99 | fi |
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 | kernel_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 | |
180 | kernel_sources_src_install() |
181 | { |
182 | cd ${BUILDDIR} |
183 | |
184 | echo "Creating linux-${PVER}-${BRANCH}-${PBUILD} sources tarball ... " |
185 | tar cvjf ${BUILDDIR}/linux-${PVER}-${BRANCH}-${PBUILD}.tar.bz2 $(basename ${SRCDIR}) || die |
186 | |
187 | echo "Moving linux-${PVER}-${BRANCH}-${PBUILD} tarball to \${BINDIR}/usr/src ... " |
188 | minstalldir /usr/src || die |
189 | mv ${BUILDDIR}/linux-${PVER}-${BRANCH}-${PBUILD}.tar.bz2 ${BINDIR}/usr/src || die |
190 | } |
191 | |
192 | # installs module-sources path/to/SRCDIR to MODDIR/MODNAME |
193 | # kernel_external_modules_install path/to/SRCDIR DESTDIRNAME |
194 | kernel_external_modules_install() |
195 | { |
196 | cd ${BUILDDIR} |
197 | |
198 | local modsrc="$1" |
199 | local moddest="$2" |
200 | local moddir="${BUILDDIR}/kernel-modules-${PVER}-${BRANCH}-${PBUILD}" |
201 | |
202 | echo "Installing ${modsrc} to ${moddir}/${moddest} ..." |
203 | install -d ${moddir} || die |
204 | mv ${modsrc} ${moddir}/${moddest} || die |
205 | } |
206 | |
207 | kernel_external_modules_tarball() |
208 | { |
209 | cd ${BUILDDIR} |
210 | |
211 | echo "Creating kernel-modules-${PVER}-${BRANCH}-${PBUILD} sources tarball ... " |
212 | tar cvjf ${BUILDDIR}/kernel-modules-${PVER}-${BRANCH}-${PBUILD}.tar.bz2 \ |
213 | kernel-modules-${PVER}-${BRANCH}-${PBUILD} || die |
214 | |
215 | echo "Moving kernel-modules-${PVER}-${BRANCH}-${PBUILD} tarball to \${BINDIR}/usr/src ... " |
216 | minstalldir /usr/src || die |
217 | mv ${BUILDDIR}/kernel-modules-${PVER}-${BRANCH}-${PBUILD}.tar.bz2 ${BINDIR}/usr/src || die |
218 | } |
219 | |
220 | kernel_src_install() |
221 | { |
222 | case ${KERNEL_TYPE} in |
223 | image) |
224 | kernel_image_src_install || die |
225 | ;; |
226 | |
227 | sources) |
228 | kernel_sources_src_install || die |
229 | ;; |
230 | esac |
231 | } |
232 | |
233 | kernel_major_version() |
234 | { |
235 | local ksrc="$@" |
236 | local kv |
237 | |
238 | if [[ -z ${ksrc} ]] |
239 | then |
240 | kv="$(uname -r|cut -d. -f1-2)" |
241 | else |
242 | local version |
243 | local patchlevel |
244 | |
245 | # get version from makefile |
246 | version=$(grep "^VERSION[[:space:]]*=[[:space:]]*[[:digit:]]" ${ksrc}/Makefile | sed "s/^.*=[[:space:]]*\([[:digit:]]\+\)/\1/g") |
247 | # get patchlevel from makefile |
248 | patchlevel=$(grep "^PATCHLEVEL[[:space:]]*=[[:space:]]*[[:digit:]]" ${ksrc}/Makefile | sed "s/^.*=[[:space:]]*\([[:digit:]]\+\)/\1/g") |
249 | # kernelversion |
250 | kv="${version}.${patchlevel}" |
251 | fi |
252 | |
253 | echo "${kv}" |
254 | } |
255 | |
256 | mod_suffix() |
257 | { |
258 | local ksrc="$@" |
259 | local mod_suffix |
260 | local kmv |
261 | |
262 | kmv=$(kernel_major_version ${ksrc}) |
263 | if [[ ${kmv//.} -ge 26 ]] |
264 | then |
265 | mod_suffix="ko" |
266 | else |
267 | mod_suffix="o" |
268 | fi |
269 | |
270 | echo ${mod_suffix} |
271 | } |
272 | |
273 | kernel_image_preinstall() |
274 | { |
275 | if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
276 | then |
277 | mount /boot &> /dev/null |
278 | fi |
279 | } |
280 | |
281 | kernel_image_preremove() |
282 | { |
283 | if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
284 | then |
285 | mount /boot &> /dev/null |
286 | fi |
287 | } |
288 | |
289 | kernel_image_postremove() |
290 | { |
291 | if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
292 | then |
293 | # remove old image entry from grub |
294 | new-kernel-pkg -v --rminitrd --remove ${KPVER}-${KBRANCH}-${KPBUILD} |
295 | fi |
296 | } |
297 | |
298 | kernel_image_postinstall() |
299 | { |
300 | [ ! -d ${MROOT}/sys ] && install -d ${MROOT}/sys |
301 | |
302 | # fixes a small glitch in <=mage-0.3.6-r15 with symlinks |
303 | [ -f ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD} ] && \ |
304 | rm ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD} |
305 | |
306 | [ -x ${MROOT}/sbin/depmod ] && |
307 | ${MROOT}/sbin/depmod -ae \ |
308 | -F /boot/System.map-${KPVER}-${KBRANCH}-${KPBUILD} \ |
309 | ${KPVER}-${KBRANCH}-${KPBUILD} |
310 | |
311 | # do not run this if ${MROOT} is set ! |
312 | if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
313 | then |
314 | new-kernel-pkg -v --mkinitrd --make-default --install ${KPVER}-${KBRANCH}-${KPBUILD} |
315 | fi |
316 | |
317 | # symlink actual kernel to /boot/vmlinuz etc... |
318 | ln -snf kernel-${KPVER}-${KBRANCH}-${KPBUILD} ${MROOT}/boot/vmlinuz |
319 | ln -snf System.map-${KPVER}-${KBRANCH}-${KPBUILD} ${MROOT}/boot/System.map |
320 | ln -snf config-${KPVER}-${KBRANCH}-${KPBUILD} ${MROOT}/boot/config |
321 | [[ -f ${MROOT}/boot/initrd-${KPVER}-${KBRANCH}-${KPBUILD}.img ]] && |
322 | ln -snf initrd-${KPVER}-${KBRANCH}-${KPBUILD}.img ${MROOT}/boot/initrd |
323 | } |
324 | |
325 | kernel_sources_postinstall() |
326 | { |
327 | # check for linux-VERSION/include as the kernel-image installs |
328 | # the file Modules.symver in the linux-VERSION directory |
329 | if [ ! -d ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD}/include ] |
330 | then |
331 | echo "Unpacking linux-${KPVER}-${KBRANCH}-${KPBUILD} source tarball ... " |
332 | tar xvjf ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD}.tar.bz2 -C ${MROOT}/usr/src |
333 | fi |
334 | |
335 | if [ ! -d ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} ] && |
336 | [ -f ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD}.tar.bz2 ] |
337 | then |
338 | echo "Unpacking kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} source tarball ... " |
339 | tar xvjf ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD}.tar.bz2 -C ${MROOT}/usr/src |
340 | fi |
341 | |
342 | # if not exist create linux symlink |
343 | if [ ! -h ${MROOT}/usr/src/linux ] |
344 | then |
345 | echo "Creating linux -> linux-${KPVER}-${KBRANCH}-${KPBUILD} symlink ... " |
346 | [ ! -d ${MROOT}/usr/src ] && install ${MROOT}/usr/src |
347 | ln -snf ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD} \ |
348 | ${MROOT}/usr/src/linux || die |
349 | fi |
350 | |
351 | # if not exist create kernel-modules symlink |
352 | if [ ! -h ${MROOT}/usr/src/kernel-modules ] && |
353 | [ -d ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} ] |
354 | then |
355 | echo "Creating kernel-modules -> kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} symlink ... " |
356 | [ ! -d ${MROOT}/usr/src ] && install ${MROOT}/usr/src |
357 | ln -snf ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} \ |
358 | ${MROOT}/usr/src/kernel-modules || die |
359 | fi |
360 | } |
361 | |
362 | export_inherits kernel src_prepare src_compile src_install |
363 | |
364 | # export pre/postinstall functions depending on KERNEL_TYPE |
365 | case ${KERNEL_TYPE} in |
366 | image) |
367 | export_inherits kernel_image preinstall preremove postinstall postremove |
368 | SPECIAL_FUNCTIONS="${SPECIAL_FUNCTIONS} kernel_image_preinstall kernel_image_preremove kernel_image_postinstall kernel_image_postremove" |
369 | ;; |
370 | sources) |
371 | export_inherits kernel_sources postinstall |
372 | SPECIAL_FUNCTIONS="${SPECIAL_FUNCTIONS} kernel_sources_postinstall" |
373 | ;; |
374 | esac |