#!/bin/sh
# Copyright © 2019-2023 Collabora Ltd.
# SPDX-License-Identifier: BSD-2-Clause
# (see debian/copyright)

# Check that the library can be linked by using pkgconf in the most
# obvious way.

set -e
set -u
set -x

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

CC="${CROSS_COMPILE}gcc"
PKG_CONFIG="${CROSS_COMPILE}pkgconf"

tempdir="$(mktemp -d)"
cd "$tempdir"

cat > trivial.c <<'EOF'
#undef NDEBUG
#include <assert.h>

#include <waffle.h>

int main (void)
{
  assert (waffle_enum_to_string (WAFFLE_DONT_CARE) != NULL);
  return 0;
}
EOF

# Deliberately word-splitting pkgconf output
# shellcheck disable=SC2046
"$CC" -o trivial trivial.c $("$PKG_CONFIG" --cflags --libs waffle-1)
test -x trivial
./trivial

rm -fr "$tempdir"
