forked from iblue/bluedelta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
59 lines (45 loc) · 1.29 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
CC=gcc
CFLAGS=-std=c11 -Wall -Werror -O3
VALGRIND=valgrind --tool=memcheck --leak-check=yes
STRIP=strip
BINARY=bluedelta
MAIN_C = main.c
MAIN_O = $(MAIN_C:.c=.o)
INCLUDES = -I./include -I.
SOURCES = $(shell find -path "./utils/*" -name "*.c")
OBJECTS = $(SOURCES:.c=.o)
TEST_SOURCES = $(shell find -path "./test/*" -name "*.c")
TEST_OBJECTS = $(TEST_SOURCES:.c=.o)
TESTS = $(TEST_SOURCES:.c=.test)
.PRECIOUS: %.c %.o %.h
$(BINARY): $(OBJECTS) $(MAIN_O)
$(CC) $(CFLAGS) -o $(BINARY) $(OBJECTS) $(MAIN_O) $(LIBS)
.c.o: $(HEADERS)
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
.PHONY: clean
clean:
rm -f $(BINARY) $(OBJECTS) $(TEST_OBJECTS) $(TESTS) $(MAIN_O)
.PHONY: stats
stats:
git ls-files | xargs wc -l
.PHONY: build
build: CFLAGS += -DNDEBUG
build: clean $(BINARY)
.PHONY: tests run_tests
test: $(TESTS) run_tests
run_tests: $(TESTS)
$(foreach test,$(TESTS),echo $(test); $(test);)
%.test: %.o $(OBJECTS)
$(CC) $(CFLAGS) -o $@ $< $(OBJECTS) $(INCLUDES) $(LIBS)
.PHONY: debug
debug: CFLAGS := $(filter-out -O3,$(CFLAGS)) -ggdb -DDEBUG -O0
ifeq ($(CC),gcc)
debug: CFLAGS += -fsanitize=address
endif
debug: clean $(BINARY)
.PHONY: debug-test
debug-test: CFLAGS := $(filter-out -O3,$(CFLAGS)) -ggdb -DDEBUG -O0
ifeq ($(CC),gcc)
debug-test: CFLAGS += -fsanitize=address
endif
debug-test: test