#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk
include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/buildflags.mk
include /usr/share/rustc/architecture.mk

export DEB_HOST_RUST_TYPE DEB_HOST_GNU_TYPE
export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS RUSTFLAGS

export CARGO_HOME = $(CURDIR)/debian/cargo_home
CARGO = $(CURDIR)/debian/bin/cargo
export DEB_CARGO_PACKAGE=cargo
export DEB_CARGO_CRATE=cargo_$(DEB_VERSION_UPSTREAM)

# Disable tests on powerpc and powerpcspe for now.
# cbmuser requested this and will fix the errors later
# TODO: once powerpc powerpcspe test failures are fixed drop this
ifneq (,$(filter $(DEB_BUILD_ARCH), powerpc powerpcspe))
	POST_TEST = || true
endif

%:
	dh $@ --with bash-completion

override_dh_auto_configure:
	$(CARGO) prepare-debian $(CURDIR)/vendor

override_dh_auto_build-arch:
	$(CARGO) build

override_dh_auto_build-indep:
	$(CARGO) doc

override_dh_auto_test:
	CFG_DISABLE_CROSS_TESTS=1 $(CARGO) test $(POST_TEST)

override_dh_auto_install:
	$(CARGO) install

override_dh_auto_clean:
	$(CARGO) clean

override_dh_clean:
	# Upstream contains a lot of these
	dh_clean -XCargo.toml.orig
