#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.

# Include architecture definitions to detect armhf/armv7l
include /usr/share/dpkg/architecture.mk

#export DH_VERBOSE = 1

# 1. Strip the 64-bit file offset flags from the default Debian flags
# These cause the "undefined reference to getVirtualFileRef" error on armhf/armv7l
export DEB_CFLAGS_MAINT_STRIP = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
export DEB_CXXFLAGS_MAINT_STRIP = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE

# See FEATURE AREAS in dpkg-buildflags(1).
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# 2. Re-enforce hardening and add our DWARF fix
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CXXFLAGS_MAINT_APPEND = -gdwarf-4

# Reduce memory pressure on 32-bit ARM linking
ifeq ($(DEB_HOST_ARCH), armhf)
    export PROCS := 2
else
    export PROCS := $(shell nproc)
endif

# See ENVIRONMENT in dpkg-buildflags(1).
# Package maintainers to append CFLAGS.
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# Package maintainers to append LDFLAGS.
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


%:
	dh $@


# dh_make generated override targets.
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
#override_dh_auto_configure:
#	dh_auto_configure -- \
#	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

override_dh_auto_configure:
	dh_auto_configure -- \
		-DCMAKE_BUILD_TYPE=Release \
		-DISPC_INCLUDE_TESTS=OFF \
		-DISPC_INCLUDE_EXAMPLES=OFF \
		-DISPC_INCLUDE_RT=ON \
		-DISPC_INCLUDE_UTILS=OFF \
		-DISPC_LIBRARY=OFF \
		-DCMAKE_VERBOSE_MAKEFILE=ON

override_dh_auto_build:
	@echo 'blhc: ignore-line-regexp: \[\ ?\ ?[0-9]+%\]\ Building\ CXX\ object\ .+\.(cpp|cc)\.o'
	dh_auto_build -- -j$(PROCS)

override_dh_dwz:
	dh_dwz --exclude=bin