#!/usr/bin/make -f
%:
	dh $@

override_dh_auto_configure:

override_dh_auto_build:
	# 1. Strip out Cargo.toml.orig reference cleanly from all JSON checksum structures
	find vendor/ -name .cargo-checksum.json -exec sed -i -E 's/"Cargo\.toml\.orig"\s*:\s*"[^"]*"\s*,?//g' {} +
	find vendor/ -name .cargo-checksum.json -exec sed -i -E 's/,\s*"Cargo\.toml\.orig"\s*:\s*"[^"]*"//g' {} +

	# 2. If running on older Cargo (like Debian 12), force-inject the unstable edition opt-in line
	@if cargo --version | grep -qE "1\.(7[0-9])\."; then \
		echo "🔧 Older Cargo detected. Injecting unstable-editions feature block..."; \
		sed -i '1s/^/cargo-features = ["unstable-editions"]\n/' Cargo.toml; \
		export CARGO_Z_FLAG="-Z unstable-options"; \
	fi; \
	\
	# 3. Compile using the offline boundaries and pass any unstable flags if needed
	cargo build --offline --release --no-default-features --features "alsa-backend native-tls with-avahi" $$CARGO_Z_FLAG

override_dh_auto_install:
	install -D -m 755 target/release/librespot debian/librespot/usr/bin/librespot
