#!/bin/sh

set -e

DEB_HOST_MULTIARCH=$(dpkg-architecture -qDEB_HOST_MULTIARCH)

WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR
cat <<EOF > test.c
#include <gl4es/gl4eshint.h>

int main()
{
    return 0;
}
EOF

# gl4es's goal is to replace system's GL library, but it depend on user how to use it

if [ -e /usr/lib/${DEB_HOST_MULTIARCH}/libGL.so ]; then
	rm -rf /usr/lib/${DEB_HOST_MULTIARCH}/libGL.so
fi

ln -sv /usr/lib/${DEB_HOST_MULTIARCH}/gl4es/libGL.so.1 /usr/lib/${DEB_HOST_MULTIARCH}/libGL.so

#ldconfig

gcc -lGL -o test test.c

echo "build: OK"
[ -x test ]
# > /dev/null because it writes this: full talloc report on 'sccp' (total      1 bytes in   1 blocks)
./test
echo "run: OK"
