#!/bin/bash

# Slackware build script for sbo-maintainer-tools

# Written by B. Watson (urchlay@slackware.uk)

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

# 20230701 bkw: update for v0.9.0.
# 20230609 bkw: update for v0.8.2.
# 20230526 bkw: update for v0.8.1.
# 20230519 bkw: update for v0.8.0.
# 20230328 bkw: update for v0.7.0.
# 20230304 bkw: update for v0.6.3.
# 20230221 bkw: update for v0.6.2.
# 20230214 bkw: update for v0.6.1.
# 20230204 bkw: update for v0.6.0.

cd $(dirname $0) ; CWD=$(pwd)

# Included in Slint by Didier Spaier didieratslintdotfr

PRGNAM=sbo-maintainer-tools
VERSION=${VERSION:-0.9.0}
BUILD=${BUILD:-1}
TAG=slint
PKGTYPE=${PKGTYPE:-txz}

ARCH=noarch

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=$CWD
PKG=$TMP/package-$PRGNAM
OUTPUT=$CWD

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
tar xf $CWD/$PRGNAM-$VERSION.tar.gz
cd $PRGNAM-$VERSION
chown -R root:root .
find -L .  -perm /111 -a \! -perm 755 -a -exec chmod 755 {} \+ -o \
        \! -perm /111 -a \! -perm 644 -a -exec chmod 644 {} \+

make install PREFIX=/usr DESTDIR=$PKG

PKGDOC=$PKG/usr/doc/$PRGNAM-$VERSION
mkdir -p $PKGDOC
cat $CWD/$PRGNAM.SlackBuild > $PKGDOC/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE
