-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
50 lines (36 loc) · 1.11 KB
/
Copy pathMakefile
File metadata and controls
50 lines (36 loc) · 1.11 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
CC := clang
CFLAGS := -std=c23 -Wall -Wextra -g -Iinclude -Itests
BUILD_DIR := build
LIB_SRC := src/vector.c
TEST_SRC := tests/vector_test.c tests/main.c
# Derive object‑and‑binary paths under $(BUILD_DIR)
LIB_OBJ := $(LIB_SRC:%.c=$(BUILD_DIR)/%.o)
TEST_OBJ := $(TEST_SRC:%.c=$(BUILD_DIR)/%.o)
ALL_OBJ := $(LIB_OBJ) $(TEST_OBJ)
LIB_STATIC := $(BUILD_DIR)/libvector.a
TEST_BIN := $(BUILD_DIR)/test_vector
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SDKROOT := $(shell xcrun --show-sdk-path)
export SDKROOT
endif
.PHONY: all test clean build_lib
all: test $(LIB_STATIC)
build_lib: $(LIB_STATIC)
$(LIB_STATIC): $(LIB_OBJ)
$(AR) rcs $@ $^
# Link everything into the test binary (in build/)
$(TEST_BIN): $(ALL_OBJ)
$(CC) $(CFLAGS) -o $@ $^
# Generic rule: build/<path>.o from <path>.c
# e.g. build/src/vector.o ← src/vector.c
# build/tests/vector.o ← tests/vector.c
$(BUILD_DIR)/%.o: %.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
test: $(TEST_BIN)
@echo "⏳ Running tests…"
@./$(TEST_BIN) || \
{ echo "❌ Tests failed!"; exit 1; }
clean:
rm -rf $(BUILD_DIR)