#!/bin/bash
ulimit -s unlimited
shopt -s extglob

# slackpkg+.SlackBuild
# by Stuart Winter for Slackware ARM.

# Record toolchain & other info for the build log:
slackbuildinfo

# Paths to skeleton port's source & real Slackware source tree:
slackset_var_cwds

# Detect whether we're building for /patches:
# This function sets the variable 'SLACKPATCHING'
slack_findpkgstore_is_stablerelease

# Temporary build locations:
shm_tmp # Use /dev/shm if >8GB RAM is available & not mounted 'noexec'
export TMPBUILD=$TMP/build-$PKGNAM
export PKG=$TMP/package-$PKGNAM
mkpkgdirs # Delete & re-create temporary directories then cd into $TMPBUILD

# Extract source:
#tar xf $CWD/$PKGNAM-$VERSION.tar.!(*sign|*asc|*sig)
#cd $PKGNAM-*/ || failextract
#slackhousekeeping

# Repackage the upstream Slackware package, since it's a noarch.
# We can apply any patches from here if need be.
#
# Note: By default an x86 32bit sample config file is installed, but this is fine
# for ARM64, as the main difference is the path names in the pkg repositories.
cd $PKG
explodepkg $SLACKUPSTREAMROOTDIR/extra/$PKGNAM/$PKGNAM-*.t?z || failextract

# Apply generic Slackware packaging policies:
cd $PKG
slackslack # set standard Slackware file/dir permissions and ownerships
slackmp    # run makepkg -l y -c n

# Perform any final checks on the package:
cd $PKG
slackhlinks     # search for any hard links
