#!/bin/sh
VER=`uname -r | cut -d. -f1,2`
KVER=`uname -r`
GCCVER=`cat /proc/version|awk '{print $7}'|cut -d. -f 1` 
if [ $GCCVER == "3" ]; then
GCCVER=`cat /proc/version|awk '{print $7}'|cut -d. -f 1,2` 
fi

if [ $VER == "2.4" ]; then
	cp Makefile.2.4 Makefile
	if [ -f precompiled/rockey-$KVER.o ]; then
		cp precompiled/rockey-$KVER.o rockey.o
		echo compiled finished!
	else
		if [ -d /lib/modules/`uname -r`/build/include/linux ]; then
			make clean
			make GCCVERSION=$GCCVER
			echo compiled finished!
		else
			echo Please install kernel source!
		fi
	fi
fi

if [ $VER == "2.6" ]; then
	cp Makefile.2.6 Makefile
	if [ -f precompiled/rockey-$KVER.ko ]; then
		cp precompiled/rockey-$KVER.ko rockey.ko
		echo compiled finished!
	else
		if [ -d /lib/modules/`uname -r`/build/include/linux ]; then
			make clean
			make GCCVERSION=$GCCVER	
			echo compiled finished!
		else
			echo Please install kernel source!
		fi
	fi
fi
