-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakefile
80 lines (62 loc) · 1.94 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
70
71
72
73
74
75
76
77
78
79
80
#
# ws2812b SPI makefile
# Philipp Schilk 2021
#
# Compiler + Flags
CC=gcc
LDFLAGS=
CFLAGS=-Wall -Wextra -Wpedantic -Werror=vla -fsanitize=address -g -Isrc -Itest/Unity
DEPFLAGS=-MMD -MP -MF $(BUILDDIR)/$*.d
SOURCES=src/ws2812b.c test/Unity/unity.c
TEST_SOURCES=$(wildcard test/*.c)
TESTS=$(addprefix $(BUILDDIR)/,$(TEST_SOURCES:.c=.out))
OBJECTS=$(addprefix $(BUILDDIR)/,$(SOURCES:.c=.o))
PREPROC_EXPANDED_SRCS=$(addprefix $(BUILDDIR)/preproc/,$(SOURCES))
PREPROC_EXPANDED_TEST_SRCS=$(addprefix $(BUILDDIR)/preproc/,$(TEST_SOURCES))
DEPENDENCIES=$(addprefix $(BUILDDIR)/,$(SOURCES:.c=.d))
DEPENDENCIES+=$(addprefix $(BUILDDIR)/,$(TEST_SOURCES:.c=.d))
BUILDDIR=build
SILENT?=
.PHONY: all run_tests build_tests clean format
all: run_tests
run_tests: build_tests
-python3 scripts/run_tests.py $(TESTS)
build_tests: $(TESTS)
clean:
rm -rf $(BUILDDIR)
format:
python3 scripts/clang_format.py
# Link tests:
$(BUILDDIR)/%.out: $(BUILDDIR)/%.o $(OBJECTS)
$(SILENT) $(CC) $(CFLAGS) $^ -o $@
# Compile sources and test sources
$(BUILDDIR)/%.o: %.c makefile
@mkdir -p $(dir $@)
$(SILENT) $(CC) -c $(CFLAGS) $(DEPFLAGS) $*.c -o $@
# Generate C files with all preproc expansion:
.PHONY: preproc_expanded
preproc_expanded: $(PREPROC_EXPANDED_SRCS) $(PREPROC_EXPANDED_TEST_SRCS)
$(BUILDDIR)/preproc/%.c: %.c makefile
@mkdir -p $(dir $@)
$(SILENT) $(CC) -c $(CFLAGS) -E -C $*.c -o $@
# Re-generate compile_commands.json using either bear or compiledb
.PHONY: compile_commands
GEN_COMP_COMMANDS_CMD=compiledb make
#GEN_COMP_COMMANDS_CMD=bear -- make
compile_commands: clean
$(GEN_COMP_COMMANDS_CMD)
.PHONY: test_watch
test_watch:
watch -c -n 1 make SILENT=@
# Keep dependencies around, make them an explicit target:
$(DEPENDENCIES):
# Keep object files and output files:
.PRECIOUS: $(BUILDDIR)/%.out
.PRECIOUS: $(BUILDDIR)/%.o
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),format)
ifneq ($(MAKECMDGOALS),compile_commands)
include $(DEPENDENCIES)
endif
endif
endif