Makefile 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. include config.mk
  2. include Makefile.vars
  3. MAKEF=$(MAKE) -f Makefile.in
  4. ALL_SRCDIRS=. base ssl event event/kcp util cpputil evpp protocol http http/client http/server mqtt
  5. CORE_SRCDIRS=. base ssl event
  6. ifeq ($(WITH_KCP), yes)
  7. CORE_SRCDIRS += event/kcp
  8. endif
  9. LIBHV_SRCDIRS = $(CORE_SRCDIRS) util
  10. LIBHV_HEADERS = hv.h hconfig.h hexport.h
  11. LIBHV_HEADERS += $(BASE_HEADERS) $(SSL_HEADERS) $(EVENT_HEADERS) $(UTIL_HEADERS)
  12. ifeq ($(WITH_PROTOCOL), yes)
  13. LIBHV_HEADERS += $(PROTOCOL_HEADERS)
  14. LIBHV_SRCDIRS += protocol
  15. endif
  16. ifeq ($(WITH_EVPP), yes)
  17. LIBHV_HEADERS += $(CPPUTIL_HEADERS) $(EVPP_HEADERS)
  18. LIBHV_SRCDIRS += cpputil evpp
  19. ifeq ($(WITH_HTTP), yes)
  20. LIBHV_HEADERS += $(HTTP_HEADERS)
  21. LIBHV_SRCDIRS += http
  22. ifeq ($(WITH_NGHTTP2), yes)
  23. LIBHV_HEADERS += $(HTTP2_HEADERS)
  24. endif
  25. ifeq ($(WITH_HTTP_SERVER), yes)
  26. LIBHV_HEADERS += $(HTTP_SERVER_HEADERS)
  27. LIBHV_SRCDIRS += http/server
  28. endif
  29. ifeq ($(WITH_HTTP_CLIENT), yes)
  30. LIBHV_HEADERS += $(HTTP_CLIENT_HEADERS)
  31. LIBHV_SRCDIRS += http/client
  32. endif
  33. endif
  34. endif
  35. ifeq ($(WITH_MQTT), yes)
  36. LIBHV_HEADERS += $(MQTT_HEADERS)
  37. LIBHV_SRCDIRS += mqtt
  38. endif
  39. default: all
  40. all: libhv examples
  41. @echo "make all done, please enjoy libhv."
  42. examples: hmain_test htimer_test hloop_test pipe_test \
  43. nc nmap tinyhttpd tinyproxyd httpd curl wget wrk consul \
  44. tcp_client_test \
  45. tcp_echo_server \
  46. tcp_chat_server \
  47. tcp_proxy_server \
  48. udp_echo_server \
  49. udp_proxy_server \
  50. socks5_proxy_server \
  51. multi-acceptor-processes \
  52. multi-acceptor-threads \
  53. one-acceptor-multi-workers \
  54. http_server_test http_client_test \
  55. websocket_server_test \
  56. websocket_client_test \
  57. mqtt_sub \
  58. mqtt_pub \
  59. mqtt_client_test \
  60. jsonrpc
  61. @echo "make examples done."
  62. clean:
  63. $(MAKEF) clean SRCDIRS="$(ALL_SRCDIRS)"
  64. $(RM) examples/*.o examples/*/*.o
  65. $(RM) include/hv
  66. @echo "make clean done."
  67. prepare:
  68. $(MKDIR) bin
  69. libhv:
  70. $(MKDIR) lib
  71. $(MAKEF) TARGET=$@ TARGET_TYPE="SHARED|STATIC" SRCDIRS="$(LIBHV_SRCDIRS)"
  72. $(MKDIR) include/hv
  73. $(CP) $(LIBHV_HEADERS) include/hv
  74. @echo "make libhv done."
  75. install:
  76. $(MKDIR) $(INSTALL_INCDIR)
  77. $(MKDIR) $(INSTALL_LIBDIR)
  78. $(CP) include/hv/* $(INSTALL_INCDIR)
  79. $(CP) lib/libhv.* $(INSTALL_LIBDIR)
  80. $(LDCONFIG)
  81. @echo "make install done."
  82. uninstall: clean
  83. $(RM) $(PREFIX)/include/hv
  84. $(RM) $(PREFIX)/lib/libhv.*
  85. @echo "make uninstall done."
  86. hmain_test: prepare
  87. $(MAKEF) TARGET=$@ SRCDIRS=". base cpputil" SRCS="examples/hmain_test.cpp"
  88. htimer_test: prepare
  89. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/htimer_test.c"
  90. hloop_test: prepare
  91. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/hloop_test.c"
  92. pipe_test: prepare
  93. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/pipe_test.c"
  94. tcp_client_test: prepare
  95. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/tcp_client_test.c"
  96. tcp_echo_server: prepare
  97. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/tcp_echo_server.c"
  98. tcp_chat_server: prepare
  99. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/tcp_chat_server.c"
  100. tcp_proxy_server: prepare
  101. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/tcp_proxy_server.c"
  102. udp_echo_server: prepare
  103. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/udp_echo_server.c"
  104. udp_proxy_server: prepare
  105. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/udp_proxy_server.c"
  106. socks5_proxy_server: prepare
  107. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/socks5_proxy_server.c"
  108. multi-acceptor-processes: prepare
  109. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/multi-thread/multi-acceptor-processes.c"
  110. multi-acceptor-threads: prepare
  111. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/multi-thread/multi-acceptor-threads.c"
  112. one-acceptor-multi-workers: prepare
  113. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/multi-thread/one-acceptor-multi-workers.c"
  114. nc: prepare
  115. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/nc.c"
  116. tinyhttpd: prepare
  117. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/tinyhttpd.c"
  118. tinyproxyd: prepare
  119. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/tinyproxyd.c"
  120. nmap: prepare libhv
  121. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) cpputil examples/nmap" DEFINES="PRINT_DEBUG"
  122. wrk: prepare
  123. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http" SRCS="examples/wrk.cpp"
  124. httpd: prepare
  125. $(RM) examples/httpd/*.o
  126. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client http/server examples/httpd"
  127. consul: prepare libhv
  128. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client examples/consul" DEFINES="PRINT_DEBUG"
  129. curl: prepare
  130. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client" SRCS="examples/curl.cpp"
  131. # $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client" SRCS="examples/curl.cpp" WITH_CURL=yes
  132. wget: prepare
  133. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client" SRCS="examples/wget.cpp"
  134. http_server_test: prepare
  135. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/server" SRCS="examples/http_server_test.cpp"
  136. http_client_test: prepare
  137. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client" SRCS="examples/http_client_test.cpp"
  138. websocket_server_test: prepare
  139. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/server" SRCS="examples/websocket_server_test.cpp"
  140. websocket_client_test: prepare
  141. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client" SRCS="examples/websocket_client_test.cpp"
  142. mqtt_sub: prepare
  143. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) mqtt" SRCS="examples/mqtt/mqtt_sub.c"
  144. mqtt_pub: prepare
  145. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) mqtt" SRCS="examples/mqtt/mqtt_pub.c"
  146. mqtt_client_test: prepare
  147. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) mqtt" SRCS="examples/mqtt/mqtt_client_test.cpp"
  148. kcptun: kcptun_client kcptun_server
  149. kcptun_client: prepare
  150. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) examples/kcptun/smux examples/kcptun/client"
  151. kcptun_server: prepare
  152. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) examples/kcptun/smux examples/kcptun/server"
  153. jsonrpc: jsonrpc_client jsonrpc_server
  154. jsonrpc_client: prepare
  155. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/jsonrpc/jsonrpc_client.c examples/jsonrpc/cJSON.c"
  156. jsonrpc_server: prepare
  157. $(RM) examples/jsonrpc/*.o
  158. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/jsonrpc/jsonrpc_server.c examples/jsonrpc/cJSON.c"
  159. protorpc: protorpc_client protorpc_server
  160. protorpc_protoc:
  161. bash examples/protorpc/proto/protoc.sh
  162. protorpc_client: prepare protorpc_protoc
  163. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) cpputil evpp examples/protorpc/generated" \
  164. SRCS="examples/protorpc/protorpc_client.cpp examples/protorpc/protorpc.c" \
  165. LIBS="protobuf"
  166. protorpc_server: prepare protorpc_protoc
  167. $(RM) examples/protorpc/*.o
  168. $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) cpputil evpp examples/protorpc/generated" \
  169. SRCS="examples/protorpc/protorpc_server.cpp examples/protorpc/protorpc.c" \
  170. LIBS="protobuf"
  171. unittest: prepare
  172. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/rbtree_test unittest/rbtree_test.c base/rbtree.c
  173. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/hbase_test unittest/hbase_test.c base/hbase.c
  174. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/mkdir_p unittest/mkdir_test.c base/hbase.c
  175. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/rmdir_p unittest/rmdir_test.c base/hbase.c
  176. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/date unittest/date_test.c base/htime.c
  177. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/hatomic_test unittest/hatomic_test.c -pthread
  178. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -o bin/hatomic_cpp_test unittest/hatomic_test.cpp -pthread
  179. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -o bin/hthread_test unittest/hthread_test.cpp -pthread
  180. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/hmutex_test unittest/hmutex_test.c base/htime.c -pthread
  181. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/connect_test unittest/connect_test.c base/hsocket.c base/htime.c
  182. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/socketpair_test unittest/socketpair_test.c base/hsocket.c
  183. $(CC) -g -Wall -O0 -std=c99 -I. -Iutil -o bin/base64 unittest/base64_test.c util/base64.c
  184. $(CC) -g -Wall -O0 -std=c99 -I. -Iutil -o bin/md5 unittest/md5_test.c util/md5.c
  185. $(CC) -g -Wall -O0 -std=c99 -I. -Iutil -o bin/sha1 unittest/sha1_test.c util/sha1.c
  186. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/hstring_test unittest/hstring_test.cpp cpputil/hstring.cpp
  187. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/hpath_test unittest/hpath_test.cpp cpputil/hpath.cpp
  188. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/hurl_test unittest/hurl_test.cpp cpputil/hurl.cpp base/hbase.c
  189. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/ls unittest/listdir_test.cpp cpputil/hdir.cpp
  190. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/ifconfig unittest/ifconfig_test.cpp cpputil/ifconfig.cpp
  191. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/defer_test unittest/defer_test.cpp
  192. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/synchronized_test unittest/synchronized_test.cpp -pthread
  193. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/threadpool_test unittest/threadpool_test.cpp -pthread
  194. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/objectpool_test unittest/objectpool_test.cpp -pthread
  195. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Ievpp -Icpputil -Ihttp -Ihttp/client -Ihttp/server -o bin/sizeof_test unittest/sizeof_test.cpp
  196. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -Iprotocol -o bin/nslookup unittest/nslookup_test.c protocol/dns.c base/hsocket.c
  197. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -Iprotocol -o bin/ping unittest/ping_test.c protocol/icmp.c base/hsocket.c base/htime.c -DPRINT_DEBUG
  198. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -Iprotocol -o bin/ftp unittest/ftp_test.c protocol/ftp.c base/hsocket.c
  199. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -Iprotocol -Iutil -o bin/sendmail unittest/sendmail_test.c protocol/smtp.c base/hsocket.c util/base64.c
  200. run-unittest: unittest
  201. bash scripts/unittest.sh
  202. check: examples
  203. bash scripts/check.sh
  204. evpp: prepare libhv
  205. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/EventLoop_test evpp/EventLoop_test.cpp -Llib -lhv -pthread
  206. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/EventLoopThread_test evpp/EventLoopThread_test.cpp -Llib -lhv -pthread
  207. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/EventLoopThreadPool_test evpp/EventLoopThreadPool_test.cpp -Llib -lhv -pthread
  208. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/TimerThread_test evpp/TimerThread_test.cpp -Llib -lhv -pthread
  209. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/TcpServer_test evpp/TcpServer_test.cpp -Llib -lhv -pthread
  210. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/TcpClient_test evpp/TcpClient_test.cpp -Llib -lhv -pthread
  211. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/TcpClientEventLoop_test evpp/TcpClientEventLoop_test.cpp -Llib -lhv -pthread
  212. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/UdpServer_test evpp/UdpServer_test.cpp -Llib -lhv -pthread
  213. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/UdpClient_test evpp/UdpClient_test.cpp -Llib -lhv -pthread
  214. # UNIX only
  215. webbench: prepare
  216. $(CC) -o bin/webbench unittest/webbench.c
  217. echo-servers:
  218. $(CXX) -g -Wall -std=c++11 -O3 -o bin/pingpong_client echo-servers/pingpong_client.cpp -lhv -pthread
  219. $(CC) -g -Wall -std=c99 -O3 -o bin/libevent_echo echo-servers/libevent_echo.c -levent
  220. $(CC) -g -Wall -std=c99 -O3 -o bin/libev_echo echo-servers/libev_echo.c -lev
  221. $(CC) -g -Wall -std=c99 -O3 -o bin/libuv_echo echo-servers/libuv_echo.c -luv
  222. $(CC) -g -Wall -std=c99 -O3 -o bin/libhv_echo echo-servers/libhv_echo.c -lhv
  223. $(CXX) -g -Wall -std=c++11 -O3 -o bin/asio_echo echo-servers/asio_echo.cpp -lboost_system -pthread
  224. $(CXX) -g -Wall -std=c++11 -O3 -o bin/poco_echo echo-servers/poco_echo.cpp -lPocoNet -lPocoUtil -lPocoFoundation
  225. # $(CXX) -g -Wall -std=c++11 -O3 -o bin/muduo_echo echo-servers/muduo_echo.cpp -lmuduo_net -lmuduo_base -pthread
  226. echo-benchmark: echo-servers
  227. bash echo-servers/benchmark.sh
  228. .PHONY: clean prepare install uninstall libhv examples unittest evpp echo-servers