#!/bin/sh

pkg=ska

if [ "$AUTOPKGTEST_TMP" = "" ]; then

	AUTOPKGTEST_TMP=`mktemp -d /tmp/${pkg}-test.XXXX`
	trap "rm -rf $AUTOPKG_TMP" 0 INT QUIT ABRT PIPE TERM

fi

cp -a /usr/share/doc/${pkg}/examples/* "${AUTOPKGTEST_TMP}"

cd $AUTOPKGTEST_TMP

sed -i 's+#include "../src/\(.*\)"+#include "\1"+' general_unittest.cpp kmers_unittest.cpp DNA_unittest.cpp

# Build google test
ln -s /usr/src/googletest/googletest
g++ -Igoogletest -Wall -Wextra -pthread -c googletest/src/gtest-all.cc
g++ -Igoogletest -Wextra -pthread -c googletest/src/gtest_main.cc
ar rv gtest_main.a gtest-all.o gtest_main.o


# Build tests
g++ -Wall -Wextra -pthread -c general.cpp
g++ -Wextra -pthread -lpthread general.o general_unittest.cpp gtest_main.a -o general_unittest -lz

g++ -Wextra -pthread -c kmers.cpp
g++ -Wextra -pthread -c DNA.cpp

      
g++ -Wextra -pthread -lpthread kmers.o DNA.o general.o kmers_unittest.cpp gtest_main.a -o kmers_unittest -lz
g++ -Wextra -pthread -lpthread DNA.o DNA_unittest.cpp gtest_main.a -o DNA_unittest  -lz

# Run built tests
./general_unittest && ./kmers_unittest && ./DNA_unittest
