-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
69 lines (49 loc) · 1.71 KB
/
Makefile
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
CCACHE = ccache
CC = clang
CFLAGS = -std=c99 -Wall -Wextra -Wno-unused-parameter -g
INCLUDE_DIRS = -Iinclude -Ivendor
ALL_C_SRCS = $(wildcard src/*.c src/*/*.c)
ALL_H_SRCS = $(wildcard src/*.h src/*/*.h)
ALL_SRCS = $(ALL_C_SRCS) $(ALL_H_SRCS)
BIN_SRCS = src/laroc.c
TEST_SRCS = $(wildcard src/*/*.test.c)
ALL_DEP_FILES = $(patsubst src/%.c,build/dep/%.d,$(ALL_C_SRCS))
ALL_OBJS = $(patsubst src/%.c,build/obj/%.o,$(ALL_C_SRCS))
BIN_OBJS = $(patsubst src/%.c,build/obj/%.o,$(BIN_SRCS))
TEST_OBJS = $(patsubst src/%.c,build/obj/%.o,$(TEST_SRCS))
LIB_OBJS = $(filter-out $(BIN_OBJS) $(TEST_OBJS),$(ALL_OBJS))
LAORC_BINS = $(patsubst src/%.c,build/bin/%,$(BIN_SRCS))
TEST_BINS = $(patsubst build/obj/%.o,build/test/%,$(TEST_OBJS))
ALL_DIRS = $(dir $(ALL_DEP_FILES) $(ALL_OBJS) $(LAORC_BINS) $(TEST_BINS))
RUN_TEST_BINS = $(addprefix run-,$(TEST_BINS))
.PHONY: all
all: $(LAORC_BINS) $(ALL_OBJS)
include vendor/stb.mak
include test/Makefile
-include $(ALL_DEP_FILES)
SORTED_ALL_DIRS = $(sort $(ALL_DIRS))
$(SORTED_ALL_DIRS):
mkdir -p $@
$(ALL_OBJS): build/obj/%.o: src/%.c | $(SORTED_ALL_DIRS)
$(CCACHE) $(CC) $(CFLAGS) $(INCLUDE_DIRS) $< -MMD -MT $@ -MF $(patsubst build/obj/%.o,build/dep/%.d,$@) -c -o $@
$(TEST_BINS): build/test/%: build/obj/%.o $(LIB_OBJS) | $(SORTED_ALL_DIRS)
$(CC) $(CFLAGS) $^ -o $@
$(LAORC_BINS): build/bin/%: build/obj/%.o $(LIB_OBJS) | $(SORTED_ALL_DIRS)
$(CC) $(CFLAGS) $^ -o $@
.PHONY: test
test: $(RUN_TEST_BINS) test-inputs
.PHONY: $(RUN_TEST_BINS)
$(RUN_TEST_BINS): run-%: %
$<
.PHONY: clang-format
clang-format:
clang-format --style=file -i $(ALL_SRCS)
.PHONY: clang-tidy
clang-tidy:
clang-tidy $(ALL_SRCS)
.PHONY: clean-dep
clean-dep:
rm -rf build/dep
.PHONY: clean
clean: clean-dep
rm -rf build