#!/bin/sh

set -e

dir=`dirname "$0"`

cd "${AUTOPKGTEST_TMP}"

cleanup() {
  ex=$?
  rm -f test.bin test.out
  exit "${ex}"
}
trap "cleanup" EXIT TERM INT

CC=cc
CFLAGS=`dpkg-buildflags --get CFLAGS`
CFLAGS="${CFLAGS} `dpkg-buildflags --get CPPFLAGS`"
CFLAGS="${CFLAGS} -I${dir}/../../cryptoint -I${dir}/../../include-build"
LDFLAGS=`dpkg-buildflags --get LDFLAGS`
LDFLAGS="${LDFLAGS} /usr/lib/`dpkg-architecture -qDEB_HOST_MULTIARCH`/lib25519.a -lrandombytes"

${CC} ${CFLAGS} -o test.bin "${dir}/../../command/lib25519-test"*.c ${LDFLAGS}

./test.bin | tee test.out

echo
echo "=== selected implementations ==="
grep 'selected implementation' test.out | cut -d ' ' -f1,4 | sort -u
