.PHONY: check build build-wasm package developer-sign clean

PACKAGE_ID := example_wasm_plugin
WASM := target/wasm32-unknown-unknown/release/example_wasm_plugin.wasm
DIST := dist
AIP := $(DIST)/$(PACKAGE_ID).aip
PACKER ?= ../../../tools/aip-pack-for-developers
CARGO_FLAGS ?=
DEVELOPER_PUBLIC_KEY ?= ../../../developer-keys/developer-signing-public.key
DEVELOPER_PRIVATE_KEY ?= ../../../developer-keys/developer-signing-private.key

check:
	cargo check $(CARGO_FLAGS) --manifest-path Cargo.toml

build: build-wasm

build-wasm:
	rustup target add wasm32-unknown-unknown
	cargo build $(CARGO_FLAGS) --manifest-path Cargo.toml --target wasm32-unknown-unknown --release
	mkdir -p $(DIST)
	cp $(WASM) plugin.wasm

package: build-wasm developer-sign

developer-sign:
	mkdir -p $(DIST)
	$(PACKER) \
		developer-sign \
		--root . \
		--output $(AIP) \
		--developer-public-key $(DEVELOPER_PUBLIC_KEY) \
		--developer-private-key $(DEVELOPER_PRIVATE_KEY)
	@echo "$(AIP)"

clean:
	rm -rf target dist plugin.wasm
