#!/bin/sh

# Copyright 2010  Marco Bonetti, Piacenza, IT
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


CWD=$(pwd)
TMP=${TMP:-/tmp}
PKG=$TMP/package-kernel-headers

VERSION=${VERSION:-2.6.33.4}
ARCH=${ARCH:-powerpc}
BUILD=${BUILD:-1}

# /usr/include/drm overlaps between this package and libdrm, however
# Slackware[64] follow this behaviour too, I think it's not that bad ;-)
# - sid77
HEADERS="asm-generic drm linux mtd rdma sound video"

rm -rf $PKG
mkdir -p $TMP $PKG
echo "Using /usr/src/linux-${VERSION}/"
echo "Make sure this is *ready*..."
mkdir -p $PKG/usr/include

( cd $PKG/usr/include
  # Copy generic headers
  for HEADER in $HEADERS; do
    cp -rv /usr/src/linux-${VERSION}/include/$HEADER .
  done
  # Copy platform specific headers
  cp -rv /usr/src/linux-${VERSION}/arch/powerpc/include/asm asm-powerpc
  ln -sf asm-powerpc asm
  # Kbuild cleanup
  find . -type f -name '*Kbuild' -delete
  find . -type f -name '*Kbuild.asm' -delete
)

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $TMP/kernel-headers-${VERSION}-${ARCH}-${BUILD}.txz

