#!/usr/bin/make -f
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DH_VERBOSE = 1

# filter incompatible options from affecting device code
CXXFLAGS := $(subst -fstack-protector-strong,-Xarch_host -fstack-protector-strong,$(CXXFLAGS))
CXXFLAGS := $(subst -fcf-protection,-Xarch_host -fcf-protection,$(CXXFLAGS))

OPTS_COMMON = \
    -DRPP_AUDIO_SUPPORT=OFF \
    -DCMAKE_CXX_COMPILER=$(shell hipconfig --hipclangpath)/clang++ \

OPTS_HIP = \
    -DBACKEND=HIP \
    -DGPU_TARGETS="$(shell rocm-target-arch --sep ';')" \

OPTS_OCL = \
    -DBACKEND=OPENCL \
    -DRPP_LEGACY_SUPPORT=ON \

OPTS_CPU = \
    -DBACKEND=CPU \

BUILDDIR_HIP = build-hip
BUILDDIR_OCL = build-ocl
BUILDDIR_CPU = build-cpu

%:
	dh $@

override_dh_auto_clean:
	dh_auto_clean --builddir=$(BUILDDIR_HIP)
	dh_auto_clean --builddir=$(BUILDDIR_OCL)
	dh_auto_clean --builddir=$(BUILDDIR_CPU)

override_dh_auto_configure:
	dh_auto_configure --builddir=$(BUILDDIR_HIP) -- $(OPTS_COMMON) $(OPTS_HIP)
	dh_auto_configure --builddir=$(BUILDDIR_OCL) -- $(OPTS_COMMON) $(OPTS_OCL)
	dh_auto_configure --builddir=$(BUILDDIR_CPU) -- $(OPTS_COMMON) $(OPTS_CPU)

override_dh_auto_build:
	dh_auto_build --builddir=$(BUILDDIR_HIP)
	dh_auto_build --builddir=$(BUILDDIR_OCL)
	dh_auto_build --builddir=$(BUILDDIR_CPU)

override_dh_auto_install:
	dh_auto_install --builddir=$(BUILDDIR_HIP) --destdir=debian/tmp/$(BUILDDIR_HIP)
	dh_auto_install --builddir=$(BUILDDIR_OCL) --destdir=debian/tmp/$(BUILDDIR_OCL)
	dh_auto_install --builddir=$(BUILDDIR_CPU) --destdir=debian/tmp/$(BUILDDIR_CPU)

override_dh_auto_test:
	:

# dwz doesn't fully support DWARF-5 yet, see #1016936
override_dh_dwz:
	:

override_dh_gencontrol:
	dh_gencontrol -- -Vrocm:GPU-Architecture="$(shell rocm-target-arch)"
