#!/bin/bash
#
#  mbsepi-apps.SlackBuild is free software; you can redistribute it and/or modify it under the
#  terms of the GNU General Public License as published by the Free Software
#  Foundation; either version 2 of the License, or any later version.
#
#  mbsepi-apps.SlackBuild is distributed in the hope that it will be useful, but WITHOUT ANY
#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
#  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License along with
#  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
#  Place - Suite 330, Boston, MA 02111-1307, USA
#

# default settings
PACKAGE="mbsepi-apps"
PACKAGE_EXT="gz"
VERSION=${VERSION:=0.10.7}
BUILD=${BUILD:=1}


if [ -f ~/.slackbuildrc ]; then
  . ~/.slackbuildrc
elif [ -f ../../runtime/slackbuildrc ]; then
  . ../../runtime/slackbuildrc
elif [ -f ../../source/runtime/slackbuildrc ]; then
  . ../../source/runtime/slackbuildrc
fi

check_required

SRC="mbsePi-apps-$VERSION.tar.$PACKAGE_EXT"
URL="https://hg.mbse.eu/mbsePi-apps/archive/tip.tar.gz"

get_source $SRC $URL
# Manual unpack and cd into the source because of the included 'tip' number.
cd $TMP
rm -rf mbsePi-apps-*
tar xfvz $CWD/$SRC
cd mbsePi-apps-*
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

CFLAGS="$SLKCFLAGS" ./configure  \
  --prefix=/usr \
  --sysconfdir=/etc \
  --mandir=/usr/man \
  --disable-wiringpi \
  --enable-simulator \
  --build=$ARCH-slackware-linux || exit 1

make ${NUMJOBS} || exit 1
make install DESTDIR=$PKG
mv $PKG/usr/bin/thermferm $PKG/usr/bin/thermferm-sim

make clean
CFLAGS="$SLKCFLAGS" ./configure  \
  --prefix=/usr \
  --sysconfdir=/etc \
  --mandir=/usr/man \
  --enable-rc433 \
  --build=$ARCH-slackware-linux || exit 1

make ${NUMJOBS} || exit 1
make install DESTDIR=$PKG


cd $PKG/etc/rc.d
  chmod 644 rc.thermferm
  mv rc.thermferm rc.thermferm.new
cd -
cd $PKG/etc/default
  mv thermferm thermferm.new
cd -


mkdir -p $DOCS
cp -a COPYING INSTALL $DOCS

echo "Install web pages.."
mkdir -p $PKG/srv
cp -a www $PKG/srv
mv $PKG/srv/www $PKG/srv/thermferm


fixup_package $PKG

# Clean up the extra stuff:
set +u
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/$PACKAGE-$VERSION
  rm -rf $PKG
fi