#!/bin/sh

set -e

# this is taken from libjsoncpp package
# Presence of $AUTOPKGTEST_TMP implies that someone will handle cleanup for us, so we
# can avoid duplicating the effort (signal handling, etc.) here.
if [ -z "$AUTOPKGTEST_TMP" ]
then
	echo "Required envvar AUTOPKGTEST_TMP \"$AUTOPKGTEST_TMP\" is not set" >&2
	exit 1
fi


# the idea was taken from spirv-llvm-translator package

cd "$AUTOPKGTEST_TMP"
cat <<EOF > CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(test)

find_package(liblucene++ REQUIRED)
find_package(liblucene++-contrib REQUIRED)

add_executable(main main.cxx)
include_directories(\${liblucene++_INCLUDE_DIRS})
include_directories(\${liblucene++-contrib_INCLUDE_DIRS})

target_link_libraries(main \${liblucene++_LIBRARIES} \${liblucene++-contrib_LIBRARIES})
EOF

cat <<EOF > main.cxx
#include <Lucene.h>
#include <LuceneException.h>
#include <BooleanQuery.h>

using namespace Lucene;
int main()
{
    auto fullQuery = newLucene<BooleanQuery>();
    return 0;
}

EOF

mkdir build && cd build
cmake .. && VERBOSE=1 make
