-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
136 lines (104 loc) · 3.62 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
#
# Rodzhang
#
#
vpath %.c src
TARGET = ./build/spate
# Import source code directory
include mk/src_dir.mk
include mk/include.mk
include mk/src_dpdk_dir.mk
include mk/dpdk.mk
include mk/src_ebpf_dir.mk
include mk/ebpf.mk
#Debug configuration:
DEBUG_C_FLAGS = -DSPATE_DEBUG -g -O0
#Release configuration:
RELEASE_C_FLAGS = -g -O3
CFLAGS = -Wall -Werror -rdynamic $(D_INC)
LIBS = -lpthread -lm -lpcap -rdynamic
ifeq ($(dpdk_enable), 1)
VERSION:=$(shell pkg-config --modversion libdpdk)
SRC_DIR += $(DPDK_SRC_DIR)
CFLAGS += $(DPDK_CFLAGS) -DDPDK_ENABLE
LIBS += $(DPDK_DEP_LIBS)
endif
ifeq ($(ebpf_enable), 1)
SRC_DIR += $(EBPF_SRC_DIR)
CFLAGS += -DEBPF_ENABLE
LIBS += $(EBPF_DEP_LIBS)
endif
ifeq ($(usdt_enable), 1)
CFLAGS += -DUSDT_ENABLE
endif
OBJ_DIR = $(foreach dir, $(SRC_DIR), $(addprefix build/, $(dir)))
SRC_C = $(foreach dir, $(SRC_DIR), $(wildcard $(dir)/*.c))
OBJECT = $(addprefix build/, $(patsubst %.c, %.o, $(SRC_C)))
$(TARGET):$(OBJECT)
gcc -g -rdynamic -o $@ $^ $(LIBS)
$(OBJECT):$(SRC_C)
gcc -c $(CFLAGS) $(patsubst %.o, %.c, $(subst build/, , $@)) -o $@
.PHONY: clean dir check debug release
debug: CFLAGS += $(DEBUG_C_FLAGS)
release: CFLAGS += $(RELEASE_C_FLAGS)
ifeq ($(ebpf_enable), 1)
debug: dir $(TARGET) $(EBPF_OBJ)
release: dir $(TARGET) $(EBPF_OBJ)
else
debug: dir $(TARGET)
release: dir $(TARGET)
endif
#Notice: Do not use variables for the rm commond! To avoid misoperation.
clean:
rm -rf ./build
dir:
mkdir -p $(OBJ_DIR)
install:
cp $(TARGET) /usr/local/bin/
.DEFAULT_GOAL := help
help:
@echo ""
@echo "This is the document that tells you how to make:"
@echo ""
@echo "Compile on Linux platform, can use command:"
@echo " \033[1;37m make debug \033[0m : compile debug version"
@echo " \033[1;37m make release \033[0m : compile release version"
@echo ""
@echo "Compile with DPDK(support Linux and DPDK), can use command:"
@echo " \033[1;37m make dpdk_enable=1 debug \033[0m : compile debug version"
@echo " \033[1;37m make dpdk_enable=1 release \033[0m : compile release version"
@echo "Note: Make sure you have installed \033[1;31mDPDK-20.11\033[0m in your system if you want to build with DPDK."
@echo ""
@echo "Compile with eBPF-offload on Linux, can use command:"
@echo " \033[1;37m make ebpf_enable=1 debug \033[0m : compile debug version"
@echo " \033[1;37m make ebpf_enable=1 release \033[0m : compile release version"
@echo "Note: Make sure you have installed \033[1;31mlibbpf\033[0m in your system if you want to build with eBPF offload."
@echo ""
@echo "Compile with all feature(support eBPF,DPDK), can use command:"
@echo " \033[1;37m make dpdk_enable=1 ebpf_enable=1 debug \033[0m "
@echo " \033[1;37m make dpdk_enable=1 ebpf_enable=1 release \033[0m "
@echo ""
@echo "Compile with usdt(for tracing), can use command:"
@echo " \033[1;37m make usdt_enable=1 debug \033[0m "
@echo ""
@echo "How to clean, use command:"
@echo " \033[1;37m make clean \033[0m : clean all compiled objects"
@echo ""
@echo "How to install, use command:"
@echo " \033[1;37m make install \033[0m : install to /usr/local/bin"
@echo ""
@echo "Note: Please make clean before make if you have already complied before, "
@echo "For example, you can enter: \033[0;33m make clean; make release -j 8 \033[0m "
@echo "For example, you can enter: \033[0;33m make clean; make dpdk_enable=1 usdt_enable=1 debug -j 8 \033[0m "
@echo "\n\n"
check:
ifeq ($(dpdk_enable), 1)
@echo "dpdk enable"
else
@echo "dpdk disable"
endif
ifeq ($(ebpf_enable), 1)
@echo "ebpf enable"
else
@echo "ebpf disable"
endif