#!/bin/bash

####################################################
# Script : kernel-sourcepackage.SlackBuild
# Purpose: Build a source package of the 2.6 Kernel
# Author : Stuart Winter <mozes@armedslack.org>
# Date...: 27-May-2006
####################################################

source /usr/share/slackdev/buildkit.sh

# Package information:
export PKGNAM=kernel-source
export VERSION=${VERSION:-2.6.30.5}
# The architecture name component of the .tgz package file name:
export PKGARCH=${PKGARCH:-noarch}
export BUILD=${BUILD:-1}
export PKGSERIES=${PKGSERIES:-k}
export SLACKPACKAGE=$PKGNAM-$VERSION-$PKGARCH-$BUILD.tgz

## ******************************************************************* ##
# For test packages - best to store in another location rather than
# overwriting the working copy in the main tree:
# export PKGSTORE=/tmp/
# mkdir -vpm755 $PKGSTORE/$PKGSERIES
## ******************************************************************* ##

CWD=$PWD
TMP=/tmp/package-kernel-source
rm -rf $TMP
mkdir -pm755 $TMP/usr/src

echo "Building source package..."

# Extract the virgin 2.6 kernel source:
cd $TMP/usr/src
tar xf $CWD/sources/linux-2.6/linux-$VERSION.tar.*
ln -vfs linux-* linux

# Configure the Kernel.  We do this so that we can build stuff like lm_sensors
# on a freshly fully installed ARM versatile system.
# We use the Versatile config file because it has I2C support which lm_sensors
# needs.
cd linux
rm -f include/linux/autoconf.h
touch include/linux/autoconf.h
#cp -fav armedslack/configs/*versatile* .config
# Eventually this will change -- I've specified a specific versatile config
# since I have two configs - one for the ARMv3 arch and the other for the armv5
# using EABI.
install -vpm644 $CWD/configs/config-versatile-linux-2.6 .config
make oldconfig
make clean
rm -f .version
find . -name '.gitignore' -print0 | xargs -0 rm -f

# We put patches and config files into an 'armedslack' 
# directory.  This way users can have one source package and
# easily find the Kernel config and patches used.
mkdir -vpm755 armedslack
cp -favv $CWD/configs/config-* armedslack/
cp -favv $CWD/sources/linux-2.6/patches armedslack/

# Install package description.  This modified from the Slackware version
# because we need to mention the additional 'armedslack' directory.
cd $TMP
mkdir -vm755 install
install -vpm644 $CWD/slack-descs/kernel-source install/slack-desc

start_fakeroot
chown -R root:root .
chmod -R og-w .

# Replace version number with a _ so it doesn't get confused with
# the package name.
# This is incase we're using any '-rc' releases.
export VERSION="$( echo $VERSION | sed 's?-??g' )"
export SLACKPACKAGE=$PKGNAM-$VERSION-$PKGARCH-$BUILD.tgz

slackmp # run makepkg
