.PHONY: help all clean test build release lint typecheck fmt check-fmt check-ripgrep check-static-regexes markdownlint nixie
APP ?= mdtablefix
CARGO ?= $(or $(shell command -v cargo 2>/dev/null),$(HOME)/.cargo/bin/cargo)
BUILD_JOBS ?=
CLIPPY_FLAGS ?= --all-targets --all-features -- -D warnings
MDLINT ?= $(or $(shell command -v markdownlint-cli2 2>/dev/null),$(HOME)/.bun/bin/markdownlint-cli2)
NIXIE ?= nixie
RG ?= rg
build: target/debug/$(APP)
release: target/release/$(APP)
all: release
clean:
$(CARGO) clean
test:
RUSTFLAGS="-D warnings" $(CARGO) test --all-targets --all-features $(BUILD_JOBS)
target/%/$(APP):
$(CARGO) build $(BUILD_JOBS) $(if $(findstring release,$(@)),--release) --bin $(APP)
lint: check-static-regexes
$(CARGO) clippy $(CLIPPY_FLAGS)
typecheck:
$(CARGO) check --all-targets --all-features $(BUILD_JOBS)
fmt:
$(CARGO) fmt --all
mdformat-all
check-fmt:
$(CARGO) fmt --all -- --check
check-ripgrep:
@command -v "$(firstword $(RG))" >/dev/null 2>&1 || { \
echo "ripgrep (rg) is required for static-regex linting" >&2; \
exit 1; \
}
check-static-regexes: check-ripgrep
@status=0; \
$(RG) -U --glob '*.rs' '\bstatic\b[^;=]*=\s*(?:[[:alnum:]_]+::)*LazyLock::new\s*\(\s*\|\|\s*(\{\s*)?(?:[[:alnum:]_]+::)*Regex::new' . || status=$$?; \
case $$status in \
0) echo "static regular expressions must use lazy_regex!"; exit 1 ;; \
1) ;; \
*) echo "failed to scan Rust sources (rg exit $$status)" >&2; exit $$status ;; \
esac
markdownlint:
$(MDLINT) "**/*.md"
nixie:
nixie --no-sandbox
help:
@grep -E '^[a-zA-Z_-]+:.*?##' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS=":"; printf "Available targets:\n"} {printf " %-20s %s\n", $$1, $$2}'