REGISTRY ?= /usr/share/cargo/registry/ltk
DOCDIR   ?= /usr/share/doc/libltk-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 doctest-md audit doc install examples clean distclean

all:
	cargo build --release

test:
	cargo test

# Typecheck the `no_run` snippets in docs/*.md by feeding each markdown
# file to `rustdoc --test`. Catches API drift in cookbook + widget
# reference: drops a renamed builder, removed function, etc. surface
# here just like `cargo test --doc` does for in-source doctests.
doctest-md:
	./scripts/doctest-md.sh

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 Cargo.toml liberux.toml $(REGISTRY)/
	cp debian/cargo-checksum.json $(REGISTRY)/.cargo-checksum.json
	install -d $(DOCDIR)
	cp -r target/doc/* $(DOCDIR)/

examples:
	LTK_THEMES_DIR=themes cargo run --release --example showcase
	LTK_THEMES_DIR=themes cargo run --release --example inputs
	LTK_THEMES_DIR=themes cargo run --release --example scroll
	LTK_THEMES_DIR=themes cargo run --release --example sliders
	LTK_THEMES_DIR=themes cargo run --release --example combo
	LTK_THEMES_DIR=themes cargo run --release --example mini_shell
	LTK_THEMES_DIR=themes cargo run --release --example widgets
	LTK_THEMES_DIR=themes cargo run --release --example pickers
	LTK_THEMES_DIR=themes cargo run --release --example dialog
	LTK_THEMES_DIR=themes cargo run --release --example carousel

clean:
	dh_clean
	cargo clean
	rm -rf target

distclean: clean
	rm -f Cargo.lock
