#!/usr/bin/make -f
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

# 安全编译参数
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND = -Wall
export DEB_CXXFLAGS_MAINT_APPEND = -Wall
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wl,-E

# reproducible 编译参数
DEB_CMAKE_EXTRA_FLAGS += -DCMAKE_SKIP_BUILD_RPATH=ON

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)

# Build-Profiles 控制
BUILD_DOCS := $(if $(filter nodoc,$(DEB_BUILD_PROFILES)),OFF,ON)
BUILD_DTK5 := $(if $(filter nodtk5,$(DEB_BUILD_PROFILES)),OFF,ON)
BUILD_DTK6 := $(if $(filter nodtk6,$(DEB_BUILD_PROFILES)),OFF,ON)

%:
	dh $@

override_dh_auto_configure:
ifeq ($(BUILD_DTK5),ON)
	mkdir -p build5
	QT_SELECT=qt5 dh_auto_configure --builddirectory=build5 -- \
		$(DEB_CMAKE_EXTRA_FLAGS) \
		-DBUILD_TESTING=OFF \
		-DBUILD_PLUGINS=OFF \
		-DBUILD_DOCS=$(BUILD_DOCS) \
		-DDTK_STATIC_TRANSLATION=YES \
		-DDTK5=ON
endif
ifeq ($(BUILD_DTK6),ON)
	mkdir -p build6
	dh_auto_configure --builddirectory=build6 -- \
		$(DEB_CMAKE_EXTRA_FLAGS) \
		-DBUILD_TESTING=OFF \
		-DBUILD_PLUGINS=OFF \
		-DBUILD_DOCS=$(BUILD_DOCS) \
		-DDTK_STATIC_TRANSLATION=YES \
		-DDTK5=OFF
endif

override_dh_auto_build:
ifeq ($(BUILD_DTK5),ON)
	QT_SELECT=qt5 dh_auto_build --builddirectory=build5
endif
ifeq ($(BUILD_DTK6),ON)
	dh_auto_build --builddirectory=build6
endif

override_dh_auto_install:
ifeq ($(BUILD_DTK5),ON)
	QT_SELECT=qt5 dh_auto_install --builddirectory=build5
endif
ifeq ($(BUILD_DTK6),ON)
	dh_auto_install --builddirectory=build6
endif

override_dh_auto_test:
ifeq ($(BUILD_DTK5),ON)
	QT_SELECT=qt5 dh_auto_test --builddirectory=build5
endif
ifeq ($(BUILD_DTK6),ON)
	dh_auto_test --builddirectory=build6
endif

override_dh_auto_clean:
	dh_auto_clean --builddirectory=build5
	dh_auto_clean --builddirectory=build6
	rm -rf build5 build6
