sqlx:
	cargo sqlx database drop -y
	cargo sqlx database create
	cargo sqlx migrate run
	cargo sqlx prepare --workspace

build-rpi:
	cross build --target arm-unknown-linux-gnueabihf

emgauwa-%.json: config/%.pkl
	pkl eval -f json -o $@ $<

configs:
	$(MAKE) emgauwa-core.json
	$(MAKE) emgauwa-controller.json

clean:
	rm -f emgauwa-controller.json
	rm -f emgauwa-controller.sqlite
	rm -f emgauwa-core.json
	rm -f emgauwa-core.sqlite
	rm -f emgauwa-dev.sqlite

emgauwa-controller_%:
	$(TOOL) build --target $* --release --bin emgauwa-controller
	mkdir -p out/releases
	cp target/$*/release/emgauwa-controller out/releases/emgauwa-controller_$*

emgauwa-core_%:
	$(TOOL) build --target $* --release --bin emgauwa-core
	mkdir -p out/releases
	cp target/$*/release/emgauwa-core out/releases/emgauwa-core_$*

emgauwa_%:
	$(MAKE) emgauwa-controller_$*
	$(MAKE) emgauwa-core_$*

releases:
	$(MAKE) TOOL=cross emgauwa_arm-unknown-linux-gnueabihf
	$(MAKE) TOOL=cargo emgauwa_x86_64-unknown-linux-gnu
	$(MAKE) TOOL=cross emgauwa_x86_64-unknown-linux-musl