#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-blackbox

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

# Explode the package framework:
cd $PKG
explodepkg $CWD/_blackbox.tar.gz

echo "+=================+"
echo "| blackbox 0.51.3.1 |"
echo "+=================+"
cd $TMP
tar xzvf $CWD/blackbox-0.51.3.1.tar.gz
cd blackbox-0.51.3.1
mkdir -p $PKG/usr/doc/blackbox-0.51.3.1
cp -a AUTHORS ChangeLog GPL-2.0 INSTALL NEWS README TODO \
  $PKG/usr/doc/blackbox-0.51.3.1
chown -R root.root $PKG/usr/doc/blackbox-0.51.3.1
./configure --prefix=/usr/X11R6 --enable-kde i386-slackware-linux
make -j 2
cd src
strip blackbox
cat blackbox > $PKG/usr/X11R6/bin/blackbox
cd ../util
strip bsetroot
cat bsetroot > $PKG/usr/X11R6/bin/bsetroot
cd ../data
cp -a menu $PKG/usr/X11R6/share/Blackbox
cd styles
cp -a blackmagic coldsteel colorpurple darkgreen default gnoid green onoid \
      pnoid previous results slatebox steelblue stylesmenu \
      $PKG/usr/X11R6/share/Blackbox/styles
chown -R root.root $PKG/usr/X11R6/share/Blackbox
mkdir -p $PKG/var/X11R6/lib/xinit
cat $CWD/xinitrc.blackbox > $PKG/var/X11R6/lib/xinit/xinitrc.blackbox
chmod 755 $PKG/var/X11R6/lib/xinit/xinitrc.blackbox

# Build the package:
cd $PKG
tar czvf $TMP/blackbox.tgz .

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/blackbox-0.51.3.1
  rm -rf $PKG
fi
