forked from RedisLabs/redisraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
151 lines (124 loc) · 3.89 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# This file is part of RedisRaft.
#
# Copyright (c) 2020-2021 Redis Ltd.
#
# RedisRaft is licensed under the Redis Source Available License (RSAL).
OS := $(shell sh -c 'uname -s 2>/dev/null || echo none')
BUILDDIR := $(CURDIR)/.build
ifeq ($(OS),Linux)
ARCH_CFLAGS := -fPIC
ARCH_LDFLAGS := -shared -Wl,-Bsymbolic-functions
else
ARCH_CFLAGS := -dynamic
ARCH_LDFLAGS := -bundle -undefined dynamic_lookup
endif
CC = gcc
CPPFLAGS = -D_POSIX_C_SOURCE=200112L -D_GNU_SOURCE
ifneq ($(TRACE),)
CPPFLAGS += -DENABLE_TRACE
endif
CFLAGS = -g -Wall -std=c99 -I$(BUILDDIR)/include $(ARCH_CFLAGS)
LDFLAGS = $(ARCH_LDFLAGS)
LIBS = \
$(BUILDDIR)/lib/libraft.a \
$(BUILDDIR)/lib/libhiredis.a \
$(BUILDDIR)/lib/libuv.a \
-lpthread
OBJECTS = \
redisraft.o \
common.o \
node.o \
node_addr.o \
join.o \
util.o \
config.o \
raft.o \
snapshot.o \
log.o \
proxy.o \
serialization.o \
cluster.o \
crc16.o \
connection.o \
commands.o
ifeq ($(COVERAGE),1)
CFLAGS += -fprofile-arcs -ftest-coverage
LIBS += -lgcov
endif
.PHONY: all
all: redisraft.so
buildinfo.h:
GIT_SHA1=`(git show-ref --head --hash=8 2>/dev/null || echo 00000000) | head -n1` && \
echo "#define REDISRAFT_GIT_SHA1 \"$$GIT_SHA1\"" > buildinfo.h
$(OBJECTS): | $(BUILDDIR)/.deps_installed buildinfo.h
redisraft.so: $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBS)
clean: clean-tests
rm -f redisraft.so buildinfo.h $(OBJECTS)
cleanall: clean
rm -rf $(BUILDDIR)
$(MAKE) -C deps clean PREFIX=$(BUILDDIR)
# ----------------------------- Unit Tests -----------------------------
DUT_CPPFLAGS = $(CPPFLAGS) -include tests/dut_premble.h
ifeq ($(OS),Linux)
DUT_CFLAGS = $(CFLAGS) -fprofile-arcs -ftest-coverage
DUT_LIBS = -lgcov
else
DUT_CFLAGS = $(CFLAGS)
DUT_LIBS =
endif
TEST_OBJECTS = \
tests/main.o \
tests/test_log.o \
tests/test_util.o \
tests/test_serialization.o
DUT_OBJECTS = \
$(patsubst %.o,tests/test-%.o,$(OBJECTS))
TEST_LIBS = $(BUILDDIR)/lib/libcmocka-static.a $(DUT_LIBS) -lpthread -ldl
.PHONY: clean-tests
clean-tests:
-rm -rf tests/tests_main $(DUT_OBJECTS) $(TEST_OBJECTS) *.gcno *.gcda tests/*.gcno tests/*.gcda tests/*.gcov tests/*lcov.info tests/.*lcov_html
tests/test-%.o: %.c
$(CC) -c $(DUT_CFLAGS) $(DUT_CPPFLAGS) -o $@ $<
.PHONY: tests
tests: unit-tests integration-tests
.PHONY: unit-tests
ifeq ($(OS),Linux)
unit-tests: tests/tests_main
./tests/tests_main && \
lcov --rc lcov_branch_coverage=1 -c -d . -d ./tests --no-external -o tests/lcov.info && \
lcov --rc lcov_branch_coverage=1 --summary tests/lcov.info
else
unit-tests: tests/tests_main
./tests/tests_main
endif
.PHONY: tests/tests_main
tests/tests_main: $(TEST_OBJECTS) $(DUT_OBJECTS)
$(CC) -o tests/tests_main $(TEST_OBJECTS) $(DUT_OBJECTS) $(LIBS) $(TEST_LIBS)
.PHONY: unit-lcov-report
unit-lcov-report: tests/lcov.info
mkdir -p tests/.lcov_html
genhtml --branch-coverage -o tests/.lcov_html tests/lcov.info
xdg-open tests/.lcov_html/index.html >/dev/null 2>&1
# ----------------------------- Integration Tests -----------------------------
PYTEST_OPTS ?= -v
.PHONY: integration-tests
integration-tests:
pytest tests/integration $(PYTEST_OPTS)
.PHONY: valgrind-tests
valgrind-tests:
pytest tests/integration $(PYTEST_OPTS) --valgrind
.PHONY: integration-lcov-report
integration-lcov-report:
lcov --rc lcov_branch_coverage=1 -c -d . --no-external -o tests/integration-lcov.info && \
lcov --rc lcov_branch_coverage=1 --summary tests/integration-lcov.info
mkdir -p tests/.integration-lcov_html
genhtml --branch-coverage -o tests/.integration-lcov_html tests/integration-lcov.info
xdg-open tests/.integration-lcov_html/index.html >/dev/null 2>&1
# ------------------------- Build dependencies -------------------------
$(BUILDDIR)/.deps_installed:
mkdir -p $(BUILDDIR)
mkdir -p $(BUILDDIR)/lib
mkdir -p $(BUILDDIR)/include
$(MAKE) -C deps PREFIX=$(BUILDDIR)
touch $(BUILDDIR)/.deps_installed