EX=demo

all: library examples

.PHONY: examples
examples:
	cargo +nightly build --examples --release --target=armv7-unknown-linux-gnueabihf

library:
	cargo +nightly build --release --target=armv7-unknown-linux-gnueabihf

test:
	# Notice we aren't using the armv7 target here
	cargo +nightly test

DEVICE_IP ?= "10.11.99.1"
run: examples
	ssh root@$(DEVICE_IP) 'kill -9 `pidof $(EX)` || true; systemctl stop xochitl || true'
	scp ./target/armv7-unknown-linux-gnueabihf/release/examples/$(EX) root@$(DEVICE_IP):~/
	ssh root@$(DEVICE_IP) './$(EX)' && $(MAKE) start-xochitl

spy-xochitl: examples
	ssh root@$(DEVICE_IP) 'systemctl stop xochitl'
	scp ./target/armv7-unknown-linux-gnueabihf/release/examples/libspy.so root@$(DEVICE_IP):~/
	ssh root@$(DEVICE_IP) 'LD_PRELOAD="/home/root/libspy.so" xochitl'

intercept-xochitl: examples
	ssh root@$(DEVICE_IP) 'systemctl stop xochitl'
	scp ./target/armv7-unknown-linux-gnueabihf/release/examples/libinterceptor.so root@$(DEVICE_IP):~/
	ssh root@$(DEVICE_IP) 'LD_PRELOAD="/home/root/libinterceptor.so" xochitl'

start-xochitl:
	ssh root@$(DEVICE_IP) 'kill -9 `pidof demo` || true; systemctl start xochitl'
