Makefile 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. #
  2. # Copyright (c) 2013 No Face Press, LLC
  3. # License http://opensource.org/licenses/mit-license.php MIT License
  4. #
  5. #
  6. # For help try, "make help"
  7. #
  8. include resources/Makefile.in-os
  9. CPROG = civetweb
  10. #CXXPROG = civetweb
  11. UNIT_TEST_PROG = civetweb_test
  12. BUILD_DIR = out
  13. # Installation directories by convention
  14. # http://www.gnu.org/prep/standards/html_node/Directory-Variables.html
  15. PREFIX = /usr/local
  16. EXEC_PREFIX = $(PREFIX)
  17. BINDIR = $(EXEC_PREFIX)/bin
  18. DATAROOTDIR = $(PREFIX)/share
  19. DOCDIR = $(DATAROOTDIR)/doc/$(CPROG)
  20. SYSCONFDIR = $(PREFIX)/etc
  21. HTMLDIR = $(DOCDIR)
  22. UNAME := $(shell uname)
  23. # desired configuration of the document root
  24. # never assume that the document_root actually
  25. # exists on the build machine. When building
  26. # a chroot, PREFIX if just a directory which
  27. # later becomes /.
  28. DOCUMENT_ROOT = $(HTMLDIR)
  29. PORTS = 8080
  30. BUILD_DIRS += $(BUILD_DIR) $(BUILD_DIR)/src
  31. LIB_SOURCES = src/civetweb.c
  32. LIB_INLINE = src/mod_lua.inl src/md5.inl
  33. APP_SOURCES = src/main.c
  34. UNIT_TEST_SOURCES = test/unit_test.c
  35. SOURCE_DIRS =
  36. OBJECTS = $(LIB_SOURCES:.c=.o) $(APP_SOURCES:.c=.o)
  37. # The unit tests include the source files directly to get visibility to the
  38. # static functions. So we clear OBJECTS so that we don't try to build or link
  39. # with any external object. Later if we find WITH_LUA=1, we'll add lua objects
  40. # to this variable so we can run lua-specific unit tests.
  41. ifeq ($(MAKECMDGOALS), unit_test)
  42. OBJECTS =
  43. BUILD_DIRS += $(BUILD_DIR)/test
  44. endif
  45. # only set main compile options if none were chosen
  46. CFLAGS += -W -Wall -O2 -D$(TARGET_OS) -Iinclude $(COPT) -DUSE_STACK_SIZE=102400
  47. LIBS = -lpthread -lm
  48. ifdef WITH_DEBUG
  49. CFLAGS += -g -DDEBUG_ENABLED
  50. else
  51. CFLAGS += -DNDEBUG
  52. endif
  53. ifdef WITH_CPP
  54. OBJECTS += src/CivetServer.o
  55. LCC = $(CXX)
  56. else
  57. LCC = $(CC)
  58. endif
  59. ifdef WITH_LUA_SHARED
  60. WITH_LUA = 1
  61. endif
  62. ifdef WITH_LUA
  63. include resources/Makefile.in-lua
  64. endif
  65. ifdef WITH_IPV6
  66. CFLAGS += -DUSE_IPV6
  67. endif
  68. ifdef WITH_WEBSOCKET
  69. CFLAGS += -DUSE_WEBSOCKET
  70. ifdef WITH_LUA
  71. CFLAGS += -DUSE_TIMERS
  72. LIBS += -lrt
  73. endif
  74. endif
  75. ifdef CONFIG_FILE
  76. CFLAGS += -DCONFIG_FILE=\"$(CONFIG_FILE)\"
  77. endif
  78. ifdef CONFIG_FILE2
  79. CFLAGS += -DCONFIG_FILE2=\"$(CONFIG_FILE2)\"
  80. endif
  81. ifdef SSL_LIB
  82. CFLAGS += -DSSL_LIB=\"$(SSL_LIB)\"
  83. endif
  84. ifdef CRYPTO_LIB
  85. CFLAGS += -DCRYPTO_LIB=\"$(CRYPTO_LIB)\"
  86. endif
  87. BUILD_DIRS += $(addprefix $(BUILD_DIR)/, $(SOURCE_DIRS))
  88. BUILD_OBJECTS = $(addprefix $(BUILD_DIR)/, $(OBJECTS))
  89. MAIN_OBJECTS = $(addprefix $(BUILD_DIR)/, $(APP_SOURCES:.c=.o))
  90. LIB_OBJECTS = $(filter-out $(MAIN_OBJECTS), $(BUILD_OBJECTS))
  91. ifeq ($(TARGET_OS),LINUX)
  92. LIBS += -ldl
  93. endif
  94. ifeq ($(TARGET_OS),LINUX)
  95. CAN_INSTALL = 1
  96. endif
  97. ifdef WITH_LUA_SHARED
  98. LIBS += -llua5.2
  99. endif
  100. ifneq (, $(findstring MINGW32, $(UNAME)))
  101. LIBS += -lws2_32 -lcomdlg32
  102. SHARED_LIB=dll
  103. else
  104. SHARED_LIB=so
  105. endif
  106. all: build
  107. help:
  108. @echo "make help show this message"
  109. @echo "make build compile"
  110. @echo "make install install on the system"
  111. @echo "make clean clean up the mess"
  112. @echo "make lib build a static library"
  113. @echo "make slib build a shared library"
  114. @echo "make unit_test build unit tests executable"
  115. @echo ""
  116. @echo " Make Options"
  117. @echo " WITH_LUA=1 build with Lua support; include Lua as static library"
  118. @echo " WITH_LUA_SHARED=1 build with Lua support; use dynamic linking to liblua5.2.so"
  119. @echo " WITH_DEBUG=1 build with GDB debug support"
  120. @echo " WITH_IPV6=1 with IPV6 support"
  121. @echo " WITH_WEBSOCKET=1 build with web socket support"
  122. @echo " WITH_CPP=1 build library with c++ classes"
  123. @echo " CONFIG_FILE=file use 'file' as the config file"
  124. @echo " CONFIG_FILE2=file use 'file' as the backup config file"
  125. @echo " DOCUMENT_ROOT=/path document root override when installing"
  126. @echo " PORTS=8080 listening ports override when installing"
  127. @echo " SSL_LIB=libssl.so.0 use versioned SSL library"
  128. @echo " CRYPTO_LIB=libcrypto.so.0 system versioned CRYPTO library"
  129. @echo " PREFIX=/usr/local sets the install directory"
  130. @echo " COPT='-DNO_SSL' method to insert compile flags"
  131. @echo ""
  132. @echo " Compile Flags"
  133. @echo " NDEBUG strip off all debug code"
  134. @echo " DEBUG build debug version (very noisy)"
  135. @echo " NO_CGI disable CGI support"
  136. @echo " NO_SSL disable SSL functionality"
  137. @echo " NO_SSL_DL link against system libssl library"
  138. @echo " NO_FILES do not serve files from a directory"
  139. @echo " MAX_REQUEST_SIZE maximum header size, default 16384"
  140. @echo ""
  141. @echo " Variables"
  142. @echo " TARGET_OS='$(TARGET_OS)'"
  143. @echo " CFLAGS='$(CFLAGS)'"
  144. @echo " CXXFLAGS='$(CXXFLAGS)'"
  145. @echo " LDFLAGS='$(LDFLAGS)'"
  146. @echo " CC='$(CC)'"
  147. @echo " CXX='$(CXX)'"
  148. build: $(CPROG) $(CXXPROG)
  149. unit_test: $(UNIT_TEST_PROG)
  150. ifeq ($(CAN_INSTALL),1)
  151. install: $(HTMLDIR)/index.html $(SYSCONFDIR)/civetweb.conf
  152. install -d -m 755 "$(DOCDIR)"
  153. install -m 644 *.md "$(DOCDIR)"
  154. install -d -m 755 "$(BINDIR)"
  155. install -m 755 $(CPROG) "$(BINDIR)/"
  156. # Install target we do not want to overwrite
  157. # as it may be an upgrade
  158. $(HTMLDIR)/index.html:
  159. install -d -m 755 "$(HTMLDIR)"
  160. install -m 644 resources/itworks.html $(HTMLDIR)/index.html
  161. install -m 644 resources/civetweb_64x64.png $(HTMLDIR)/
  162. # Install target we do not want to overwrite
  163. # as it may be an upgrade
  164. $(SYSCONFDIR)/civetweb.conf:
  165. install -d -m 755 "$(SYSCONFDIR)"
  166. install -m 644 resources/civetweb.conf "$(SYSCONFDIR)/"
  167. @sed -i 's#^document_root.*$$#document_root $(DOCUMENT_ROOT)#' "$(SYSCONFDIR)/civetweb.conf"
  168. @sed -i 's#^listening_ports.*$$#listening_ports $(PORTS)#' "$(SYSCONFDIR)/civetweb.conf"
  169. else
  170. install:
  171. @echo "Target not flagged for installation. Use CAN_INSTALL=1 to force"
  172. @echo "As a precaution only LINUX targets are set as installable."
  173. @echo "If the target is linux-like, use CAN_INSTALL=1 option."
  174. endif
  175. lib: lib$(CPROG).a
  176. slib: lib$(CPROG).$(SHARED_LIB)
  177. clean:
  178. rm -rf $(BUILD_DIR)
  179. distclean: clean
  180. @rm -rf VS2012/Debug VS2012/*/Debug VS2012/*/*/Debug
  181. @rm -rf VS2012/Release VS2012/*/Release VS2012/*/*/Release
  182. rm -f $(CPROG) lib$(CPROG).so lib$(CPROG).a *.dmg *.msi *.exe lib$(CPROG).dll lib$(CPROG).dll.a
  183. rm -f $(UNIT_TEST_PROG)
  184. lib$(CPROG).a: $(LIB_OBJECTS)
  185. @rm -f $@
  186. ar cq $@ $(LIB_OBJECTS)
  187. lib$(CPROG).so: CFLAGS += -fPIC
  188. lib$(CPROG).so: $(LIB_OBJECTS)
  189. $(LCC) -shared -o $@ $(CFLAGS) $(LDFLAGS) $(LIB_OBJECTS)
  190. lib$(CPROG).dll: CFLAGS += -fPIC
  191. lib$(CPROG).dll: $(LIB_OBJECTS)
  192. $(LCC) -shared -o $@ $(CFLAGS) $(LDFLAGS) $(LIB_OBJECTS) $(LIBS) -Wl,--out-implib,lib$(CPROG).dll.a
  193. $(UNIT_TEST_PROG): CFLAGS += -Isrc
  194. $(UNIT_TEST_PROG): $(LIB_SOURCES) $(LIB_INLINE) $(UNIT_TEST_SOURCES) $(BUILD_OBJECTS)
  195. $(LCC) -o $@ $(CFLAGS) $(LDFLAGS) $(UNIT_TEST_SOURCES) $(BUILD_OBJECTS) $(LIBS)
  196. $(CPROG): $(BUILD_OBJECTS)
  197. $(LCC) -o $@ $(CFLAGS) $(LDFLAGS) $(BUILD_OBJECTS) $(LIBS)
  198. $(CXXPROG): $(BUILD_OBJECTS)
  199. $(CXX) -o $@ $(CFLAGS) $(LDFLAGS) $(BUILD_OBJECTS) $(LIBS)
  200. $(BUILD_OBJECTS): $(BUILD_DIRS)
  201. $(BUILD_DIRS):
  202. -@mkdir -p "$@"
  203. $(BUILD_DIR)/%.o : %.cpp
  204. $(CXX) -c $(CFLAGS) $(CXXFLAGS) $< -o $@
  205. $(BUILD_DIR)/%.o : %.c
  206. $(CC) -c $(CFLAGS) $< -o $@
  207. # This rules is used to keep the code formatted in a reasonable manor
  208. # For this to work astyle must be installed and in the path
  209. # http://sourceforge.net/projects/astyle
  210. indent:
  211. astyle --suffix=none --style=linux --indent=spaces=4 --lineend=linux include/*.h src/*.c src/*.cpp src/*.inl examples/*/*.c examples/*/*.cpp
  212. .PHONY: all help build install clean lib so