REGISTRY ?= /usr/share/cargo/registry/ltk-webkit
DOCDIR   ?= /usr/share/doc/libltk-webkit-doc/html

# Targets are recipes, not files. Listing them as PHONY tells make to
# ignore filesystem entries with the same name — without this `examples`
# silently no-ops because the `examples/` directory exists, and `doc`
# would do the same once `target/doc` is around.
.PHONY: all test audit doc install examples clean distclean

all:
	cargo build --release

test:
	cargo test

audit:
	@command -v cargo-audit >/dev/null 2>&1 || cargo install cargo-audit --locked
	cargo audit

doc:
	cargo doc --no-deps

install: doc
	install -d $(REGISTRY)
	cp -r src crates Cargo.toml SPIKE.md $(REGISTRY)/
	cp debian/cargo-checksum.json $(REGISTRY)/.cargo-checksum.json
	install -d $(DOCDIR)
	cp -r target/doc/* $(DOCDIR)/

examples:
	cargo run --release --example spike
	cargo run --release --example buffer_import
	# `render_in_window` is the interactive demo — exits when the user
	# closes the window. Tolerate non-zero exit codes from any example
	# because libwpewebkit can race during process teardown and
	# segfault on its way out, which is harmless for a demo binary.
	-cargo run --release --example render_in_window

clean:
	dh_clean
	cargo clean
	rm -rf target

distclean: clean
	rm -f Cargo.lock
