#!/bin/sh
set -eu
work="$AUTOPKGTEST_TMP"
legacy="$PWD/debian/tests/legacy-src/include"
for probe in legacy-rgba legacy-manifest; do
    c++ -std=c++17 -O2 -I"$legacy" -I"$legacy/OpenEXR" \
        $(pkg-config --cflags OpenEXR) "debian/tests/legacy-src/$probe.cpp" \
        -o "$work/$probe" $(pkg-config --libs OpenEXR)
done
# Both calls must resolve in the installed library, not in the probe itself.
readelf --dyn-syms -W "$work/legacy-manifest" | grep 'UND.*_M_default_appendE'
readelf --dyn-syms -W "$work/legacy-manifest" | grep 'UND.*_M_realloc_appendIJS2_EEEvDpOT_'
"$work/legacy-rgba" "$work"
"$work/legacy-manifest"
c++ -std=c++17 -O2 $(pkg-config --cflags OpenEXR) \
    debian/tests/src/multipart-rgba.cpp -o "$work/multipart-rgba" \
    $(pkg-config --libs OpenEXR)
"$work/multipart-rgba" "$work/multipart.exr"
mkdir "$work/cmake-source"
cat > "$work/cmake-source/main.cpp" <<'EOF'
#include <OpenEXR/openexr_conf.h>
#include <OpenEXR/ImfThreading.h>
int main() { return OPENEXR_IMF_NAMESPACE::globalThreadCount() < 0; }
EOF
cat > "$work/cmake-source/CMakeLists.txt" <<'EOF'
cmake_minimum_required(VERSION 3.16)
project(consumer LANGUAGES CXX)
find_package(OpenEXR CONFIG REQUIRED)
add_executable(consumer main.cpp)
target_link_libraries(consumer PRIVATE OpenEXR::OpenEXR)
EOF
cmake -S "$work/cmake-source" -B "$work/cmake-build"
cmake --build "$work/cmake-build"
"$work/cmake-build/consumer"
