#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

# The name of the build-*.txt profile to choose
BUILD_NAME = win$(DEB_HOST_ARCH_BITS)

# The directory in which we will build
BUILD_DIR   = build-$(BUILD_NAME)

%:
	dh $@ --buildsystem=ninja --builddirectory=$(BUILD_DIR)

# fails with: unrecognized option '-z'
export DEB_BUILD_MAINT_OPTIONS := hardening=-relro

# disabled, even with workarounds it does not work
# see https://sourceware.org/bugzilla/show_bug.cgi?id=12762
# LDFLAGS += -flto -fuse-linker-plugin -Wl,-allow-multiple-definition -flto-partition=none

# Meson flags
# TODO: why do dll files end-up in the bindir directory???
MESON_FLAGS = --buildtype=plain \
               --cross-file=build-$(BUILD_NAME).txt \
			   --prefix=/usr \
			   --bindir=lib/dxvk/wine$(DEB_HOST_ARCH_BITS)-development \
			   --libdir=lib/dxvk/wine$(DEB_HOST_ARCH_BITS)-development \
               -Dwine_libdir=/usr/lib/$(DEB_HOST_MULTIARCH)/wine-development/$(subst linux-gnu,windows,$(DEB_HOST_MULTIARCH))/ \
               $(BUILD_DIR)

override_dh_auto_configure:
	echo "blhc: ignore-line-regexp: C\+\+ linker for the build machine: .*"
	echo "MESON_FLAGS: $(MESON_FLAGS)"
	meson $(MESON_FLAGS)

execute_after_dh_auto_install:
	# we could change the install script but then the previous installations would be broken
	rename 's/\.dll$$/.dll.so/' debian/tmp/usr/lib/dxvk/wine$(DEB_HOST_ARCH_BITS)-development/*.dll

override_dh_shlibdeps:
	dh_shlibdeps -- -l/usr/lib/$(DEB_HOST_MULTIARCH)/wine-development
