# Development tasks. # # make list the targets # make test run the suite # make lint luacheck if installed, otherwise luac -p; touches nothing # make build byte-compile every module into build/ # # LUA pins the interpreter. It defaults to `lua`; override it to run the suite # on another one, e.g. `make test LUA=lua5.4` or `make test LUA=luajit`. LUA ?= lua LUAC ?= luac SOURCES := cepis.lua $(wildcard cepis/*.lua) ALL_LUA := $(SOURCES) $(wildcard test/*.lua) .DEFAULT_GOAL := help .PHONY: help test lint format build check clean help: @echo 'Targets:' @echo ' test run the test suite (LUA=$(LUA))' @echo ' lint luacheck when installed, else $(LUAC) -p (read-only)' @echo ' format apply stylua when installed (writes)' @echo ' build byte-compile every module into build/' @echo ' check lint + test + build, in that order' @echo ' clean remove build artefacts' @echo @echo 'Override the interpreter with e.g. make test LUA=luajit' test: @$(LUA) test/run.lua # Read-only by design, so it is safe in CI and in a pre-commit hook. luacheck # is the real linter; luac -p is the fallback that needs nothing installed and # still catches a syntax error before the suite does. lint: @if command -v luacheck >/dev/null 2>&1; then \ luacheck $(ALL_LUA); \ else \ echo '==> luacheck not installed, checking syntax with $(LUAC) -p'; \ $(LUAC) -p $(ALL_LUA) && echo 'syntax ok'; \ fi format: @if command -v stylua >/dev/null 2>&1; then \ stylua $(ALL_LUA); \ else \ echo '==> stylua not installed, nothing was formatted'; \ fi build: @mkdir -p build @for source in $(SOURCES); do \ $(LUAC) -o "build/$$(echo $$source | tr / _)c" "$$source" || exit 1; \ done @echo 'byte-compiled into build/' # The order matters: lint is the fastest to fail, so a broken run reports the # cheapest problem first. check: lint test build clean: rm -rf build