Ver código fonte

Fixes to enable building using MinGW-w64 or TDM-GCC

Eric Tsau 10 anos atrás
pai
commit
6d4e019c38
3 arquivos alterados com 40 adições e 20 exclusões
  1. 29 17
      Makefile
  2. 7 0
      docs/Building.md
  3. 4 3
      src/main.c

+ 29 - 17
Makefile

@@ -25,7 +25,10 @@ DOCDIR = $(DATAROOTDIR)/doc/$(CPROG)
 SYSCONFDIR = $(PREFIX)/etc
 SYSCONFDIR = $(PREFIX)/etc
 HTMLDIR = $(DOCDIR)
 HTMLDIR = $(DOCDIR)
 
 
-UNAME := $(shell uname)
+# build tools
+MKDIR = mkdir -p
+RMF = rm -f
+RMRF = rm -rf
 
 
 # desired configuration of the document root
 # desired configuration of the document root
 # never assume that the document_root actually
 # never assume that the document_root actually
@@ -35,15 +38,17 @@ UNAME := $(shell uname)
 DOCUMENT_ROOT = $(HTMLDIR)
 DOCUMENT_ROOT = $(HTMLDIR)
 PORTS = 8080
 PORTS = 8080
 
 
-BUILD_DIRS += $(BUILD_DIR) $(BUILD_DIR)/src
+BUILD_DIRS = $(BUILD_DIR) $(BUILD_DIR)/src $(BUILD_DIR)/resources
 
 
 LIB_SOURCES = src/civetweb.c
 LIB_SOURCES = src/civetweb.c
 LIB_INLINE  = src/mod_lua.inl src/md5.inl
 LIB_INLINE  = src/mod_lua.inl src/md5.inl
 APP_SOURCES = src/main.c
 APP_SOURCES = src/main.c
+WINDOWS_RESOURCES = resources/res.rc
 UNIT_TEST_SOURCES = test/unit_test.c
 UNIT_TEST_SOURCES = test/unit_test.c
 SOURCE_DIRS =
 SOURCE_DIRS =
 
 
 OBJECTS = $(LIB_SOURCES:.c=.o) $(APP_SOURCES:.c=.o)
 OBJECTS = $(LIB_SOURCES:.c=.o) $(APP_SOURCES:.c=.o)
+BUILD_RESOURCES =
 
 
 # The unit tests include the source files directly to get visibility to the
 # The unit tests include the source files directly to get visibility to the
 # static functions.  So we clear OBJECTS so that we don't try to build or link
 # static functions.  So we clear OBJECTS so that we don't try to build or link
@@ -115,21 +120,25 @@ LIB_OBJECTS = $(filter-out $(MAIN_OBJECTS), $(BUILD_OBJECTS))
 
 
 ifeq ($(TARGET_OS),LINUX)
 ifeq ($(TARGET_OS),LINUX)
   LIBS += -ldl
   LIBS += -ldl
+  CAN_INSTALL = 1
 endif
 endif
 
 
-ifeq ($(TARGET_OS),LINUX)
-  CAN_INSTALL = 1
+ifeq ($(TARGET_OS),WIN32)
+  MKDIR = mkdir
+  RMF = del /q
+  RMRF = rmdir /s /q
 endif
 endif
 
 
 ifdef WITH_LUA_SHARED
 ifdef WITH_LUA_SHARED
   LIBS += -llua5.2
   LIBS += -llua5.2
 endif
 endif
 
 
-ifneq (, $(findstring MINGW32, $(UNAME)))
-  LIBS += -lws2_32 -lcomdlg32
-  SHARED_LIB=dll
+ifneq (, $(findstring mingw32, $(shell gcc -dumpmachine)))
+  BUILD_RESOURCES = $(BUILD_DIR)/$(WINDOWS_RESOURCES:.rc=.o)
+  LIBS := $(filter-out -lrt, $(LIBS)) -lws2_32 -lcomdlg32 -mwindows
+  SHARED_LIB = dll
 else
 else
-  SHARED_LIB=so
+  SHARED_LIB = so
 endif
 endif
 
 
 all: build
 all: build
@@ -214,16 +223,16 @@ lib: lib$(CPROG).a
 slib: lib$(CPROG).$(SHARED_LIB)
 slib: lib$(CPROG).$(SHARED_LIB)
 
 
 clean:
 clean:
-	rm -rf $(BUILD_DIR)
+	$(RMRF) $(BUILD_DIR)
 
 
 distclean: clean
 distclean: clean
-	@rm -rf VS2012/Debug VS2012/*/Debug  VS2012/*/*/Debug
-	@rm -rf VS2012/Release VS2012/*/Release  VS2012/*/*/Release
-	rm -f $(CPROG) lib$(CPROG).so lib$(CPROG).a *.dmg *.msi *.exe lib$(CPROG).dll lib$(CPROG).dll.a
-	rm -f $(UNIT_TEST_PROG)
+	@$(RMRF) VS2012/Debug VS2012/*/Debug  VS2012/*/*/Debug
+	@$(RMRF) VS2012/Release VS2012/*/Release  VS2012/*/*/Release
+	$(RMF) $(CPROG) lib$(CPROG).so lib$(CPROG).a *.dmg *.msi *.exe lib$(CPROG).dll lib$(CPROG).dll.a
+	$(RMF) $(UNIT_TEST_PROG)
 
 
 lib$(CPROG).a: $(LIB_OBJECTS)
 lib$(CPROG).a: $(LIB_OBJECTS)
-	@rm -f $@
+	@$(RMF) $@
 	ar cq $@ $(LIB_OBJECTS)
 	ar cq $@ $(LIB_OBJECTS)
 
 
 lib$(CPROG).so: CFLAGS += -fPIC
 lib$(CPROG).so: CFLAGS += -fPIC
@@ -238,8 +247,8 @@ $(UNIT_TEST_PROG): CFLAGS += -Isrc
 $(UNIT_TEST_PROG): $(LIB_SOURCES) $(LIB_INLINE) $(UNIT_TEST_SOURCES) $(BUILD_OBJECTS)
 $(UNIT_TEST_PROG): $(LIB_SOURCES) $(LIB_INLINE) $(UNIT_TEST_SOURCES) $(BUILD_OBJECTS)
 	$(LCC) -o $@ $(CFLAGS) $(LDFLAGS) $(UNIT_TEST_SOURCES) $(BUILD_OBJECTS) $(LIBS)
 	$(LCC) -o $@ $(CFLAGS) $(LDFLAGS) $(UNIT_TEST_SOURCES) $(BUILD_OBJECTS) $(LIBS)
 
 
-$(CPROG): $(BUILD_OBJECTS)
-	$(LCC) -o $@ $(CFLAGS) $(LDFLAGS) $(BUILD_OBJECTS) $(LIBS)
+$(CPROG): $(BUILD_OBJECTS) $(BUILD_RESOURCES)
+	$(LCC) -o $@ $(CFLAGS) $(LDFLAGS) $(BUILD_OBJECTS) $(BUILD_RESOURCES) $(LIBS)
 
 
 $(CXXPROG): $(BUILD_OBJECTS)
 $(CXXPROG): $(BUILD_OBJECTS)
 	$(CXX) -o $@ $(CFLAGS) $(LDFLAGS) $(BUILD_OBJECTS) $(LIBS)
 	$(CXX) -o $@ $(CFLAGS) $(LDFLAGS) $(BUILD_OBJECTS) $(LIBS)
@@ -247,7 +256,7 @@ $(CXXPROG): $(BUILD_OBJECTS)
 $(BUILD_OBJECTS): $(BUILD_DIRS)
 $(BUILD_OBJECTS): $(BUILD_DIRS)
 
 
 $(BUILD_DIRS):
 $(BUILD_DIRS):
-	-@mkdir -p "$@"
+	-@$(MKDIR) "$@"
 
 
 $(BUILD_DIR)/%.o : %.cpp
 $(BUILD_DIR)/%.o : %.cpp
 	$(CXX) -c $(CFLAGS) $(CXXFLAGS) $< -o $@
 	$(CXX) -c $(CFLAGS) $(CXXFLAGS) $< -o $@
@@ -255,6 +264,9 @@ $(BUILD_DIR)/%.o : %.cpp
 $(BUILD_DIR)/%.o : %.c
 $(BUILD_DIR)/%.o : %.c
 	$(CC) -c $(CFLAGS) $< -o $@
 	$(CC) -c $(CFLAGS) $< -o $@
 
 
+$(BUILD_RESOURCES) : $(WINDOWS_RESOURCES)
+	windres $< $@
+
 # This rules is used to keep the code formatted in a reasonable manor
 # This rules is used to keep the code formatted in a reasonable manor
 # For this to work astyle must be installed and in the path
 # For this to work astyle must be installed and in the path
 # http://sourceforge.net/projects/astyle
 # http://sourceforge.net/projects/astyle

+ 7 - 0
docs/Building.md

@@ -11,10 +11,17 @@ https://github.com/bel2125/civetweb
 Building for Windows
 Building for Windows
 ---------
 ---------
 
 
+#### Using Visual Studio
 Open the *VS2012/civetweb.sln* in Visual Studio.
 Open the *VS2012/civetweb.sln* in Visual Studio.
 To include SSL support, you may have to use yaSSL.  However, it is GPL licensed.
 To include SSL support, you may have to use yaSSL.  However, it is GPL licensed.
 See [yaSSL.md](https://github.com/bel2125/civetweb/blob/master/docs/yaSSL.md) for more information.
 See [yaSSL.md](https://github.com/bel2125/civetweb/blob/master/docs/yaSSL.md) for more information.
 
 
+#### Using MinGW-w64 or TDM-GCC
+In the start menu locate and run the "Run terminal" batch file. For TDM-GCC this is named "MinGW Command Prompt".
+Navigate to the civetweb sources directory and run:
+```
+mingw32-make CC=gcc
+```
 
 
 Building for Linux, BSD, and OSX
 Building for Linux, BSD, and OSX
 ---------
 ---------

+ 4 - 3
src/main.c

@@ -45,9 +45,13 @@
 #include "civetweb.h"
 #include "civetweb.h"
 
 
 #ifdef _WIN32
 #ifdef _WIN32
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0501 /* Target Windows XP or higher */
+#endif
 #include <windows.h>
 #include <windows.h>
 #include <winsvc.h>
 #include <winsvc.h>
 #include <shlobj.h>
 #include <shlobj.h>
+#include <io.h>
 
 
 #define getcwd(a,b) _getcwd(a,b)
 #define getcwd(a,b) _getcwd(a,b)
 #if !defined(__MINGW32__)
 #if !defined(__MINGW32__)
@@ -1500,9 +1504,6 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
     return DefWindowProc(hWnd, msg, wParam, lParam);
     return DefWindowProc(hWnd, msg, wParam, lParam);
 }
 }
 
 
-#include <fcntl.h>
-#include <io.h>
-
 static int MakeConsole() {
 static int MakeConsole() {
     DWORD err;
     DWORD err;
     int ok = (GetConsoleWindow() != NULL);
     int ok = (GetConsoleWindow() != NULL);