-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
194 lines (175 loc) · 5.74 KB
/
Makefile
File metadata and controls
194 lines (175 loc) · 5.74 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Luarocks path for amalg and other tools
LUAROCKS_PATH := $(shell luarocks path --lr-path 2>/dev/null)
# Lua path for local modules (src, vendor)
LUA_PATH_LOCAL := ./?.lua;./?/init.lua;./src/?.lua;./src/?/init.lua;./vendor/?.lua;$(LUAROCKS_PATH)
# Default target
.PHONY: all
all: format lint test build
# Run tests
.PHONY: test
test:
./run_tests.sh
# Run test matrix
.PHONY: test-matrix
test-matrix:
./run_tests_matrix.sh
# Run specific test suite for test matrix
.PHONY: test-matrix-%
test-matrix-%:
./run_tests_matrix.sh $*
# Run specific test suite
.PHONY: test-%
test-%:
./run_tests.sh $*
# Run benchmarks
.PHONY: bench
bench:
./run_benchmarks.sh
# Run bench matrix
.PHONY: bench-matrix
bench-matrix:
./run_benchmarks_matrix.sh
# Run specific bench suite for bench matrix
.PHONY: bench-matrix-%
bench-matrix-%:
./run_benchmarks_matrix.sh $*
# Run specific benchmark suite
.PHONY: bench-%
bench-%:
./run_benchmarks.sh $*
build/amalg.cache: src/bitn/init.lua
@echo "Generating amalgamation cache..."
@mkdir -p build
@if command -v amalg.lua >/dev/null 2>&1; then \
LUA_PATH="$(LUA_PATH_LOCAL)" lua -lamalg src/bitn/init.lua && mv amalg.cache build || exit 1; \
echo "Generated amalg.cache"; \
else \
echo "Error: amalg not found."; \
echo "Please install amalg: luarocks install amalg"; \
echo "Or run: make install-deps"; \
exit 1; \
fi
# Build single-file distributions
.PHONY: build
build: build/amalg.cache
@echo "Building single-file distribution..."
@if command -v amalg.lua >/dev/null 2>&1; then \
LUA_PATH="$(LUA_PATH_LOCAL)" amalg.lua -o build/bitn.lua -C ./build/amalg.cache || exit 1;\
echo "Built build/bitn.lua"; \
VERSION=$$(git describe --exact-match --tags 2>/dev/null || echo "dev"); \
if [ "$$VERSION" != "dev" ]; then \
echo "Injecting version $$VERSION..."; \
sed -i.bak 's/VERSION = "dev"/VERSION = "'$$VERSION'"/' build/bitn.lua && rm build/bitn.lua.bak; \
fi; \
echo "Testing version function..."; \
LUA_VERSION=$$(lua -e 'local b = require("build.bitn"); print(b.version())' 2>/dev/null || echo "test failed"); \
if [ "$$LUA_VERSION" = "$$VERSION" ]; then \
echo "Version correctly set to: $$VERSION"; \
else \
echo "Version test failed. Expected: $$VERSION, Got: $$LUA_VERSION"; \
fi; \
else \
echo "Error: amalg not found."; \
echo "Please install amalg: luarocks install amalg"; \
echo "Or run: make install-deps"; \
exit 1; \
fi
# Install all development dependencies
.PHONY: install-deps
install-deps:
@echo "Installing development dependencies..."
@echo ""
@echo "=== Installing system tools ==="
@if command -v brew >/dev/null 2>&1; then \
echo "Using Homebrew to install tools..."; \
brew install lua-language-server stylua || true; \
else \
echo "Please install the following manually:"; \
echo " - lua-language-server: https://github.com/LuaLS/lua-language-server/releases"; \
echo " - stylua: https://github.com/JohnnyMorganz/StyLua/releases"; \
echo " - luarocks: https://github.com/luarocks/luarocks/wiki/Download"; \
fi
@echo ""
@echo "=== Installing Lua tools ==="
@if command -v luarocks >/dev/null 2>&1; then \
echo "Using LuaRocks to install tools..."; \
luarocks install luacheck || exit 1; \
luarocks install amalg || exit 1; \
else \
echo "luarocks not found. Please install it first."; \
echo " macOS: brew install luarocks"; \
echo " Linux: apt-get install luarocks"; \
exit 1; \
fi
# Format Lua code with stylua
.PHONY: format
format:
@if command -v stylua >/dev/null 2>&1; then \
echo "Running stylua..."; \
stylua --indent-type Spaces --column-width 120 --line-endings Unix \
--indent-width 2 --quote-style AutoPreferDouble \
src/ 2>/dev/null; \
else \
echo "stylua not found. Install with: make install-deps"; \
exit 1; \
fi
# Check Lua formatting
.PHONY: format-check
format-check:
@if command -v stylua >/dev/null 2>&1; then \
echo "Running stylua check..."; \
stylua --check --indent-type Spaces --column-width 120 --line-endings Unix \
--indent-width 2 --quote-style AutoPreferDouble \
src/; \
else \
echo "stylua not found. Install with: make install-deps"; \
exit 1; \
fi
# Lint the code with luacheck
.PHONY: lint
lint:
@if command -v luacheck >/dev/null 2>&1; then \
echo "Running luacheck..."; \
luacheck src/; \
else \
echo "luacheck not found. Install with: make install-deps"; \
exit 1; \
fi
.PHONY: check
check: format-check lint
@echo "Code quality checks complete."
# Clean generated files
.PHONY: clean
clean:
rm -rf build/
# Help
.PHONY: help
help:
@echo "Lua bitN Library - Makefile targets"
@echo ""
@echo "Testing:"
@echo " make test - Run all tests"
@echo " make test-<name> - Run specific test (e.g., make test-bit32)"
@echo " make test-matrix - Run tests across all Lua versions"
@echo " make test-matrix-<name> - Run specific test across all Lua versions"
@echo ""
@echo "Benchmarking:"
@echo " make bench - Run all benchmarks"
@echo " make bench-<name> - Run specific benchmark (e.g., make bench-bit32)"
@echo " make bench-matrix - Run benchmarks across all Lua versions"
@echo " make bench-matrix-<name> - Run specific benchmark across all Lua versions"
@echo ""
@echo "Building:"
@echo " make build - Build single-file distribution"
@echo ""
@echo "Code Quality:"
@echo " make check - Run format-check and lint"
@echo " make format - Format code with stylua"
@echo " make format-check - Check code formatting"
@echo " make lint - Lint code with luacheck"
@echo ""
@echo "Setup:"
@echo " make install-deps - Install development dependencies"
@echo " make clean - Remove generated files"
@echo ""
@echo " make help - Show this help"