#!/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

# Package metadata:
export PKGNAM=rpm
export VERSION=${VERSION:-4.16.1.3}
export BUILD=${BUILD:-4}
export PKGSERIES=${PKGSERIES:-ap}
export SLACKPACKAGE=$PKGNAM-$VERSION-$PKGARCH-$BUILD.txz

# Ensure base ARM packages are installed first:
slackbasedeps

# Let's build only against mozilla-nss rather than anything else in the mozilla packages:
removepkg mozilla-firefox seamonkey seamonkey-solibs mozilla-thunderbird
{ slackcheckpkgdeps mozilla-nss || installpkg $PKGSTORE/l/mozilla-nss-[0-9]*.t?z || exit 99 ; }

# This is working around a bug in Slackware ARM. Not sure why it's broken yet.
removepkg db48

# Ensure additional dependencies:
{ slackcheckpkgdeps bzip2           || installpkg $PKGSTORE/a/bzip2-[0-9]*.t?z   || exit 99; }
{ slackcheckpkgdeps dbus            || installpkg $PKGSTORE/a/dbus-[0-9]*.t?z    || exit 99; }
{ slackcheckpkgdeps file            || installpkg $PKGSTORE/a/file-[0-9]*.t?z    || exit 99; }
{ slackcheckpkgdeps xz              || installpkg $PKGSTORE/a/xz-[0-9]*.t?z      || exit 99; }
{ slackcheckpkgdeps python2         || installpkg $PKGSTORE/d/python2-[0-9]*.t?z  || exit 99; }
{ slackcheckpkgdeps python3         || installpkg $PKGSTORE/d/python3-[0-9]*.t?z || exit 99; }
{ slackcheckpkgdeps db48            || installpkg $PKGSTORE/l/db48-[0-9]*.t?z    || exit 99; }
{ slackcheckpkgdeps libarchive      || installpkg $PKGSTORE/l/libarchive-[0-9]*.t?z || exit 99; }
{ slackcheckpkgdeps popt            || installpkg $PKGSTORE/l/popt-[0-9]*.t?z    || exit 99; }

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

#{ slackcheckpkgdeps mozilla-firefox     || installpkg $PKGSTORE/xap/mozilla-firefox-[0-9]*.t?z || exit 99 ; }
#{ slackcheckpkgdeps mozilla-thunderbird || installpkg $PKGSTORE/xap/mozilla-thunderbird-[0-9]*.t?z || exit 99 ; }
# but we do need some seamonkey libraries:
#{ slackcheckpkgdeps seamonkey   || installpkg $PKGSTORE/xap/seamonkey-[0-9]*.t?z || exit 99 ; }
#{ slackcheckpkgdeps seamonkey-solibs || installpkg $PKGSTORE/l/seamonkey-solibs-[0-9]*.t?z || exit 99 ; }

# In Slack390's prototype script, Mark says:
# This package seems to have problems when either automake or autoconf are
# installed. This may get fixed in the future, but be prepared to removepkg them
# if problems still occur. The autoconf problem manifested itself as a gcc parse
# error in popt/config.h.
###
# Since I have so many bizarre problems with rpm, I'll take heed of his
# caution:
#slackfailpkgdeps autoconf     || removepkg autoconf
#slackfailpkgdeps autoconf2.13 || removepkg autoconf2.13
#slackfailpkgdeps automake     || removepkg automake

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

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