#!/bin/sh
# autopkgtest check: Build and run a program against libthai, to verify that
# the headers and pkg-config file are installed correctly

set -e

WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR

if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then
    CROSS_COMPILE="$DEB_HOST_GNU_TYPE-"
else
    CROSS_COMPILE=
fi

cat <<EOF > libthaitest.c
#include <thai/tis.h>
#include <thai/thinp.h>
#include <assert.h>

int main (int argc, char *argv[])
{
  assert (th_isaccept (TIS_KO_KAI, TIS_SARA_AA, ISC_STRICT));
  return 0;
}
EOF

${CROSS_COMPILE}gcc -o libthaitest libthaitest.c $(${CROSS_COMPILE}pkg-config --cflags --libs libthai)
echo "build: OK"
[ -x libthaitest ]
./libthaitest
echo "run: OK"
