#!/bin/sh

[ -z $PREPKG ] && exit 1

PACKAGE=ndiswrapper
VERSION=1.55
KERNEL=$(uname -r | sed 's,-smp,,')
FILES=$(cd $(dirname $0) ; pwd)

# notes:
# - single build for both uni/smp modules. this absolutely requires
#   hackage to /usr/src/linux-*. some day I'll document said hackage

mkdir -p $PREPKG/{install,etc/$PACKAGE,usr/doc/$PACKAGE-$VERSION}/

chown -R root:root .
make $MAKEJOBS KVERS=$KERNEL &> make.output || exit 1
make DESTDIR=$PREPKG KVERS=$KERNEL install &> make_install.output || exit 1
make -C driver clean &> make_clean.output || exit 1
make $MAKEJOBS KVERS=$KERNEL-smp -C driver &> make-smp.output || exit 1
make DESTDIR=$PREPKG KVERS=$KERNEL-smp -C driver install \
  &> make_install-smp.output || exit 1

# tidy up
rm -f $PREPKG/lib/modules/*/modules.*

cp -p AUTHORS ChangeLog INSTALL README \
  $PREPKG/usr/doc/$PACKAGE-$VERSION/
gzip -r9 $PREPKG/usr/man/

cp $FILES/{doinst.sh,slack-desc} $PREPKG/install/
sed -i "s,@KERNEL@,$KERNEL,g" $PREPKG/install/doinst.sh

find $PREPKG -exec file {} \; \
  | awk -F : '/ ELF / {print $1}' \
  | xargs strip -p --strip-unneeded
