-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
93 lines (74 loc) · 2.28 KB
/
Makefile
File metadata and controls
93 lines (74 loc) · 2.28 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
# Cyan Library Makefile
# Header-only C11 library with property-based testing
CC ?= gcc
# Use gnu11 to support GCC extensions (nested functions for defer, cleanup attribute)
CFLAGS = -std=gnu11 -Wall -Wextra -I include -I vendor/theft/inc
LDFLAGS = -L vendor/theft/build -ltheft -lm
# Platform detection - add macOS-specific flags
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
CFLAGS += -D_XOPEN_SOURCE=700
endif
# Sanitizer flags (enabled with SANITIZE=1)
ifdef SANITIZE
CFLAGS += -fsanitize=address,undefined -fno-omit-frame-pointer
LDFLAGS += -fsanitize=address,undefined
endif
# Debug flags (enabled with DEBUG=1)
ifdef DEBUG
CFLAGS += -g -O0
else
CFLAGS += -O2
endif
# Directories
SRC_DIR = tests
BUILD_DIR = build
INCLUDE_DIR = include/cyan
# Test sources and objects (exclude standalone test files with their own main())
TEST_SRCS = $(filter-out $(SRC_DIR)/test_macos_clang_compat.c,$(wildcard $(SRC_DIR)/*.c))
TEST_OBJS = $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(TEST_SRCS))
TEST_BIN = $(BUILD_DIR)/test_runner
# Theft library
THEFT_DIR = vendor/theft
THEFT_LIB = $(THEFT_DIR)/build/libtheft.a
.PHONY: all test clean theft dirs
all: dirs theft $(TEST_BIN)
dirs:
@mkdir -p $(BUILD_DIR)
# Build theft library
theft: $(THEFT_LIB)
# Theft source files
THEFT_SRCS = $(wildcard $(THEFT_DIR)/src/*.c)
THEFT_OBJS = $(patsubst $(THEFT_DIR)/src/%.c,$(THEFT_DIR)/build/%.o,$(THEFT_SRCS))
$(THEFT_LIB): $(THEFT_OBJS)
ar rcs $@ $^
$(THEFT_DIR)/build/%.o: $(THEFT_DIR)/src/%.c
@mkdir -p $(THEFT_DIR)/build
$(CC) -c $< -I $(THEFT_DIR)/inc -I $(THEFT_DIR)/src -o $@
# Build test objects
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | dirs
$(CC) $(CFLAGS) -c $< -o $@
# Link test runner
$(TEST_BIN): $(TEST_OBJS) $(THEFT_LIB)
$(CC) $(TEST_OBJS) $(LDFLAGS) -o $@
# Run tests
test: all
@echo "Running tests..."
./$(TEST_BIN)
# Clean build artifacts
clean:
rm -rf $(BUILD_DIR)
rm -rf $(THEFT_DIR)/build
# Help target
help:
@echo "Cyan Library Build System"
@echo ""
@echo "Targets:"
@echo " all - Build test runner (default)"
@echo " test - Build and run tests"
@echo " clean - Remove build artifacts"
@echo " help - Show this help"
@echo ""
@echo "Options:"
@echo " SANITIZE=1 - Enable AddressSanitizer and UBSan"
@echo " DEBUG=1 - Enable debug symbols, disable optimization"