diff --git a/Makefile b/Makefile index cc873865..2c3954a0 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,10 @@ DOCDIR = $(DATAROOTDIR)/doc/$(CPROG) SYSCONFDIR = $(PREFIX)/etc HTMLDIR = $(DOCDIR) -UNAME := $(shell uname) +# build tools +MKDIR = mkdir -p +RMF = rm -f +RMRF = rm -rf # desired configuration of the document root # never assume that the document_root actually @@ -35,15 +38,17 @@ UNAME := $(shell uname) DOCUMENT_ROOT = $(HTMLDIR) 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_INLINE = src/mod_lua.inl src/md5.inl APP_SOURCES = src/main.c +WINDOWS_RESOURCES = resources/res.rc UNIT_TEST_SOURCES = test/unit_test.c SOURCE_DIRS = OBJECTS = $(LIB_SOURCES:.c=.o) $(APP_SOURCES:.c=.o) +BUILD_RESOURCES = # 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 @@ -115,21 +120,25 @@ LIB_OBJECTS = $(filter-out $(MAIN_OBJECTS), $(BUILD_OBJECTS)) ifeq ($(TARGET_OS),LINUX) LIBS += -ldl + CAN_INSTALL = 1 endif -ifeq ($(TARGET_OS),LINUX) - CAN_INSTALL = 1 +ifeq ($(TARGET_OS),WIN32) + MKDIR = mkdir + RMF = del /q + RMRF = rmdir /s /q endif ifdef WITH_LUA_SHARED LIBS += -llua5.2 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 - SHARED_LIB=so + SHARED_LIB = so endif all: build @@ -214,16 +223,16 @@ lib: lib$(CPROG).a slib: lib$(CPROG).$(SHARED_LIB) clean: - rm -rf $(BUILD_DIR) + $(RMRF) $(BUILD_DIR) 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) - @rm -f $@ + @$(RMF) $@ ar cq $@ $(LIB_OBJECTS) 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) $(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) $(CXX) -o $@ $(CFLAGS) $(LDFLAGS) $(BUILD_OBJECTS) $(LIBS) @@ -247,7 +256,7 @@ $(CXXPROG): $(BUILD_OBJECTS) $(BUILD_OBJECTS): $(BUILD_DIRS) $(BUILD_DIRS): - -@mkdir -p "$@" + -@$(MKDIR) "$@" $(BUILD_DIR)/%.o : %.cpp $(CXX) -c $(CFLAGS) $(CXXFLAGS) $< -o $@ @@ -255,6 +264,9 @@ $(BUILD_DIR)/%.o : %.cpp $(BUILD_DIR)/%.o : %.c $(CC) -c $(CFLAGS) $< -o $@ +$(BUILD_RESOURCES) : $(WINDOWS_RESOURCES) + windres $< $@ + # 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 # http://sourceforge.net/projects/astyle diff --git a/docs/Building.md b/docs/Building.md index eb8f73f2..010a502a 100644 --- a/docs/Building.md +++ b/docs/Building.md @@ -11,10 +11,17 @@ https://github.com/bel2125/civetweb Building for Windows --------- +#### Using 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. 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 --------- diff --git a/src/main.c b/src/main.c index 7fe90873..e9a9110c 100644 --- a/src/main.c +++ b/src/main.c @@ -45,9 +45,13 @@ #include "civetweb.h" #ifdef _WIN32 +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0501 /* Target Windows XP or higher */ +#endif #include #include #include +#include #define getcwd(a,b) _getcwd(a,b) #if !defined(__MINGW32__) @@ -1500,9 +1504,6 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, return DefWindowProc(hWnd, msg, wParam, lParam); } -#include -#include - static int MakeConsole() { DWORD err; int ok = (GetConsoleWindow() != NULL);