#!/usr/bin/make -f

export DH_VERBOSE = 1

include /usr/share/dpkg/pkg-info.mk
export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
export DEB_HOST_RUST_TYPE DEB_HOST_GNU_TYPE
# temporary fix on i386
# should be removed once https://github.com/briansmith/ring/issues/1999 is
# fixed
ifeq "$(shell dpkg-architecture -q DEB_HOST_ARCH)" "i386"
	export RUSTFLAGS=-C target-feature=+sse2
endif
#export RUSTFLAGS=-C linker=bpf-linker'

export HOME=$(CURDIR)/debian/home
export RUSTC_BOOTSTRAP=1
export CARGO_HOME=$(CURDIR)/debian/cargo_home
export DEB_CARGO_CRATE=mitmproxy_rs_$(DEB_VERSION_UPSTREAM)
export RUST_BACKTRACE=1


export CARGO=/usr/share/cargo/bin/cargo

%:
	dh $@ --with python3 #--buildsystem=pybuild --sourcedirectory=mitmproxy-linux

execute_after_dh_auto_clean:
	rm -f Cargo.lock

override_dh_auto_configure:
	mkdir -p $(CARGO_HOME)
	dh_auto_configure
	#rustup install stable
	rustup toolchain install 1.88 --component rust-src

override_dh_auto_build:
#	cargo install bpf-linker
	cargo build  --manifest-path Cargo.toml

execute_after_dh_install:
	mkdir -p debian/python3-mitmproxy-rs/usr/lib/python3/dist-packages/mitmproxy_rs
	mv target/debug/libmitmproxy_rs*.so debian/python3-mitmproxy-rs/usr/lib/python3/dist-packages/mitmproxy_rs/mitmproxy_rs.abi3.so
