#!/bin/sh
set -e


echo "HOME: ${HOME}"
if [ ! -d "${HOME}" ]; then
  HOME="$(mktemp -d)"
  echo "created stub HOME ${HOME}" 1>&2
fi
export HOME
ls -lhad "${HOME}"

dpkg-source --before-build `pwd`
PCDEPS="jack flac vorbis vorbisenc vorbisfile ogg libjpeg libpng zlib"

# resave the project with the system module-paths
xvfb-run -a Projucer --resave extras/UnitTestRunner/UnitTestRunner.jucer
# build the UnitTests
make -C extras/UnitTestRunner/Builds/LinuxMakefile \
	CFLAGS="$(pkg-config --cflags ${PCDEPS})" \
	LDFLAGS="$(pkg-config --libs ${PCDEPS})" \
	CONFIG=Release \
	V=1
# run the UnitTests
./extras/UnitTestRunner/Builds/LinuxMakefile/build/UnitTestRunner
