From f3f77ae9f2687185e4e50c81649e24a2959b6a1a Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Sun, 14 Oct 2018 14:06:58 +0000 Subject: [PATCH] fixed some code for win32 --- moo/configure | 15 +++++++++++++++ moo/configure.ac | 15 +++++++++++++++ moo/lib/Makefile.am | 6 ++++++ moo/lib/Makefile.in | 32 +++++++++++++++++++++++++++----- moo/lib/main.c | 40 ++++++++++++++++++++++++++++++++++------ moo/lib/moo-cmn.h | 1 - moo/mod/_con.c | 3 ++- 7 files changed, 99 insertions(+), 13 deletions(-) diff --git a/moo/configure b/moo/configure index d06f206..e2dfb02 100755 --- a/moo/configure +++ b/moo/configure @@ -21441,6 +21441,11 @@ $as_echo "#define MOO_UNICODE_SIZE 4" >>confdefs.h $as_echo "#define MOO_ENABLE_UNICODE 1" >>confdefs.h + if test "${platform_win32}" = "yes" + then + CFLAGS="$CFLAGS -DUNICODE -D_UNICODE" + CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE" + fi elif test "${enable_unicode}" = "yes:2" then @@ -21449,6 +21454,11 @@ $as_echo "#define MOO_UNICODE_SIZE 2" >>confdefs.h $as_echo "#define MOO_ENABLE_UNICODE 1" >>confdefs.h + if test "${platform_win32}" = "yes" + then + CFLAGS="$CFLAGS -DUNICODE -D_UNICODE" + CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE" + fi elif test "${enable_unicode}" = "yes" then @@ -21457,6 +21467,11 @@ $as_echo "#define MOO_UNICODE_SIZE 1" >>confdefs.h $as_echo "#define MOO_ENABLE_UNICODE 1" >>confdefs.h + if test "${platform_win32}" = "yes" + then + CFLAGS="$CFLAGS -DUNICODE -D_UNICODE" + CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE" + fi elif test "${enable_unicode}" = "no:4" then diff --git a/moo/configure.ac b/moo/configure.ac index 498f5e0..9d6a203 100644 --- a/moo/configure.ac +++ b/moo/configure.ac @@ -667,14 +667,29 @@ if test "${enable_unicode}" = "yes:4" then AC_DEFINE([MOO_UNICODE_SIZE],[4],[Unicode character type size]) AC_DEFINE([MOO_ENABLE_UNICODE],[1],[Use the unicode character type as the default character type]) + if test "${platform_win32}" = "yes" + then + [CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"] + [CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"] + fi elif test "${enable_unicode}" = "yes:2" then AC_DEFINE([MOO_UNICODE_SIZE],[2],[Unicode character type size]) AC_DEFINE([MOO_ENABLE_UNICODE],[1],[Use the unicode character type as the default character type]) + if test "${platform_win32}" = "yes" + then + [CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"] + [CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"] + fi elif test "${enable_unicode}" = "yes" then AC_DEFINE([MOO_UNICODE_SIZE],[1],[Unicode character type size]) AC_DEFINE([MOO_ENABLE_UNICODE],[1],[Use the unicode character type as the default character type]) + if test "${platform_win32}" = "yes" + then + [CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"] + [CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"] + fi elif test "${enable_unicode}" = "no:4" then AC_DEFINE([MOO_UNICODE_SIZE],[4],[Unicode character type size]) diff --git a/moo/lib/Makefile.am b/moo/lib/Makefile.am index 69f8928..611dc2c 100644 --- a/moo/lib/Makefile.am +++ b/moo/lib/Makefile.am @@ -116,9 +116,15 @@ endif bin_PROGRAMS = moo moo_SOURCES = main.c +if WIN32 +moo_SOURCES += poll-msw.c poll-msw.h +endif moo_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD) moo_LDFLAGS = $(LDFLAGS_ALL_COMMON) moo_LDADD = $(LIBADD_LIB_COMMON) -lmoo $(PTHREAD_LIBS) +if WIN32 +moo_LDADD += $(SOCKET_LIBS) +endif if ENABLE_STATIC_MODULE moo_DEPENDENCIES = libmoo.la endif diff --git a/moo/lib/Makefile.in b/moo/lib/Makefile.in index eaa3c4b..753829d 100644 --- a/moo/lib/Makefile.in +++ b/moo/lib/Makefile.in @@ -110,8 +110,11 @@ host_triplet = @host@ @ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_13 = -lmoo-x11 @ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_14 = $(abs_builddir)/../mod/libmoo-x11.la bin_PROGRAMS = moo$(EXEEXT) +@WIN32_TRUE@am__append_15 = poll-msw.c poll-msw.h +@WIN32_TRUE@am__append_16 = $(SOCKET_LIBS) @ENABLE_STATIC_MODULE_FALSE@moo_DEPENDENCIES = $(am__DEPENDENCIES_5) \ -@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) +@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) \ +@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_6) subdir = lib ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \ @@ -180,8 +183,11 @@ libmoo_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(libmoo_la_LDFLAGS) $(LDFLAGS) -o $@ PROGRAMS = $(bin_PROGRAMS) -am_moo_OBJECTS = moo-main.$(OBJEXT) +am__moo_SOURCES_DIST = main.c poll-msw.c poll-msw.h +@WIN32_TRUE@am__objects_1 = moo-poll-msw.$(OBJEXT) +am_moo_OBJECTS = moo-main.$(OBJEXT) $(am__objects_1) moo_OBJECTS = $(am_moo_OBJECTS) +@WIN32_TRUE@am__DEPENDENCIES_6 = $(am__DEPENDENCIES_1) moo_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(moo_LDFLAGS) $(LDFLAGS) -o $@ @@ -220,7 +226,7 @@ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = SOURCES = $(libmoo_la_SOURCES) $(moo_SOURCES) -DIST_SOURCES = $(libmoo_la_SOURCES) $(moo_SOURCES) +DIST_SOURCES = $(libmoo_la_SOURCES) $(am__moo_SOURCES_DIST) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -481,10 +487,11 @@ libmoo_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_6) \ @ENABLE_STATIC_MODULE_TRUE@libmoo_la_DEPENDENCIES = $(abs_builddir)/../mod/libmoo-stdio.la \ @ENABLE_STATIC_MODULE_TRUE@ $(am__append_8) $(am__append_10) \ @ENABLE_STATIC_MODULE_TRUE@ $(am__append_12) $(am__append_14) -moo_SOURCES = main.c +moo_SOURCES = main.c $(am__append_15) moo_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD) moo_LDFLAGS = $(LDFLAGS_ALL_COMMON) -moo_LDADD = $(LIBADD_LIB_COMMON) -lmoo $(PTHREAD_LIBS) +moo_LDADD = $(LIBADD_LIB_COMMON) -lmoo $(PTHREAD_LIBS) \ + $(am__append_16) @ENABLE_STATIC_MODULE_TRUE@moo_DEPENDENCIES = libmoo.la all: moo-cfg.h $(MAKE) $(AM_MAKEFLAGS) all-am @@ -654,6 +661,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-utf8.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-utl.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/moo-main.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/moo-poll-msw.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @@ -833,6 +841,20 @@ moo-main.obj: main.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o moo-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi` +moo-poll-msw.o: poll-msw.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT moo-poll-msw.o -MD -MP -MF $(DEPDIR)/moo-poll-msw.Tpo -c -o moo-poll-msw.o `test -f 'poll-msw.c' || echo '$(srcdir)/'`poll-msw.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/moo-poll-msw.Tpo $(DEPDIR)/moo-poll-msw.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='poll-msw.c' object='moo-poll-msw.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o moo-poll-msw.o `test -f 'poll-msw.c' || echo '$(srcdir)/'`poll-msw.c + +moo-poll-msw.obj: poll-msw.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT moo-poll-msw.obj -MD -MP -MF $(DEPDIR)/moo-poll-msw.Tpo -c -o moo-poll-msw.obj `if test -f 'poll-msw.c'; then $(CYGPATH_W) 'poll-msw.c'; else $(CYGPATH_W) '$(srcdir)/poll-msw.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/moo-poll-msw.Tpo $(DEPDIR)/moo-poll-msw.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='poll-msw.c' object='moo-poll-msw.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o moo-poll-msw.obj `if test -f 'poll-msw.c'; then $(CYGPATH_W) 'poll-msw.c'; else $(CYGPATH_W) '$(srcdir)/poll-msw.c'; fi` + mostlyclean-libtool: -rm -f *.lo diff --git a/moo/lib/main.c b/moo/lib/main.c index a9eabdc..6d33700 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -46,6 +46,14 @@ # if defined(MOO_HAVE_CFG_H) && defined(MOO_ENABLE_LIBLTDL) # include # define USE_LTDL +# else +# define USE_WIN_DLL + /* TODO: write sys_dl_error() properly */ +# define sys_dl_error() win_dlerror() +# define sys_dl_open(x) LoadLibraryExA(x, MOO_NULL, 0) +# define sys_dl_openext(x) LoadLibraryExA(x, MOO_NULL, 0) +# define sys_dl_close(x) FreeLibrary(x) +# define sys_dl_getsym(x,n) GetProcAddress(x,n) # endif # include "poll-msw.h" @@ -110,7 +118,7 @@ # define sys_dl_close(x) dlclose(x) # define sys_dl_getsym(x,n) dlsym(x,n) # elif defined(__APPLE__) || defined(__MACOSX__) -# define USE_MACH_O +# define USE_MACH_O_DYLD # include # define sys_dl_error() mach_dlerror() # define sys_dl_open(x) mach_dlopen(x) @@ -203,7 +211,7 @@ # else # if defined(USE_DLFCN) # define MOO_DEFAULT_PFMODPOSTFIX ".so" -# elif defined(USE_MACH_O) +# elif defined(USE_MACH_O_DYLD) # define MOO_DEFAULT_PFMODPOSTFIX ".dylib" # else # define MOO_DEFAULT_PFMODPOSTFIX "" @@ -828,7 +836,27 @@ static void syserrstrb (moo_t* moo, int syserr, moo_bch_t* buf, moo_oow_t len) /* ========================================================================= */ -#if defined(USE_MACH_O) +#if defined(USE_WIN_DLL) + +static const char* win_dlerror (void) +{ + /* TODO: handle wchar_t, moo_ooch_t etc? */ + static char buf[256]; + DWORD rc; + + rc = FormatMessageA ( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + buf, MOO_COUNTOF(buf), MOO_NULL + ); + while (rc > 0 && buf[rc - 1] == '\r' || buf[rc - 1] == '\n') + { + buf[--rc] = '\0'; + } + return buf; +} + +#elif defined(USE_MACH_O_DYLD) static const char* mach_dlerror_str = ""; static void* mach_dlopen (const char* path) @@ -897,7 +925,7 @@ static const char* mach_dlerror (void) static void* dl_open (moo_t* moo, const moo_ooch_t* name, int flags) { -#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O) +#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O_DYLD) || defined(USE_WIN_DLL) moo_bch_t stabuf[128], * bufptr; moo_oow_t ucslen, bcslen, bufcapa; void* handle; @@ -1045,7 +1073,7 @@ static void* dl_open (moo_t* moo, const moo_ooch_t* name, int flags) static void dl_close (moo_t* moo, void* handle) { -#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O) +#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O_DYLD) || defined(USE_WIN_DLL) MOO_DEBUG1 (moo, "Closed DL handle %p\n", handle); sys_dl_close (handle); @@ -1057,7 +1085,7 @@ static void dl_close (moo_t* moo, void* handle) static void* dl_getsym (moo_t* moo, void* handle, const moo_ooch_t* name) { -#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O) +#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O_DYLD) || defined(USE_WIN_DLL) moo_bch_t stabuf[64], * bufptr; moo_oow_t bufcapa, ucslen, bcslen, i; const moo_bch_t* symname; diff --git a/moo/lib/moo-cmn.h b/moo/lib/moo-cmn.h index 11b89e9..16db360 100644 --- a/moo/lib/moo-cmn.h +++ b/moo/lib/moo-cmn.h @@ -84,7 +84,6 @@ typedef signed char moo_int8_t; #endif - /* moo_int16_t */ #if defined(MOO_SIZEOF_SHORT) && (MOO_SIZEOF_SHORT == 2) # define MOO_HAVE_UINT16_T diff --git a/moo/mod/_con.c b/moo/mod/_con.c index b84a0b4..abd60aa 100644 --- a/moo/mod/_con.c +++ b/moo/mod/_con.c @@ -29,8 +29,9 @@ #include #include -#if defined(_WIN32) +#if defined(_WIN32) +# include #elif defined(__DOS__) #else