#!/bin/bash

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

source /usr/share/slackdev/buildkit.sh

# Package information:
export PKGNAM=kernel-source
# If it's an -rc release, remove the hyphen and rename
# the source archive.  It makes packaging and scripting all play happily.
#export VERSION=${VERSION:-2.6.34rc7}
export VERSION=${VERSION:-2.6.33.5}
# The architecture name component of the .tgz package file name:
# This used to be "noarch" but it's a package of the kernel source tree that
# has been compiled for ARM, so I believe it should be tagged by architecture.
export PKGARCH=${PKGARCH:-arm}
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 previously compiled "kirkwood" kernel source.
# We use the "kirkwood" kernels because they're (at the time of writing - May 2010)
# are the most widely used hardware platform for Slackware ARM.
cd $TMP/usr/src
tar xf $CWD/compiled-sources/kirkwood-kernel-$VERSION-compiled.tar.*
# Ensure that the linux dir name matches the $VERSION of the package so that
# in the a/kernel-modules package, the /lib/modules/*/{build,source} 
# symlinks are correct.  
mv -fv linux-* linux-$VERSION
ln -vfs linux-$VERSION linux
cd linux || exit 1

# Prepare:
make clean
make prepare
#rm -fv .version
find . -name '.gitignore' -print0 | xargs -0 rm -f

# 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
