#!/usr/bin/make -f

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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# OBS has no network at build time, so cargo builds from the vendor/ directory
# the orig tarball carries and never from crates.io (debian/README.source).
# CARGO_HOME has to be inside the tree as well: the build user on an OBS worker
# has no writable home.
export CARGO_HOME = $(CURDIR)/debian/cargo_home
export CARGO_NET_OFFLINE = true

# cargo's release profile carries no debug info, which would leave dh_strip
# producing an empty -dbgsym package.
export CARGO_PROFILE_RELEASE_DEBUG = true

# build.rs asks git for the version string; a source package has no .git, so
# debian/patches/0001 reads it from here instead.
export HPSP_VERSION = $(DEB_VERSION_UPSTREAM:+ds=)

%:
	dh $@

override_dh_auto_build:
	cargo build --release --locked --offline
	target/release/hyprland-preview-share-picker schema >target/schema.json

override_dh_auto_test:
	cargo test --release --locked --offline

# dh_clean deletes every *.orig file in the tree, and cargo vendor ships a
# Cargo.toml.orig in each crate that its .cargo-checksum.json lists, so a build
# that runs clean first would refuse every vendored crate.
override_dh_clean:
	dh_clean -XCargo.toml.orig

override_dh_auto_clean:
	cargo clean --offline
	$(RM) -r $(CARGO_HOME)
