Win32: MinGW GCC compatibility.

Several warnings silenced, notably (ngx_socket_t) -1 is now checked
on socket operations instead of -1, as ngx_socket_t is unsigned on win32
and gcc complains on comparison.

With this patch, it's now possible to compile nginx using mingw gcc,
with options we normally compile on win32.
diff --git a/auto/lib/openssl/conf b/auto/lib/openssl/conf
index 528ee17..a65815f 100644
--- a/auto/lib/openssl/conf
+++ b/auto/lib/openssl/conf
@@ -33,6 +33,10 @@
             CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
             CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
             CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
+
+            if [ "$NGX_PLATFORM" = win32 ]; then
+                CORE_LIBS="$CORE_LIBS -lgdi32 -lcrypt32 -lws2_32"
+            fi
         ;;
     esac
 
diff --git a/auto/lib/pcre/conf b/auto/lib/pcre/conf
index 3458600..939f01b 100644
--- a/auto/lib/pcre/conf
+++ b/auto/lib/pcre/conf
@@ -73,6 +73,11 @@
 
         *)
             have=NGX_PCRE . auto/have
+
+            if [ "$NGX_PLATFORM" = win32 ]; then
+                have=PCRE_STATIC . auto/have
+            fi
+
             CORE_DEPS="$CORE_DEPS $PCRE/pcre.h"
             LINK_DEPS="$LINK_DEPS $PCRE/.libs/libpcre.a"
             CORE_LIBS="$CORE_LIBS $PCRE/.libs/libpcre.a"
diff --git a/auto/lib/pcre/make b/auto/lib/pcre/make
index c50d12f..0a27a11 100644
--- a/auto/lib/pcre/make
+++ b/auto/lib/pcre/make
@@ -23,14 +23,16 @@
         ngx_pcre=`echo \-DPCRE=\"$PCRE\" | sed -e "s/\//$ngx_regex_dirsep/g"`
     ;;
 
+    *)
+        ngx_makefile=
+    ;;
+
 esac
 
 
-case "$NGX_PLATFORM" in
+if [ -n "$ngx_makefile" ]; then
 
-    win32)
-
-        cat << END                                            >> $NGX_MAKEFILE
+    cat << END                                                >> $NGX_MAKEFILE
 
 `echo "$PCRE/pcre.lib:	$PCRE/pcre.h $NGX_MAKEFILE"			\
 	| sed -e "s/\//$ngx_regex_dirsep/g"`
@@ -41,10 +43,9 @@
 
 END
 
-    ;;
+else
 
-    *)
-        cat << END                                            >> $NGX_MAKEFILE
+    cat << END                                                >> $NGX_MAKEFILE
 
 $PCRE/pcre.h:	$PCRE/Makefile
 
@@ -60,6 +61,4 @@
 
 END
 
-    ;;
-
-esac
+fi
diff --git a/auto/lib/zlib/make b/auto/lib/zlib/make
index 9401a1d..7875ef6 100644
--- a/auto/lib/zlib/make
+++ b/auto/lib/zlib/make
@@ -24,6 +24,10 @@
         ngx_zlib=`echo \-DZLIB=\"$ZLIB\" | sed -e "s/\//$ngx_regex_dirsep/g"`
     ;;
 
+    *)
+        ngx_makefile=
+    ;;
+
 esac
 
 
@@ -33,13 +37,30 @@
 case "$NGX_PLATFORM" in
 
     win32)
-        cat << END                                            >> $NGX_MAKEFILE
+
+        if [ -n "$ngx_makefile" ]; then
+            cat << END                                        >> $NGX_MAKEFILE
 
 `echo "$ZLIB/zlib.lib:	$NGX_MAKEFILE" | sed -e "s/\//$ngx_regex_dirsep/g"`
 	\$(MAKE) -f auto/lib/zlib/$ngx_makefile $ngx_opt $ngx_zlib
 
 END
 
+        else
+
+            cat << END                                        >> $NGX_MAKEFILE
+
+$ZLIB/libz.a:	$NGX_MAKEFILE
+	cd $ZLIB \\
+	&& \$(MAKE) distclean \\
+	&& \$(MAKE) -f win32/Makefile.gcc \\
+		CFLAGS="$ZLIB_OPT" CC="\$(CC)" \\
+		libz.a
+
+END
+
+        fi
+
         done=YES
     ;;
 
diff --git a/auto/os/win32 b/auto/os/win32
index 21a54ba..0b9b461 100644
--- a/auto/os/win32
+++ b/auto/os/win32
@@ -9,10 +9,21 @@
 CORE_DEPS="$WIN32_DEPS"
 CORE_SRCS="$WIN32_SRCS $IOCP_SRCS"
 OS_CONFIG="$WIN32_CONFIG"
-CORE_LIBS="$CORE_LIBS advapi32.lib ws2_32.lib"
 NGX_ICONS="$NGX_WIN32_ICONS"
 SELECT_SRCS=$WIN32_SELECT_SRCS
 
+case "$NGX_CC_NAME" in
+
+    gcc)
+        CORE_LIBS="$CORE_LIBS -ladvapi32 -lws2_32"
+    ;;
+
+    *)
+        CORE_LIBS="$CORE_LIBS advapi32.lib ws2_32.lib"
+    ;;
+
+esac
+
 EVENT_MODULES="$EVENT_MODULES $IOCP_MODULE"
 EVENT_FOUND=YES