#!/bin/sh -x

export DEB_VERSION_UPSTREAM=$(dpkg-parsechangelog -SVersion|sed -e s:-[^-]*$::)

dpkg-source --before-build $(pwd)
patch -p1 < debian/patches/autopkgtest-Use-system-library-to-run-test.patch
sed -i s:-Werror:-Wextra: CMakeLists.txt
dh_auto_configure -- \
  -DENABLE_STATIC=NO

# From now on, the test fails if there's error
set -e

JOBS=$(($(nproc)*2))
(cd obj-*/examples; make -j$JOBS)
(cd obj-*/src; make -j$JOBS)
(cd obj-*/tests; make -j$JOBS)

export CTEST_OUTPUT_ON_FAILURE=1
dh_auto_test
