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

# This rules file has 2 streams, the build-debian-devel stream builds
# the static library and the build-debian-release builds the dynamic
# library.

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

include /usr/share/dpkg/architecture.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all


ARCH_WITH_LLHTTP = amd64 arm64 armel armhf mips64el ppc64el riscv64 s390x loong64 ppc64

BUILD_TESTS = $(if $(filter nocheck,$(DEB_BUILD_OPTIONS)),OFF,ON)
COMMON_CMAKE_FLAGS = \
	-DBUILD_CLI=OFF \
	-DBUILD_TESTS=$(BUILD_TESTS) \
	-DCERT_LOCATION=/etc/ssl/certs/ca-certificates.crt \
	-DDISABLE_ONLINE_TESTS=ON \
	-DENABLE_REPRODUCIBLE_BUILDS=ON \
	-DREGEX_BACKEND=pcre2 \
	-DUSE_GSSAPI=ON \
	-DUSE_HTTPS=OpenSSL \
	-DUSE_NTLMCLIENT=OFF \
	-DUSE_SSH=ON

ifneq (,$(filter $(ARCH_WITH_LLHTTP),$(DEB_HOST_ARCH)))
COMMON_CMAKE_FLAGS += \
	-DUSE_HTTP_PARSER=llhttp
endif

ifeq ($(DEB_HOST_ARCH),ppc64el)
  export DEB_CFLAGS_MAINT_APPEND = -O2
endif

# The stat() in the Git fs layer has some issues
export GITTEST_FLAKY_STAT = true

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure --builddirectory=build-debian-devel -- \
		-DBUILD_SHARED_LIBS=OFF \
		$(COMMON_CMAKE_FLAGS)
	dh_auto_configure --builddirectory=build-debian-release -- \
		-DBUILD_SHARED_LIBS=ON \
		$(COMMON_CMAKE_FLAGS)

override_dh_auto_build:
	dh_auto_build --builddirectory=build-debian-devel
	dh_auto_build --builddirectory=build-debian-release

override_dh_auto_install:
	dh_auto_install --builddirectory=build-debian-devel
	dh_auto_install --builddirectory=build-debian-release

execute_after_dh_auto_install:


override_dh_auto_test:
	dh_auto_test --builddirectory=build-debian-devel
	dh_auto_test --builddirectory=build-debian-release

