#!/bin/bash

# brandy.SlackBuild
# by Stuart Winter <mozes@slackware.com>
# 29-Dec-2004

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

# Paths to skeleton port's source & real Slackware source tree:
#export CWD=$SLACKSOURCE/$PKGSERIES/$PKGNAM
export CWD=$PWD PORTCWD=$PWD

# Temporary build locations:
export TMPBUILD=$TMP/build-$PKGNAM
export PKG=$TMP/package-$PKGNAM
mkpkgdirs # Delete & re-create temporary directories then cd into $TMPBUILD

# Extract source:
tar xvvf $CWD/sources/brandy*orig*tar*
cd $PKGNAM-* || exit 1
slackhousekeeping

# Apply a couple of patches:
tar xvvf $CWD/sources/brandy*debian*
auto_apply_patch debian/patches/01-version.patch || exit 1

# Build:
make CC="cc $ARCH_CFLAGS" || failmake

# Install into package framework:
mkdir -p $PKG/usr/{bin,man/man1}
install -vpm755 brandy $PKG/usr/bin
install -vpm644 debian/brandy.1 $PKG/usr/man/man1

# Add 'BASIC detokenizer'.  This isn't part of the Brandy package but
# was written to detokenize (turn the BASIC tokens into human readable text).  This
# is especially useful for examining your old BASIC programs on a machine that
# doesn't have a BBC BASIC editor - like Linux for example! :)
xzcat $CWD/bbcbascat.xz > $PKG/usr/bin/bbcbascat 
chmod 755 $PKG/usr/bin/bbcbascat

# Install docs:
mkdir -p $PKG/usr/doc/$PKGNAM-$VERSION
cp -a COPYING README docs/* \
     $PKG/usr/doc/$PKGNAM-$VERSION

# Apply Slackware packaging policies:
cd $PKG
slackstripall   # strip all .a archives and all ELFs
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackslack      # chown -R root:root, chmod -R og-w, slackchown (root:bin), slack644docs
slackdesc       # install slack-desc and doinst.sh

# /extra has packages in separate dirs:
export PKGSERIES=$PKGSERIES/$PKGNAM

slackmp         # run makepkg -l y -c n

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