#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/pkg-info.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all reproducible=+all future=+lfs

FILAMENT_VERSION := $(shell echo $(DEB_VERSION_UPSTREAM) | sed 's/[+~]dfsg[0-9]*$$//')
FILAMENT_SOVERSION := $(shell echo $(FILAMENT_VERSION) | cut -d. -f1,2)

# Filament assumes that VkSurfaceKHR is a pointer type, which is only true on 64 bit
ifeq ($(DEB_HOST_ARCH_BITS),64)
SUPPORTS_VULKAN = ON
else
SUPPORTS_VULKAN = OFF
endif

export DEB_CPPFLAGS_MAINT_APPEND += -DNDEBUG

ifneq (,$(filter $(DEB_HOST_ARCH), armel m68k mipsel powerpc sh4))
  export DEB_CXXFLAGS_MAINT_APPEND += -Wl,--no-as-needed -latomic -Wl,--as-needed
endif

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
		-DCMAKE_C_COMPILER=clang-11 -DCMAKE_CXX_COMPILER=clang++-11 \
		-DFILAMENT_SKIP_SAMPLES=ON \
		-DFILAMENT_ENABLE_JAVA=OFF \
		-DUSE_STATIC_LIBCXX=OFF \
		-DFILAMENT_SUPPORTS_VULKAN=$(SUPPORTS_VULKAN) \
		-DFILAMENT_VERSION=$(FILAMENT_VERSION) \
		-DFILAMENT_SOVERSION=$(FILAMENT_SOVERSION) \
		-DFILAMENT_LIBDIR=lib/$(DEB_HOST_MULTIARCH) \
		-DFILAMENT_INCLUDEDIR=include/filament-$(FILAMENT_SOVERSION) \
		-DFILAMENT_CMAKEDIR=lib/$(DEB_HOST_MULTIARCH)/cmake/filament-$(FILAMENT_SOVERSION)

override_dh_auto_clean:
	dh_auto_clean
	rm -f ImportExecutables-None.cmake

override_dh_dwz:
	dh_dwz || true
