#!/usr/bin/make -f

include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/pkg-info.mk
include /usr/share/dpkg/architecture.mk
include /usr/share/rustc/architecture.mk
export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS DEB_HOST_RUST_TYPE DEB_HOST_GNU_TYPE
export PATH := /usr/share/cargo/bin:$(PATH)
export CARGO_HOME = $(CURDIR)/debian/cargo_home
export DEB_CARGO_CRATE = task
export DEB_BUILD_MAINT_OPTIONS=hardening=+all
HOST_ARCH_BITS := $(shell dpkg-architecture -qDEB_HOST_ARCH_BITS)
DPKG_EXPORT_BUILDFLAGS=1

export CMAKE_BUILD_TYPE=release

%:
	dh $@ --with shell_completions

override_dh_auto_clean:
	dh_clean
	rm -f cmake.h commit.h test/basetest/*.pyc test/simpletap/*.pyc
	rm -rf obj-*

execute_before_dh_auto_configure:
	cargo prepare-debian debian/cargo_registry --link-from-system
	cargo generate-lockfile --offline

override_dh_auto_configure:
	find . -type f -exec sed -i '1s|^#!/usr/bin/env python3|#!/usr/bin/python3|;' {} \;
	dh_auto_configure -- -DTASK_RCDIR=share/taskwarrior -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DSYSTEM_CORROSION=ON

override_dh_auto_install:
	# Needed by #710321
	dh_auto_install
	rm -rf debian/taskwarrior/usr/share/doc/task
	rm -f debian/taskwarrior/usr/share/taskwarrior/refresh

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)
	dh_auto_test
endif

.PHONY: get-orig-source
get-orig-source:
	sh ./debian/get-orig-source.sh $(DEB_VERSION_UPSTREAM)

# vim:ts=4 sw=4 noet
