#!/bin/sh
# AUTHOR: D-Link
# MODIFIED BY: Uli Wolf <ffp@wolf-u.li> (http://wolf-u.li / http://nas-tweaks.net)

# This was tested on the DNS-320/DNS-325-package from
#  ftp://ftp.dlink.de/dns/dns-320/driver_software/DNS-320_GPL_code_revA.tgz

if [ ! -d "arm-none-linux-gnueabi-6xxx" ]; then
	# directory did not exists unpack it
	echo "Extracting arm-none-linux-gnueabi-6xxx.tgz..."
	tar zxf arm-none-linux-gnueabi-6xxx.tgz
	echo "done."
fi

export WORKDIR=$(pwd)
export PATH=${WORKDIR}/arm-none-linux-gnueabi-6xxx/bin:$PATH
export CC=arm-none-linux-gnueabi-gcc
export CROSS_COMPILE=arm-none-linux-gnueabi-
export CXX=${CROSS_COMPILE}g++
export RANLIB=arm-none-linux-gnueabi-ranlib
export LD=arm-none-linux-gnueabi-ld
export STRIP=arm-none-linux-gnueabi-strip
env|sort

# Unpack Ramdisk if not existant
if [ ! -d "ramdisk" ]; then
	echo "Extracting ramdisk.tgz..."
	tar xzf ramdisk.tgz
	echo "done."
fi
PATH=${WORKDIR}/ramdisk:$PATH

# Extract kernel if not existant
if [ ! -d "linux-2.6.22.18" ]; then
	echo "Extracting kernel..."
	tar xzf linux-2.6.22.18.tgz
	echo "done."
fi

# Configure Kernel
cd ./linux-2.6.22.18
sh cv.sh
# Clean up
make clean

# Menubased configuration
make menuconfig
# Make Kernel
#make
# Make Kernelmodules
make modules
# Make uImage
#make uImage

cd ../

