#!/usr/bin/make -f

# Enable verbose build by default, disable when terse is specified.
ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
VERBOSE=1
else
VERBOSE=0
endif

unexport ELF_PACKAGE_METADATA

%:
	dh $@

override_dh_auto_build:
	# Always set CROSS_COMPILE, which also works for native builds.
	# Strip binaries, since dh_strip may not be called for arch:all.
	CROSS_COMPILE=riscv64-linux-gnu- make \
		V=$(VERBOSE) \
		FW_PAYLOAD=n \
		O=debian/build64 \
		PLATFORM=generic ; \

	CROSS_COMPILE=riscv64-linux-gnu- make \
		V=$(VERBOSE) \
		FW_PAYLOAD=n \
		O=debian/build32 \
		PLATFORM_RISCV_XLEN=32 \
		PLATFORM=generic ; \

	for elffile in debian/build*/platform/generic/firmware/fw_*.elf ; do \
		riscv64-linux-gnu-strip --remove-section=.comment \
			--remove-section=.note \
			$${elffile} ; \
	done

override_dh_installdocs:
	dh_installdocs --exclude=doxygen.cfg

override_dh_auto_install:
	dh_auto_install --sourcedir=debian/build64
	dh_auto_install --sourcedir=debian/build32

override_dh_auto_clean:
	dh_auto_clean
	rm -rf debian/build32 debian/build64