--- libxml2/configure.ac.orig	2017-10-14 18:31:09.612676600 -0400
+++ libxml2/configure.ac	2017-10-14 18:32:22.644421900 -0400
@@ -478,6 +478,9 @@ AC_SUBST(WITH_LZMA)
 CPPFLAGS=${_cppflags}
 LIBS=${_libs}
 
+echo Checking compiler features
+  AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough=0],[CFLAGS="$CFLAGS -Wimplicit-fallthrough=0"],,[[$CFLAGS_WERROR]])
+
 echo Checking headers
 
 dnl Checks for header files.
--- libxml2/include/libxml/threads.h.orig	2017-10-12 17:39:06.649084500 -0400
+++ libxml2/include/libxml/threads.h	2017-10-12 17:42:03.012397100 -0400
@@ -13,6 +13,10 @@
 
 #include <libxml/xmlversion.h>
 
+#if defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS)
+#include "windows.h"
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -72,8 +76,17 @@ XMLPUBFUN void XMLCALL
 XMLPUBFUN xmlGlobalStatePtr XMLCALL
 			xmlGetGlobalState(void);
 
-#if defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && defined(LIBXML_STATIC_FOR_DLL)
-int XMLCALL xmlDllMain(void *hinstDLL, unsigned long fdwReason, void *lpvReserved);
+#ifdef HAVE_PTHREAD_H
+#elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
+#if defined(LIBXML_STATIC_FOR_DLL)
+BOOL XMLCALL
+xmlDllMain(ATTRIBUTE_UNUSED HINSTANCE hinstDLL, DWORD fdwReason,
+           ATTRIBUTE_UNUSED LPVOID lpvReserved);
+#else
+BOOL WINAPI
+DllMain(ATTRIBUTE_UNUSED HINSTANCE hinstDLL, DWORD fdwReason,
+        ATTRIBUTE_UNUSED LPVOID lpvReserved);
+#endif
 #endif
 
 #ifdef __cplusplus
--- libxml2/libxml.h.orig	2017-10-12 17:45:23.138297500 -0400
+++ libxml2/libxml.h	2017-10-12 17:45:59.105744500 -0400
@@ -109,7 +109,7 @@ int xmlNop(void);
 #endif
 #endif
 #endif
-#if !defined(PIC) && !defined(NOLIBTOOL)
+#if !defined(PIC) && !defined(NOLIBTOOL) && !defined(LIBXML_STATIC)
 #  define LIBXML_STATIC
 #endif
 #endif /* ! __XML_LIBXML_H__ */
--- libxml2/include/libxml/hash.h.orig	2017-10-12 19:16:45.562103100 -0400
+++ libxml2/include/libxml/hash.h	2017-10-12 19:19:08.114196900 -0400
@@ -52,9 +52,11 @@ extern "C" {
  * This macro violated ISO C aliasing rules (gcc4 on s390 broke)
  * so it is disabled now
  */
-
+#if __GNUC__ > 5
+#define XML_CAST_FPTR(fptr) (*(void **)(&fptr))
+#else
 #define XML_CAST_FPTR(fptr) fptr
-
+#endif
 
 /*
  * function types:
--- libxml2/trionan.c.orig	2017-10-13 13:42:50.227783100 -0400
+++ libxml2/trionan.c	2017-10-13 14:57:29.098875300 -0400
@@ -187,6 +187,7 @@ TRIO_ARGS1((values),
   return result;
 }
 
+#if !defined(__MINGW32__) && !defined(__MSYS__)
 /*
  * trio_is_special_quantity
  */
@@ -228,10 +229,10 @@ TRIO_ARGS1((number),
   }
   return is_negative;
 }
+#endif
 
 #endif /* USE_IEEE_754 */
 
-
 /**
    Generate negative zero.

--- libxml2/testapi.c.orig	2017-10-15 04:33:05.506393600 -0400
+++ libxml2/testapi.c	2017-10-15 05:10:56.222524500 -0400
@@ -8,6 +8,10 @@
  * daniel@veillard.com
  */
 
+/* winsock2.h included in wsockcompat.h must come before windows.h */
+#if defined _WIN32
+#include "wsockcompat.h"
+#endif
 #include "libxml.h"
 #include <stdio.h>
 
@@ -18106,7 +18110,7 @@ test_xmlSchematronNewParserCtxt(void) {
     return(test_ret);
 }
 
-#ifdef LIBXML_SCHEMATRON_ENABLED
+#if defined(LIBXML_SCHEMATRON_ENABLED) && !defined(__MINGW32__) && !defined(__MSYS__)
 
 #define gen_nb_xmlSchematronPtr 1
 static xmlSchematronPtr gen_xmlSchematronPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -18126,7 +18130,7 @@ test_xmlSchematronNewValidCtxt(void) {
     return(test_ret);
 }
 
-#ifdef LIBXML_SCHEMATRON_ENABLED
+#if defined LIBXML_SCHEMATRON_ENABLED && !defined(__MINGW32__) && !defined(__MSYS__)
 
 #define gen_nb_xmlSchematronParserCtxtPtr 1
 static xmlSchematronParserCtxtPtr gen_xmlSchematronParserCtxtPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
@@ -18625,13 +18629,14 @@ test_xmlBufShrink(void) {
     return(test_ret);
 }
 
-
+#if !defined (__MINGW32__) && !defined(__MSYS__)
 #define gen_nb_const_xmlBufPtr 1
 static xmlBufPtr gen_const_xmlBufPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
     return(NULL);
 }
 static void des_const_xmlBufPtr(int no ATTRIBUTE_UNUSED, const xmlBufPtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
 }
+#endif
 
 static int
 test_xmlBufUse(void) {
@@ -34623,7 +34628,7 @@ test_xmlSchemaParse(void) {
     return(test_ret);
 }
 
-#ifdef LIBXML_SCHEMAS_ENABLED
+#if defined LIBXML_SCHEMAS_ENABLED && !defined(__MINGW32__) && !defined(__MSYS__)
 
 #define gen_nb_xmlSAXHandlerPtr_ptr 1
 static xmlSAXHandlerPtr * gen_xmlSAXHandlerPtr_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
--- libxml2/runtest.c.orig	2017-10-14 15:11:41.995529500 -0400
+++ libxml2/runtest.c	2017-10-14 15:20:57.076248100 -0400
@@ -3962,8 +3962,12 @@ static const char *testfiles[] = {
     "test/threads/invalid.xml",
 };
 
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define OKAY 1
+#else
 static const char *Okay = "OK";
 static const char *Failed = "Failed";
+#endif
 
 #ifndef xmlDoValidityCheckingDefaultValue
 #error xmlDoValidityCheckingDefaultValue is not a macro
@@ -3972,12 +3976,21 @@ static const char *Failed = "Failed";
 #error xmlGenericErrorContext is not a macro
 #endif
 
+#if defined(_WIN32) && !defined(__CYGWIN__)
+static DWORD
+thread_specific_data(void *private_data)
+#else
 static void *
 thread_specific_data(void *private_data)
+#endif
 {
     xmlDocPtr myDoc;
     const char *filename = (const char *) private_data;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+    DWORD okay = OKAY;
+#else
     int okay = 1;
+#endif
 
     if (!strcmp(filename, "test/threads/invalid.xml")) {
         xmlDoValidityCheckingDefaultValue = 0;
@@ -4016,9 +4029,13 @@ thread_specific_data(void *private_data)
             okay = 0;
         }
     }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+    return (okay);
+#else
     if (okay == 0)
         return ((void *) Failed);
     return ((void *) Okay);
+#endif
 }
 
 #if defined(_WIN32) && !defined(__CYGWIN__)
@@ -4032,7 +4049,7 @@ static HANDLE tid[MAX_ARGC];
 static DWORD WINAPI
 win32_thread_specific_data(void *private_data)
 {
-    return((DWORD) thread_specific_data(private_data));
+    return(thread_specific_data(private_data));
 }
 
 static int
@@ -4084,7 +4101,7 @@ testThread(void)
 
         xmlCatalogCleanup();
         for (i = 0; i < num_threads; i++) {
-            if (results[i] != (DWORD) Okay) {
+            if (results[i] != OKAY) {
                 fprintf(stderr, "Thread %d handling %s failed\n",
 		        i, testfiles[i]);
 	        res = 1;
--- libxml2/nanohttp.c.orig	2017-10-15 05:38:02.063055700 -0400
+++ libxml2/nanohttp.c	2017-10-15 05:47:39.373225800 -0400
@@ -1088,7 +1088,7 @@ xmlNanoHTTPConnectHost(const char *host,
 
 	for (res = result; res; res = res->ai_next) {
 	    if (res->ai_family == AF_INET) {
-		if (res->ai_addrlen > sizeof(sockin)) {
+		if (res->ai_addrlen > (socklen_t)sizeof(sockin)) {
 		    __xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n");
 		    freeaddrinfo (result);
 		    return INVALID_SOCKET;
@@ -1098,7 +1098,7 @@ xmlNanoHTTPConnectHost(const char *host,
 		addr = (struct sockaddr *)&sockin;
 #ifdef SUPPORT_IP6
 	    } else if (have_ipv6 () && (res->ai_family == AF_INET6)) {
-		if (res->ai_addrlen > sizeof(sockin6)) {
+		if (res->ai_addrlen > (socklen_t)sizeof(sockin6)) {
 		    __xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n");
 		    freeaddrinfo (result);
 		    return INVALID_SOCKET;
--- libxml2/nanoftp.c.orig	2017-10-15 05:49:01.330256300 -0400
+++ libxml2/nanoftp.c	2017-10-15 05:58:07.442098600 -0400
@@ -14,6 +14,10 @@
 #define HAVE_SYS_TIME_H
 #endif /* TESTING */
 
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include <wsockcompat.h>
+#endif
+
 #define IN_LIBXML
 #include "libxml.h"
 
@@ -75,10 +79,6 @@
 #endif
 
 
-#if defined(_WIN32) && !defined(__CYGWIN__)
-#include <wsockcompat.h>
-#endif
-
 /**
  * A couple portability macros
  */
@@ -901,7 +901,7 @@ xmlNanoFTPConnect(void *ctx) {
 	    __xmlIOErr(XML_FROM_FTP, 0, "getaddrinfo failed");
 	    return (-1);
 	}
-	if (tmp->ai_addrlen > sizeof(ctxt->ftpAddr)) {
+	if (tmp->ai_addrlen > (socklen_t)sizeof(ctxt->ftpAddr)) {
 	    if (result)
 		freeaddrinfo (result);
 	    __xmlIOErr(XML_FROM_FTP, 0, "gethostbyname address mismatch");
--- libxml2/testrecurse.c.orig	2017-10-15 08:07:00.240675300 -0400
+++ libxml2/testrecurse.c	2017-10-15 08:13:59.021086500 -0400
@@ -69,9 +69,14 @@ typedef struct
 } glob_t;
 
 #define GLOB_DOOFFS 0
+#if defined __MINGW32__
+static int glob(const char *pattern,
+                glob_t *pglob) {
+#else
 static int glob(const char *pattern, int flags,
                 int errfunc(const char *epath, int eerrno),
                 glob_t *pglob) {
+#endif
     glob_t *ret;
     WIN32_FIND_DATA FindFileData;
     HANDLE hFind;
@@ -823,7 +828,11 @@ launchTests(testDescPtr tst) {
 	glob_t globbuf;
 
 	globbuf.gl_offs = 0;
+#if defined(__MINGW32__)
+	glob(tst->in, &globbuf);
+#else
 	glob(tst->in, GLOB_DOOFFS, NULL, &globbuf);
+#endif
 	for (i = 0;i < globbuf.gl_pathc;i++) {
 	    if (!checkTestFile(globbuf.gl_pathv[i]))
 	        continue;
