#! /bin/sh
set -e

if [ "${AUTOPKGTEST_TMP}" = "" ]
then
	AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
	# shellcheck disable=SC2064
	trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi
cd "$AUTOPKGTEST_TMP"

ROCM_CLANG_PREFIX="/usr/lib/rocm/llvm/bin"

# Verify that clang++ -stdlib=libc++ can compile and link against the
# system libc++ (this bundle does not ship its own libc++; see d/rules
# LLVM_TOOL_LIBCXX_BUILD=OFF). If this fails without
# 0012-help-finding-libc++.patch, the patch may still be carrying its
# weight; if it passes, the patch is redundant.

cat > hello.cpp << END
#include <iostream>
int main(void) {
    std::cout << "hello from libc++\n";
    return 0;
}
END

echo "$ ${ROCM_CLANG_PREFIX}/clang++ -stdlib=libc++ hello.cpp -o hello"
${ROCM_CLANG_PREFIX}/clang++ -stdlib=libc++ hello.cpp -o hello

echo "$ ./hello"
./hello

echo "$ ldd hello"
ldd hello | tee ldd.log
grep -q "libc++" ldd.log
echo "ok: binary links against libc++"
