forked from 1T17/GGcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
96 lines (76 loc) · 2.45 KB
/
Makefile
File metadata and controls
96 lines (76 loc) · 2.45 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
# Compiler and flags
CC = gcc
CFLAGS = -g -Wall -Werror -Wpedantic -Wextra \
-DUNITY_SUPPORT_64 -DUNITY_INCLUDE_DOUBLE \
-I./include -Isrc -Isrc/lexer -Isrc/parser -Isrc/runtime -Isrc/semantic -Isrc/generator -Isrc/utils
# Windows cross-compiler
CC_WIN = x86_64-w64-mingw32-gcc
# Main source files
SRC = $(wildcard src/*.c src/lexer/*.c src/error/*.c src/parser/*.c src/semantic/*.c src/generator/*.c src/runtime/*.c src/utils/*.c src/config/*.c)
OUT = GGCODE/ggcode
# Test discovery
TEST_SRC := $(wildcard tests/test_*.c)
TEST_BINS := $(patsubst tests/%.c,bin/%,$(TEST_SRC))
UNITY = tests/Unity/src/unity.c
UNITY_URL = https://github.com/ThrowTheSwitch/Unity/archive/refs/heads/master.zip
UNITY_DIR = tests/Unity
# Main target
all: $(OUT)
# Build main program
$(OUT): $(SRC)
$(CC) $(CFLAGS) -o $@ $^ -lm
# Windows build target with psapi for memory info
.PHONY: win
win:
$(CC_WIN) $(CFLAGS) -o $(OUT).exe $(SRC) -lm -lpsapi
# Build all test binaries (excluding src/main.c to avoid duplicate main)
tests: unity $(TEST_BINS)
bin/%: tests/%.c $(filter-out src/main.c, $(SRC)) $(UNITY)
@mkdir -p bin
$(CC) $(CFLAGS) -o $@ $^ -lm
# Run all tests with final summary
.PHONY: test
test: tests
@echo ""
@PASS_TOTAL=0; FAIL_TOTAL=0; \
for t in $(TEST_BINS); do \
echo "🧪 Running $$t..."; \
./$$t > .testlog.tmp; cat .testlog.tmp; \
PASS=$$(grep -c ":PASS" .testlog.tmp); \
FAIL=$$(grep -c ":FAIL" .testlog.tmp); \
PASS_TOTAL=$$((PASS_TOTAL + PASS)); \
FAIL_TOTAL=$$((FAIL_TOTAL + FAIL)); \
echo "→ Summary for $$t: $$PASS Pass, $$FAIL Fail"; \
echo ""; \
if [ $$FAIL -gt 0 ]; then exit 1; fi; \
done; \
rm -f .testlog.tmp; \
echo "============================="; \
echo "✅ All Tests Done"; \
echo "🧪 Total: $$PASS_TOTAL Pass, $$FAIL_TOTAL Fail"; \
echo "============================="
# Download and setup Unity framework
.PHONY: unity
unity:
@if [ ! -d "$(UNITY_DIR)" ]; then \
echo "Downloading Unity test framework..."; \
mkdir -p tests; \
curl -L $(UNITY_URL) -o tests/unity.zip; \
unzip -q tests/unity.zip -d tests; \
mv tests/Unity-master $(UNITY_DIR); \
rm tests/unity.zip; \
echo "Unity downloaded to $(UNITY_DIR)"; \
else \
echo "Unity already present."; \
fi
.PHONY: node
node:
@mkdir -p node
$(CC) -shared -fPIC -o node/libggcode.so \
src/bindings/nodejs.c $(SRC) \
$(CFLAGS) -lm
# Clean build and test artifacts
.PHONY: clean
clean:
@mkdir -p bin
rm -f $(OUT) bin/* win/*.exe .testlog.tmp