#!/bin/sh
# autopkgtest check: Build and run a simple program using pkgconf

set -e

# Require $AUTOPKGTEST_TMP for temporary build files
if [ -z "$AUTOPKGTEST_TMP" ]
then
        echo "Required envvar \"$AUTOPKGTEST_TMP\" is not set" >&2
        exit 1
fi

cp debian/tests/smoke-test.c "$AUTOPKGTEST_TMP"
cp debian/tests/smoke-test-output.txt "$AUTOPKGTEST_TMP"
cd "$AUTOPKGTEST_TMP"

gcc -Wall -Werror -o ./test1 smoke-test.c -lSheenBidi
echo "build1: OK"
gcc -Wall -Werror -o ./test2 smoke-test.c $(pkg-config --cflags --libs sheenbidi)
echo "build2: OK"

run_test() {
  echo "$1: running"
  "$1" | tee "$1.output"
  diff -u smoke-test-output.txt "$1.output"
  echo "$1: OK"
}

run_test ./test1
run_test ./test2