-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
executable file
·186 lines (131 loc) · 7.52 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
178
179
180
181
182
183
184
185
186
LUA_PATH ?= ./3rd/lua
LUA_INC ?= ./3rd/lua/src
LUA_STATIC_LIB ?= ./3rd/lua/src/liblua.a
LIBEV_PATH ?= 3rd/libev
LIBEV_INC ?= 3rd/libev
LIBEV_SHARE_LIB ?= 3rd/libev/.libs/libev.so
TC_PATH ?= 3rd/gperftools
TC_INC ?= 3rd/gperftools/src/gperftools
TC_STATIC_LIB= 3rd/gperftools/.libs/libtcmalloc_and_profiler.a
EFENCE_PATH ?= ./3rd/electric-fence
EFENCE_STATIC_LIB ?= ./3rd/electric-fence/libefence.a
# $(warning $(SIGAR_LUA_SRC))
# $(shell find $(SIGAR_LUA_INC) -maxdepth 3 -type d)
# $(foreach dir,$(SIGAR_LUA_DIR),$(wildcard $(dir)/*.c))
# find . -type f -exec dos2unix {} \;
# makefile自动找到第一个目标去执行
# .PHONY 声明变量是命令而非目标文件,在目标没有依赖,而又存在目标文件时
LUA_CLIB_PATH ?= ./.libs
LUA_CLIB_SRC ?= ./luaclib
LUA_CLIB = ev worker profiler dump serialize redis bson mongo util lfs cjson http ikcp fastaoi toweraoi pathfinder nav mysql protocolparser protocolcore filter0 filter1 co snapshot
CONVERT_PATH ?= ./luaclib/convert
CONVERT_SRC ?= $(wildcard $(CONVERT_PATH)/milo/*.cpp)
CONVERT_OBJ = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(CONVERT_SRC)))
DOUBLE_CONVERSION_SRC ?= $(wildcard $(CONVERT_PATH)/double-conversion/*.cc)
DOUBLE_CONVERSION_OBJ = $(patsubst %.cc,%.o,$(DOUBLE_CONVERSION_SRC))
MAIN_PATH ?= ./src
MAIN_SRC ?= $(wildcard $(MAIN_PATH)/*.c)
MAIN_OBJ = $(patsubst %.c,%.o,$(patsubst %.cc,%.o,$(MAIN_SRC)))
TARGET ?= event
CC=gcc
CFLAGS=-g -Wall -O3 -fno-omit-frame-pointer $(DEFINE)
LDFLAGS=-lrt -lm -ldl -lpthread -lssl -lunwind -lstdc++
STATIC_LIBS=$(LUA_STATIC_LIB) $(TC_STATIC_LIB)
DEFINE=-DUSE_TC
SHARED=-fPIC --shared
.PHONY : all clean debug libc efence
all : \
$(LIBEV_SHARE_LIB) \
$(STATIC_LIBS) \
$(TARGET) \
$(foreach v, $(LUA_CLIB), $(LUA_CLIB_PATH)/$(v).so)
cp $(TARGET) $(TARGET).raw && strip $(TARGET).raw
$(LUA_STATIC_LIB) :
cd $(LUA_PATH) && make linux
$(EFENCE_STATIC_LIB) :
cd $(EFENCE_PATH) && make
$(TC_STATIC_LIB) :
cd $(TC_PATH) && sh autogen.sh && ./configure && make
$(LIBEV_SHARE_LIB) :
cd $(LIBEV_PATH) && ./configure && make
$(LUA_CLIB_PATH):
mkdir $(LUA_CLIB_PATH)
$(CONVERT_PATH)/milo/%.o:$(CONVERT_PATH)/milo/%.cpp
$(CC) $(CFLAGS) -fPIC -o $@ -c $<
$(CONVERT_PATH)/double-conversion/%.o:$(CONVERT_PATH)/double-conversion/%.cc
$(CC) $(CFLAGS) -fPIC -o $@ -c $< -I$(CONVERT_PATH)
$(MAIN_PATH)/%.o:$(MAIN_PATH)/%.c
$(CC) $(CFLAGS) -o $@ -c $< -I$(LUA_INC) -I$(TC_INC)
$(MAIN_PATH)/%.o:$(MAIN_PATH)/%.cc
$(CC) $(CFLAGS) -o $@ -c $< -I$(LUA_INC) -I$(TC_INC)
debug :
$(MAKE) $(ALL) CFLAGS="-g -Wall -Wno-unused-value -fno-omit-frame-pointer" TC_STATIC_LIB="3rd/gperftools/.libs/libtcmalloc_debug.a" LDFLAGS="-lrt -lm -ldl -lprofiler -lpthread -lssl -lstdc++"
leak :
$(MAKE) $(ALL) CC=clang CFLAGS="-g -Wall -Wno-unused-value -fno-omit-frame-pointer -fsanitize=address -fsanitize=leak" DEFINE="" STATIC_LIBS="$(LUA_STATIC_LIB) $(LIBEVENT_STATIC_LIB)" LDFLAGS="-lrt -lm -ldl -lpthread -lssl -lstdc++"
libc :
$(MAKE) $(ALL) DEFINE="" STATIC_LIBS="$(LUA_STATIC_LIB) $(LIBEVENT_STATIC_LIB)" LDFLAGS="-lrt -lm -ldl -lpthread -lssl -lstdc++"
efence :
$(MAKE) $(ALL) DEFINE="" STATIC_LIBS="$(LUA_STATIC_LIB) $(LIBEVENT_STATIC_LIB) $(EFENCE_STATIC_LIB)" LDFLAGS="-lrt -lm -ldl -lpthread -lssl -lstdc++"
$(TARGET) : $(MAIN_OBJ) $(STATIC_LIBS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -Wl,-E
$(LUA_CLIB_PATH)/ev.so : $(LUA_CLIB_SRC)/lua-ev.c $(LUA_CLIB_SRC)/lua-client.c $(LUA_CLIB_SRC)/common.c $(LUA_CLIB_SRC)/socket_event.c $(LUA_CLIB_SRC)/socket_util.c $(LUA_CLIB_SRC)/object_container.c $(LIBEV_SHARE_LIB) | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) -Wno-strict-aliasing $(SHARED) $^ -o $@ -I$(LUA_INC) -I$(LIBEV_INC)
$(LUA_CLIB_PATH)/worker.so : $(LUA_CLIB_SRC)/lua-worker.c $(LUA_CLIB_SRC)/message_queue.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
$(LUA_CLIB_PATH)/profiler.so : $(LUA_CLIB_SRC)/lua-profiler.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
$(LUA_CLIB_PATH)/dump.so : $(LUA_CLIB_SRC)/lua-dump.c ./3rd/lua-cjson/dtoa.c $(CONVERT_OBJ) | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) -Wno-uninitialized $(SHARED) $^ -o $@ -I$(LUA_INC) -I$(CONVERT_PATH)
$(LUA_CLIB_PATH)/serialize.so : $(LUA_CLIB_SRC)/lua-serialize.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
$(LUA_CLIB_PATH)/redis.so : $(LUA_CLIB_SRC)/lua-redis.c $(CONVERT_OBJ) | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC) -I$(CONVERT_PATH)
$(LUA_CLIB_PATH)/bson.so : $(LUA_CLIB_SRC)/lua-bson.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
$(LUA_CLIB_PATH)/mongo.so : $(LUA_CLIB_SRC)/lua-mongo.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
$(LUA_CLIB_PATH)/util.so : $(LUA_CLIB_SRC)/lua-util.c $(LUA_CLIB_SRC)/common.c $(CONVERT_OBJ) $(DOUBLE_CONVERSION_OBJ) ./3rd/linenoise/linenoise.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) -Wno-unused-value $(SHARED) $^ -o $@ -I$(LUA_INC) -I$(CONVERT_PATH) -I$(CONVERT_PATH)/ -I./3rd/linenoise
$(LUA_CLIB_PATH)/lfs.so : ./3rd/luafilesystem/src/lfs.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
$(LUA_CLIB_PATH)/cjson.so : $(filter-out ./3rd/lua-cjson/g_fmt.c ./3rd/lua-cjson/dtoa.c,$(foreach v, $(wildcard ./3rd/lua-cjson/*.c), $(v))) | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
$(LUA_CLIB_PATH)/http.so : $(LUA_CLIB_SRC)/lua-http-parser.c ./3rd/http-parser/http_parser.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC) -I./3rd/http-parser
$(LUA_CLIB_PATH)/ikcp.so : $(LUA_CLIB_SRC)/lua-ikcp.c $(LUA_CLIB_SRC)/ikcp.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
$(LUA_CLIB_PATH)/fastaoi.so : $(LUA_CLIB_SRC)/lua-fast-aoi.c $(LUA_CLIB_SRC)/pool.c $(LUA_CLIB_SRC)/object_container.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
$(LUA_CLIB_PATH)/toweraoi.so : $(LUA_CLIB_SRC)/lua-tower-aoi.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC) -I./3rd/klib
$(LUA_CLIB_PATH)/pathfinder.so : $(LUA_CLIB_SRC)/lua-pathfinder.c $(LUA_CLIB_SRC)/pathfinder.c $(LUA_CLIB_SRC)/minheap.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
$(LUA_CLIB_PATH)/nav.so : $(LUA_CLIB_SRC)/lua-nav.c $(LUA_CLIB_SRC)/nav_loader.c $(LUA_CLIB_SRC)/nav_finder.c $(LUA_CLIB_SRC)/nav_tile.c $(LUA_CLIB_SRC)/minheap.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
$(LUA_CLIB_PATH)/mysql.so : $(LUA_CLIB_SRC)/lua-mysql.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC) -lmysqlclient
$(LUA_CLIB_PATH)/protocolparser.so : $(LUA_CLIB_SRC)/lua-protocol-parser.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
$(LUA_CLIB_PATH)/protocolcore.so : $(LUA_CLIB_SRC)/lua-protocol.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
$(LUA_CLIB_PATH)/filter0.so : $(LUA_CLIB_SRC)/lua-filter0.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC) -I./3rd/klib -liconv
$(LUA_CLIB_PATH)/filter1.so : $(LUA_CLIB_SRC)/lua-filter1.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC) -I./3rd/klib
$(LUA_CLIB_PATH)/co.so : $(LUA_CLIB_SRC)/lua-co.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
$(LUA_CLIB_PATH)/snapshot.so : $(LUA_CLIB_SRC)/lua-snapshot.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I$(LUA_INC)
clean :
rm -rf $(TARGET) $(TARGET).raw
rm -rf $(LUA_CLIB_PATH)
rm -rf src/*.o
rm -rf luaclib/convert/milo/*.o
rm -rf luaclib/convert/double-conversion/*.o
cleanall :
make clean
cd $(LUA_PATH) && make clean
cd $(LIBEV_PATH) && make clean
# cd $(TC_PATH) && make distclean
cd $(TC_PATH) && make clean
cd $(EFENCE_PATH) && make clean