update Windows support
Stefan Schuermans

Stefan Schuermans commited on 2017-09-24 08:46:27
Showing 5 changed files, with 34 additions and 4 deletions.

... ...
@@ -80,6 +80,21 @@ ifeq ($(patsubst MINGW32%,MINGW32,$(OS_RAW)),MINGW32)
80 80
   EX_LIBS    += -lwsock32
81 81
 endif
82 82
 
83
+ifeq ($(CROSS_WIN),1)
84
+  OS         := mingw32
85
+  CC         := x86_64-w64-mingw32-gcc
86
+  AR         := ar
87
+  RANLIB     := ranlib
88
+  LEXT       := dll
89
+  LEXTSUF    :=
90
+  BSUF       := .exe
91
+  INSTALL    := install
92
+  DEFINES    += -DWINDOWS
93
+  SH_LDFLAGS += -shared
94
+  SH_LIBS    += -lwsock32
95
+  EX_LIBS    += -lwsock32
96
+endif
97
+
83 98
 ifeq ($(OS),)
84 99
   $(error unsupported operating system $(OS_RAW))
85 100
 endif
... ...
@@ -1,5 +1,8 @@
1 1
 *.d
2 2
 *.o
3 3
 blink
4
+blink.exe
4 5
 event
6
+event.exe
5 7
 fade
8
+fade.exe
... ...
@@ -36,11 +36,11 @@
36 36
 #  define ETP_THREAD_FUNC(func) void * (func)(void *vp_displayer)
37 37
 #endif
38 38
 
39
-/** return a void pointer from a thread function */
39
+/** return values for thread functions */
40 40
 #ifdef WINDOWS
41
-#  define ETP_THREAD_RETURN(vp) return (DWORD)(vp);
41
+#  define ETP_THREAD_RETURN_OK (0)
42 42
 #else
43
-#  define ETP_THREAD_RETURN(vp) return (vp);
43
+#  define ETP_THREAD_RETURN_OK (NULL)
44 44
 #endif
45 45
 
46 46
 /** type for a thread ID */
... ...
@@ -78,7 +78,18 @@ etp_display_t *etp_display_create(const char *sz_config_file,
78 78
   /* set up UDP socket */
79 79
 
80 80
   /* create socket */
81
+#ifdef WINDOWS
82
+  p_display->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
83
+  if (p_display->sock != INVALID_SOCKET) {
84
+    u_long arg = 1;
85
+    if (ioctlsocket(p_display->sock, FIONBIO, &arg) != 0) {
86
+      closesocket(p_display->sock);
87
+      p_display->sock = INVALID_SOCKET;
88
+    }
89
+  }
90
+#else
81 91
   p_display->sock = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP);
92
+#endif
82 93
   if (!etp_sock_is_valid(p_display->sock)) {
83 94
     etp_display_free(p_display);
84 95
     if (p_msg_func) {
... ...
@@ -20,6 +20,7 @@
20 20
 #include <sys/time.h>
21 21
 #include <stdlib.h>
22 22
 
23
+#include <intern/net.h> // first because of winsock2.h ordering
23 24
 #include <etherpix/display.h>
24 25
 #include <etherpix/displayer.h>
25 26
 #include <etherpix/msg.h>
... ...
@@ -313,6 +314,6 @@ ETP_THREAD_FUNC(etp_displayer_thread)
313 314
 
314 315
   etp_thread_mutex_unlock(&p_displayer->mtx);
315 316
 
316
-  ETP_THREAD_RETURN(NULL);
317
+  return ETP_THREAD_RETURN_OK;
317 318
 }
318 319
 
319 320