#!/bin/sh
# autopkgtest check: Build and run a program to verify that the
# headers and pkg-config file are installed correctly
# (C) 2012 Canonical Ltd.
# (C) 2018-2020 Simon McVittie
# Authors: Martin Pitt, Simon McVittie

set -eux

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

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

cp src/examples/introspect-providers.c "$WORKDIR"
cd "$WORKDIR"

# Deliberately word-splitting pkg-config's output:
# shellcheck disable=SC2046
"${CROSS_COMPILE}gcc" -o introspect-providers introspect-providers.c $("${CROSS_COMPILE}pkg-config" --cflags --libs goa-backend-1.0)
[ -x introspect-providers ]
dbus-run-session -- xvfb-run -a ./introspect-providers
