#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

MESON_OPTS=--wrap-mode=default -Dman=true

ifneq ($(filter pkg.phoc.embedwlroots,$(DEB_BUILD_PROFILES)),)
    MESON_OPTS += -Dembed-wlroots=enabled --default-library=static
else
    MESON_OPTS += -Dembed-wlroots=disabled
endif

ifneq ($(filter pkg.phoc.sanitizers,$(DEB_BUILD_PROFILES)),)
    MESON_OPTS += -Db_sanitize=address,undefined
    # workaround false positives with Byzantium's GCC version
    CFLAGS += -Wno-stringop-overflow -Wno-array-bounds -Wno-restrict
endif

ifneq ($(filter pkg.phoc.trace,$(DEB_BUILD_PROFILES)),)
    MESON_OPTS += -Ddtrace=enabled
endif

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- $(MESON_OPTS)

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp

override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
        LC_ALL=C.UTF-8 xvfb-run ninja -C _build test
endif
