#!/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=llvm
export VERSION=${VERSION:-22.1.4}
export BUILD=${BUILD:-1}
slack_var_pkgseries

# If building in /patches for a Stable Release, we drop the packages into the
# '/patches' directory within the configured Slackware tree:
slack_findpkgstore_is_stablerelease && {
    export PKGSTORE=$PORTPATCHPKGS
    export PKGSERIES=/ # unset as it's not required for patches
    export BUILD=3_slack35.0
    mkdir -vpm755 $PKGSTORE/$PKGSERIES ;}

## ******************************************************************* ##
# For test packages - store in another location rather than overwriting
# the working copy in the main tree:
# export PKGSTORE=/tmp/
# mkdir -vpm755 $PKGSTORE/$PKGSERIES
## ******************************************************************* ##

# Set package name:
export SLACKPACKAGE=$PKGNAM-$VERSION-$PKGARCH-$BUILD.txz

# Ensure base ARM packages are installed first:
slackbasedeps

# Ensure $PKGNAM isn't already installed.
# We want to build with gcc since we have a cross toolchain for it.  Building
# llvm with llvm takes >1 day, although this is what we do on x86 Slackware.
# Perhaps in the future.
#
# We need llvm to build itself now, since libcxxabi does not build with gcc.
#
#slackfailpkgdeps $PKGNAM || removepkg $PKGNAM

# Some package builds remove llvm, so let's make sure it's
# present.  There is a bootstrap option to build llvm with GCC but
# we use a self-hosted llvm to build itself in Slackware.
#{ slackcheckpkgdeps llvm || installpkg $PKGSTORE/d/llvm-[0-9]*.t?z      || exit 99; }

# Ensure specific build dependencies (mainly libraries):

# There's a problem with gcc-go on arm at the moment in that it seems to stall
# when the system is under load, which causes the Go test on LLVM to fail; so
# let's remove it util it works again.
#removepkg gcc-go

# 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
