#!/bin/sh -e

# This script builds the GTK version.

PKGNAME=Plus42`uname -s`
if [ $# -eq 0 ]; then
  DO_BIN=1
  DO_DEC=1
elif [ $1 = dec ]; then
  DO_BIN=0
  DO_DEC=1
elif [ $1 = bin ]; then
  DO_BIN=1
  DO_DEC=0
else
  echo "Usage: $0 [bin|dec]"
  exit 1
fi

if [ -f /usr/include/alsa/asoundlib.h ]; then
  ALSA='AUDIO_ALSA=1'
else
  ALSA=
fi

if [ -z $MK ]; then
  if which gmake > /dev/null; then
    MK=gmake
  else
    MK=make
  fi
fi
export MK

unset BCD_MATH
cd gtk
if [ $DO_BIN -eq 1 ]; then
  $MK clean
  $MK $ALSA
fi
if [ $DO_DEC -eq 1 ]; then
  $MK clean
  $MK BCD_MATH=1 $ALSA
fi
cd ..

rm -rf $PKGNAME
mkdir $PKGNAME
cp gtk/README.txt $PKGNAME
if [ $DO_BIN -eq 1 ]; then
  cp gtk/plus42bin $PKGNAME
  strip $PKGNAME/plus42bin
fi
if [ $DO_DEC -eq 1 ]; then
  cp gtk/plus42dec $PKGNAME
  strip $PKGNAME/plus42dec
fi
cp gtk/icon-128x128.png $PKGNAME/plus42icon-128x128.png
mkdir -p packages
tar cvfz packages/$PKGNAME.tgz $PKGNAME
rm -rf $PKGNAME
