From 97bb6792e84959178bc62867684906ffd84d1e39 Mon Sep 17 00:00:00 2001 From: Sebastien Duthil Date: Sat, 8 Jun 2013 19:22:09 -0400 Subject: [PATCH] modifications to allow cross-compilation to win32 --- README.txt | 2 ++ src/Makefile | 31 ++++++++++++++++++++++--------- src/udt.h | 18 +++++++++--------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/README.txt b/README.txt index 29fbf80..e41d402 100644 --- a/README.txt +++ b/README.txt @@ -23,6 +23,8 @@ CONTENT: To make: make -e os=XXX arch=YYY +Windows (cross-compilation): + make CXX='compiler' os=WIN32 XXX: [LINUX(default), BSD, OSX] YYY: [IA32(default), POWERPC, IA64, AMD64] diff --git a/src/Makefile b/src/Makefile index b601263..7808cf3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,6 @@ -C++ = g++ -g +ifndef CXX + CXX = g++ +endif ifndef os os = LINUX @@ -8,7 +10,10 @@ ifndef arch arch = IA32 endif -CCFLAGS = -fPIC -Wall -pthread -Wextra -D$(os) #-finline-functions -O3 -fno-strict-aliasing #-msse3 +CCFLAGS = -g -fPIC -Wall -pthread -Wextra -D$(os) #-finline-functions -O3 -fno-strict-aliasing #-msse3 +ifeq ($(os), WIN32) +CCFLAGS = -g -fPIC -Wall -pthread -Wextra -D$(os) -DUDT_EXPORTS -D_WIN32_WINNT=0x0501 +endif ifeq ($(arch), IA32) CCFLAGS += -DIA32 @@ -33,16 +38,24 @@ endif OBJS = md5.o common.o window.o list.o buffer.o packet.o channel.o queue.o ccc.o cache.o core.o epoll.o api.o DIR = $(shell pwd) -all: libudt.so libudt.a udt +ifneq ($(os), WIN32) +all: libudt udt +else +all: libudt libudt.a udt +endif %.o: %.cpp %.h udt.h - $(C++) $(CCFLAGS) $< -c + $(CXX) $(CCFLAGS) $< -c -libudt.so: $(OBJS) -ifneq ($(os), OSX) - $(C++) -shared -o $@ $^ -else - $(C++) -dynamiclib -o libudt.dylib -lstdc++ -lpthread -lm $^ +libudt: $(OBJS) +ifeq ($(os), LINUX) + $(CXX) -shared -o libudt.so $^ +endif +ifeq ($(os), OS_X) + $(CXX) -dynamiclib -o libudt.dylib -lstdc++ -lpthread -lm $^ +endif +ifeq ($(os), WIN32) + $(CXX) -shared -o libudt.dll $^ -Wl,--out-implib,libudt_dll.a -L/usr/i486-mingw32/lib -lws2_32 endif libudt.a: $(OBJS) diff --git a/src/udt.h b/src/udt.h index 1641c99..46d77b8 100644 --- a/src/udt.h +++ b/src/udt.h @@ -71,15 +71,15 @@ written by #ifdef WIN32 #ifndef __MINGW__ // Explicitly define 32-bit and 64-bit numbers - typedef __int32 int32_t; - typedef __int64 int64_t; - typedef unsigned __int32 uint32_t; - #ifndef LEGACY_WIN32 - typedef unsigned __int64 uint64_t; - #else - // VC 6.0 does not support unsigned __int64: may cause potential problems. - typedef __int64 uint64_t; - #endif + /* typedef __int32 int32_t; */ + /* typedef __int64 int64_t; */ + /* typedef unsigned __int32 uint32_t; */ + /* #ifndef LEGACY_WIN32 */ + /* typedef unsigned __int64 uint64_t; */ + /* #else */ + /* // VC 6.0 does not support unsigned __int64: may cause potential problems. */ + /* typedef __int64 uint64_t; */ + /* #endif */ #ifdef UDT_EXPORTS #define UDT_API __declspec(dllexport)