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

set -e
set -u
set -x

# Test that we can compile a simple project using meson and ninja.

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

# Meson wants a real locale
export LC_ALL=C.UTF-8

n=0

meson "$tmpdir/b" "$(pwd)/examples/meson-glib"
ninja -v -C "$tmpdir/b"
"$tmpdir/b/hello"
ninja -v -C "$tmpdir/b" clean
n=$((n + 1))
echo "ok $n"
rm -fr "$tmpdir/b"

meson --native-file gcc-4.6.txt "$tmpdir/b" "$(pwd)/examples/meson-glib"
ninja -v -C "$tmpdir/b"
"$tmpdir/b/hello"
ninja -v -C "$tmpdir/b" clean
n=$((n + 1))
echo "ok $n"
rm -fr "$tmpdir/b"

meson --native-file gcc-4.8.txt "$tmpdir/b" "$(pwd)/examples/meson-glib"
ninja -v -C "$tmpdir/b"
"$tmpdir/b/hello"
ninja -v -C "$tmpdir/b" clean
n=$((n + 1))
echo "ok $n"
rm -fr "$tmpdir/b"

meson --native-file gcc-5.txt "$tmpdir/b" "$(pwd)/examples/meson-glib"
ninja -v -C "$tmpdir/b"
"$tmpdir/b/hello"
ninja -v -C "$tmpdir/b" clean
n=$((n + 1))
echo "ok $n"
rm -fr "$tmpdir/b"

meson --native-file gcc-9.txt "$tmpdir/b" "$(pwd)/examples/meson-glib"
ninja -v -C "$tmpdir/b"
"$tmpdir/b/hello"
ninja -v -C "$tmpdir/b" clean
n=$((n + 1))
echo "ok $n"
rm -fr "$tmpdir/b"

meson --native-file clang.txt "$tmpdir/b" "$(pwd)/examples/meson-glib"
ninja -v -C "$tmpdir/b"
"$tmpdir/b/hello"
ninja -v -C "$tmpdir/b" clean
n=$((n + 1))
echo "ok $n"
rm -fr "$tmpdir/b"

meson --native-file clang-3.4.txt "$tmpdir/b" "$(pwd)/examples/meson-glib"
ninja -v -C "$tmpdir/b"
"$tmpdir/b/hello"
ninja -v -C "$tmpdir/b" clean
n=$((n + 1))
echo "ok $n"
rm -fr "$tmpdir/b"

meson --native-file clang-3.6.txt "$tmpdir/b" "$(pwd)/examples/meson-glib"
ninja -v -C "$tmpdir/b"
"$tmpdir/b/hello"
ninja -v -C "$tmpdir/b" clean
n=$((n + 1))
echo "ok $n"
rm -fr "$tmpdir/b"

meson --native-file clang-3.8.txt "$tmpdir/b" "$(pwd)/examples/meson-glib"
ninja -v -C "$tmpdir/b"
"$tmpdir/b/hello"
ninja -v -C "$tmpdir/b" clean
n=$((n + 1))
echo "ok $n"
rm -fr "$tmpdir/b"

echo "1..$n"

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