-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathMakefile
177 lines (130 loc) · 6.15 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
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
TOPDIR ?= ${CURDIR}
include config.mk
RTE_TARGET ?= x86_64-native-linuxapp-gcc
RTE_SDK = $(TOPDIR)/3rd/dpdk
ifeq ($(shell test -e $(RTE_SDK)/$(RTE_TARGET) || echo -n no),no)
$(error please build DPDK first. build command: 'make -C $(RTE_SDK) install T=$(RTE_TARGET)')
endif
include $(RTE_SDK)/mk/rte.vars.mk
# these variables are exported as environment variables in dpdk makefile,
# but it is useless for himongo(ARCH will cause compile error) and liburcu.
# so unexport it.
unexport CFLAGS
unexport LDFLAGS
unexport ARCH
ifeq ($(DEBUG), 1)
SHUKE_CFLAGS=-DSK_TEST
OPTIMIZATION ?=-O0
endif
SHUKE_BUILD_DIR ?= build
OPTIMIZATION ?=-O3
PREFIX?=/usr/local
INSTALL_BIN=$(PREFIX)/bin
INSTALL=install
# PROJECT_ROOT:=$(abspath .)
HIMONGO_STATICLIB:=3rd/himongo/libhimongo.a
URCU_STATIC_LIBS:=3rd/liburcu/src/.libs/liburcu-cds.a 3rd/liburcu/src/.libs/liburcu.a
LUAJIT_STATICLIB:=3rd/luajit/src/libluajit.a
SHUKE_SRC_DIR:=src
# Default settings
STD=-std=gnu99
WARN=-Wall -W
OPT=$(OPTIMIZATION)
DEBUG_FLAGS=-g -ggdb
LIB_DIR_LIST=/usr/local/lib \
$(RTE_SDK)/$(RTE_TARGET)/lib
INC_DIR_LIST=$(SHUKE_SRC_DIR) \
3rd \
3rd/liburcu/include \
3rd/liburcu/src \
3rd/luajit/src
# $(RTE_SDK)/$(RTE_TARGET)/include
SRC_LIST := admin.c ae.c anet.c conf.c dict.c dpdk_module.c \
dpdk_kni.c dnspacket.c debug.c mongo.c \
rbtree.c rculfhash-mm-socket.c sds.c shuke.c \
str.c utils.c zparser.c zmalloc.c tcpserver.c \
ltree.c toml.c zone.c \
sk_lua_util.c sk_lua_log.c sk_lua_var.c sk_lua_dns.c
SHUKE_SRC := $(foreach v, $(SRC_LIST), $(SHUKE_SRC_DIR)/$(v))
SHUKE_OBJ := $(patsubst %.c,$(SHUKE_BUILD_DIR)/%.o,$(SRC_LIST))
FINAL_CFLAGS=$(STD) $(WARN) $(OPT) $(DEBUG_FLAGS) $(CFLAGS) $(SHUKE_CFLAGS) $(MACROS)
FINAL_LDFLAGS=$(LDFLAGS) $(SHUKE_LDFLAGS) $(DEBUG_FLAGS)
FINAL_LIBS=$(HIMONGO_STATICLIB) $(URCU_STATIC_LIBS) $(LUAJIT_STATICLIB) -pthread -lrt
# FINAL_CFLAGS += -include $(RTE_SDK)/$(RTE_TARGET)/include/rte_config.h -msse4.2
FINAL_CFLAGS += $(addprefix -I,$(INC_DIR_LIST))
FINAL_LDFLAGS += $(addprefix -L,$(LIB_DIR_LIST))
SHUKE_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS)
SHUKE_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS)
SHUKE_INSTALL=$(QUIET_INSTALL)$(INSTALL)
CCCOLOR="\033[34m"
LINKCOLOR="\033[34;1m"
SRCCOLOR="\033[33m"
BINCOLOR="\033[37;1m"
MAKECOLOR="\033[32;1m"
ENDCOLOR="\033[0m"
ifndef V
QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2;
QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
QUIET_INSTALL = @printf ' %b %b\n' $(LINKCOLOR)INSTALL$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
endif
# include $(RTE_SDK)/mk/rte.extapp.mk
all: $(SHUKE_BUILD_DIR) $(SHUKE_BUILD_DIR)/shuke-server
Makefile.dep:
set -e; rm -f $@; \
$(CC) -I$(SHUKE_SRC_DIR) -I3rd -MM $(SHUKE_SRC) > Makefile.dep 2> /dev/null || true; \
sed "s/^\([^\.]*\.o\)/$(SHUKE_BUILD_DIR)\/\1/g" $@ > $@.$$$$; \
mv -f $@.$$$$ $@; \
rm -f $@.$$$$
-include Makefile.dep
-include $(SHUKE_BUILD_DIR)/.make-settings
persist-settings: clean
echo PREV_FINAL_CFLAGS=$(FINAL_CFLAGS) >> $(SHUKE_BUILD_DIR)/.make-settings
echo PREV_FINAL_LDFLAGS=$(FINAL_LDFLAGS) >> $(SHUKE_BUILD_DIR)/.make-settings
.PHONY: persist-settings
# Prerequisites target
$(SHUKE_BUILD_DIR)/.make-prerequisites:
@touch $@
# Clean everything, persist settings and build dependencies if anything changed
ifneq ($(strip $(PREV_FINAL_CFLAGS)), $(strip $(FINAL_CFLAGS)))
$(SHUKE_BUILD_DIR)/.make-prerequisites: persist-settings
endif
ifneq ($(strip $(PREV_FINAL_LDFLAGS)), $(strip $(FINAL_LDFLAGS)))
$(SHUKE_BUILD_DIR)/.make-prerequisites: persist-settings
endif
$(SHUKE_BUILD_DIR)/shuke-server: 3rd $(SHUKE_OBJ)
$(SHUKE_LD) -o $@ $(SHUKE_OBJ) $(DPDKLIBS) $(FINAL_LIBS)
$(SHUKE_BUILD_DIR)/%.o: $(SHUKE_SRC_DIR)/%.c $(SHUKE_BUILD_DIR)/.make-prerequisites
$(SHUKE_CC) -c $< -o $@
clean:
-rm -f $(SHUKE_BUILD_DIR)/shuke-server $(SHUKE_BUILD_DIR)/*.o Makefile.dep
-(rm -f $(SHUKE_BUILD_DIR)/.make-*)
.PHONY:clean
distclean: clean
-(make -C 3rd/himongo clean)
-(make -C 3rd/liburcu clean)
.PHONY: distclean
$(SHUKE_BUILD_DIR):
mkdir -p $(SHUKE_BUILD_DIR)
@PHONY: $(SHUKE_BUILD_DIR)
3rd: $(HIMONGO_STATICLIB) $(URCU_STATIC_LIBS) $(LUAJIT_STATICLIB)
update3rd:
rm -rf 3rd/himongo 3rd/liburcu && git submodule update --init
$(HIMONGO_STATICLIB): 3rd/himongo/Makefile
cd 3rd/himongo && make
3rd/himongo/Makefile:
git submodule update --init
$(URCU_STATIC_LIBS): 3rd/liburcu/Makefile
cd 3rd/liburcu && make
3rd/liburcu/Makefile: | 3rd/liburcu/bootstrap
cd 3rd/liburcu && ./bootstrap && ./configure
3rd/liburcu/bootstrap:
git submodule update --init
3rd/luajit/Makefile:
git submodule update --init
$(LUAJIT_STATICLIB): 3rd/luajit/Makefile
make -C 3rd/luajit
install: all
@mkdir -p $(INSTALL_BIN)
$(SHUKE_INSTALL) build/shuke-server $(INSTALL_BIN)
#Libraries of dpdk
DPDKLIBS = -Wl,-lrte_pipeline -Wl,-lrte_table -Wl,-lrte_port -Wl,-lrte_pdump -Wl,-lrte_distributor -Wl,-lrte_ip_frag -Wl,-lrte_meter -Wl,-lrte_sched -Wl,-lrte_lpm -Wl,--whole-archive -Wl,-lrte_acl -Wl,--no-whole-archive -Wl,-lrte_jobstats -Wl,-lrte_metrics -Wl,-lrte_bitratestats -Wl,-lrte_latencystats -Wl,-lrte_power -Wl,-lrte_timer -Wl,-lrte_efd -Wl,-lrte_cfgfile -Wl,--whole-archive -Wl,-lrte_hash -Wl,-lrte_vhost -Wl,-lrte_kvargs -Wl,-lrte_mbuf -Wl,-lrte_net -Wl,-lrte_ethdev -Wl,-lrte_cryptodev -Wl,-lrte_eventdev -Wl,-lrte_mempool -Wl,-lrte_mempool_ring -Wl,-lrte_ring -Wl,-lrte_eal -Wl,-lrte_cmdline -Wl,-lrte_reorder -Wl,-lrte_kni -Wl,-lrte_mempool_stack -Wl,-lrte_pmd_af_packet -Wl,-lrte_pmd_ark -Wl,-lrte_pmd_avp -Wl,-lrte_pmd_bnxt -Wl,-lrte_pmd_bond -Wl,-lrte_pmd_cxgbe -Wl,-lrte_pmd_e1000 -Wl,-lrte_pmd_ena -Wl,-lrte_pmd_enic -Wl,-lrte_pmd_fm10k -Wl,-lrte_pmd_i40e -Wl,-lrte_pmd_ixgbe -Wl,-lrte_pmd_kni -Wl,-lrte_pmd_lio -Wl,-lrte_pmd_nfp -Wl,-lrte_pmd_null -Wl,-lrte_pmd_qede -Wl,-lrte_pmd_ring -Wl,-lrte_pmd_sfc_efx -Wl,-lrte_pmd_tap -Wl,-lrte_pmd_thunderx_nicvf -Wl,-lrte_pmd_virtio -Wl,-lrte_pmd_vhost -Wl,-lrte_pmd_vmxnet3_uio -Wl,-lrte_pmd_null_crypto -Wl,-lrte_pmd_crypto_scheduler -Wl,-lrte_pmd_skeleton_event -Wl,-lrte_pmd_sw_event -Wl,-lrte_pmd_octeontx_ssovf -Wl,--no-whole-archive -Wl,-lrt -Wl,-lm -Wl,-ldl -Wl,-export-dynamic -Wl,-export-dynamic