#!/bin/sh
# (c) MandrakeSoft, Chmouel Boudjnah <chmouel@mandrakesoft.com>
# 	$Id: kheader,v 1.2 2000/08/28 14:32:58 flepied Exp $	
#
# kheader: This shell script regenerate the /boot/kernel.h header for
#	   /usr/include/linux/{autoconf,version}.h
#
# chkconfig: 235 95 20
# description: This shell script regenerate the /boot/kernel.h header for
#	   /usr/include/linux/{autoconf,version}.h
#

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

: ${HEADERFILE:=/boot/kernel.h}
[ -d $(dirname $HEADERFILE) ] || exit 0
uname -r|grep -q mdk || exit 0 # we assume if it is not a mdk kernel all
		               # the links in /usr/src/linux are ok

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

generate () {
    table;
    cat > $HEADERFILE << 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_LINUS
#define __BOOT_KERNEL_LINUS $LINUS
#endif

#ifndef __BOOT_KERNEL_UP
#define __BOOT_KERNEL_UP $STD
#endif

#endif
EOF
}

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
    ;;
    stop)
    rm -f /var/lock/subsys/kheader
    ;;
    status)
    ;;
    *)
    echo "Usage: $(basename $0) start"
    exit 0
    ;;
esac
