#!/usr/bin/make -f

export DH_VERBOSE = 1
export CARGO_HOME = $(CURDIR)/debian/.cargo-home

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
  NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
  CARGO_JOBS = -j $(NUMJOBS)
endif

%:
	dh $@

override_dh_auto_configure:
	mkdir -p $(CARGO_HOME)
	printf '[source.crates-io]\nreplace-with = "vendored-sources"\n\n[source.vendored-sources]\ndirectory = "$(CURDIR)/vendor"\n' > $(CARGO_HOME)/config.toml

override_dh_auto_build:
	CARGO_PROFILE_RELEASE_DEBUG=true CARGO_PROFILE_RELEASE_STRIP=false cargo build $(CARGO_JOBS) --release --offline --locked -p yara-x-cli

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	cargo test $(CARGO_JOBS) --offline --locked -p yara-x-cli -p yara-x
endif

override_dh_auto_install:
	install -Dm 0755 target/release/yr debian/yara-x/usr/bin/yr
	install -d debian/yara-x/usr/share/bash-completion/completions
	./target/release/yr completion bash > debian/yara-x/usr/share/bash-completion/completions/yr

override_dh_auto_clean:
	rm -rf target debian/.cargo-home
	dh_auto_clean
