#!/usr/bin/make -f

export DH_VERBOSE = 1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic

export CXXFLAGS +=-Wno-error=unused-but-set-variable \
		  -Wno-error=unused-variable \
		  -Wno-error=mismatched-new-delete \
		  -Wno-error=sign-compare \
		  -Wno-error=reorder \
		  -Wno-error=deprecated-declarations

include /usr/share/dpkg/pkg-info.mk
export DEB_VERSION_UPSTREAM

CONFIGURE_ARGS = -DCMAKE_BUILD_TYPE=Debug \
	-DLIB_SUFFIX=/$(DEB_HOST_MULTIARCH)

ifeq ($(DEB_HOST_ARCH),arm64)
	CONFIGURE_ARGS += -DXRT_EDGE_BUILD=yes
endif

%:
#ifeq ($(DEB_HOST_ARCH),arm64)
#	dh $@ --with dkms
#else
	dh $@
#endif

override_dh_auto_configure:
	dh_auto_configure --sourcedir=src -- $(CONFIGURE_ARGS)

override_dh_auto_build:
	dh_auto_build --sourcedir=src

override_dh_auto_install:
	dh_auto_install --sourcedir=src

	rm -rf $(CURDIR)/debian/tmp/usr/bin/unwrapped/

#ifeq ($(DEB_HOST_ARCH),arm64)
#	dh_install -p zocl-edge-dkms -Xpcie -Xtools -XCMakeLists.txt \
#		src/runtime_src/core/* usr/src/zocl-edge-$(DEB_VERSION_UPSTREAM)/
#endif

	rm -rf $(CURDIR)/debian/tmp/usr/src

	# Fix lintian: script-with-language-extension
ifeq ($(DEB_HOST_ARCH),amd64)
	mv $(CURDIR)/debian/tmp/usr/bin/plp_program.sh \
		$(CURDIR)/debian/tmp/usr/bin/plp_program
	mv $(CURDIR)/debian/tmp/usr/bin/mpd \
		$(CURDIR)/debian/tmp/usr/bin/xrt_mpd
endif

override_dh_missing:

override_dh_auto_test:
	-dh_auto_test

#override_dh_dkms:
#ifeq ($(DEB_HOST_ARCH),arm64)
#	dh_dkms -p zocl-edge-dkms -V $(DEB_VERSION_UPSTREAM)
#endif
