#!/bin/bash
#
# arm/build
# Check package dependencies, set metadata and launch
# package build script.
# by Stuart Winter <mozes@slackware.com>
#
source /usr/share/slackdev/buildkit.sh

export VERSION=${VERSION:-4.4.302}
export BUILD=${BUILD:-1_slack14.2}
export PKGSERIES=${PKGSERIES:-patches}

## ******************************************************************* ##
# 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
## ******************************************************************* ##

# Assume we want to build a Versatile Kernel if we did not
# specify any particular arch type:
if [ -z "$1" ]; then
   # For this package only, we use branded hardware names as the $ARCH: riscpc, iyonix, cats, netwinder, riscstation
   # export SLKARCH=riscpc
   export SLKARCH=armv7
 else
   export SLKARCH=$1
fi

# Ensure build dependencies are met:
# We require Das U-Boot 'mkimage' tool to build the 'uImage' Kernels
# for the ARM Kirkwood and other platforms using the U-Boot Linux loader.
{ slackcheckpkgdeps u-boot-tools || installpkg $PKGSTORE/a/u-boot-tools-[0-9]*.t?z || exit 99 ; }
# udev, mdadm & lvm2 are included in the initrd so we need the minstalled
# on the system (the mkinitrd script takes the versions from the running system)
{ slackcheckpkgdeps eudev || installpkg $PKGSTORE/a/eudev-[0-9]*.t?z || exit 99 ; }
{ slackcheckpkgdeps mdadm || installpkg $PKGSTORE/a/mdadm-[0-9]*.t?z || exit 99 ; }
{ slackcheckpkgdeps lvm2 || installpkg $PKGSTORE/a/lvm2-[0-9]*.t?z || exit 99 ; }
# DTC (Device Tree Compiler) is needed for ARM kernels since Linux 3.7.
{ slackcheckpkgdeps device-tree-compiler || installpkg $PKGSTORE/d/device-tree-compiler-[0-9]*.t?z || exit 99 ; }
# We use rsync to keep the DTBs in place:
{ slackcheckpkgdeps rsync || installpkg $PKGSTORE/n/rsync-[0-9]*.t?z || exit 99 ; }

export PKGNAM=kernel_$SLKARCH
export SLACKPACKAGE=$PKGNAM-$VERSION-$PKGARCH-$BUILD.txz

# Launch the package build script:
BUILDLOG=$( basename $SLACKPACKAGE .t?z ).build.log
( ./kernel.SlackBuild ) >& /dev/stdout | tee $BUILDLOG || exit 1

# Compress the build log:
bzip2 -9fvz $BUILDLOG

