Makefile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. include config.mk
  2. include Makefile.vars
  3. MAKEF=$(MAKE) -f Makefile.in
  4. ALL_SRCDIRS=. base ssl event util cpputil evpp protocol http http/client http/server
  5. LIBHV_SRCDIRS = . base ssl event util
  6. LIBHV_HEADERS = hv.h hconfig.h hexport.h
  7. LIBHV_HEADERS += $(BASE_HEADERS) $(SSL_HEADERS) $(EVENT_HEADERS) $(UTIL_HEADERS)
  8. ifeq ($(WITH_PROTOCOL), yes)
  9. LIBHV_HEADERS += $(PROTOCOL_HEADERS)
  10. LIBHV_SRCDIRS += protocol
  11. endif
  12. ifeq ($(WITH_EVPP), yes)
  13. LIBHV_HEADERS += $(CPPUTIL_HEADERS) $(EVPP_HEADERS)
  14. LIBHV_SRCDIRS += cpputil evpp
  15. ifeq ($(WITH_HTTP), yes)
  16. LIBHV_HEADERS += $(HTTP_HEADERS)
  17. LIBHV_SRCDIRS += http
  18. ifeq ($(WITH_HTTP_SERVER), yes)
  19. LIBHV_HEADERS += $(HTTP_SERVER_HEADERS)
  20. LIBHV_SRCDIRS += http/server
  21. endif
  22. ifeq ($(WITH_HTTP_CLIENT), yes)
  23. LIBHV_HEADERS += $(HTTP_CLIENT_HEADERS)
  24. LIBHV_SRCDIRS += http/client
  25. endif
  26. endif
  27. endif
  28. default: all
  29. all: libhv examples
  30. examples: hmain_test htimer_test hloop_test \
  31. nc nmap httpd curl wget consul \
  32. tcp_echo_server \
  33. tcp_chat_server \
  34. tcp_proxy_server \
  35. udp_echo_server \
  36. udp_proxy_server \
  37. multi-acceptor-processes \
  38. multi-acceptor-threads \
  39. one-acceptor-multi-workers \
  40. http_server_test http_client_test \
  41. websocket_server_test \
  42. websocket_client_test \
  43. jsonrpc \
  44. clean:
  45. $(MAKEF) clean SRCDIRS="$(ALL_SRCDIRS)"
  46. $(RM) examples/*.o examples/*/*.o
  47. $(RM) include/hv
  48. prepare:
  49. $(MKDIR) bin
  50. libhv:
  51. $(MKDIR) lib
  52. $(MAKEF) TARGET=$@ TARGET_TYPE="SHARED|STATIC" SRCDIRS="$(LIBHV_SRCDIRS)"
  53. $(MKDIR) include/hv
  54. $(CP) $(LIBHV_HEADERS) include/hv
  55. install:
  56. $(MKDIR) $(INSTALL_INCDIR)
  57. $(MKDIR) $(INSTALL_LIBDIR)
  58. $(CP) include/hv/* $(INSTALL_INCDIR)
  59. $(CP) lib/libhv.* $(INSTALL_LIBDIR)
  60. hmain_test: prepare
  61. $(MAKEF) TARGET=$@ SRCDIRS=". base cpputil" SRCS="examples/hmain_test.cpp"
  62. htimer_test: prepare
  63. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/htimer_test.c"
  64. hloop_test: prepare
  65. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/hloop_test.c"
  66. tcp_echo_server: prepare
  67. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/tcp_echo_server.c"
  68. tcp_chat_server: prepare
  69. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/tcp_chat_server.c"
  70. tcp_proxy_server: prepare
  71. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/tcp_proxy_server.c"
  72. udp_echo_server: prepare
  73. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/udp_echo_server.c"
  74. udp_proxy_server: prepare
  75. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/udp_proxy_server.c"
  76. multi-acceptor-processes: prepare
  77. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/multi-thread/multi-acceptor-processes.c"
  78. multi-acceptor-threads: prepare
  79. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/multi-thread/multi-acceptor-threads.c"
  80. one-acceptor-multi-workers: prepare
  81. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/multi-thread/one-acceptor-multi-workers.c"
  82. nc: prepare
  83. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/nc.c"
  84. nmap: prepare
  85. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event cpputil examples/nmap" DEFINES="PRINT_DEBUG"
  86. httpd: prepare
  87. $(RM) examples/httpd/*.o
  88. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client http/server examples/httpd"
  89. consul: prepare
  90. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client examples/consul" DEFINES="PRINT_DEBUG"
  91. curl: prepare
  92. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client" SRCS="examples/curl.cpp"
  93. # $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client" SRCS="examples/curl.cpp" WITH_CURL=yes
  94. wget: prepare
  95. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client" SRCS="examples/wget.cpp"
  96. http_server_test: prepare
  97. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/server" SRCS="examples/http_server_test.cpp"
  98. http_client_test: prepare
  99. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client" SRCS="examples/http_client_test.cpp"
  100. websocket_server_test: prepare
  101. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/server" SRCS="examples/websocket_server_test.cpp"
  102. websocket_client_test: prepare
  103. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client" SRCS="examples/websocket_client_test.cpp"
  104. jsonrpc: jsonrpc_client jsonrpc_server
  105. jsonrpc_client: prepare
  106. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/jsonrpc/jsonrpc_client.c examples/jsonrpc/jsonrpc.c examples/jsonrpc/cJSON.c"
  107. jsonrpc_server: prepare
  108. $(RM) examples/jsonrpc/*.o
  109. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/jsonrpc/jsonrpc_server.c examples/jsonrpc/jsonrpc.c examples/jsonrpc/cJSON.c"
  110. protorpc: protorpc_client protorpc_server
  111. protorpc_protoc:
  112. bash examples/protorpc/proto/protoc.sh
  113. protorpc_client: prepare protorpc_protoc
  114. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event cpputil evpp examples/protorpc/generated" \
  115. SRCS="examples/protorpc/protorpc_client.cpp examples/protorpc/protorpc.c" \
  116. LIBS="protobuf"
  117. protorpc_server: prepare protorpc_protoc
  118. $(RM) examples/protorpc/*.o
  119. $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event cpputil evpp examples/protorpc/generated" \
  120. SRCS="examples/protorpc/protorpc_server.cpp examples/protorpc/protorpc.c" \
  121. LIBS="protobuf"
  122. unittest: prepare
  123. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/mkdir_p unittest/mkdir_test.c base/hbase.c
  124. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/rmdir_p unittest/rmdir_test.c base/hbase.c
  125. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/date unittest/date_test.c base/htime.c
  126. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/hatomic_test unittest/hatomic_test.c -pthread
  127. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -o bin/hatomic_cpp_test unittest/hatomic_test.cpp -pthread
  128. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -o bin/hthread_test unittest/hthread_test.cpp -pthread
  129. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/hmutex_test unittest/hmutex_test.c base/htime.c -pthread
  130. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/connect_test unittest/connect_test.c base/hsocket.c base/htime.c
  131. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/socketpair_test unittest/socketpair_test.c base/hsocket.c
  132. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/hstring_test unittest/hstring_test.cpp cpputil/hstring.cpp
  133. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/hpath_test unittest/hpath_test.cpp cpputil/hpath.cpp
  134. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/ls unittest/listdir_test.cpp cpputil/hdir.cpp
  135. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/ifconfig unittest/ifconfig_test.cpp cpputil/ifconfig.cpp
  136. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/defer_test unittest/defer_test.cpp
  137. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/synchronized_test unittest/synchronized_test.cpp -pthread
  138. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/threadpool_test unittest/threadpool_test.cpp -pthread
  139. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Icpputil -o bin/objectpool_test unittest/objectpool_test.cpp -pthread
  140. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -Iprotocol -o bin/nslookup unittest/nslookup_test.c protocol/dns.c
  141. $(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
  142. $(CC) -g -Wall -O0 -std=c99 -I. -Ibase -Iprotocol -o bin/ftp unittest/ftp_test.c protocol/ftp.c base/hsocket.c
  143. $(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
  144. run-unittest: unittest
  145. bash scripts/unittest.sh
  146. check: examples
  147. bash scripts/check.sh
  148. evpp: prepare libhv
  149. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/EventLoop_test evpp/EventLoop_test.cpp -Llib -lhv -pthread
  150. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/EventLoopThread_test evpp/EventLoopThread_test.cpp -Llib -lhv -pthread
  151. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/EventLoopThreadPool_test evpp/EventLoopThreadPool_test.cpp -Llib -lhv -pthread
  152. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/TcpServer_test evpp/TcpServer_test.cpp -Llib -lhv -pthread
  153. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/TcpClient_test evpp/TcpClient_test.cpp -Llib -lhv -pthread
  154. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/UdpServer_test evpp/UdpServer_test.cpp -Llib -lhv -pthread
  155. $(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Ievpp -o bin/UdpClient_test evpp/UdpClient_test.cpp -Llib -lhv -pthread
  156. # UNIX only
  157. webbench: prepare
  158. $(CC) -o bin/webbench unittest/webbench.c
  159. echo-servers:
  160. $(CXX) -g -Wall -std=c++11 -o bin/pingpong_client echo-servers/pingpong_client.cpp -lhv -pthread
  161. $(CC) -g -Wall -std=c99 -o bin/libevent_echo echo-servers/libevent_echo.c -levent
  162. $(CC) -g -Wall -std=c99 -o bin/libev_echo echo-servers/libev_echo.c -lev
  163. $(CC) -g -Wall -std=c99 -o bin/libuv_echo echo-servers/libuv_echo.c -luv
  164. $(CC) -g -Wall -std=c99 -o bin/libhv_echo echo-servers/libhv_echo.c -lhv
  165. $(CXX) -g -Wall -std=c++11 -o bin/asio_echo echo-servers/asio_echo.cpp -lboost_system -pthread
  166. $(CXX) -g -Wall -std=c++11 -o bin/poco_echo echo-servers/poco_echo.cpp -lPocoNet -lPocoUtil -lPocoFoundation
  167. # $(CXX) -g -Wall -std=c++11 -o bin/muduo_echo echo-servers/muduo_echo.cpp -lmuduo_net -lmuduo_base -pthread
  168. echo-benchmark: echo-servers
  169. bash echo-servers/benchmark.sh
  170. .PHONY: clean prepare install libhv examples unittest evpp echo-servers