Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
114 lines (92 loc) · 3.22 KB
/
Copy pathMakefile
File metadata and controls
114 lines (92 loc) · 3.22 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
# Compiler
CC = gcc
CFLAGS = -Wall -Wextra -std=c99
# Third-party sources build without -Wall: their warnings are not ours.
TP_CFLAGS = -std=c99 -O2
# Target
TARGET = main
# Object files
OBJS = main.o \
sensor/sensor.o \
source/source.o \
scheduler/scheduler.o \
history/history.o \
config/config.o \
http/http.o \
ui/layout.o \
ui/dashboard.o \
third_party/civetweb/civetweb.o \
third_party/cjson/cJSON.o
TP_OBJS = third_party/civetweb/civetweb.o \
third_party/cjson/cJSON.o
# Flags from installed packages (Homebrew on macOS, apt on Linux)
RAYLIB_CFLAGS = $(shell pkg-config --cflags raylib)
RAYLIB_LIBS = $(shell pkg-config --libs raylib)
YAML_CFLAGS = $(shell pkg-config --cflags yaml-0.1)
YAML_LIBS = $(shell pkg-config --libs yaml-0.1)
SSL_CFLAGS = $(shell pkg-config --cflags openssl)
SSL_LIBS = $(shell pkg-config --libs openssl)
# CivetWeb requires an explicit OpenSSL API version for its TLS code.
# NO_SSL_DL links OpenSSL directly instead of dlopen()ing it at runtime.
OPENSSL_MAJOR = $(shell pkg-config --modversion openssl 2>/dev/null | cut -d. -f1)
ifeq ($(OPENSSL_MAJOR),1)
SSL_DEFS = -DOPENSSL_API_1_1 -DNO_SSL_DL
else
SSL_DEFS = -DOPENSSL_API_3_0 -DNO_SSL_DL
endif
ALL_CFLAGS = $(RAYLIB_CFLAGS) $(YAML_CFLAGS) $(SSL_CFLAGS) -pthread
ALL_LIBS = $(RAYLIB_LIBS) $(YAML_LIBS) $(SSL_LIBS) -pthread -lm
# Module sources linked into every test binary
# (ui/dashboard.c is excluded: only the main binary needs Raylib)
MODULE_SRCS = history/history.c sensor/sensor.c source/source.c \
scheduler/scheduler.c config/config.c http/http.c ui/layout.c \
third_party/cjson/cJSON.c third_party/civetweb/civetweb.c
# Auto-discover tests:
# Every file named tests/test_*.c becomes its own executable.
TEST_SRCS = $(wildcard tests/test_*.c)
TEST_BINS = $(patsubst tests/test_%.c,test_%,$(TEST_SRCS))
# -------------------------
# Main program
# -------------------------
# Final link step
$(TARGET): $(OBJS)
$(CC) $(OBJS) -o $(TARGET) $(ALL_LIBS)
# -------------------------
# Compilation
# -------------------------
# Compile project .c files into .o files
%.o: %.c
$(CC) $(CFLAGS) $(ALL_CFLAGS) -c $< -o $@
# Third-party sources: no project warnings, position-independent.
# A static pattern rule so it always wins over the generic %.o rule.
$(TP_OBJS): third_party/%.o: third_party/%.c
$(CC) $(TP_CFLAGS) $(SSL_CFLAGS) $(SSL_DEFS) -c $< -o $@
# -------------------------
# Tests
# -------------------------
# Build and run every test binary
test: $(TEST_BINS)
@if [ -z "$(TEST_SRCS)" ]; then \
echo "No tests found - create tests/test_*.c files"; \
exit 1; \
fi
@echo "--- Running $(words $(TEST_BINS)) test file(s) ---"
@fail=0; \
for t in $(TEST_BINS); do \
./$$t || fail=1; \
done; \
if [ $$fail -eq 0 ]; then \
echo "ALL TESTS PASSED"; \
else \
echo "SOME TESTS FAILED"; \
exit 1; \
fi
# Each test file compiles into its own binary
# tests/test_foo.c -> test_foo
test_%: tests/test_%.c $(MODULE_SRCS)
$(CC) $(CFLAGS) $(YAML_CFLAGS) $(SSL_CFLAGS) $(SSL_DEFS) -I. $< $(MODULE_SRCS) -o $@ $(YAML_LIBS) $(SSL_LIBS) -pthread -lm
# -------------------------
# Cleanup
# -------------------------
clean:
rm -f $(OBJS) $(TARGET) $(TEST_BINS)