Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
199 lines (171 loc) · 5.1 KB
/
Copy pathMakefile
File metadata and controls
199 lines (171 loc) · 5.1 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Makefile to run unit tests for Homa
LINUX_VERSION ?= $(shell uname -r)
KDIR ?= /lib/modules/$(LINUX_VERSION)/build
LINUX_SRC_DIR ?= /ouster/linux-stable
CC ?= gcc
CXX ?= g++
PERL ?= perl
ARCH ?= x86
all: test
KERN_INCLUDES := \
-I$(KDIR)/arch/x86/include \
-I$(KDIR)/arch/x86/include/generated \
-I$(KDIR)/include \
-I$(KDIR)/arch/x86/include/uapi \
-I$(KDIR)/arch/x86/include/generated/uapi \
-I$(KDIR)/include/uapi \
-I$(KDIR)/include/generated/uapi
CINCLUDES := \
-I. \
-I.. \
$(KERN_INCLUDES) \
-include $(KDIR)/include/linux/kconfig.h
CCINCLUDES := \
-I. \
-I.. \
$(KERN_KINCLUDES)
DEFS := -D__KERNEL__ \
-D__UNIT_TEST__ \
-D KBUILD_MODNAME='"homa"'
ifneq ($(__STRIP__),)
DEFS += -D__STRIP__
endif
WARNS := -Wall -Wundef -Wno-trigraphs -Wno-sign-compare -Wuninitialized \
-Wno-strict-aliasing -Wunused-but-set-variable -Werror
CFLAGS := $(WARNS) -Wstrict-prototypes -MD -no-pie -g $(CINCLUDES) $(DEFS) \
-fsanitize=address -fno-omit-frame-pointer
CCFLAGS := -std=c++11 $(WARNS) -MD -g $(CCINCLUDES) $(DEFS) \
-fsanitize=address -fno-omit-frame-pointer
TEST_SRCS := unit_homa_incoming.c \
unit_homa_interest.c \
unit_homa_outgoing.c \
unit_homa_peer.c \
unit_homa_pool.c \
unit_homa_plumbing.c \
unit_homa_rpc.c \
unit_homa_sock.c \
unit_homa_timer.c \
unit_homa_tx_pool.c \
unit_homa_utils.c \
unit_timetrace.c
ifeq ($(__STRIP__),)
TEST_SRCS += unit_homa_grant.c \
unit_homa_hijack.c \
unit_homa_metrics.c \
unit_homa_offload.c \
unit_homa_qdisc.c
endif
TEST_OBJS := $(patsubst %.c,%.o,$(TEST_SRCS))
HOMA_SRCS := homa_devel.c \
homa_interest.c \
homa_incoming.c \
homa_outgoing.c \
homa_peer.c \
homa_pool.c \
homa_plumbing.c \
homa_rpc.c \
homa_sock.c \
homa_timer.c \
homa_tx_pool.c \
homa_utils.c \
timetrace.c
ifeq ($(__STRIP__),)
HOMA_SRCS += homa_grant.c \
homa_hijack.c \
homa_metrics.c \
homa_offload.c \
homa_qdisc.c
endif
HOMA_OBJS := $(patsubst %.c,%.o,$(HOMA_SRCS)) rbtree.o rhashtable.o
OTHER_SRCS := ccutils.cc \
main.c \
mock.c \
utils.c
OTHER_OBJS := $(patsubst %.c,%.o,$(patsubst %.cc,%.o,$(OTHER_SRCS)))
OBJS := $(TEST_OBJS) $(HOMA_OBJS) $(OTHER_OBJS)
CLEANS = unit $(OBJS) *.d .deps
# This seems to be the only way to disable the built-in implicit rules
# for %:%.c and %:%.cc.
.SUFFIXES:
%.o: ../%.c
$(CC) -c $(CFLAGS) $< -o $@
%.e: ../%.c
$(CC) -E $(CFLAGS) $< -o $@
%.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
%.e: %.c
$(CC) -E $(CFLAGS) $< -o $@
%.o: %.cc
$(CXX) -c $(CCFLAGS) $< -o $@
%.e: %.cc
$(CXX) -E $(CCFLAGS) $< -o $@
dummyFile:
$(CXX) -c $(CCFLAGS) \
-I $(LINUX_SRC_DIR)/include \
-I $(LINUX_SRC_DIR)/arch/x86/include \
-I $(LINUX_SRC_DIR)/arch/x86/include/generated \
-include $(LINUX_SRC_DIR)/include/linux/kconfig.h \
-O2 $< -o $@
# Note: Without -O2 there will be strange compiler errors such as
# 'asm operand 2 probably does not match constraints'.
rhashtable.o: rhashtable.c
$(CC) -c $(CFLAGS) -O2 -fno-sanitize=address $< -o $@
unit: $(OBJS)
$(CXX) $(CFLAGS) $^ -o $@
test: unit
./unit
# Additional definitions for running unit tests using stripped sources.
S_HOMA_SRCS := $(patsubst %,stripped/%,$(filter-out timetrace.c, $(HOMA_SRCS)))
S_HOMA_OBJS := $(patsubst %.c,%.o,$(S_HOMA_SRCS))
S_HOMA_HDRS := stripped/homa.h \
stripped/homa_impl.h \
stripped/homa_peer.h \
stripped/homa_pool.h \
stripped/homa_receiver.h \
stripped/homa_rpc.h \
stripped/homa_sock.h \
stripped/homa_stub.h \
stripped/homa_wire.h
stripped/%.c: ../%.c
../util/strip.py --alt $< > $@
stripped/%.h: ../%.h
../util/strip.py --alt $< > $@
S_TEST_OBJS := $(patsubst %,stripped/%,$(filter-out unit_timetrace.o, $(TEST_OBJS)))
S_OBJS := $(S_HOMA_OBJS) $(S_TEST_OBJS) $(patsubst %,stripped/%,$(OTHER_OBJS))
$(S_OBJS): | stripped $(S_HOMA_HDRS)
stripped:
mkdir -p stripped
stripped/%.o: stripped/%.c
$(CC) -c $(patsubst -I..,-Istripped,$(CFLAGS)) $< -o $@
stripped/%.o: %.c
$(CC) -c $(patsubst -I..,-Istripped,$(CFLAGS)) $< -o $@
stripped/%.o: %.cc
$(CXX) -c $(patsubst -I..,-Istripped,$(CCFLAGS)) $< -o $@
s_unit: $(S_OBJS)
$(CXX) $(CFLAGS) $^ -o $@ -lasan
s_test: s_unit
./s_unit
CLEANS += s_unit
# The target below shouldn't be needed: theoretically, any code that is
# sensitive to IPv4 vs. IPv6 should be tested explicitly, regardless of
# the --ipv4 argument.
test_both: unit
@echo "Testing with IPv4 default:"
./unit --ipv4
@echo "Testing with IPv6 default:"
./unit
clean:
rm -f $(CLEANS)
rm -rf stripped
# This magic (along with the -MD gcc option) automatically generates makefile
# dependencies for header files included from C source files we compile,
# and keeps those dependencies up-to-date every time we recompile.
# See 'mergedep.pl' for more information.
.deps: $(wildcard *.d stripped/*.d)
@mkdir -p $(@D)
$(PERL) mergedep.pl $@ $^
-include .deps
# The following target is useful for debugging Makefiles; it
# prints the value of a make variable.
print-%:
@echo $* = $($*)