Skip to content

Commit 04e14cf

Browse files
committed
Makeile: rewrite build system, including proper dependencies
1 parent dbe436f commit 04e14cf

File tree

13 files changed

+326
-132
lines changed

13 files changed

+326
-132
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.o
2+
*.d
23
*.so
34
*.swp
45
*.swo

Makefile

+79-132
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,93 @@
11
-include Makefile.local
22

3+
##############################################################################
4+
# Compile, link, and install flags
5+
6+
CPPFLAGS += -Iinclude/
7+
CPPFLAGS += $(EXTRA_CPPFLAGS)
8+
CFLAGS += -std=gnu99 -O3 -g -Wall -Werror -march=native -fno-omit-frame-pointer
9+
CFLAGS += $(EXTRA_CFLAGS)
10+
CFLAGS_SHARED += $(CFLAGS) -fPIC
11+
LDFLAGS += -pthread -g
12+
LDFLAGS += $(EXTRA_LDFLAGS)
13+
LDLIBS += -lm -lpthread -lrt -ldl
14+
LDLIBS += $(EXTRA_LDLIBS)
15+
316
PREFIX ?= /usr/local
417
SBINDIR ?= $(PREFIX)/sbin
518
LIBDIR ?= $(PREFIX)/lib
619
INCDIR ?= $(PREFIX)/include
720

8-
RTE_SDK ?= /usr/
921

10-
CFLAGS += -std=gnu99 -O3 -g -Wall -Werror -I. -Iinclude/ -march=native -fno-omit-frame-pointer
11-
LDFLAGS += -pthread -g
22+
##############################################################################
23+
# DPDK configuration
1224

13-
RTE_SDK ?= $(HOME)/dpdk/x86_64-native-linuxapp-gcc
25+
# Prefix for dpdk
26+
RTE_SDK ?= /usr/
27+
# mpdts to compile
1428
DPDK_PMDS ?= ixgbe i40e tap virtio
1529

16-
CFLAGS+= -I$(RTE_SDK)/include -I$(RTE_SDK)/include/dpdk
17-
CFLAGS+= -I$(RTE_SDK)/include/x86_64-linux-gnu/dpdk/
18-
LDFLAGS+= -L$(RTE_SDK)/lib/
30+
DPDK_CPPFLAGS += -I$(RTE_SDK)/include -I$(RTE_SDK)/include/dpdk \
31+
-I$(RTE_SDK)/include/x86_64-linux-gnu/dpdk/
32+
DPDK_LDFLAGS+= -L$(RTE_SDK)/lib/
33+
DPDK_LDLIBS+= \
34+
-Wl,--whole-archive \
35+
$(addprefix -lrte_pmd_,$(DPDK_PMDS)) \
36+
-lrte_eal \
37+
-lrte_mempool \
38+
-lrte_mempool_ring \
39+
-lrte_hash \
40+
-lrte_ring \
41+
-lrte_kvargs \
42+
-lrte_ethdev \
43+
-lrte_mbuf \
44+
-lnuma \
45+
-lrte_bus_pci \
46+
-lrte_pci \
47+
-lrte_cmdline \
48+
-lrte_timer \
49+
-lrte_net \
50+
-lrte_kni \
51+
-lrte_bus_vdev \
52+
-lrte_gso \
53+
-Wl,--no-whole-archive \
54+
-ldl \
55+
$(EXTRA_LIBS_DPDK)
1956

20-
LIBS_DPDK= -Wl,--whole-archive
21-
LIBS_DPDK+= $(addprefix -lrte_pmd_,$(DPDK_PMDS))
22-
LIBS_DPDK+= -lrte_eal -lrte_mempool -lrte_mempool_ring \
23-
-lrte_hash -lrte_ring -lrte_kvargs -lrte_ethdev \
24-
-lrte_mbuf -lnuma -lrte_bus_pci -lrte_pci \
25-
-lrte_cmdline -lrte_timer -lrte_net -lrte_kni \
26-
-lrte_bus_vdev -lrte_gso \
27-
-Wl,--no-whole-archive -ldl $(EXTRA_LIBS_DPDK)
2857

29-
LDLIBS += -lm -lpthread -lrt -ldl
58+
##############################################################################
59+
60+
include mk/recipes.mk
61+
62+
DEPS :=
63+
CLEAN :=
64+
TARGETS :=
3065

31-
UTILS_OBJS = $(addprefix lib/utils/,utils.o rng.o timeout.o)
32-
TASCOMMON_OBJS = $(addprefix tas/,tas.o config.o shm.o)
33-
SLOWPATH_OBJS = $(addprefix tas/slow/,kernel.o packetmem.o appif.o appif_ctx.o \
34-
nicif.o cc.o tcp.o arp.o routing.o kni.o)
35-
FASTPATH_OBJS = $(addprefix tas/fast/,fastemu.o network.o \
36-
qman.o trace.o fast_kernel.o fast_appctx.o fast_flows.o)
37-
STACK_OBJS = $(addprefix lib/tas/,init.o kernel.o conn.o connect.o)
38-
SOCKETS_OBJS = $(addprefix lib/sockets/,control.o transfer.o context.o manage_fd.o \
39-
epoll.o libc.o)
40-
INTERPOSE_OBJS = $(addprefix lib/sockets/,interpose.o)
41-
CFLAGS += -I. -Ilib/tas/include -Ilib/sockets/include
42-
43-
shared_objs = $(patsubst %.o,%.shared.o,$(1))
44-
45-
TESTS_AUTO= \
46-
tests/libtas/tas_ll \
47-
tests/libtas/tas_sockets \
48-
tests/tas_unit/fastpath \
49-
50-
TESTS_AUTO_FULL= \
51-
tests/full/tas_linux \
52-
53-
TESTS= \
54-
tests/lowlevel \
55-
tests/lowlevel_echo \
56-
tests/usocket_accept \
57-
tests/usocket_connect \
58-
tests/usocket_accrx \
59-
tests/usocket_conntx \
60-
tests/usocket_conntx_large \
61-
tests/usocket_move \
62-
tests/usocket_epoll_eof \
63-
tests/usocket_shutdown \
64-
tests/bench_ll_echo \
65-
$(TESTS_AUTO) \
66-
$(TESTS_AUTO_FULL)
67-
68-
69-
all: lib/libtas_sockets.so lib/libtas_interpose.so \
70-
lib/libtas.so \
71-
tools/tracetool tools/statetool tools/scaletool \
72-
tas/tas
73-
74-
tests: $(TESTS)
75-
76-
# run all simple testcases
77-
run-tests: $(TESTS_AUTO)
78-
tests/libtas/tas_ll
79-
tests/libtas/tas_sockets
80-
tests/tas_unit/fastpath
81-
82-
# run full tests that run full TAS
83-
run-tests-full: $(TESTS_AUTO_FULL) tas/tas
84-
tests/full/tas_linux
85-
86-
docs:
87-
cd doc && doxygen
88-
89-
tas/%.o: CFLAGS+=-Itas/include
90-
tas/tas: LDLIBS+=$(LIBS_DPDK)
91-
tas/tas: $(TASCOMMON_OBJS) $(FASTPATH_OBJS) $(SLOWPATH_OBJS) $(UTILS_OBJS)
92-
93-
flexnic/tests/tcp_common: flexnic/tests/tcp_common.o
94-
95-
tests/lowlevel: tests/lowlevel.o lib/libtas.so
96-
tests/lowlevel_echo: tests/lowlevel_echo.o lib/libtas.so
97-
98-
tests/usocket_accept: tests/usocket_accept.o lib/libtas_sockets.so
99-
tests/usocket_connect: tests/usocket_connect.o lib/libtas_sockets.so
100-
tests/usocket_accrx: tests/usocket_accrx.o lib/libtas_sockets.so
101-
tests/usocket_conntx: tests/usocket_conntx.o lib/libtas_sockets.so
102-
tests/usocket_conntx_large: tests/usocket_conntx_large.o \
103-
lib/libtas_sockets.so
104-
tests/usocket_move: tests/usocket_move.o lib/libtas_sockets.so
105-
tests/usocket_epoll_eof: tests/usocket_epoll_eof.o
106-
tests/usocket_shutdown: tests/usocket_shutdown.o
107-
tests/bench_ll_echo: tests/bench_ll_echo.o lib/libtas.so
108-
109-
tests/libtas/tas_ll: tests/libtas/tas_ll.o tests/libtas/harness.o \
110-
tests/libtas/harness.o tests/testutils.o lib/libtas.so
111-
tests/libtas/tas_sockets: tests/libtas/tas_sockets.o tests/libtas/harness.o \
112-
tests/libtas/harness.o tests/testutils.o lib/libtas_sockets.so
113-
114-
tests/tas_unit/%.o: CFLAGS+=-Itas/include
115-
tests/tas_unit/fastpath: LDLIBS+=-lrte_eal
116-
tests/tas_unit/fastpath: tests/tas_unit/fastpath.o tests/testutils.o \
117-
tas/fast/fast_flows.o
118-
119-
tests/full/%.o: CFLAGS+=-Itas/include
120-
tests/full/tas_linux: tests/full/tas_linux.o tests/full/fulltest.o lib/libtas.so
121-
122-
tools/tracetool: tools/tracetool.o
123-
tools/statetool: tools/statetool.o lib/libtas.so
124-
tools/scaletool: tools/scaletool.o lib/libtas.so
125-
126-
lib/libtas_sockets.so: $(call shared_objs, \
127-
$(SOCKETS_OBJS) $(STACK_OBJS) $(UTILS_OBJS))
128-
129-
lib/libtas_interpose.so: $(call shared_objs, \
130-
$(INTERPOSE_OBJS) $(SOCKETS_OBJS) $(STACK_OBJS) $(UTILS_OBJS))
131-
132-
lib/libtas.so: $(call shared_objs, $(UTILS_OBJS) $(STACK_OBJS))
133-
134-
%.shared.o: %.c
135-
$(CC) $(CFLAGS) -fPIC -c -o $@ $<
136-
137-
%.so:
138-
$(CC) $(LDFLAGS) -shared $^ $(LOADLIBES) $(LDLIBS) -o $@
66+
# Subdirectories
13967

68+
dir := lib
69+
include $(dir)/rules.mk
70+
71+
dir := tas
72+
include $(dir)/rules.mk
73+
74+
dir := tools
75+
include $(dir)/rules.mk
76+
77+
dir := tests
78+
include $(dir)/rules.mk
79+
80+
dir := doc
81+
include $(dir)/rules.mk
82+
83+
84+
##############################################################################
85+
# Top level targets
86+
87+
all: $(TARGETS)
14088

14189
clean:
142-
rm -f *.o tas/*.o tas/fast/*.o tas/slow/*.o lib/utils/*.o \
143-
lib/tas/*.o lib/sockets/*.o tests/*.o tests/*/*.o tools/*.o \
144-
lib/libtas_sockets.so lib/libtas_interpose.so \
145-
lib/libtas.so \
146-
$(TESTS) \
147-
tools/tracetool tools/statetool tools/scaletool \
148-
tas/tas
90+
rm -rf $(CLEAN) $(DEPS)
14991

15092
install: tas/tas lib/libtas_sockets.so lib/libtas_interpose.so \
15193
lib/libtas.so tools/statetool
@@ -164,4 +106,9 @@ uninstall:
164106
rm -f $(DESTDIR)$(LIBDIR)/libtas_sockets.so
165107
rm -f $(DESTDIR)$(LIBDIR)/libtas.so
166108

167-
.PHONY: all tests clean docs install uninstall run-tests
109+
110+
.DEFAULT_GOAL := all
111+
.PHONY: all clean
112+
113+
# Include dependencies
114+
-include $(DEPS)

doc/rules.mk

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
include mk/subdir_pre.mk
2+
3+
docs:
4+
cd doc && doxygen
5+
6+
CLEAN += doc/html doc/latex
7+
8+
.PHONY: docs
9+
10+
include mk/subdir_post.mk

lib/rules.mk

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
include mk/subdir_pre.mk
2+
3+
dir := $(d)/utils
4+
include $(dir)/rules.mk
5+
6+
dir := $(d)/tas
7+
include $(dir)/rules.mk
8+
9+
dir := $(d)/sockets
10+
include $(dir)/rules.mk
11+
12+
include mk/subdir_post.mk

lib/sockets/rules.mk

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
include mk/subdir_pre.mk
2+
3+
LIB_SOCKETS_OBJS = $(addprefix $(d)/, \
4+
control.o transfer.o context.o manage_fd.o epoll.o libc.o)
5+
LIB_SOCKETS_SOBJS := $(LIB_SOCKETS_OBJS:.o=.shared.o)
6+
7+
LIB_SINT_OBJS = $(addprefix $(d)/,interpose.o)
8+
LIB_SINT_SOBJS := $(LIB_SINT_OBJS:.o=.shared.o)
9+
10+
allobjs := $(LIB_SOCKETS_OBJS) $(LIB_SOCKETS_SOBJS) $(LIB_SINT_OBJS) \
11+
$(LIB_SINT_SOBJS)
12+
13+
LIB_SOCKETS_CPPFLAGS := -I$(d)/include/ -Ilib/tas/include
14+
15+
$(LIB_SOCKETS_OBJS): CPPFLAGS += $(LIB_SOCKETS_CPPFLAGS)
16+
$(LIB_SOCKETS_SOBJS): CPPFLAGS += $(LIB_SOCKETS_CPPFLAGS)
17+
$(LIB_SINT_OBJS): CPPFLAGS += $(LIB_SOCKETS_CPPFLAGS)
18+
$(LIB_SINT_SOBJS): CPPFLAGS += $(LIB_SOCKETS_CPPFLAGS)
19+
20+
lib/libtas_sockets.so: $(LIB_SOCKETS_SOBJS) $(LIB_TAS_SOBJS) \
21+
$(LIB_UTILS_SOBJS)
22+
23+
lib/libtas_interpose.so: $(LIB_SINT_SOBJS) $(LIB_SOCKETS_SOBJS) \
24+
$(LIB_TAS_SOBJS) $(LIB_UTILS_SOBJS)
25+
26+
DEPS += $(allobjs:.o=.d)
27+
CLEAN += $(allobjs) lib/libtas_sockets.so lib/libtas_interpose.so
28+
TARGETS += lib/libtas_sockets.so lib/libtas_interpose.so
29+
30+
include mk/subdir_post.mk

lib/tas/rules.mk

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
include mk/subdir_pre.mk
2+
3+
LIB_TAS_OBJS := $(addprefix $(d)/, \
4+
init.o kernel.o conn.o connect.o)
5+
LIB_TAS_SOBJS := $(LIB_TAS_OBJS:.o=.shared.o)
6+
7+
LIB_TAS_CPPFLAGS := -I$(d)/include/
8+
9+
$(LIB_TAS_OBJS): CPPFLAGS += $(LIB_TAS_CPPFLAGS)
10+
$(LIB_TAS_SOBJS): CPPFLAGS += $(LIB_TAS_CPPFLAGS)
11+
12+
lib/libtas.so: $(LIB_TAS_SOBJS) $(LIB_UTILS_SOBJS)
13+
14+
DEPS += $(LIB_TAS_OBJS:.o=.d) $(LIB_TAS_SOBJS:.o=.d)
15+
CLEAN += $(LIB_TAS_OBJS) $(LIB_TAS_SOBJS) lib/libtas.so
16+
TARGETS += lib/libtas.so
17+
18+
include mk/subdir_post.mk

lib/utils/rules.mk

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
include mk/subdir_pre.mk
2+
3+
LIB_UTILS_OBJS := $(addprefix $(d)/, \
4+
rng.o timeout.o utils.o)
5+
LIB_UTILS_SOBJS := $(LIB_UTILS_OBJS:.o=.shared.o)
6+
7+
DEPS += $(LIB_UTILS_OBJS:.o=.d) $(LIB_UTILS_SOBJS:.o=.d)
8+
CLEAN += $(LIB_UTILS_OBJS) $(LIB_UTILS_SOBJS)
9+
10+
include mk/subdir_post.mk

mk/recipes.mk

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Generic recipes
2+
3+
DEPFLAGS ?= -MT $@ -MMD -MP -MF $(@:.o=.Td)
4+
OUTPUT_OPTION.c ?= -o $@
5+
POSTCOMPILE_DEPS = mv -f $(@:.o=.Td) $(@:.o=.d)
6+
7+
# Compile C to object file while generating dependency
8+
COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) -c
9+
%.o: %.c
10+
%.o: %.c %.d
11+
$(COMPILE.c) $(OUTPUT_OPTION.c) $<
12+
@$(POSTCOMPILE_DEPS)
13+
14+
# Compile C to position independent object file while generating dependency
15+
COMPILE_SHARED.c = $(CC) $(DEPFLAGS) $(CFLAGS_SHARED) $(CPPFLAGS) -c
16+
%.shared.o: %.c
17+
%.shared.o: %.c %.shared.d
18+
$(COMPILE_SHARED.c) $(OUTPUT_OPTION.c) $<
19+
@$(POSTCOMPILE_DEPS)
20+
21+
# Link binary from objects
22+
LINK = $(CC) $(LDFLAGS)
23+
%: %.o
24+
$(LINK) $^ $(LDLIBS) -o $@
25+
26+
# Link shared library from objects
27+
LINK.so = $(CC) $(LDFLAGS) -shared
28+
%.so:
29+
$(LINK.so) $^ $(LDLIBS) $(OUTPUT_OPTION.c)
30+
31+
%.d: ;
32+
.PRECIOUS: %.d

mk/subdir_post.mk

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
d := $(dirstack_$(sp))
2+
sp := $(basename $(sp))

mk/subdir_pre.mk

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sp := $(sp).x
2+
dirstack_$(sp) := $(d)
3+
d := $(dir)

tas/rules.mk

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
include mk/subdir_pre.mk
2+
3+
objs_top := tas.o config.o shm.o
4+
objs_sp := kernel.o packetmem.o appif.o appif_ctx.o nicif.o cc.o tcp.o arp.o \
5+
routing.o kni.o
6+
objs_fp := fastemu.o network.o qman.o trace.o fast_kernel.o fast_appctx.o \
7+
fast_flows.o
8+
9+
TAS_OBJS := $(addprefix $(d)/, \
10+
$(objs_top) \
11+
$(addprefix slow/, $(objs_sp)) \
12+
$(addprefix fast/, $(objs_fp)))
13+
14+
exec := $(d)/tas
15+
16+
TAS_CPPFLAGS := -Iinclude/ -I$(d)/include/ $(DPDK_CPPFLAGS)
17+
TAS_CFLAGS := $(DPDK_CFLAGS)
18+
19+
$(TAS_OBJS): CPPFLAGS += $(TAS_CPPFLAGS)
20+
$(TAS_OBJS): CFLAGS += $(TAS_CFLAGS)
21+
22+
$(exec): LDFLAGS += $(DPDK_LDFLAGS)
23+
$(exec): LDLIBS += $(DPDK_LDLIBS)
24+
$(exec): $(TAS_OBJS) $(LIB_UTILS_OBJS)
25+
26+
DEPS += $(TAS_OBJS:.o=.d)
27+
CLEAN += $(TAS_OBJS) $(exec)
28+
TARGETS += $(exec)
29+
30+
include mk/subdir_post.mk

0 commit comments

Comments
 (0)