#/bin/sh

# To build the debian package you need:
#
# 1) Configure FriCAS using '--prefix=/usr'
#
# 2) Build
#
# 3) make DESTDIR=`pwd`/debian/tmp install
#
# 4) Put 'control' and 'changelog' files in the 'debian' subdirectory
#    of the build tree
#
# 5) Run this script (from within build directory).

# Stop on errors
set -e

# find the platform subdirectory

TDIR=debian/tmp/usr/lib/fricas/target
PLF=""
for A in $(ls $TDIR); do
    if [ -d $TDIR/$A ] ; then
        if [ "$PLF"x != x ] ; then
            echo $TDIR1: contains more then one subdirectory
        else
            PLF=$A
        fi
    fi
done

AX=$TDIR/$PLF

echo AX=$AX

# generate shared library dependencies
dpkg-shlibdeps \
$AX/bin/AXIOMsys \
$AX/bin/asq \
$AX/bin/clef \
$AX/bin/htadd \
$AX/bin/hypertex \
$AX/bin/sman \
$AX/bin/viewAlone \
$AX/lib/ex2ht \
$AX/lib/hthits \
$AX/lib/session \
$AX/lib/spadbuf \
$AX/lib/spadclient \
$AX/lib/view2D \
$AX/lib/view3D \
$AX/lib/viewman

# proper package build
mkdir debian/tmp/DEBIAN
dpkg-gencontrol
fakeroot dpkg --build debian/tmp ..
