#!/bin/bash
# Copyright © 2019 Collabora Ltd.
# SPDX-License-Identifier: BSD-3-Clause
# (See debian/copyright)

set -e
set -u
set -x

# Test that we can compile a simple C++ project using make and clang++.

echo "1..2"

tmpdir="$(mktemp -d)"
cleanup () {
    rm -fr "$tmpdir"
}
trap cleanup 0 INT QUIT ABRT PIPE TERM

cp -a examples/cxx/* "$tmpdir"

make -C "$tmpdir" V=1 CC=clang-4.0 CXX=clang++-4.0
"$tmpdir/hello"
make -C "$tmpdir" V=1 CC=clang-4.0 CXX=clang++-4.0 clean

echo "ok 1"

# If this is the official SDK image, check that clang-4.0 is the default.

if grep -q '^VARIANT="\?SDK"\?$' /usr/lib/os-release; then
    case "$(clang++ --version 2>&1)" in
        (*version\ 4.*)
            echo "ok 2"
            ;;

        (*version\ [1-35-9].*)
            echo "not ok 2 - Unsupported clang version"
            clang++ --version
            exit 1
            ;;

        (*)
            echo "not ok 2 - Could not parse version"
            clang++ --version
            exit 1
            ;;
    esac
else
    echo "ok 2 # SKIP this does not appear to be a SDK image"
fi

# vim:set sw=4 sts=4 et ft=sh:
