#!/usr/bin/make -f

include /usr/share/dpkg/default.mk
include /usr/share/rustc/architecture.mk
export DEB_HOST_RUST_TYPE

export DEB_HOST_RUST_TYPE DEB_HOST_GNU_TYPE
export PATH := /usr/share/cargo/bin:$(PATH)
export CARGO=/usr/share/cargo/bin/cargo
export CARGO_HOME=$(CURDIR)/debian/cargo_home
export DEB_CARGO_CRATE=$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM)
export DEB_BUILD_MAINT_OPTIONS=hardening=+all
HOST_ARCH_BITS := $(shell dpkg-architecture -qDEB_HOST_ARCH_BITS)

%:
	dh $@

execute_before_dh_auto_configure:
	mv Cargo.lock Cargo.lock.orig
	cargo prepare-debian debian/cargo_registry --link-from-system

override_dh_auto_configure:
	dh_auto_configure -- -DTASK_RCDIR=share/taskwarrior -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DSYSTEM_CORROSION=ON

execute_after_dh_auto_install:
	# Needed by #710321
	rm -rf debian/taskwarrior/usr/share/doc/task
	rm -f debian/taskwarrior/usr/share/taskwarrior/refresh
	CARGO_BUILT_USING_TARGET_DIR="$(wildcard obj-${DEB_HOST_GNU_TYPE}/cargo/task_*/$(DEB_HOST_RUST_TYPE)/release)" /usr/share/cargo/bin/dh-cargo-built-using taskwarrior

override_dh_auto_test:
	# a number of tests are predicated on 64-bit time_t etc; rather than
	# needing lots of special skip rules for what are at best marginal
	# targets, just skip testing on non-64-bit arches
ifeq ($(HOST_ARCH_BITS),64)
	cp test/bash_tap_tw.sh test/bash_tap.sh obj-${DEB_HOST_GNU_TYPE}/
	cp doc/rc/default.theme obj-${DEB_HOST_GNU_TYPE}/test/
	dh_auto_test
endif

execute_before_dh_auto_clean:
	if [ -f Cargo.lock.orig ] ; then mv Cargo.lock.orig Cargo.lock ; fi

# vim:ts=4 sw=4 noet
