#!/bin/bash

# arm/build
# Check package dependencies, set metadata and launch
# package build script.
# by Stuart Winter <stuart@armedslack.org>
#
source /usr/share/slackdev/buildkit.sh

# Package metadata:
export PKGNAM=net-snmp
export VERSION=${VERSION:-5.4.2.1}
export PKGARCH=${PKGARCH:-arm}
export BUILD=${BUILD:-1}
export PKGSERIES=${PKGSERIES:-n}
export SLACKPACKAGE=$PKGNAM-$VERSION-$PKGARCH-$BUILD.tgz

# Reset the ARM file system: restore it to the 'factory settings'
# as it were (this has no effect when building natively):
sboxsysrestore

# Ensure base ARM packages are installed first:
slackbasedeps

# Ensure $PKGNAM isn't already installed:
slackfailpkgdeps $PKGNAM || removepkg $PKGNAM

# Ensure specific build dependencies (mainly libraries):
{ slackcheckpkgdeps bzip2   || installpkg $PKGSTORE/a/bzip2-*.tgz || exit 99 ; }
# You can build an RPM MIB module which causes net-snmp to be linked against
# ap/rpm package, but for ARMedslack I've disabled this since rpm is a bit
# shaky on ARM anyway (at least the ancient version in Slackware), and I
# don't want to have this package break later down the line, if I have
# to remove rpm.
# { slackcheckpkgdeps rpm     || installpkg $PKGSTORE/ap/rpm-*.tgz || exit 99 ; }
{ slackcheckpkgdeps popt    || installpkg $PKGSTORE/l/popt-*.tgz || exit 99 ; }
{ slackcheckpkgdeps openssl || installpkg $PKGSTORE/n/openssl-*.tgz || exit 99 ; }

# Launch the package build script:
BUILDLOG=$( basename $SLACKPACKAGE .tgz ).build.log
( ./$PKGNAM.SlackBuild ) >& /dev/stdout | tee $BUILDLOG

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