#!/usr/bin/make -f

export CARGO_HOME = $(CURDIR)/debian/cargo

%:
	dh $@

override_dh_auto_build:
	# Generate vendor if not present (for offline builds)
	if [ ! -d vendor ]; then \
		cargo vendor; \
		mkdir -p .cargo; \
		echo '[source.crates-io]' > .cargo/config.toml; \
		echo 'replace-with = "vendored-sources"' >> .cargo/config.toml; \
		echo '[source.vendored-sources]' >> .cargo/config.toml; \
		echo 'directory = "vendor"' >> .cargo/config.toml; \
		for f in vendor/*/.cargo-checksum.json; do \
			sed -i 's/"files":{[^}]*}/"files":{}/' "$$f" || true; \
		done; \
	fi
	export CARGO_NET_OFFLINE=true
	cargo build --release --verbose --offline

override_dh_auto_install:
	install -D -m 755 target/release/lsport debian/lsport/usr/bin/lsport
	install -D -m 644 debian/lsport.1 debian/lsport/usr/share/man/man1/lsport.1

override_dh_auto_clean:
	cargo clean || true
	rm -rf $(CARGO_HOME)
	rm -rf vendor .cargo

override_dh_auto_test:
	# Skip tests during package build
