#!/usr/bin/make -f

%:
	dh $@

# Header-only library: there is no build system at the top level, so build and
# run every shipped example and test explicitly instead of relying on
# dh_auto_test.  tests/perftest1.cc (a 70 second benchmark without assertions)
# and tests/spp_bitset_test.cc (needs a header that upstream does not ship) are
# left out; see debian/README.test.
override_dh_auto_test:
	set -e ; top=$$(pwd) ; \
	for src in examples/*.cc tests/spp_test.cc tests/spp_alloc_test.cc \
	           tests/spp_relative_include_test.cc ; do \
	    name=$$(basename $$src .cc) ; \
	    rm -rf test/$$name ; mkdir -p test/$$name ; \
	    cd test/$$name ; \
	    case $$name in \
	        spp_relative_include_test) \
	            $(CXX) -O2 -std=c++11 -D_XOPEN_SOURCE=700 \
	                -o $$name $$top/$$src ;; \
	        *) \
	            $(CXX) -O2 -std=c++11 -D_XOPEN_SOURCE=700 -I$$top \
	                -o $$name $$top/$$src ;; \
	    esac ; \
	    ./$$name > /dev/null ; \
	    cd $$top ; \
	done
	rm -rf test

# dh_installexamples keeps the upstream directory names, and thus the
# provenance of each file, only when it is given an exclude, so pass -X.
override_dh_installexamples:
	dh_installexamples -X spp_bitset_test -X vsprojects
