#!/bin/bash

# Slackware build script for hatari_tos_roms
# Written by B. Watson (urchlay@slackware.uk)

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

# The version number is just the date when this script was modified.
# The actual TOS ROM versions are 1.02, 1.04, 2.06

# 20230107 bkw: add missing doc dir. Include our own README since
# there otherwise isn't one.

# 20141029 bkw: fix missing : in VERSION BUILD TAG assignments

# 20140825 bkw:
# - include the 1.04 images, since hatari needs them to allow direct
#   launching of .prg files from the command line.
# - simplify script, the US images used to be optional, now they're
#   required, and we don't need code to modify the slack-desc either.

# I thought about gzipping these, since hatari supports gzipped roms, but
# they're not taking up that much space (1088K uncompressed, 670K gzipped),
# plus other emulators than hatari can use these, and might not support .gz

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

PRGNAM=hatari_tos_roms
VERSION=${VERSION:-20230107}
ARCH=noarch
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

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

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e

rm -rf $PKG
mkdir -p $PKG/usr/share/hatari $PKG/install

cd $PKG/usr/share/hatari

unzip $CWD/tos_uk.zip
unzip $CWD/tos_us.zip
unzip $CWD/tos104uk.zip
unzip $CWD/tos104us.zip

mv Tos206.img tos-2.06-uk.img
mv Tos102.img tos-1.02-uk.img
mv Tos206us.img tos-2.06-us.img
mv Tos102us.img tos-1.02-us.img
mv tos104uk.img tos-1.04-uk.img
mv tos104us.img tos-1.04-us.img

chown root:root *
chmod 644 *

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

cat $CWD/slack-desc >$PKG/install/slack-desc
cat $CWD/doinst.sh >$PKG/install/doinst.sh

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