#!/usr/bin/make -f

export DEB_CARGO_PACKAGE=cosmic-comp
export CARGO_HOME=$(CURDIR)/debian/cargo-home

%:
	dh $@

override_dh_auto_clean:
	# Avoid upstream distclean which removes .cargo and vendor
	:

override_dh_auto_configure:
	mkdir -p .cargo
	# Full vendor configuration including all Git overrides for offline build
	( \
		echo '[source.crates-io]'; \
		echo 'replace-with = "vendored-sources"'; \
		echo '[source.vendored-sources]'; \
		echo 'directory = "vendor"'; \
		echo ''; \
		echo '[source."git+https://github.com/Drakulix/id-tree.git?branch=feature%2Fcopy_clone#632a57d6d49160e18d7300fa7edae52281ec5482"]'; \
		echo 'git = "https://github.com/Drakulix/id-tree.git"'; \
		echo 'branch = "feature/copy_clone"'; \
		echo 'replace-with = "vendored-sources"'; \
		echo '[source."git+https://github.com/jackpot51/rust-atomicwrites#043ab4859d53ffd3d55334685303d8df39c9f768"]'; \
		echo 'git = "https://github.com/jackpot51/rust-atomicwrites"'; \
		echo 'replace-with = "vendored-sources"'; \
		echo '[source."git+https://github.com/pop-os//cosmic-protocols?branch=main#160b086abe03cd34a8a375d7fbe47b24308d1f38"]'; \
		echo 'git = "https://github.com/pop-os//cosmic-protocols"'; \
		echo 'branch = "main"'; \
		echo 'replace-with = "vendored-sources"'; \
		echo '[source."git+https://github.com/pop-os/cosmic-randr/#6e8e795970fa06d434af22775e415b517f7552d3"]'; \
		echo 'git = "https://github.com/pop-os/cosmic-randr/"'; \
		echo 'replace-with = "vendored-sources"'; \
		echo '[source."git+https://github.com/pop-os/cosmic-settings-daemon#defa9f790432c70054ca1f39737d879ada5d0252"]'; \
		echo 'git = "https://github.com/pop-os/cosmic-settings-daemon"'; \
		echo 'replace-with = "vendored-sources"'; \
		echo '[source."git+https://github.com/pop-os/cosmic-text.git#f31b9d86959676d97fde54ff5907a58ab4308897"]'; \
		echo 'git = "https://github.com/pop-os/cosmic-text.git"'; \
		echo 'replace-with = "vendored-sources"'; \
		echo '[source."git+https://github.com/pop-os/dbus-settings-bindings#0fa672f8dadb884001ef9a251b149ed432879629"]'; \
		echo 'git = "https://github.com/pop-os/dbus-settings-bindings"'; \
		echo 'replace-with = "vendored-sources"'; \
		echo '[source."git+https://github.com/pop-os/freedesktop-icons#7a61a704f6d1ec41f71cbe766e3cc484858523fa"]'; \
		echo 'git = "https://github.com/pop-os/freedesktop-icons"'; \
		echo 'replace-with = "vendored-sources"'; \
		echo '[source."git+https://github.com/pop-os/glyphon.git?tag=iced-0.14-dev#6ef9d12a20cfd0f7bdf38136a26ded9f7459ec8b"]'; \
		echo 'git = "https://github.com/pop-os/glyphon.git"'; \
		echo 'tag = "iced-0.14-dev"'; \
		echo 'replace-with = "vendored-sources"'; \
		echo '[source."git+https://github.com/pop-os/libcosmic/#384e8f6e219bb458720eafa5bb971b832c057f23"]'; \
		echo 'git = "https://github.com/pop-os/libcosmic/"'; \
		echo 'replace-with = "vendored-sources"'; \
		echo '[source."git+https://github.com/pop-os/smithay-clipboard?tag=pop-dnd-5#5a3007def49eb678d1144850c9ee04b80707c56a"]'; \
		echo 'git = "https://github.com/pop-os/smithay-clipboard"'; \
		echo 'tag = "pop-dnd-5"'; \
		echo 'replace-with = "vendored-sources"'; \
		echo '[source."git+https://github.com/pop-os/softbuffer?tag=cosmic-4.0#a3f77e251e7422803f693df6e3fc313c010c4dcb"]'; \
		echo 'git = "https://github.com/pop-os/softbuffer"'; \
		echo 'tag = "cosmic-4.0"'; \
		echo 'replace-with = "vendored-sources"'; \
		echo '[source."git+https://github.com/pop-os/window_clipboard.git?tag=pop-0.13-2#6b9faab87bea9cebec6ae036906fd67fed254f5f"]'; \
		echo 'git = "https://github.com/pop-os/window_clipboard.git"'; \
		echo 'tag = "pop-0.13-2"'; \
		echo 'replace-with = "vendored-sources"'; \
		echo '[source."git+https://github.com/smithay/smithay.git?rev=da42569#da42569e7a0e1669acb1e15d96cbb500a27cb266"]'; \
		echo 'git = "https://github.com/smithay/smithay.git"'; \
		echo 'rev = "da42569"'; \
		echo 'replace-with = "vendored-sources"'; \
	) > .cargo/config.toml

override_dh_auto_build:
	cargo build --release --offline

override_dh_auto_test:
	:

override_dh_auto_install:
	mkdir -p $(CURDIR)/debian/cosmic-comp/usr/bin
	install -m755 target/release/cosmic-comp $(CURDIR)/debian/cosmic-comp/usr/bin/
