#!/bin/sh

# Paul Gevers <elbrus@debian.org>, 2016

# Stop if an error occurs
set -e

# Patch the build tree to only build tools and demos
patch -p1 -i debian/tests/only-tools-and-demos.patch

# copy files not distributed in libmotif-dev
# MrmWidget.h is needed by wmldbcreate.c
cp lib/Mrm/MrmWidget.h tools/wml/
cp lib/Mrm/MrmWidget.h demos/lib/Exm/wml/
# XmI.h is needed by getsubres.c
cp lib/Xm/XmI.h demos/programs/getsubres/
# XmStrDefsI.h is needed by XmI.h
# autogenerated in lib/Xm/
cp debian/tests/XmStrDefsI.h demos/programs/getsubres/

dh_autoreconf --as-needed
dh_auto_configure

dh_auto_build

# Clean up after succesful build
dh_auto_clean
dh_autoreconf_clean
dh_clean
rm -f demos/programs/getsubres/XmStrDefsI.h
rm -f demos/programs/getsubres/XmI.h
rm -f demos/lib/Exm/wml/MrmWidget.h
rm -f tools/wml/MrmWidget.h
patch -p1 --force --reverse -i debian/tests/only-tools-and-demos.patch

# Shouldn't this always be cleaned up?
find . -name Makefile -delete
rm include/config.h include/stamp-h1 lib/Xm/xmstring.list
