Commit f291ff6e authored by Matthew Waters's avatar Matthew Waters 🐨

usrsctp: fix for mingw builds on windows

parent 1f0b7aa5
......@@ -40,6 +40,8 @@ class Recipe(recipe.Recipe):
files_libs = ['libusrsctp']
files_devel = ['include/usrsctp.h']
patches = ['libusrsctp/0001-auto-Fix-build-for-mingw.patch']
def extract(self):
super(recipe.Recipe, self).extract()
......@@ -68,12 +70,4 @@ class Recipe(recipe.Recipe):
copyreplacetree(os.path.join(recipe_path, "net"),
os.path.join(usrsctplib_path, "net"))
self.append_env("CPPFLAGS", "-I %s" % os.path.join(usrsctplib_path, "platform"))
# Disable compilation of examples
shell.replace(os.path.join(self.build_dir, 'Makefile.am'),
{'SUBDIRS = usrsctplib programs':
'SUBDIRS = usrsctplib'})
# Disable -Werror
shell.replace(os.path.join(self.build_dir, 'configure.ac'),
{'-Werror':
'-Wno-error'})
super(recipe.Recipe, self).configure()
From 727d02952459cd1949532d252e33b7e85b243a43 Mon Sep 17 00:00:00 2001
From: Matthew Waters <matthew@centricular.com>
Date: Wed, 17 Oct 2018 17:58:38 +1100
Subject: [PATCH] auto: Fix build for mingw
---
Makefile.am | 2 +-
configure.ac | 36 ++++++++++++++++++++++++++---------
programs/ekr_peer.c | 2 +-
programs/rtcweb.c | 2 +-
usrsctplib/Makefile.am | 3 ++-
usrsctplib/netinet/sctp_pcb.c | 5 +++++
usrsctplib/user_recv_thread.c | 4 ++++
usrsctplib/user_socket.c | 14 +++++++++++---
usrsctplib/user_socketvar.h | 2 ++
9 files changed, 54 insertions(+), 16 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index e9e17e2..2e72c8b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -28,7 +28,7 @@
# SUCH DAMAGE.
#
-SUBDIRS = usrsctplib programs
+SUBDIRS = usrsctplib
EXTRA_DIST = bootstrap Makefile.nmake
ACLOCAL_AMFLAGS = -I m4
# pkgconfig_DATA = usrsctp.pc
diff --git a/configure.ac b/configure.ac
index 2339ea7..05209a5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,6 +75,10 @@ openbsd*)
solaris*)
CFLAGS="$CFLAGS -D_XPG4_2"
;;
+mingw32*)
+ CFLAGS="$CFLAGS -std=c99 -D__Userspace_os_Windows"
+ LIBLIBADD="-lws2_32 -liphlpapi"
+ ;;
esac
if test "x$GCC" = "xyes" -o "x$CC" = "xclang" ; then
@@ -92,7 +96,7 @@ AC_ARG_ENABLE(warnings-as-errors,
enable_warnings_as_errors=$enableval,enable_warnings_as_errors=yes)
if test "x$ac_supports_gcc_flags" = "xyes" -a x$enable_warnings_as_errors = xyes; then
AC_MSG_RESULT(yes)
- CFLAGS="$CFLAGS -Werror"
+ CFLAGS="$CFLAGS -Wno-error"
else
AC_MSG_RESULT(no)
fi
@@ -178,17 +182,31 @@ AC_CHECK_MEMBER(struct sockaddr_conn.sconn_len,
[#include "usrsctplib/usrsctp.h"])
AC_MSG_CHECKING(for socklen_t)
-AC_TRY_COMPILE([#ifdef HAVE_SYS_TYPES_H
- #include <sys/types.h>
- #endif
- #include <sys/socket.h>],
- [socklen_t x; x = 1; return ((int)x);],
- [AC_MSG_RESULT(yes)],
- [AC_MSG_RESULT(int)
- AC_DEFINE(socklen_t, int, [Define a type for socklen_t.])])
+case $host_os in
+mingw32*)
+ AC_TRY_COMPILE([#include <winsock2.h>
+ #include <ws2tcpip.h>],
+ [socklen_t x; x = 1; return ((int)x);],
+ [AC_MSG_RESULT(yes)],
+ [AC_MSG_RESULT(int)
+ AC_DEFINE(socklen_t, int, [Define a type for socklen_t.])])
+
+ ;;
+*)
+ AC_TRY_COMPILE([#ifdef HAVE_SYS_TYPES_H
+ #include <sys/types.h>
+ #endif
+ #include <sys/socket.h>],
+ [socklen_t x; x = 1; return ((int)x);],
+ [AC_MSG_RESULT(yes)],
+ [AC_MSG_RESULT(int)
+ AC_DEFINE(socklen_t, int, [Define a type for socklen_t.])])
+ ;;
+esac
AC_C_BIGENDIAN
+AC_SUBST([LIBLIBADD])
AC_SUBST([LIBCFLAGS])
AC_SUBST([APPCFLAGS])
dnl AC_CONFIG_FILES([usrsctp.pc])
diff --git a/programs/ekr_peer.c b/programs/ekr_peer.c
index b3cfe62..a6fe565 100644
--- a/programs/ekr_peer.c
+++ b/programs/ekr_peer.c
@@ -486,7 +486,7 @@ main(int argc, char *argv[])
perror("usrsctp_connect");
}
for (;;) {
-#ifdef _WIN32
+#if defined(_WIN32) && defined(_MSC_VER)
if (gets_s(line, LINE_LENGTH) == NULL) {
#else
if (fgets(line, LINE_LENGTH, stdin) == NULL) {
diff --git a/programs/rtcweb.c b/programs/rtcweb.c
index 1e0b734..9087c65 100644
--- a/programs/rtcweb.c
+++ b/programs/rtcweb.c
@@ -1426,7 +1426,7 @@ main(int argc, char *argv[])
unlock_peer_connection(&peer_connection);
for (;;) {
-#ifdef _WIN32
+#if defined(_WIN32) && defined(_MSC_VER)
if (gets_s(line, LINE_LENGTH) == NULL) {
#else
if (fgets(line, LINE_LENGTH, stdin) == NULL) {
diff --git a/usrsctplib/Makefile.am b/usrsctplib/Makefile.am
index 85240b7..395c6c0 100644
--- a/usrsctplib/Makefile.am
+++ b/usrsctplib/Makefile.am
@@ -76,6 +76,7 @@ libusrsctp_la_SOURCES = user_atomic.h \
netinet6/sctp6_var.h \
netinet6/sctp6_usrreq.c
libusrsctp_la_CFLAGS = $(LIBCFLAGS)
-libusrsctp_la_LDFLAGS = -version-info 1:0:0
+libusrsctp_la_LDFLAGS = -version-info 1:0:0 -no-undefined
+libusrsctp_la_LIBADD = $(LIBLIBADD)
include_HEADERS = usrsctp.h
diff --git a/usrsctplib/netinet/sctp_pcb.c b/usrsctplib/netinet/sctp_pcb.c
index 9e9fca0..3800691 100755
--- a/usrsctplib/netinet/sctp_pcb.c
+++ b/usrsctplib/netinet/sctp_pcb.c
@@ -86,6 +86,11 @@ VNET_DEFINE(struct sctp_base_info, system_base_info);
struct sctp_base_info system_base_info;
#endif
+#if defined(__Userspace_os_Windows) && defined(__GNUC__)
+/* mingw doesn't include a compat define for this */
+#define IN6_ARE_ADDR_EQUAL IN6_ADDR_EQUAL
+#endif
+
/* FIX: we don't handle multiple link local scopes */
/* "scopeless" replacement IN6_ARE_ADDR_EQUAL */
#ifdef INET6
diff --git a/usrsctplib/user_recv_thread.c b/usrsctplib/user_recv_thread.c
index b1a9d01..aed249e 100755
--- a/usrsctplib/user_recv_thread.c
+++ b/usrsctplib/user_recv_thread.c
@@ -64,6 +64,10 @@
# error "Can't determine socket option to use to get UDP IP"
#endif
+#ifndef IPV6_V6ONLY
+#define IPV6_V6ONLY 27
+#endif
+
void recv_thread_destroy(void);
#define MAXLEN_MBUF_CHAIN 32 /* What should this value be? */
#define ROUNDUP(a, size) (((a) & ((size)-1)) ? (1 + ((a) | ((size)-1))) : (a))
diff --git a/usrsctplib/user_socket.c b/usrsctplib/user_socket.c
index 1f5f77f..5c5d3ee 100755
--- a/usrsctplib/user_socket.c
+++ b/usrsctplib/user_socket.c
@@ -3245,7 +3245,10 @@ usrsctp_dumppacket(const void *buf, size_t len, int outbound)
char *dump_buf, *packet;
#ifdef _WIN32
struct timeb tb;
- struct tm t;
+ struct tm *t;
+#ifdef _MSC_VER
+ struct tm t_val;
+#endif
#else
struct timeval tv;
struct tm *t;
@@ -3261,10 +3264,15 @@ usrsctp_dumppacket(const void *buf, size_t len, int outbound)
pos = 0;
#ifdef _WIN32
ftime(&tb);
- localtime_s(&t, &tb.time);
+#ifdef _MSC_VER
+ localtime_s(&t_val, &tb.time);
+ t = &t_val;
+#else
+ t = localtime(&tb.time);
+#endif
_snprintf_s(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_LENGTH, PREAMBLE_FORMAT,
outbound ? 'O' : 'I',
- t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm));
+ t->tm_hour, t->tm_min, t->tm_sec, (long)(1000 * tb.millitm));
#else
gettimeofday(&tv, NULL);
sec = (time_t)tv.tv_sec;
diff --git a/usrsctplib/user_socketvar.h b/usrsctplib/user_socketvar.h
index ffc8270..3dd6267 100755
--- a/usrsctplib/user_socketvar.h
+++ b/usrsctplib/user_socketvar.h
@@ -102,7 +102,9 @@ struct uio {
*/
#if defined (__Userspace_os_Windows)
#define AF_ROUTE 17
+#if !defined(__GNUC__)
typedef __int32 pid_t;
+#endif
typedef unsigned __int32 uid_t;
enum sigType {
SIGNAL = 0,
--
2.19.0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment