-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
139 lines (112 loc) · 3.56 KB
/
Copy pathMakefile
File metadata and controls
139 lines (112 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# LuaScript — Makefile
#
# Thin wrapper over the `go` toolchain. Everything still works with plain `go`
# commands (see CLAUDE.md / README); these targets just bundle the common ones.
#
# make # build the binary
# make run FILE=examples/05_types.lsc
# make test # full suite
# make help # list every target
# ---- configuration ---------------------------------------------------------
PKG := ./cmd/luascript
BINARY := luascript
# Windows produces a .exe; detect it so `make run`/`make clean` line up.
ifeq ($(OS),Windows_NT)
BINARY := luascript.exe
endif
GO ?= go
GOFLAGS ?=
# FILE is the script `make run` executes; override on the command line.
FILE ?= examples/01_basics.lsc
# PKGS/RUN target a single package/test for the focused test targets.
PKGS ?= ./...
RUN ?=
# FUZZ selects which fuzz target `make fuzz` exercises (FuzzLexer / FuzzParser).
FUZZ ?= FuzzParser
FUZZPKG ?= ./internal/compiler/parser/
FUZZTIME ?= 30s
.DEFAULT_GOAL := build
# ---- build / run -----------------------------------------------------------
## build: compile the interpreter to ./$(BINARY)
.PHONY: build
build:
$(GO) build $(GOFLAGS) -o $(BINARY) $(PKG)
## run: run a script (make run FILE=examples/05_types.lsc)
.PHONY: run
run:
$(GO) run $(PKG) $(FILE)
## repl: start the interactive REPL
.PHONY: repl
repl:
$(GO) run $(PKG) -i
## install: install the binary into $GOBIN / $GOPATH/bin
.PHONY: install
install:
$(GO) install $(PKG)
# ---- tests -----------------------------------------------------------------
## test: run the full test suite
.PHONY: test
test:
$(GO) test $(PKGS)
## test-v: run the full test suite, verbose
.PHONY: test-v
test-v:
$(GO) test -v $(PKGS)
## test-race: run the suite with the race detector
.PHONY: test-race
test-race:
$(GO) test -race $(PKGS)
## test-one: run one package/test (make test-one PKGS=./internal/vm/ RUN=TestFoo)
.PHONY: test-one
test-one:
$(GO) test -v $(PKGS) $(if $(RUN),-run $(RUN),)
## cover: write a coverage profile and print the summary
.PHONY: cover
cover:
$(GO) test -coverprofile=coverage.out $(PKGS)
$(GO) tool cover -func=coverage.out | tail -1
## cover-html: open the coverage profile in a browser
.PHONY: cover-html
cover-html: cover
$(GO) tool cover -html=coverage.out
## bench: run benchmarks (the *_bench_test.go files live under ./internal/vm)
.PHONY: bench
bench:
$(GO) test -bench=. -benchmem $(if $(filter ./...,$(PKGS)),./internal/vm/,$(PKGS))
## fuzz: run a fuzz target (make fuzz FUZZ=FuzzLexer FUZZPKG=./internal/compiler/lexer/)
.PHONY: fuzz
fuzz:
$(GO) test -fuzz=$(FUZZ) -fuzztime=$(FUZZTIME) $(FUZZPKG)
# ---- quality ---------------------------------------------------------------
## fmt: format all Go sources
.PHONY: fmt
fmt:
$(GO) fmt ./...
## fmt-check: fail if any Go source is not gofmt-clean
.PHONY: fmt-check
fmt-check:
@unformatted=$$(gofmt -l .); \
if [ -n "$$unformatted" ]; then \
echo "These files are not gofmt-clean:"; echo "$$unformatted"; exit 1; \
fi
## vet: run go vet
.PHONY: vet
vet:
$(GO) vet ./...
## tidy: tidy and verify go.mod / go.sum
.PHONY: tidy
tidy:
$(GO) mod tidy
## check: fmt-check + vet + test (the pre-commit gate)
.PHONY: check
check: fmt-check vet test
# ---- housekeeping ----------------------------------------------------------
## clean: remove build artifacts
.PHONY: clean
clean:
$(GO) clean
rm -f $(BINARY) coverage.out
## help: list available targets
.PHONY: help
help:
@grep -hE '^## ' $(MAKEFILE_LIST) | sed -e 's/## //' | sort | awk -F': ' '{ printf " \033[36m%-14s\033[0m %s\n", $$1, $$2 }'