#!/usr/bin/make -f

%:
	dh $@ --builddirectory=build

CRYFS_BUILD_TYPE = "-DCMAKE_BUILD_TYPE=Debug"
ifeq (,$(filter debug,$(DEB_BUILD_OPTIONS)))
	CRYFS_BUILD_TYPE = "-DCMAKE_BUILD_TYPE=Release"
endif

CRYFS_BUILD_TESTS = "-DBUILD_TESTING=OFF"
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	CRYFS_BUILD_TESTS = "-DBUILD_TESTING=ON"
endif

override_dh_auto_configure:
	mkdir -p build
	dpkg-architecture
	if `dpkg-architecture -e armel` || `dpkg-architecture -e armhf` || `dpkg-architecture -e s390x`; then \
	    echo "Performing armel/armhf/s390x build"; \
	    dh_auto_configure -- -DDISABLE_ASM=ON $(CRYFS_BUILD_TESTS) -DCRYFS_UPDATE_CHECKS=OFF $(CRYFS_BUILD_TYPE); \
	else \
	    dh_auto_configure -- $(CRYFS_BUILD_TESTS) -DCRYFS_UPDATE_CHECKS=OFF $(CRYFS_BUILD_TYPE); \
	fi

override_dh_auto_test:
	./build/test/blobstore/blobstore-test 2>&1
	./build/test/blockstore/blockstore-test --gtest_filter='-CacheTest_RaceCondition.*' 2>&1
	# Config Compatibility tests fail on s390x, mipsel, and hppa archs
	./build/test/cryfs/cryfs-test --gtest_filter='-CryConfigCompatibilityTest.*' 2>&1
	./build/test/parallelaccessstore/parallelaccessstore-test 2>&1
	./build/test/gitversion/gitversion-test 2>&1
	# Test fails with pbuilder, and mipsel
	# ./build/test/cpp-utils/cpp-utils-test --gtest_filter='-HomedirTest.*' 2>&1
	# ./build/test/cryfs-cli/cryfs-cli-test
	# Test requires root (and fuse)
	# ./build/test/fspp/fspp-test
