Makefile 6.3 KB

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