Makefile 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. include platform.mk
  2. LUA_CLIB_PATH ?= luaclib
  3. CSERVICE_PATH ?= cservice
  4. SKYNET_BUILD_PATH ?= .
  5. CFLAGS = -g -O2 -Wall -I$(LUA_INC) $(MYCFLAGS)
  6. # CFLAGS += -DUSE_PTHREAD_LOCK
  7. # lua
  8. LUA_STATICLIB := 3rd/lua/liblua.a
  9. LUA_LIB ?= $(LUA_STATICLIB)
  10. LUA_INC ?= 3rd/lua
  11. $(LUA_STATICLIB) :
  12. cd 3rd/lua && $(MAKE) CC='$(CC) -std=gnu99' $(PLAT)
  13. # https : turn on TLS_MODULE to add https support
  14. TLS_MODULE=ltls
  15. TLS_LIB=
  16. TLS_INC=
  17. # jemalloc
  18. JEMALLOC_STATICLIB := 3rd/jemalloc/lib/libjemalloc_pic.a
  19. JEMALLOC_INC := 3rd/jemalloc/include/jemalloc
  20. all : jemalloc
  21. .PHONY : jemalloc update3rd
  22. MALLOC_STATICLIB := $(JEMALLOC_STATICLIB)
  23. $(JEMALLOC_STATICLIB) : 3rd/jemalloc/Makefile
  24. cd 3rd/jemalloc && $(MAKE) CC=$(CC)
  25. 3rd/jemalloc/autogen.sh :
  26. git submodule update --init
  27. 3rd/jemalloc/Makefile : | 3rd/jemalloc/autogen.sh
  28. cd 3rd/jemalloc && ./autogen.sh --with-jemalloc-prefix=je_ --enable-prof
  29. jemalloc : $(MALLOC_STATICLIB)
  30. update3rd :
  31. rm -rf 3rd/jemalloc && git submodule update --init
  32. # skynet
  33. CSERVICE = snlua logger gate harbor
  34. LUA_CLIB = skynet \
  35. client cjson util \
  36. bson md5 sproto lpeg snowflake $(TLS_MODULE)
  37. LUA_CLIB_SKYNET = \
  38. lua-skynet.c lua-seri.c \
  39. lua-socket.c \
  40. lua-mongo.c \
  41. lua-netpack.c \
  42. lua-memory.c \
  43. lua-profile.c \
  44. lua-multicast.c \
  45. lua-cluster.c \
  46. lua-crypt.c lsha1.c \
  47. lua-sharedata.c \
  48. lua-stm.c \
  49. lua-debugchannel.c \
  50. lua-datasheet.c \
  51. lua-sharetable.c \
  52. \
  53. SKYNET_SRC = skynet_main.c skynet_handle.c skynet_module.c skynet_mq.c \
  54. skynet_server.c skynet_start.c skynet_timer.c skynet_error.c \
  55. skynet_harbor.c skynet_env.c skynet_monitor.c skynet_socket.c socket_server.c \
  56. malloc_hook.c skynet_daemon.c skynet_log.c
  57. all : \
  58. $(SKYNET_BUILD_PATH)/skynet \
  59. $(foreach v, $(CSERVICE), $(CSERVICE_PATH)/$(v).so) \
  60. $(foreach v, $(LUA_CLIB), $(LUA_CLIB_PATH)/$(v).so)
  61. $(SKYNET_BUILD_PATH)/skynet : $(foreach v, $(SKYNET_SRC), skynet-src/$(v)) $(LUA_LIB) $(MALLOC_STATICLIB)
  62. $(CC) $(CFLAGS) -o $@ $^ -Iskynet-src -I$(JEMALLOC_INC) $(LDFLAGS) $(EXPORT) $(SKYNET_LIBS) $(SKYNET_DEFINES)
  63. $(LUA_CLIB_PATH) :
  64. mkdir $(LUA_CLIB_PATH)
  65. $(CSERVICE_PATH) :
  66. mkdir $(CSERVICE_PATH)
  67. define CSERVICE_TEMP
  68. $$(CSERVICE_PATH)/$(1).so : service-src/service_$(1).c | $$(CSERVICE_PATH)
  69. $$(CC) $$(CFLAGS) $$(SHARED) $$< -o $$@ -Iskynet-src
  70. endef
  71. $(foreach v, $(CSERVICE), $(eval $(call CSERVICE_TEMP,$(v))))
  72. $(LUA_CLIB_PATH)/skynet.so : $(addprefix lualib-src/,$(LUA_CLIB_SKYNET)) | $(LUA_CLIB_PATH)
  73. $(CC) $(CFLAGS) $(SHARED) $^ -o $@ -Iskynet-src -Iservice-src -Ilualib-src
  74. $(LUA_CLIB_PATH)/bson.so : lualib-src/lua-bson.c | $(LUA_CLIB_PATH)
  75. $(CC) $(CFLAGS) $(SHARED) -Iskynet-src $^ -o $@
  76. $(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)
  77. $(CC) $(CFLAGS) $(SHARED) -I3rd/lua-md5 $^ -o $@
  78. $(LUA_CLIB_PATH)/client.so : lualib-src/lua-clientsocket.c lualib-src/lua-crypt.c lualib-src/lsha1.c | $(LUA_CLIB_PATH)
  79. $(CC) $(CFLAGS) $(SHARED) $^ -o $@ -lpthread
  80. $(LUA_CLIB_PATH)/sproto.so : lualib-src/sproto/sproto.c lualib-src/sproto/lsproto.c | $(LUA_CLIB_PATH)
  81. $(CC) $(CFLAGS) $(SHARED) -Ilualib-src/sproto $^ -o $@
  82. $(LUA_CLIB_PATH)/ltls.so : lualib-src/ltls.c | $(LUA_CLIB_PATH)
  83. $(CC) $(CFLAGS) $(SHARED) -Iskynet-src -L$(TLS_LIB) -I$(TLS_INC) $^ -o $@ -lssl
  84. $(LUA_CLIB_PATH)/util.so : lualib-src/lua-util.c | $(LUA_CLIB_PATH)
  85. $(CC) $(CFLAGS) $(SHARED) -Iskynet-src $^ -o $@ -luuid
  86. $(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 | $(LUA_CLIB_PATH)
  87. $(CC) $(CFLAGS) $(SHARED) -I3rd/lpeg $^ -o $@
  88. $(LUA_CLIB_PATH)/cjson.so : 3rd/lua-cjson/fpconv.c 3rd/lua-cjson/lua_cjson.c 3rd/lua-cjson/strbuf.c | $(LUA_CLIB_PATH)
  89. $(CC) $(CFLAGS) $(SHARED) -I3rd/lua-cjson $^ -o $@
  90. $(LUA_CLIB_PATH)/snowflake.so : lualib-src/lua-snowflake.c | $(LUA_CLIB_PATH)
  91. $(CC) $(CFLAGS) $(SHARED) -Iskynet-src $^ -o $@
  92. clean :
  93. rm -f $(SKYNET_BUILD_PATH)/skynet $(CSERVICE_PATH)/*.so $(LUA_CLIB_PATH)/*.so && \
  94. rm -rf $(SKYNET_BUILD_PATH)/*.dSYM $(CSERVICE_PATH)/*.dSYM $(LUA_CLIB_PATH)/*.dSYM
  95. cleanall: clean
  96. ifneq (,$(wildcard 3rd/jemalloc/Makefile))
  97. cd 3rd/jemalloc && $(MAKE) clean && rm Makefile
  98. cd 3rd/lua-cjson && $(MAKE) clean
  99. endif
  100. cd 3rd/lua && $(MAKE) clean
  101. rm -f $(LUA_STATICLIB)