#!/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 project using gcc 5 with the -m32 option.

case "$(dpkg --print-architecture)" in
    (amd64|i386)
        ;;
    (*)
        echo "1..0 # SKIP - not x86"
        exit 0
        ;;
esac

echo "1..1"

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

cp -a examples/make-glib/* "$tmpdir"

gnu_tuple="$(dpkg-architecture -ai386 -qDEB_HOST_GNU_TYPE 2>/dev/null)"
CC="gcc-5 -m32"
CXX="g++-5 -m32"
PKG_CONFIG="${gnu_tuple}-pkg-config"

make -C "$tmpdir" V=1 CC="$CC" CXX="$CXX" PKG_CONFIG="$PKG_CONFIG"
file "$tmpdir/hello"
grep -F /lib/ld-linux.so.2 "$tmpdir/hello"
"$tmpdir/hello"
make -C "$tmpdir" V=1 CC="$CC" CXX="$CXX" PKG_CONFIG="$PKG_CONFIG" clean

echo "ok 1"

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