#!/bin/sh

APP=kernel
VERSION=5.4.41
BUILD=1sml

. ${BUILDVARS:-/etc/buildvars}

if [ "$ARCH" != "x86_64" ] ; then
	echo "$APP not being built for $ARCH" 
	exit 0
fi

if ! [ -d "/share/linux-$VERSION" ] ; then
	echo "Kernel source not found in /share! " 
	echo "Aborting!"
	exit 1
fi

prepdirs
rm -rf $APP-$VERSION

cd /share/linux-$VERSION
if ! [ -e .config ] ; then
	echo "Kernel configuration file .config not found!"
	echo "Aborting!" 
	exit 1
fi

make clean
make oldconfig

make
make modules 
make prepare 

make INSTALL_MOD_PATH=$PKG modules_install

mkdir -p $PKG/boot
  cp arch/x86/boot/bzImage "$PKG/boot/vmlinuz-$VERSION"
  cp System.map "$PKG/boot/System.map-$VERSION"
  cp "/share/linux-$VERSION/.config" "$PKG/boot/config-$VERSION"

 ( cd $PKG/boot ; ln -s vmlinuz-$VERSION vmlinuz ) 
 ( cd $PKG/boot ; ln -s System.map-$VERSION System.map )
 ( cd $PKG ; find . -name "*.cmd" -exec rm -f "{}" \+ )

copystr
/bin/makepkg -l y -c n $PKGDEST/$APP-$VERSION-$ARCH-$BUILD.txz
