blob: 387da4b7d2e623f6df79b41fcd7843346794e630 (
plain)
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
|
CC ?= gcc
SRCDIR ?= src
TSTDIR ?= test
GENDIR ?= gen
OBJDIR ?= obj
LIBS = -lm -lmicrohttpd -lprom
INCS = -Isrc/ -Igen/ -I. -Ithirdparty/crypto-algorithms/
CFLAGS ?= -O3 -D_FORTIFY_SOURCE=2 -Wall -g
# add all the required Cflags
CFLAGS += -std=gnu11 -fms-extensions -flto
APP_MAIN_SOURCES = src/main.c
APP_SOURCES = $(filter-out $(APP_MAIN_SOURCES),$(shell find $(SRCDIR) -name "*.c"))
APP_SOURCES += thirdparty/crypto-algorithms/sha256.c
APP_OBJS = $(APP_SOURCES:%.c=$(OBJDIR)/%.o)
APP_MAIN_OBJS = $(APP_MAIN_SOURCES:%.c=$(OBJDIR)/%.o)
APP_DEPS = $(APP_OBJS:%.o=%.d)
APP_MAIN_DEPS = $(APP_MAIN_OBJS:%.o=%.d)
TEST_LIB_SOURCES = thirdparty/Unity/src/unity.c
TEST_LIB_OBJS = $(TEST_LIB_SOURCES:%.c=$(OBJDIR)/%.o)
TEST_LIB_DEPS = $(TEST_LIB_SOURCES:%.c=%.d)
TEST_LIB_INCS = -Ithirdparty/Unity/src/
TEST_LIB_CFLAGS = -DUNITY_INCLUDE_DOUBLE
TEST_LIB_LIBS = -lcurl
TEST_SOURCES = $(shell find $(TSTDIR) -name "*.c")
TEST_EXES = $(TEST_SOURCES:%.c=$(OBJDIR)/%)
TEST_DEPS = $(TEST_SOURCES:%.c=%.d)
print-% : ; @echo $* = $($*)
-include $(APP_DEPS) $(TEST_LIB_DEPS) $(TEST_DEPS)
# We don't really need to run the tests for bear to record them
compile_commands.json: clean Makefile $(APP_SOURCES) $(TEST_LIB_SOURCES) $(TEST_SOURCES)
@rm -f "$@"
bear -- make $(TEST_EXES) dht
dht: $(APP_MAIN_OBJS) $(APP_OBJS)
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(APP_MAIN_OBJS) $(APP_OBJS) $(LIBS)
$(OBJDIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(INCS) -MMD -o $@ -c $<
clean:
@rm -rf $(OBJDIR)
@rm -f dht
.PHONY: version
version:
@echo "$(COMPTON_VERSION)"
# Unit tests!
# Run all tests
.PHONY: test
test: $(TEST_EXES)
$(foreach test,$(TEST_EXES),./$(test) &&) true
$(OBJDIR)/test/%: $(APP_OBJS) $(TEST_LIB_OBJS) $(OBJDIR)/test/%.o $(OBJDIR)/test/%.runner.o
$(CC) $(LDFLAGS) $(TEST_LIB_CFLAGS) $(CFLAGS) -o $@ $^ $(LIBS) $(TEST_LIB_LIBS)
$(OBJDIR)/test/%.runner.c: test/%.c
@mkdir -p $(dir $@)
ruby thirdparty/Unity/auto/generate_test_runner.rb $< $@
# Test code needs test includes
$(OBJDIR)/test/%.o: test/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(TEST_LIB_CFLAGS) $(TEST_LIB_INCS) $(INCS) -MMD -o $@ -c $<
# Generated test sources are located under obj
$(OBJDIR)/test/%.o: $(OBJDIR)/test/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(TEST_LIB_CFLAGS) $(TEST_LIB_INCS) $(INCS) -MMD -o $@ -c $<
# Test code needs test includes
$(OBJDIR)/thirdparty/Unity/%.o: thirdparty/Unity/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(TEST_LIB_CFLAGS) $(TEST_LIB_INCS) $(INCS) -MMD -o $@ -c $<
.DEFAULT_GOAL := all
all: test dht
|