forked from cloudwu/skynet
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
280 lines (220 loc) · 7.86 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
include platform.mk
LUA_CLIB_PATH ?= luaclib
CSERVICE_PATH ?= cservice
RS232_CLIB_PATH ?= luaclib/rs232
SKYNET_BUILD_PATH ?= .
CFLAGS = -g -O2 -Wall -I$(LUA_INC) $(MYCFLAGS)
# CFLAGS += -DUSE_PTHREAD_LOCK
# lua
LUA_STATICLIB := 3rd/lua/liblua.a
LUA_LIB ?= $(LUA_STATICLIB)
LUA_INC ?= 3rd/lua
$(LUA_STATICLIB) :
cd 3rd/lua && $(MAKE) CC='$(CC) -std=gnu99' $(PLAT)
# https : turn on TLS_MODULE to add https support
TLS_MODULE=ltls
TLS_LIB=
TLS_INC=
# jemalloc
JEMALLOC_STATICLIB := 3rd/jemalloc/lib/libjemalloc_pic.a
JEMALLOC_INC := 3rd/jemalloc/include/jemalloc
all : jemalloc
.PHONY : jemalloc update3rd
MALLOC_STATICLIB := $(JEMALLOC_STATICLIB)
$(JEMALLOC_STATICLIB) : 3rd/jemalloc/Makefile
cd 3rd/jemalloc && $(MAKE) CC=$(CC)
3rd/jemalloc/autogen.sh :
git submodule update --init
3rd/jemalloc/Makefile : | 3rd/jemalloc/autogen.sh
cd 3rd/jemalloc && ./autogen.sh --with-jemalloc-prefix=je_ --enable-prof $(JEMALLOC_FLAGS)
jemalloc : $(MALLOC_STATICLIB)
update3rd :
rm -rf 3rd/jemalloc && git submodule update --init
# skynet
CSERVICE = snlua logger gate harbor
LUA_CLIB = skynet \
client \
bson md5 sproto lpeg $(TLS_MODULE) \
\
LUA_EX_CLIB = \
lfs cjson iconv \
rs232/core mosquitto \
lcurl zlib lsocket \
lcrypt qpack luevent \
\
ICONV_LIBS :=
ifeq ($(PLAT),openwrt)
ICONV_LIBS := -Bstatic -l:libiconv.a -L$(STAGING_DIR)/usr/lib/libiconv-full-full/lib -I$(STAGING_DIR)/usr/lib/libiconv-full-full/include
else
ifeq ($(PLAT),android)
ICONV_LIBS := -liconv
else
LUA_EX_CLIB += enet libmodbus
endif
endif
LUA_CLIB_SKYNET = \
lua-skynet.c lua-seri.c \
lua-socket.c \
lua-mongo.c \
lua-netpack.c \
lua-memory.c \
lua-multicast.c \
lua-cluster.c \
lua-crypt.c lsha1.c \
lua-sharedata.c \
lua-stm.c \
lua-debugchannel.c \
lua-datasheet.c \
lua-sharetable.c \
\
SKYNET_SRC = skynet_main.c skynet_handle.c skynet_module.c skynet_mq.c \
skynet_server.c skynet_start.c skynet_timer.c skynet_error.c \
skynet_harbor.c skynet_env.c skynet_monitor.c skynet_socket.c socket_server.c \
malloc_hook.c skynet_daemon.c skynet_log.c
all : \
$(SKYNET_BUILD_PATH)/skynet \
$(foreach v, $(CSERVICE), $(CSERVICE_PATH)/$(v).so) \
$(foreach v, $(LUA_CLIB), $(LUA_CLIB_PATH)/$(v).so) \
$(foreach v, $(LUA_EX_CLIB), $(LUA_CLIB_PATH)/$(v).so)
$(SKYNET_BUILD_PATH)/skynet : $(foreach v, $(SKYNET_SRC), skynet-src/$(v)) $(LUA_LIB) $(MALLOC_STATICLIB)
$(CC) $(CFLAGS) -o $@ $^ -Iskynet-src -I$(JEMALLOC_INC) $(LDFLAGS) $(EXPORT) $(SKYNET_LIBS) $(SKYNET_DEFINES)
$(LUA_CLIB_PATH) :
mkdir $(LUA_CLIB_PATH)
$(CSERVICE_PATH) :
mkdir $(CSERVICE_PATH)
$(RS232_CLIB_PATH):
mkdir $(RS232_CLIB_PATH)
define CSERVICE_TEMP
$$(CSERVICE_PATH)/$(1).so : service-src/service_$(1).c | $$(CSERVICE_PATH)
$$(CC) $$(CFLAGS) $$(SHARED) $$< -o $$@ -Iskynet-src
endef
$(foreach v, $(CSERVICE), $(eval $(call CSERVICE_TEMP,$(v))))
$(LUA_CLIB_PATH)/skynet.so : $(addprefix lualib-src/,$(LUA_CLIB_SKYNET)) | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -Iskynet-src -Iservice-src -Ilualib-src
$(LUA_CLIB_PATH)/bson.so : lualib-src/lua-bson.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -Iskynet-src $^ -o $@
$(LUA_CLIB_PATH)/md5.so : 3rd/lua-md5/md5.c 3rd/lua-md5/md5lib.c 3rd/lua-md5/compat-5.2.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -I3rd/lua-md5 $^ -o $@
$(LUA_CLIB_PATH)/client.so : lualib-src/lua-clientsocket.c lualib-src/lua-crypt.c lualib-src/lsha1.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@
$(LUA_CLIB_PATH)/sproto.so : lualib-src/sproto/sproto.c lualib-src/sproto/lsproto.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -Ilualib-src/sproto $^ -o $@
$(LUA_CLIB_PATH)/ltls.so : lualib-src/ltls.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -Iskynet-src -L$(TLS_LIB) -I$(TLS_INC) $^ -o $@ -lssl -lcrypto
$(LUA_CLIB_PATH)/lpeg.so : 3rd/lpeg/lpcap.c 3rd/lpeg/lpcode.c 3rd/lpeg/lpprint.c 3rd/lpeg/lptree.c 3rd/lpeg/lpvm.c 3rd/lpeg/lpcset.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -I3rd/lpeg $^ -o $@
$(LUA_CLIB_PATH)/lfs.so : 3rd/luafilesystem/src/lfs.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -I3rd/luafilesystem/src $^ -o $@
$(LUA_CLIB_PATH)/cjson.so : 3rd/cjson/fpconv.c 3rd/cjson/lua_cjson.c 3rd/cjson/strbuf.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -I3rd/cjson $^ -o $@
$(LUA_CLIB_PATH)/iconv.so : 3rd/iconv/luaiconv.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -I3rd/iconv $^ -o $@ $(ICONV_LIBS)
$(LUA_CLIB_PATH)/enet.so : 3rd/lua-enet/enet.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -I3rd/enet $^ -o $@ -lenet
$(LUA_CLIB_PATH)/rs232/core.so : 3rd/librs232/src/rs232.c 3rd/librs232/src/rs232_posix.c 3rd/librs232/bindings/lua/luars232.c | $(RS232_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -I3rd/librs232/include $^ -o $@
$(LUA_CLIB_PATH)/libmodbus.so : 3rd/lua-libmodbus/lua-libmodbus.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -I3rd/lua-libmodbus $^ -o $@ -lmodbus
$(LUA_CLIB_PATH)/zlib.so : 3rd/lua-zlib/lua_zlib.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -I3rd/lua-zlib $^ -o $@ -lz
$(LUA_CLIB_PATH)/lsocket.so : 3rd/lsocket/lsocket.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -I3rd/lsocket $^ -o $@
$(LUA_CLIB_PATH)/qpack.so : 3rd/lua-qpack/lua_qpack.c 3rd/lua-qpack/qpack/qpack.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -I3rd/lua-qpack $^ -o $@
$(LUA_CLIB_PATH)/luevent.so : 3rd/lua-uevent/lua_uevent.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -I3rd/lua-uevent $^ -o $@
LUA_CLIB_MQTT_MOSQ = \
lib/actions.c \
lib/alias_mosq.c \
lib/callbacks.c \
lib/connect.c \
lib/handle_auth.c \
lib/handle_connack.c \
lib/handle_disconnect.c \
lib/handle_ping.c \
lib/handle_pubackcomp.c \
lib/handle_publish.c \
lib/handle_pubrec.c \
lib/handle_pubrel.c \
lib/handle_suback.c \
lib/handle_unsuback.c \
lib/helpers.c \
lib/logging_mosq.c \
lib/loop.c \
lib/memory_mosq.c \
lib/messages_mosq.c \
lib/misc_mosq.c \
lib/mosquitto.c \
lib/net_mosq.c \
lib/net_mosq_ocsp.c \
lib/options.c \
lib/packet_datatypes.c \
lib/packet_mosq.c \
lib/property_mosq.c \
lib/read_handle.c \
lib/send_connect.c \
lib/send_disconnect.c \
lib/send_mosq.c \
lib/send_publish.c \
lib/send_subscribe.c \
lib/send_unsubscribe.c \
lib/socks_mosq.c \
lib/srv_mosq.c \
lib/thread_mosq.c \
lib/time_mosq.c \
lib/tls_mosq.c \
lib/utf8_mosq.c \
lib/util_mosq.c \
lib/util_topic.c \
lib/will_mosq.c \
\
LUA_CLIB_MOSQ = \
lua-mosquitto.c \
\
LUA_CLIB_MOSQ_INCLUDES = \
-I3rd/lua-mosquitto/deps/mosquitto -I3rd/lua-mosquitto/deps/mosquitto/lib -I3rd/lua-mosquitto/deps/mosquitto/include -I3rd/lua-mosquitto -I3rd/lua-mosquitto/deps/mosquitto/deps
$(LUA_CLIB_PATH)/mosquitto.so : $(addprefix 3rd/lua-mosquitto/deps/mosquitto/,$(LUA_CLIB_MQTT_MOSQ)) $(addprefix 3rd/lua-mosquitto/,$(LUA_CLIB_MOSQ)) | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ $(LUA_CLIB_MOSQ_INCLUDES) -DVERSION=\"1.4.12\" -DWITH_TLS -DWITH_TLS_PSK -lssl -lcrypto
LUA_CLIB_LCURL = \
src/l52util.c \
src/lceasy.c \
src/lcerror.c \
src/lchttppost.c \
src/lcmime.c \
src/lcmulti.c \
src/lcshare.c \
src/lcurlapi.c \
src/lcurl.c \
src/lcutils.c \
\
$(LUA_CLIB_PATH)/lcurl.so : $(addprefix 3rd/curl/,$(LUA_CLIB_LCURL)) | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I3rd/curl/src -DPTHREADS -lcurl
LUA_CLIB_LCRYPT = \
src/aes.c \
src/b64.c \
src/crc.c \
src/des.c \
src/dh.c \
src/hex.c \
src/hmac.c \
src/hmac_ex.c \
src/lcrypt.c \
src/lsys.c \
src/rc.c \
src/rsa.c \
src/sha.c \
src/sm.c \
src/url.c \
src/uuid.c
$(LUA_CLIB_PATH)/lcrypt.so : $(addprefix 3rd/lcrypt/,$(LUA_CLIB_LCRYPT)) | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -I3rd/lcrypt/src -DPTHREADS -lcrypto
clean :
rm -f $(SKYNET_BUILD_PATH)/skynet $(CSERVICE_PATH)/*.so $(LUA_CLIB_PATH)/*.so && \
rm -rf $(SKYNET_BUILD_PATH)/*.dSYM $(CSERVICE_PATH)/*.dSYM $(LUA_CLIB_PATH)/*.dSYM
rm -rf $(RS232_CLIB_PATH)
cleanall: clean
ifneq (,$(wildcard 3rd/jemalloc/Makefile))
cd 3rd/jemalloc && $(MAKE) clean && rm Makefile
endif
cd 3rd/lua && $(MAKE) clean
rm -f $(LUA_STATICLIB)