aboutsummaryrefslogtreecommitdiffstats
path: root/mandriva/kheader
blob: d237fe20aa98e943e9c70a18212318679a078258 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/sh
# (c) Mandriva, Chmouel Boudjnah <chmouel@mandriva.com>
# 	$Id$	
#
# kheader: This shell script regenerate the /boot/kernel.h header for \
#	   /usr/src/linux/include/{autoconf,version}.h
#
# chkconfig: 235 95 20
# description: This shell script regenerate the /boot/kernel.h header for \
#	   /usr/src/linux/include/{autoconf,version}.h
#

. /etc/rc.d/init.d/functions

: ${KERNEL_H:=/boot/kernel.h}
: ${HEADERFILE:=${KERNEL_H}-`uname -r`}
[ -d $(dirname $HEADERFILE) ] || exit 0

table() {
k=$(uname -r|sed 's/.*mdk//')
case $k in
	fb)
	    ENT=0;FB=1;SMP=0;SECURE=0;STD=0;
	;;
	smp)
	    ENT=0;FB=0;SMP=1;SECURE=0;STD=0;   
	;;
	enterprise)
	    ENT=1;FB=0;SMP=0;SECURE=0;STD=0;   
	;;
	secure)
	    ENT=0;FB=0;SMP=0;SECURE=1;STD=0;   
	;;
	*)
	    ENT=0;FB=0;SMP=0;SECURE=0;STD=1;   
	esac
}

generate () {
    table;
    # do not overwrite exsisting header, it confuses
    # kernel make and forces it to recompile everything
    cat > $HEADERFILE.tmp << EOF
/* This file is automatically generated at boot time. */
#ifndef __BOOT_KERNEL_H_
#define __BOOT_KERNEL_H_

#ifndef __BOOT_KERNEL_SMP
#define __BOOT_KERNEL_SMP $SMP
#endif

#ifndef __BOOT_KERNEL_FB
#define __BOOT_KERNEL_FB $FB
#endif

#ifndef __BOOT_KERNEL_SECURE
#define __BOOT_KERNEL_SECURE $SECURE
#endif

#ifndef __BOOT_KERNEL_ENTERPRISE
#define __BOOT_KERNEL_ENTERPRISE $ENT
#endif

#ifndef __BOOT_KERNEL_UP
#define __BOOT_KERNEL_UP $STD
#endif

#endif
EOF

cmp -s $HEADERFILE $HEADERFILE.tmp || mv -f $HEADERFILE.tmp $HEADERFILE
rm -f $HEADERFILE.tmp

if [ -f $KERNEL_H ] ; then
    rm -f $KERNEL_H
fi

ln -sf $HEADERFILE $KERNEL_H
}

function remove_orphaned {
    local version= i=
    for i in /boot/kernel.h-* /boot/System.map-* /boot/config-*; do
	version=${i#*-}
	[[ -f /boot/vmlinuz-${version} ]] || rm -f ${i}
    done
}

case $1 in 
    start)
    # We don't log this command, because most users don't want to hear this (c) Chmou
	generate
	touch /var/lock/subsys/kheader
	;;
    restart)
	;;
    reload)
	generate
	;;
    stop)
	remove_orphaned;
	rm -f /var/lock/subsys/kheader
	;;
    status)
	;;
    *)
    gprintf "Usage: %s\n" "$(basename $0) {start|stop|reload|restart}"
    exit 0
    ;;
esac