#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1
#export DEB_BUILD_OPTIONS+=nocheck

DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)

SKIP_TESTS=long
#internal compiler not working yet
SKIP_TESTS+=compile
#poco feature unsuported in current debian release
SKIP_TESTS+=00416
#base64
SKIP_TESTS+=00732
#flaky test
SKIP_TESTS+=00417

#tests affected by SSE disable
SKIP_TESTS+=00120 00161 00212 00232 00273 00284 00506 00647 00704 00720 00800

#fails on buildd O_DIRECT?
SKIP_TESTS+=00750

ifeq ($(DEB_HOST_ARCH),ppc64el)
	SKIP_TESTS+=00047
endif

#
# LP: #1840511 cleanup
#

# libm precision on exp() related functions
SKIP_TESTS+=00536 00534

# long_http_bufferization ?
SKIP_TESTS+=00429

# system processes port ? (bind: error already in use)
SKIP_TESTS+=00379

# clickhouse-clang not found
SKIP_TESTS+=00281

# end of LP: #1840511 cleanup

# Python3 porting, skip failing tests (we're gonna have to work on them at some point, just not now)
SKIP_TESTS+=00730 00646 00612 00309

export TEST_OPT=--skip ${SKIP_TESTS}

ifdef DH_VERBOSE
	TEST_ARGS=--verbose
endif

#exclude with_server test on archs other than listed ones
ifeq (,$(filter $(DEB_HOST_ARCH),amd64 arm64 ppc64el))
	TEST_ARGS+="-E with_server"
endif

CMAKE_FLAGS = -DUNBUNDLED=1 -DUSE_STATIC_LIBRARIES=0 USE_UNWIND=0 -DCLICKHOUSE_SPLIT_BINARY=1 -DVERSION_DESCRIBE=$(shell dpkg-parsechangelog -S Version)

ifeq ($(DEB_HOST_ARCH),amd64)
	CMAKE_FLAGS+=-DENABLE_IPO=1
endif

%:
	dh $@  --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure -- $(CMAKE_FLAGS)

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dh_auto_test -- ARGS+=$(TEST_ARGS)
endif
