Bug 134113: make NSPR build on Win32 using MinGW gcc. The patch is
authorwtc%netscape.com
Mon, 20 Jan 2003 16:26:24 +0000
changeset 2662 1951408071bb16171d4c2653aee8522ca58082e1
parent 2659 4d13cef91f320914411ae2550082d0f0233aa184
child 2663 54ee56fb0fb0f626a4454a8d3a95f60021f1c18e
push idunknown
push userunknown
push dateunknown
bugs134113
Bug 134113: make NSPR build on Win32 using MinGW gcc. The patch is contributed by Chris Seawood <seawood@cls.org> and Dan Mosedale <dmose@mozilla.org>. r=wtc. Modified files: configure configure.in config/Makefile.in autoconf.mk.in now.c rules.mk lib/ds/Makefile.in lib/libc/src/Makefile.in lib/msgc/src/Makefile.in prtypes.h _winnt.h pr/src/Makefile.in prmapopt.c pr/src/md/windows/Makefile.in ntio.c ntmisc.c pr/tests/Makefile.in runtests.ksh pr/tests/dll/Makefile.in
config/Makefile.in
config/autoconf.mk.in
config/now.c
config/rules.mk
configure
configure.in
lib/ds/Makefile.in
lib/libc/src/Makefile.in
lib/msgc/src/Makefile.in
pr/include/md/_winnt.h
pr/include/prtypes.h
pr/src/Makefile.in
pr/src/io/prmapopt.c
pr/src/md/windows/Makefile.in
pr/src/md/windows/ntio.c
pr/src/md/windows/ntmisc.c
pr/tests/Makefile.in
pr/tests/dll/Makefile.in
pr/tests/runtests.ksh
--- a/config/Makefile.in
+++ b/config/Makefile.in
@@ -114,18 +114,20 @@ ifeq (,$(filter-out OS2 WINNT,$(OS_ARCH)
 TARGETS = $(PROGS)
 else
 PROGS	+= $(OBJDIR)/nsinstall$(PROG_SUFFIX)
 TARGETS = $(PROGS) $(PLSRCS:.pl=)
 endif
 
 OUTOPTION = -o # end of the line
 ifeq (,$(filter-out WINNT WIN95,$(OS_TARGET)))
+ifndef NS_USE_GCC
 OUTOPTION = /Fe
 endif
+endif
 
 # Redefine MAKE_OBJDIR for just this directory
 define MAKE_OBJDIR
 if test ! -d $(@D); then rm -rf $(@D); mkdir $(@D); else true; fi
 endef
 
 export:: $(TARGETS)
 	rm -f $(dist_bindir)/nspr-config
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -55,19 +55,18 @@ ASFLAGS		= @ASFLAGS@
 CC		= @CC@
 CCC		= @CXX@
 NS_USE_GCC	= @GNU_CC@
 AR		= @AR@
 AR_FLAGS	= @AR_FLAGS@
 LD		= @LD@
 RANLIB		= @RANLIB@
 PERL		= @PERL@
-DLLTOOL		= @DLLTOOL@
-WINDRES		= @WINDRES@
 RC		= @RC@
+RCFLAGS		= @RCFLAGS@
 STRIP		= @STRIP@
 NSINSTALL	= @NSINSTALL@
 FILTER		= @FILTER@
 IMPLIB		= @IMPLIB@
 CYGWIN_WRAPPER	= @CYGWIN_WRAPPER@
 
 OS_CPPFLAGS	= @CPPFLAGS@
 OS_CFLAGS	= $(OS_CPPFLAGS) @CFLAGS@ $(DSO_CFLAGS)
--- a/config/now.c
+++ b/config/now.c
@@ -90,18 +90,23 @@ int main(int argc, char **argv)
     __int64 now;
     FILETIME ft;
     GetSystemTimeAsFileTime(&ft);
     CopyMemory(&now, &ft, sizeof(now));
     /*
      * 116444736000000000 is the number of 100-nanosecond intervals
      * between Jan. 1, 1601 and Jan. 1, 1970.
      */
+#ifdef __GNUC__
+    now = (now - 116444736000000000LL) / 10LL;
+    fprintf(stdout, "%lld", now);
+#else
     now = (now - 116444736000000000i64) / 10i64;
     fprintf(stdout, "%I64d", now);
+#endif
 
 #elif defined(XP_OS2_VACPP)
 /* no long long or i64 so we use a string */
 #include <string.h>
   char buf[24];
   char tbuf[7];
   time_t now;
   long mtime;
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -282,17 +282,17 @@ alltags:
 	find . -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' \) -print | xargs etags -a
 	find . -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' \) -print | xargs ctags -a
 
 $(NFSPWD):
 	cd $(@D); $(MAKE) $(@F)
 
 $(PROGRAM): $(OBJS)
 	@$(MAKE_OBJDIR)
-ifeq ($(OS_ARCH),WINNT)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
 	$(CC) $(OBJS) -Fe$@ -link $(LDFLAGS) $(OS_LIBS) $(EXTRA_LIBS)
 else
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
 	$(CC) $(OBJS) -Fe$@ $(LDFLAGS) $(OS_LIBS) $(EXTRA_LIBS)
 else
 	$(CC) -o $@ $(CFLAGS) $(OBJS) $(LDFLAGS)
 endif
 endif
@@ -309,30 +309,30 @@ else
 	$(AR) $(AR_FLAGS) $(OBJS) $(AR_EXTRA_ARGS)
 endif
 	$(RANLIB) $@
 
 ifeq ($(OS_TARGET), OS2)
 $(IMPORT_LIBRARY): $(SHARED_LIBRARY)
 	$(IMPLIB) $@ $(SHARED_LIBRARY).def
 endif
-    
+
 $(SHARED_LIBRARY): $(OBJS) $(MAPFILE)
 	@$(MAKE_OBJDIR)
 	rm -f $@
 ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
 	echo "#!" > $(OBJDIR)/lib$(LIBRARY_NAME)_syms
 	nm -B -C -g $(OBJS) \
 		| awk '/ [T,D] / {print $$3}' \
 		| sed -e 's/^\.//' \
 		| sort -u >> $(OBJDIR)/lib$(LIBRARY_NAME)_syms
 	$(LD) $(XCFLAGS) -o $@ $(OBJS) -bE:$(OBJDIR)/lib$(LIBRARY_NAME)_syms \
 		-bM:SRE -bnoentry $(OS_LIBS) $(EXTRA_LIBS)
 else	# AIX 4.1
-ifeq ($(OS_ARCH), WINNT)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
 	$(LINK_DLL) -MAP $(DLLBASE) $(DLL_LIBS) $(EXTRA_LIBS) $(OBJS)
 else
 ifeq ($(OS_ARCH),OS2)
 # append ( >> ) doesn't seem to be working under OS/2 gmake. Run through OS/2 shell instead.	
 	@cmd /C "echo LIBRARY $(notdir $(basename $(SHARED_LIBRARY))) INITINSTANCE TERMINSTANCE >$@.def"
 	@cmd /C "echo PROTMODE >>$@.def"
 	@cmd /C "echo CODE    LOADONCALL MOVEABLE DISCARDABLE >>$@.def"
 	@cmd /C "echo DATA    PRELOAD MOVEABLE MULTIPLE NONSHARED >>$@.def"	
@@ -358,46 +358,50 @@ endif
 
 ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
 $(RES): $(RESNAME)
 	@$(MAKE_OBJDIR)
 ifeq ($(OS_TARGET),OS2)
 	$(RC) -DOS2 -r $< $@
 else
 # The resource compiler does not understand the -U option.
-	$(RC) $(filter-out -U%,$(DEFINES)) $(INCLUDES) -Fo$@ $<
+ifdef NS_USE_GCC
+	$(RC) $(RCFLAGS) $(filter-out -U%,$(DEFINES)) $(INCLUDES:-I%=--include-dir %) -o $@ $<
+else
+	$(RC) $(RCFLAGS) $(filter-out -U%,$(DEFINES)) $(INCLUDES) -Fo$@ $<
+endif # GCC
 endif
 	@echo $(RES) finished
 endif
 
 $(MAPFILE): $(LIBRARY_NAME).def
 	@$(MAKE_OBJDIR)
 ifeq ($(OS_ARCH),SunOS)
 	grep -v ';-' $< | \
 	sed -e 's,;+,,' -e 's; DATA ;;' -e 's,;;,,' -e 's,;.*,;,' > $@
 endif
 
 $(OBJDIR)/%.$(OBJ_SUFFIX): %.cpp
 	@$(MAKE_OBJDIR)
-ifeq ($(OS_ARCH), WINNT)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
 	$(CCC) -Fo$@ -c $(CCCFLAGS) $<
 else
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
 	$(CCC) -Fo$@ -c $(CCCFLAGS) $<
 else
 	$(CCC) -o $@ -c $(CCCFLAGS) $<
 endif
 endif
 
 WCCFLAGS1 = $(subst /,\\,$(CFLAGS))
 WCCFLAGS2 = $(subst -I,-i=,$(WCCFLAGS1))
 WCCFLAGS3 = $(subst -D,-d,$(WCCFLAGS2))
 $(OBJDIR)/%.$(OBJ_SUFFIX): %.c
 	@$(MAKE_OBJDIR)
-ifeq ($(OS_ARCH), WINNT)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
 	$(CC) -Fo$@ -c $(CFLAGS) $<
 else
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
 	$(CC) -Fo$@ -c $(CFLAGS) $<
 else
 	$(CC) -o $@ -c $(CFLAGS) $<
 endif
 endif
--- a/configure
+++ b/configure
@@ -1787,60 +1787,23 @@ else
   echo "$ac_t""no" 1>&6
 fi
 
 test -n "$STRIP" && break
 done
 test -n "$STRIP" || STRIP="echo"
 
     fi
-    if test -z "$DLLTOOL"; then
-	    for ac_prog in "${target_alias}-dlltool" "${target}-dlltool"
-do
-# Extract the first word of "$ac_prog", so it can be a program name with args.
-set dummy $ac_prog; ac_word=$2
-echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1802: checking for $ac_word" >&5
-if eval "test \"`echo '$''{'ac_cv_prog_DLLTOOL'+set}'`\" = set"; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  if test -n "$DLLTOOL"; then
-  ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test.
-else
-  IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
-  ac_dummy="$PATH"
-  for ac_dir in $ac_dummy; do
-    test -z "$ac_dir" && ac_dir=.
-    if test -f $ac_dir/$ac_word; then
-      ac_cv_prog_DLLTOOL="$ac_prog"
-      break
-    fi
-  done
-  IFS="$ac_save_ifs"
-fi
-fi
-DLLTOOL="$ac_cv_prog_DLLTOOL"
-if test -n "$DLLTOOL"; then
-  echo "$ac_t""$DLLTOOL" 1>&6
-else
-  echo "$ac_t""no" 1>&6
-fi
-
-test -n "$DLLTOOL" && break
-done
-test -n "$DLLTOOL" || DLLTOOL="echo"
-
-    fi
     if test -z "$WINDRES"; then
 	    for ac_prog in "${target_alias}-windres" "${target}-windres"
 do
 # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1839: checking for $ac_word" >&5
+echo "configure:1802: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_WINDRES'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$WINDRES"; then
   ac_cv_prog_WINDRES="$WINDRES" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1868,17 +1831,17 @@ test -n "$WINDRES" || WINDRES="echo"
     fi
 
 else
     for ac_prog in $CCC c++ g++ gcc CC cxx cc++ cl
 do
 # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1877: checking for $ac_word" >&5
+echo "configure:1840: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CXX'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CXX"; then
   ac_cv_prog_CXX="$CXX" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1900,33 +1863,33 @@ else
 fi
 
 test -n "$CXX" && break
 done
 test -n "$CXX" || CXX="gcc"
 
 
 echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:1909: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works" >&5
+echo "configure:1872: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works" >&5
 
 ac_ext=C
 # CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
 ac_cpp='$CXXCPP $CPPFLAGS'
 ac_compile='${CXX-g++} -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
 ac_link='${CXX-g++} -o conftest${ac_exeext} $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cxx_cross
 
 cat > conftest.$ac_ext << EOF
 
-#line 1920 "configure"
+#line 1883 "configure"
 #include "confdefs.h"
 
 int main(){return(0);}
 EOF
-if { (eval echo configure:1925: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1888: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   ac_cv_prog_cxx_works=yes
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
     ac_cv_prog_cxx_cross=no
   else
     ac_cv_prog_cxx_cross=yes
   fi
 else
@@ -1942,31 +1905,31 @@ ac_compile='${CC-cc} -c $CFLAGS $CPPFLAG
 ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo "$ac_t""$ac_cv_prog_cxx_works" 1>&6
 if test $ac_cv_prog_cxx_works = no; then
   { echo "configure: error: installation or configuration problem: C++ compiler cannot create executables." 1>&2; exit 1; }
 fi
 echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:1951: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:1914: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler" >&5
 echo "$ac_t""$ac_cv_prog_cxx_cross" 1>&6
 cross_compiling=$ac_cv_prog_cxx_cross
 
 echo $ac_n "checking whether we are using GNU C++""... $ac_c" 1>&6
-echo "configure:1956: checking whether we are using GNU C++" >&5
+echo "configure:1919: checking whether we are using GNU C++" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gxx'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.C <<EOF
 #ifdef __GNUC__
   yes;
 #endif
 EOF
-if { ac_try='${CXX-g++} -E conftest.C'; { (eval echo configure:1965: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CXX-g++} -E conftest.C'; { (eval echo configure:1928: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gxx=yes
 else
   ac_cv_prog_gxx=no
 fi
 fi
 
 echo "$ac_t""$ac_cv_prog_gxx" 1>&6
 
@@ -1975,17 +1938,17 @@ if test $ac_cv_prog_gxx = yes; then
 else
   GXX=
 fi
 
 ac_test_CXXFLAGS="${CXXFLAGS+set}"
 ac_save_CXXFLAGS="$CXXFLAGS"
 CXXFLAGS=
 echo $ac_n "checking whether ${CXX-g++} accepts -g""... $ac_c" 1>&6
-echo "configure:1984: checking whether ${CXX-g++} accepts -g" >&5
+echo "configure:1947: checking whether ${CXX-g++} accepts -g" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_cxx_g'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   echo 'void f(){}' > conftest.cc
 if test -z "`${CXX-g++} -g -c conftest.cc 2>&1`"; then
   ac_cv_prog_cxx_g=yes
 else
   ac_cv_prog_cxx_g=no
@@ -2012,17 +1975,17 @@ else
 fi
 
     if test "$CXX" = "cl" -a -z "$CC"; then
         CC=$CXX
     else        
         # Extract the first word of "gcc", so it can be a program name with args.
 set dummy gcc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2021: checking for $ac_word" >&5
+echo "configure:1984: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CC"; then
   ac_cv_prog_CC="$CC" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -2042,17 +2005,17 @@ if test -n "$CC"; then
 else
   echo "$ac_t""no" 1>&6
 fi
 
 if test -z "$CC"; then
   # Extract the first word of "cc", so it can be a program name with args.
 set dummy cc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2051: checking for $ac_word" >&5
+echo "configure:2014: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CC"; then
   ac_cv_prog_CC="$CC" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_prog_rejected=no
@@ -2093,17 +2056,17 @@ else
 fi
 
   if test -z "$CC"; then
     case "`uname -s`" in
     *win32* | *WIN32*)
       # Extract the first word of "cl", so it can be a program name with args.
 set dummy cl; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2102: checking for $ac_word" >&5
+echo "configure:2065: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CC"; then
   ac_cv_prog_CC="$CC" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -2125,33 +2088,33 @@ else
 fi
  ;;
     esac
   fi
   test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; }
 fi
 
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:2134: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+echo "configure:2097: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
 
 ac_ext=c
 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
 ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cc_cross
 
 cat > conftest.$ac_ext << EOF
 
-#line 2145 "configure"
+#line 2108 "configure"
 #include "confdefs.h"
 
 main(){return(0);}
 EOF
-if { (eval echo configure:2150: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2113: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   ac_cv_prog_cc_works=yes
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
     ac_cv_prog_cc_cross=no
   else
     ac_cv_prog_cc_cross=yes
   fi
 else
@@ -2167,31 +2130,31 @@ ac_compile='${CC-cc} -c $CFLAGS $CPPFLAG
 ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo "$ac_t""$ac_cv_prog_cc_works" 1>&6
 if test $ac_cv_prog_cc_works = no; then
   { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
 fi
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:2176: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:2139: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
-echo "configure:2181: checking whether we are using GNU C" >&5
+echo "configure:2144: checking whether we are using GNU C" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.c <<EOF
 #ifdef __GNUC__
   yes;
 #endif
 EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:2190: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:2153: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gcc=yes
 else
   ac_cv_prog_gcc=no
 fi
 fi
 
 echo "$ac_t""$ac_cv_prog_gcc" 1>&6
 
@@ -2200,17 +2163,17 @@ if test $ac_cv_prog_gcc = yes; then
 else
   GCC=
 fi
 
 ac_test_CFLAGS="${CFLAGS+set}"
 ac_save_CFLAGS="$CFLAGS"
 CFLAGS=
 echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
-echo "configure:2209: checking whether ${CC-cc} accepts -g" >&5
+echo "configure:2172: checking whether ${CC-cc} accepts -g" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   echo 'void f(){}' > conftest.c
 if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then
   ac_cv_prog_cc_g=yes
 else
   ac_cv_prog_cc_g=no
@@ -2233,72 +2196,72 @@ else
     CFLAGS="-O2"
   else
     CFLAGS=
   fi
 fi
 
     fi
     echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
-echo "configure:2242: checking how to run the C preprocessor" >&5
+echo "configure:2205: checking how to run the C preprocessor" >&5
 # On Suns, sometimes $CPP names a directory.
 if test -n "$CPP" && test -d "$CPP"; then
   CPP=
 fi
 if test -z "$CPP"; then
 if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
     # This must be in double quotes, not single quotes, because CPP may get
   # substituted into the Makefile and "${CC-cc}" will confuse make.
   CPP="${CC-cc} -E"
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp.
   cat > conftest.$ac_ext <<EOF
-#line 2257 "configure"
+#line 2220 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2263: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2226: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   CPP="${CC-cc} -E -traditional-cpp"
   cat > conftest.$ac_ext <<EOF
-#line 2274 "configure"
+#line 2237 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2280: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2243: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   CPP="${CC-cc} -nologo -E"
   cat > conftest.$ac_ext <<EOF
-#line 2291 "configure"
+#line 2254 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2297: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2260: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
@@ -2315,17 +2278,17 @@ fi
 else
   ac_cv_prog_CPP="$CPP"
 fi
 echo "$ac_t""$CPP" 1>&6
 
     # Extract the first word of "ranlib", so it can be a program name with args.
 set dummy ranlib; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2324: checking for $ac_word" >&5
+echo "configure:2287: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$RANLIB"; then
   ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -2347,17 +2310,17 @@ else
   echo "$ac_t""no" 1>&6
 fi
 
     for ac_prog in as
 do
 # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2356: checking for $ac_word" >&5
+echo "configure:2319: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_AS'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   case "$AS" in
   /*)
   ac_cv_path_AS="$AS" # Let the user override the test with a path.
   ;;
   ?:/*)			 
@@ -2388,17 +2351,17 @@ test -n "$AS" && break
 done
 test -n "$AS" || AS="$CC"
 
     for ac_prog in ar
 do
 # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2397: checking for $ac_word" >&5
+echo "configure:2360: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_AR'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   case "$AR" in
   /*)
   ac_cv_path_AR="$AR" # Let the user override the test with a path.
   ;;
   ?:/*)			 
@@ -2429,17 +2392,17 @@ test -n "$AR" && break
 done
 test -n "$AR" || AR="echo not_ar"
 
     for ac_prog in ld link
 do
 # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2438: checking for $ac_word" >&5
+echo "configure:2401: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_LD'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   case "$LD" in
   /*)
   ac_cv_path_LD="$LD" # Let the user override the test with a path.
   ;;
   ?:/*)			 
@@ -2470,17 +2433,17 @@ test -n "$LD" && break
 done
 test -n "$LD" || LD="echo not_ld"
 
     for ac_prog in strip
 do
 # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2479: checking for $ac_word" >&5
+echo "configure:2442: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_STRIP'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   case "$STRIP" in
   /*)
   ac_cv_path_STRIP="$STRIP" # Let the user override the test with a path.
   ;;
   ?:/*)			 
@@ -2506,63 +2469,22 @@ if test -n "$STRIP"; then
 else
   echo "$ac_t""no" 1>&6
 fi
 
 test -n "$STRIP" && break
 done
 test -n "$STRIP" || STRIP="echo not_strip"
 
-    for ac_prog in dlltool
-do
-# Extract the first word of "$ac_prog", so it can be a program name with args.
-set dummy $ac_prog; ac_word=$2
-echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2520: checking for $ac_word" >&5
-if eval "test \"`echo '$''{'ac_cv_path_DLLTOOL'+set}'`\" = set"; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  case "$DLLTOOL" in
-  /*)
-  ac_cv_path_DLLTOOL="$DLLTOOL" # Let the user override the test with a path.
-  ;;
-  ?:/*)			 
-  ac_cv_path_DLLTOOL="$DLLTOOL" # Let the user override the test with a dos path.
-  ;;
-  *)
-  IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
-  ac_dummy="$PATH"
-  for ac_dir in $ac_dummy; do 
-    test -z "$ac_dir" && ac_dir=.
-    if test -f $ac_dir/$ac_word; then
-      ac_cv_path_DLLTOOL="$ac_dir/$ac_word"
-      break
-    fi
-  done
-  IFS="$ac_save_ifs"
-  ;;
-esac
-fi
-DLLTOOL="$ac_cv_path_DLLTOOL"
-if test -n "$DLLTOOL"; then
-  echo "$ac_t""$DLLTOOL" 1>&6
-else
-  echo "$ac_t""no" 1>&6
-fi
-
-test -n "$DLLTOOL" && break
-done
-test -n "$DLLTOOL" || DLLTOOL="echo not_dlltool"
-
     for ac_prog in windres
 do
 # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2561: checking for $ac_word" >&5
+echo "configure:2483: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_WINDRES'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   case "$WINDRES" in
   /*)
   ac_cv_path_WINDRES="$WINDRES" # Let the user override the test with a path.
   ;;
   ?:/*)			 
@@ -2614,39 +2536,39 @@ rm -f a.out
 
 if test "$cross_compiling"  = "yes"; then
     CROSS_COMPILE=1
 else
     CROSS_COMPILE=
 fi
 
 echo $ac_n "checking for gcc -pipe support""... $ac_c" 1>&6
-echo "configure:2623: checking for gcc -pipe support" >&5
+echo "configure:2545: checking for gcc -pipe support" >&5
 if test -n "$GNU_CC" && test -n "$GNU_CXX" && test -n "$GNU_AS"; then
     echo '#include <stdio.h>' > dummy-hello.c
     echo 'int main() { printf("Hello World\n"); return 0; }' >> dummy-hello.c
     ${CC} -S dummy-hello.c -o dummy-hello.s 2>&5
     cat dummy-hello.s | ${AS} -o dummy-hello.S - 2>&5
     if test $? = 0; then
         _res_as_stdin="yes"
     else
         _res_as_stdin="no"
     fi
     if test "$_res_as_stdin" = "yes"; then
         _SAVE_CFLAGS=$CFLAGS
         CFLAGS="$CFLAGS -pipe"
         cat > conftest.$ac_ext <<EOF
-#line 2638 "configure"
+#line 2560 "configure"
 #include "confdefs.h"
  #include <stdio.h> 
 int main() {
 printf("Hello World\n");
 ; return 0; }
 EOF
-if { (eval echo configure:2645: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:2567: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   _res_gcc_pipe="yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   _res_gcc_pipe="no" 
 fi
@@ -2669,17 +2591,17 @@ fi
 fi # SKIP_COMPILER_CHECKS
 
 if test -z "$SKIP_PATH_CHECKS"; then
     for ac_prog in perl5 perl
 do
 # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2678: checking for $ac_word" >&5
+echo "configure:2600: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_PERL'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   case "$PERL" in
   /*)
   ac_cv_path_PERL="$PERL" # Let the user override the test with a path.
   ;;
   ?:/*)			 
@@ -2899,27 +2821,27 @@ EOF
 
     cat >> confdefs.h <<\EOF
 #define SYSV 1
 EOF
 
     DSO_LDOPTS='-brtl -bM:SRE -bnoentry -bexpall'
     ac_safe=`echo "sys/atomic_op.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for sys/atomic_op.h""... $ac_c" 1>&6
-echo "configure:2908: checking for sys/atomic_op.h" >&5
+echo "configure:2830: checking for sys/atomic_op.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2913 "configure"
+#line 2835 "configure"
 #include "confdefs.h"
 #include <sys/atomic_op.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2918: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2840: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -3069,36 +2991,36 @@ EOF
     PR_MD_ARCH_DIR=beos
     RESOLVE_LINK_SYMBOLS=1
     case "${target_cpu}" in
     i?86)
         _OPTIMIZE_FLAGS=-O2
         _DEBUG_FLAGS='-gdwarf-2 -O0'
         MKSHLIB='$(CCC) $(DSO_LDOPTS) -o $@'
         echo $ac_n "checking for gethostbyaddr in -lbind""... $ac_c" 1>&6
-echo "configure:3078: checking for gethostbyaddr in -lbind" >&5
+echo "configure:3000: checking for gethostbyaddr in -lbind" >&5
 ac_lib_var=`echo bind'_'gethostbyaddr | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
 LIBS="-lbind  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 3086 "configure"
+#line 3008 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char gethostbyaddr();
 
 int main() {
 gethostbyaddr()
 ; return 0; }
 EOF
-if { (eval echo configure:3097: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3019: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=no"
 fi
@@ -3797,41 +3719,38 @@ EOF
 
     cat >> confdefs.h <<\EOF
 #define WIN32 1
 EOF
 
     PR_MD_ARCH_DIR=windows
     RESOLVE_LINK_SYMBOLS=1
     NSINSTALL='$(CYGWIN_WRAPPER) nsinstall'
+    CYGWIN_WRAPPER='sh $(topsrcdir)/build/cygwin-wrapper'
 
     if test -n "$GNU_CC"; then
-        cat >> confdefs.h <<\EOF
-#define NONAMELESSUNION 1
-EOF
-
-        MKSHLIB='$(DLLTOOL) --as=$(AS) -k --dllname $*.dll --output-lib $@'
+        CC="$CC -mno-cygwin"
+        CXX="$CXX -mno-cygwin"
+        DLL_SUFFIX=dll
+        MKSHLIB='$(CC) -shared -Wl,--export-all-symbols -Wl,--out-implib -Wl,$(IMPORT_LIBRARY) $(DLLBASE) -o $(subst $(OBJDIR)/,,$(SHARED_LIBRARY))'
+        RC=$WINDRES
+        RCFLAGS='-O coff'
     else
-        case "$target" in
-        *-mingw*|*-cygwin*)
-            CYGWIN_WRAPPER='sh $(topsrcdir)/build/cygwin-wrapper'
-            ;;
-        esac
-        CC='$(CYGWIN_WRAPPER) cl'
-        CXX='$(CYGWIN_WRAPPER) cl'
+        CC=cl
+        CXX=cl
         LD=link
         AR='lib -NOLOGO -OUT:"$@"'
         AR_FLAGS=
         RANLIB='echo not_ranlib'
         STRIP='echo not_strip'
-        RC='$(CYGWIN_WRAPPER) rc.exe'
+        RC=rc.exe
         GARBAGE='$(OBJDIR)/vc20.pdb $(OBJDIR)/vc40.pdb'
-	    OBJ_SUFFIX=obj
-	    LIB_SUFFIX=lib
-	    DLL_SUFFIX=dll
+        OBJ_SUFFIX=obj
+        LIB_SUFFIX=lib
+        DLL_SUFFIX=dll
         
         CFLAGS="$CFLAGS -W3 -nologo -GF -Gy"
 
         if test -n "$MOZ_DEBUG"; then
             cat >> confdefs.h <<\EOF
 #define _DEBUG 1
 EOF
 
@@ -3893,16 +3812,18 @@ EOF
 #define WINNT 1
 EOF
 
     else
         cat >> confdefs.h <<\EOF
 #define WIN95 1
 EOF
 
+        # undefine WINNT as some versions of mingw gcc define it by default
+        DEFINES="$DEFINES -UWINNT"
         cat >> confdefs.h <<\EOF
 #define _PR_GLOBAL_THREADS_ONLY 1
 EOF
 
     fi
 
     if test "$CPU_ARCH" = "x86"; then
         CPU_ARCH_TAG=
@@ -4234,27 +4155,27 @@ EOF
     if test -z "$GNU_CC"; then
         CC="$CC -std1 -ieee_with_inexact"
         if test "$OS_RELEASE" != "V2.0"; then
             CC="$CC -readonly_strings"
         fi
         _OPTIMIZE_FLAGS="$_OPTIMIZE_FLAGS -Olimit 4000"
         ac_safe=`echo "machine/builtins.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for machine/builtins.h""... $ac_c" 1>&6
-echo "configure:4243: checking for machine/builtins.h" >&5
+echo "configure:4164: checking for machine/builtins.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4248 "configure"
+#line 4169 "configure"
 #include "confdefs.h"
 #include <machine/builtins.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:4253: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:4174: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -4648,17 +4569,16 @@ EOF
     cat >> confdefs.h <<\EOF
 #define _PR_GLOBAL_THREADS_ONLY 1
 EOF
 
     OBJ_SUFFIX=obj
     LIB_SUFFIX=lib
     DLL_SUFFIX=dll
     ASM_SUFFIX=asm
-    DLLTOOL=''
     RC=rc.exe
     PR_MD_ARCH_DIR=os2
     PROG_SUFFIX=.exe
     NSINSTALL=nsinstall
     MDCPUCFG_H=_os2.cfg
     RESOLVE_LINK_SYMBOLS=1
 
     # EMX/GCC build
@@ -4753,22 +4673,22 @@ EOF
 
     ;;
    
 esac
 
 if test -z "$SKIP_LIBRARY_CHECKS"; then
 
 echo $ac_n "checking for dlopen""... $ac_c" 1>&6
-echo "configure:4762: checking for dlopen" >&5
+echo "configure:4682: checking for dlopen" >&5
 if eval "test \"`echo '$''{'ac_cv_func_dlopen'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4767 "configure"
+#line 4687 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char dlopen(); below.  */
 #include <assert.h>
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char dlopen();
@@ -4781,17 +4701,17 @@ int main() {
 #if defined (__stub_dlopen) || defined (__stub___dlopen)
 choke me
 #else
 dlopen();
 #endif
 
 ; return 0; }
 EOF
-if { (eval echo configure:4790: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4710: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_dlopen=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_func_dlopen=no"
 fi
@@ -4800,36 +4720,36 @@ fi
 
 if eval "test \"`echo '$ac_cv_func_'dlopen`\" = yes"; then
   echo "$ac_t""yes" 1>&6
   :
 else
   echo "$ac_t""no" 1>&6
 
     echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "configure:4809: checking for dlopen in -ldl" >&5
+echo "configure:4729: checking for dlopen in -ldl" >&5
 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
 LIBS="-ldl  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 4817 "configure"
+#line 4737 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char dlopen();
 
 int main() {
 dlopen()
 ; return 0; }
 EOF
-if { (eval echo configure:4828: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4748: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=no"
 fi
@@ -4847,23 +4767,23 @@ fi
 
 fi
 
 
 
 
 if test $ac_cv_prog_gcc = yes; then
     echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6
-echo "configure:4856: checking whether ${CC-cc} needs -traditional" >&5
+echo "configure:4776: checking whether ${CC-cc} needs -traditional" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
     ac_pattern="Autoconf.*'x'"
   cat > conftest.$ac_ext <<EOF
-#line 4862 "configure"
+#line 4782 "configure"
 #include "confdefs.h"
 #include <sgtty.h>
 Autoconf TIOCGETP
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -4871,17 +4791,17 @@ else
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=no
 fi
 rm -f conftest*
 
 
   if test $ac_cv_prog_gcc_traditional = no; then
     cat > conftest.$ac_ext <<EOF
-#line 4880 "configure"
+#line 4800 "configure"
 #include "confdefs.h"
 #include <termio.h>
 Autoconf TCGETA
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -4895,22 +4815,22 @@ echo "$ac_t""$ac_cv_prog_gcc_traditional
   if test $ac_cv_prog_gcc_traditional = yes; then
     CC="$CC -traditional"
   fi
 fi
 
 for ac_func in lchown strerror
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4904: checking for $ac_func" >&5
+echo "configure:4824: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4909 "configure"
+#line 4829 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
 #include <assert.h>
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char $ac_func();
@@ -4923,17 +4843,17 @@ int main() {
 #if defined (__stub_$ac_func) || defined (__stub___$ac_func)
 choke me
 #else
 $ac_func();
 #endif
 
 ; return 0; }
 EOF
-if { (eval echo configure:4932: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4852: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=no"
 fi
@@ -4962,17 +4882,17 @@ if test "${enable_strip+set}" = set; the
 fi
 
 
 case "${target_os}" in
 hpux*)
 if test -z "$GNU_CC"; then
 
     echo $ac_n "checking for +Olit support""... $ac_c" 1>&6
-echo "configure:4971: checking for +Olit support" >&5
+echo "configure:4891: checking for +Olit support" >&5
 if eval "test \"`echo '$''{'ac_cv_hpux_usable_olit_option'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
                   ac_cv_hpux_usable_olit_option=no
         rm -f conftest*
         echo 'int main() { return 0; }' | cat > conftest.c
         ${CC-cc} ${CFLAGS} +Olit=all -o conftest conftest.c > conftest.out 2>&1
         if test $? -eq 0; then
@@ -4996,17 +4916,17 @@ echo "$ac_t""$ac_cv_hpux_usable_olit_opt
 fi
 ;;
 esac
 
 
 
 
 echo $ac_n "checking for pthread_create in -lpthreads""... $ac_c" 1>&6
-echo "configure:5005: checking for pthread_create in -lpthreads" >&5
+echo "configure:4925: checking for pthread_create in -lpthreads" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5018,17 +4938,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lpthread""... $ac_c" 1>&6
-echo "configure:5027: checking for pthread_create in -lpthread" >&5
+echo "configure:4947: checking for pthread_create in -lpthread" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5040,17 +4960,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc_r""... $ac_c" 1>&6
-echo "configure:5049: checking for pthread_create in -lc_r" >&5
+echo "configure:4969: checking for pthread_create in -lc_r" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5062,17 +4982,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc""... $ac_c" 1>&6
-echo "configure:5071: checking for pthread_create in -lc" >&5
+echo "configure:4991: checking for pthread_create in -lc" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5214,17 +5134,17 @@ EOF
     fi
 fi
 
 
 if test -n "$USE_PTHREADS"; then
       rm -f conftest*
    ac_cv_have_dash_pthread=no
    echo $ac_n "checking whether ${CC-cc} accepts -pthread""... $ac_c" 1>&6
-echo "configure:5223: checking whether ${CC-cc} accepts -pthread" >&5
+echo "configure:5143: checking whether ${CC-cc} accepts -pthread" >&5
    echo 'int main() { return 0; }' | cat > conftest.c
    ${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1
    if test $? -eq 0; then
 	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthread`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 	    ac_cv_have_dash_pthread=yes
 		case "$target_os" in
 	    freebsd*)
 # Freebsd doesn't use -pthread for compiles, it uses them for linking
@@ -5237,17 +5157,17 @@ echo "configure:5223: checking whether $
 	fi
     fi
     rm -f conftest*
     echo "$ac_t""$ac_cv_have_dash_pthread" 1>&6
 
 			    ac_cv_have_dash_pthreads=no
     if test "$ac_cv_have_dash_pthread" = "no"; then
 	    echo $ac_n "checking whether ${CC-cc} accepts -pthreads""... $ac_c" 1>&6
-echo "configure:5246: checking whether ${CC-cc} accepts -pthreads" >&5
+echo "configure:5166: checking whether ${CC-cc} accepts -pthreads" >&5
     	echo 'int main() { return 0; }' | cat > conftest.c
 	    ${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1
     	if test $? -eq 0; then
 	    	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthreads`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 			    ac_cv_have_dash_pthreads=yes
 			    CFLAGS="$CFLAGS -pthreads"
 			    CXXFLAGS="$CXXFLAGS -pthreads"
 		    fi
@@ -5532,16 +5452,23 @@ else
 fi
 
 if test -n "$USE_64"; then
     COMPILER_TAG=_64
 fi
 
 RELEASE_OBJDIR_NAME="${OS_CONFIG}${CPU_ARCH_TAG}${COMPILER_TAG}${IMPL_STRATEGY}${OBJDIR_TAG}.${OBJDIR_SUFFIX}"
 
+case "$target_os" in
+mingw*|cygwin*|msvc*|mksnt*)
+    CC="\$(CYGWIN_WRAPPER) $CC"
+    CXX="\$(CYGWIN_WRAPPER) $CXX"
+    RC="\$(CYGWIN_WRAPPER) $RC"
+    ;;
+esac
 
 
 
 
 
 
 
 
@@ -5845,17 +5772,16 @@ s%@dist_libdir@%$dist_libdir%g
 s%@WHOAMI@%$WHOAMI%g
 s%@HOST_CC@%$HOST_CC%g
 s%@CXX@%$CXX%g
 s%@RANLIB@%$RANLIB%g
 s%@AR@%$AR%g
 s%@AS@%$AS%g
 s%@LD@%$LD%g
 s%@STRIP@%$STRIP%g
-s%@DLLTOOL@%$DLLTOOL%g
 s%@WINDRES@%$WINDRES%g
 s%@CPP@%$CPP%g
 s%@PERL@%$PERL%g
 s%@SHELL_OVERRIDE@%$SHELL_OVERRIDE%g
 s%@MOZILLA_CLIENT@%$MOZILLA_CLIENT%g
 s%@HOST_CFLAGS@%$HOST_CFLAGS%g
 s%@GNU_CC@%$GNU_CC%g
 s%@CROSS_COMPILE@%$CROSS_COMPILE%g
@@ -5907,16 +5833,17 @@ s%@NOSUCHFILE@%$NOSUCHFILE%g
 s%@MOZ_OBJFORMAT@%$MOZ_OBJFORMAT%g
 s%@ULTRASPARC_LIBRARY@%$ULTRASPARC_LIBRARY%g
 s%@OBJDIR@%$OBJDIR%g
 s%@OBJDIR_NAME@%$OBJDIR_NAME%g
 s%@RELEASE_OBJDIR_NAME@%$RELEASE_OBJDIR_NAME%g
 s%@NSINSTALL@%$NSINSTALL%g
 s%@OPTIMIZER@%$OPTIMIZER%g
 s%@RC@%$RC%g
+s%@RCFLAGS@%$RCFLAGS%g
 s%@DLLFLAGS@%$DLLFLAGS%g
 s%@EXEFLAGS@%$EXEFLAGS%g
 s%@OS_DLLFLAGS@%$OS_DLLFLAGS%g
 s%@CYGWIN_WRAPPER@%$CYGWIN_WRAPPER%g
 
 CEOF
 EOF
 
--- a/configure.in
+++ b/configure.in
@@ -414,19 +414,16 @@ if test "$target" != "$host"; then
 	    AC_CHECK_PROGS(AS, "${target_alias}-as" "${target}-as", echo)
     fi
     if test -z "$LD"; then
 	    AC_CHECK_PROGS(LD, "${target_alias}-ld" "${target}-ld", echo)
     fi
     if test -z "$STRIP"; then
 	    AC_CHECK_PROGS(STRIP, "${target_alias}-strip" "${target}-strip", echo)
     fi
-    if test -z "$DLLTOOL"; then
-	    AC_CHECK_PROGS(DLLTOOL, "${target_alias}-dlltool" "${target}-dlltool", echo)
-    fi
     if test -z "$WINDRES"; then
 	    AC_CHECK_PROGS(WINDRES, "${target_alias}-windres" "${target}-windres", echo)
     fi
 
 else
     AC_PROG_CXX
     if test "$CXX" = "cl" -a -z "$CC"; then
         CC=$CXX
@@ -434,17 +431,16 @@ else
         AC_PROG_CC
     fi
     AC_PROG_CPP
     AC_PROG_RANLIB
     AC_PATH_PROGS(AS, as, $CC)
     AC_PATH_PROGS(AR, ar, echo not_ar)
     AC_PATH_PROGS(LD, ld link, echo not_ld)
     AC_PATH_PROGS(STRIP, strip, echo not_strip)
-    AC_PATH_PROGS(DLLTOOL, dlltool, echo not_dlltool)
     AC_PATH_PROGS(WINDRES, windres, echo not_windres)
     if test -z "$HOST_CC"; then
 	    HOST_CC="$CC"
     fi
     if test -z "$HOST_CFLAGS"; then
 	    HOST_CFLAGS="$CFLAGS"
     fi
 fi
@@ -1212,38 +1208,38 @@ case "$target" in
     ;;
 
 *-mingw*|*-cygwin*|*-msvc*|*-mksnt*)
     AC_DEFINE(XP_PC)
     AC_DEFINE(WIN32)
     PR_MD_ARCH_DIR=windows
     RESOLVE_LINK_SYMBOLS=1
     NSINSTALL='$(CYGWIN_WRAPPER) nsinstall'
+    CYGWIN_WRAPPER='sh $(topsrcdir)/build/cygwin-wrapper'
 
     if test -n "$GNU_CC"; then
-        AC_DEFINE(NONAMELESSUNION)
-        MKSHLIB='$(DLLTOOL) --as=$(AS) -k --dllname $*.dll --output-lib $@'
+        CC="$CC -mno-cygwin"
+        CXX="$CXX -mno-cygwin"
+        DLL_SUFFIX=dll
+        MKSHLIB='$(CC) -shared -Wl,--export-all-symbols -Wl,--out-implib -Wl,$(IMPORT_LIBRARY) $(DLLBASE) -o $(subst $(OBJDIR)/,,$(SHARED_LIBRARY))'
+        RC=$WINDRES
+        RCFLAGS='-O coff'
     else
-        case "$target" in
-        *-mingw*|*-cygwin*)
-            CYGWIN_WRAPPER='sh $(topsrcdir)/build/cygwin-wrapper'
-            ;;
-        esac
-        CC='$(CYGWIN_WRAPPER) cl'
-        CXX='$(CYGWIN_WRAPPER) cl'
+        CC=cl
+        CXX=cl
         LD=link
         AR='lib -NOLOGO -OUT:"$@"'
         AR_FLAGS=
         RANLIB='echo not_ranlib'
         STRIP='echo not_strip'
-        RC='$(CYGWIN_WRAPPER) rc.exe'
+        RC=rc.exe
         GARBAGE='$(OBJDIR)/vc20.pdb $(OBJDIR)/vc40.pdb'
-	    OBJ_SUFFIX=obj
-	    LIB_SUFFIX=lib
-	    DLL_SUFFIX=dll
+        OBJ_SUFFIX=obj
+        LIB_SUFFIX=lib
+        DLL_SUFFIX=dll
         
         CFLAGS="$CFLAGS -W3 -nologo -GF -Gy"
 
         if test -n "$MOZ_DEBUG"; then
             AC_DEFINE(_DEBUG)
         else
             DEFINES="$DEFINES -U_DEBUG"
         fi
@@ -1293,16 +1289,18 @@ case "$target" in
     if test -n "$USE_STATIC_TLS"; then
         AC_DEFINE(_PR_USE_STATIC_TLS)
     fi
 
     if test "$OS_TARGET" = "WINNT"; then
         AC_DEFINE(WINNT)
     else
         AC_DEFINE(WIN95)
+        # undefine WINNT as some versions of mingw gcc define it by default
+        DEFINES="$DEFINES -UWINNT"
         AC_DEFINE(_PR_GLOBAL_THREADS_ONLY)
     fi
 
     if test "$CPU_ARCH" = "x86"; then
         CPU_ARCH_TAG=
     else
         CPU_ARCH_TAG=$CPU_ARCH
     fi
@@ -1743,17 +1741,16 @@ mips-sony-newsos*)
     AC_DEFINE(XP_OS2)
     AC_DEFINE(XP_PC)
     AC_DEFINE(BSD_SELECT)
     AC_DEFINE(_PR_GLOBAL_THREADS_ONLY)
     OBJ_SUFFIX=obj
     LIB_SUFFIX=lib
     DLL_SUFFIX=dll
     ASM_SUFFIX=asm
-    DLLTOOL=''
     RC=rc.exe
     PR_MD_ARCH_DIR=os2
     PROG_SUFFIX=.exe
     NSINSTALL=nsinstall
     MDCPUCFG_H=_os2.cfg
     RESOLVE_LINK_SYMBOLS=1
 
     # EMX/GCC build
@@ -2310,16 +2307,27 @@ fi
 
 if test -n "$USE_64"; then
     COMPILER_TAG=_64
 fi
 
 RELEASE_OBJDIR_NAME="${OS_CONFIG}${CPU_ARCH_TAG}${COMPILER_TAG}${IMPL_STRATEGY}${OBJDIR_TAG}.${OBJDIR_SUFFIX}"
 
 dnl ========================================================
+dnl Use cygwin wrapper for win32 builds
+dnl ========================================================
+case "$target_os" in
+mingw*|cygwin*|msvc*|mksnt*)
+    CC="\$(CYGWIN_WRAPPER) $CC"
+    CXX="\$(CYGWIN_WRAPPER) $CXX"
+    RC="\$(CYGWIN_WRAPPER) $RC"
+    ;;
+esac
+
+dnl ========================================================
 dnl Substitution of found variables.
 dnl ========================================================
 AC_SUBST(SHELL_OVERRIDE)
 
 AC_SUBST(MOZILLA_CLIENT)
 AC_SUBST(CC)
 AC_SUBST(CXX)
 AC_SUBST(CFLAGS)
@@ -2376,18 +2384,16 @@ AC_SUBST(MACOS_DEPLOYMENT_TARGET)
 
 AC_SUBST(DEFINES)
 AC_SUBST(DEFS)
 AC_SUBST(AR)
 AC_SUBST(AR_FLAGS)
 AC_SUBST(AS)
 AC_SUBST(ASFLAGS)
 AC_SUBST(LD)
-AC_SUBST(DLLTOOL)
-AC_SUBST(WINDRES)
 AC_SUBST(RANLIB)
 AC_SUBST(PERL)
 AC_SUBST(STRIP)
 AC_SUBST(FILTER)
 AC_SUBST(IMPLIB)
 
 AC_SUBST(OS_LIBS)
 AC_SUBST(RESOLVE_LINK_SYMBOLS)
@@ -2397,16 +2403,17 @@ AC_SUBST(MOZ_OBJFORMAT)
 AC_SUBST(ULTRASPARC_LIBRARY)
 
 AC_SUBST(OBJDIR)
 AC_SUBST(OBJDIR_NAME)
 AC_SUBST(RELEASE_OBJDIR_NAME)
 AC_SUBST(NSINSTALL)
 AC_SUBST(OPTIMIZER)
 AC_SUBST(RC)
+AC_SUBST(RCFLAGS)
 AC_SUBST(DLLFLAGS)
 AC_SUBST(EXEFLAGS)
 AC_SUBST(OS_DLLFLAGS)
 AC_SUBST(CYGWIN_WRAPPER)
 
 dnl ========================================================
 dnl Generate output files.
 dnl ========================================================
--- a/lib/ds/Makefile.in
+++ b/lib/ds/Makefile.in
@@ -54,20 +54,23 @@ HEADERS = \
 	plarenas.h \
 	plarena.h \
 	plhash.h \
 	$(NULL)
 
 HEADERS := $(addprefix $(srcdir)/, $(HEADERS))
 
 ifeq ($(OS_ARCH), WINNT)
+ifdef NS_USE_GCC
+DLLBASE=-Wl,--image-base -Wl,0x30000000
+else
 DLLBASE=/BASE:0x30000000
+endif # GCC
 RES=$(OBJDIR)/plds.res
 RESNAME=plds.rc
-OS_LIBS = user32.lib
 endif # WINNT
 
 ifeq ($(OS_ARCH), AIX)
 ifeq ($(CLASSIC_NSPR),1)
 OS_LIBS = -lc
 else
 OS_LIBS = -lc_r
 endif
@@ -119,17 +122,17 @@ include $(topsrcdir)/config/rules.mk
 #
 ECHO = echo
 TINC = $(OBJDIR)/_pl_bld.h
 PROD = $(notdir $(SHARED_LIBRARY))
 NOW = $(MOD_DEPTH)/config/$(OBJDIR)/now
 SH_DATE = $(shell date "+%Y-%m-%d %T")
 SH_NOW = $(shell $(NOW))
 
-ifeq ($(OS_ARCH), WINNT)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
 	SUF = i64
 else
 	SUF = LL
 endif
 
 GARBAGE += $(TINC)
 
 $(TINC):
@@ -139,17 +142,17 @@ GARBAGE += $(TINC)
 	    $(ECHO) '#define _BUILD_TIME $(SH_NOW)$(SUF)' >> $(TINC); \
 	else \
 	    true; \
 	fi
 	@$(ECHO) '#define _PRODUCTION "$(PROD)"' >> $(TINC)
 
 
 $(OBJDIR)/plvrsion.$(OBJ_SUFFIX): plvrsion.c $(TINC)
-ifeq ($(OS_ARCH), WINNT)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
 	$(CC) -Fo$@ -c $(CFLAGS) -I$(OBJDIR) $<
 else
 ifeq ($(MOZ_OS2_TOOLS), VACPP)
 	$(CC) -Fo$@ -c $(CFLAGS) -I$(OBJDIR) $<
 else
 	$(CC) -o $@ -c $(CFLAGS) -I$(OBJDIR) $<
 endif
 endif
--- a/lib/libc/src/Makefile.in
+++ b/lib/libc/src/Makefile.in
@@ -64,17 +64,21 @@ CSRCS =\
 	$(NULL)
 
 LIBRARY_NAME	= plc
 LIBRARY_VERSION	= $(MOD_MAJOR_VERSION)
 
 RELEASE_LIBS = $(TARGETS)
 
 ifeq ($(OS_ARCH),WINNT)
+ifdef NS_USE_GCC
+DLLBASE=-Wl,--image-base -Wl,0x30000000
+else
 DLLBASE=/BASE:0x30000000
+endif
 RES=$(OBJDIR)/plc.res
 RESNAME=plc.rc
 endif # WINNT
 
 ifeq ($(OS_ARCH), AIX)
 ifeq ($(CLASSIC_NSPR),1)
 OS_LIBS = -lc
 else
@@ -121,17 +125,17 @@ include $(topsrcdir)/config/rules.mk
 #
 ECHO = echo
 TINC = $(OBJDIR)/_pl_bld.h
 PROD = $(notdir $(SHARED_LIBRARY))
 NOW = $(MOD_DEPTH)/config/$(OBJDIR)/now
 SH_DATE = $(shell date "+%Y-%m-%d %T")
 SH_NOW = $(shell $(NOW))
 
-ifeq ($(OS_ARCH), WINNT)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
 	SUF = i64
 else
 	SUF = LL
 endif
 
 GARBAGE += $(TINC)
 
 $(TINC):
@@ -141,17 +145,17 @@ GARBAGE += $(TINC)
 	    $(ECHO) '#define _BUILD_TIME $(SH_NOW)$(SUF)' >> $(TINC); \
 	else \
 	    true; \
 	fi
 	@$(ECHO) '#define _PRODUCTION "$(PROD)"' >> $(TINC)
 
 
 $(OBJDIR)/plvrsion.$(OBJ_SUFFIX): plvrsion.c $(TINC)
-ifeq ($(OS_ARCH), WINNT)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
 	$(CC) -Fo$@ -c $(CFLAGS) -I$(OBJDIR) $<
 else
 ifeq ($(MOZ_OS2_TOOLS), VACPP)
 	$(CC) -Fo$@ -c $(CFLAGS) -I$(OBJDIR) $<
 else
 	$(CC) -o $@ -c $(CFLAGS) -I$(OBJDIR) $<
 endif
 endif
--- a/lib/msgc/src/Makefile.in
+++ b/lib/msgc/src/Makefile.in
@@ -60,17 +60,21 @@ NSPR_VERSION = $(MOD_MAJOR_VERSION)
 
 EXTRA_LIBS = $(LIBNSPR)
 
 ifdef RESOLVE_LINK_SYMBOLS
 EXTRA_LIBS += $(OS_LIBS)
 endif
 
 ifeq ($(OS_ARCH), WINNT)
+ifdef NS_USE_GCC
+DLLBASE=-Wl,--image-base -Wl,0x30000000
+else
 DLLBASE=/BASE:0x30000000
+endif # GCC
 #RES=$(OBJDIR)/ds.res
 #RESNAME=$(MOD_DEPTH)/pr/src/nspr.rc
 #OS_LIBS = user32.lib
 endif # WINNT
 
 LIBRARY_NAME = msgc
 LIBRARY_VERSION = $(MOD_MAJOR_VERSION)
 
--- a/pr/include/md/_winnt.h
+++ b/pr/include/md/_winnt.h
@@ -42,16 +42,19 @@
     #define _WIN32_WINNT 0x0400
 #elif   (_WIN32_WINNT < 0x0400)
     #undef  _WIN32_WINNT
     #define _WIN32_WINNT 0x0400
 #endif /* _WIN32_WINNT */
 
 #include <windows.h>
 #include <winsock.h>
+#ifdef __MINGW32__
+#include <mswsock.h>
+#endif
 #include <errno.h>
 
 #include "prio.h"
 #include "prclist.h"
 
 /*
  * Internal configuration macros
  */
--- a/pr/include/prtypes.h
+++ b/pr/include/prtypes.h
@@ -465,18 +465,22 @@ typedef PRUint8 PRPackedBool;
 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
 
 #ifdef MOZ_UNICODE
 /*
  * EXPERIMENTAL: This type may be removed in a future release.
  */
 #ifndef __PRUNICHAR__
 #define __PRUNICHAR__
+#if defined(WIN32) || defined(XP_MAC)
+typedef wchar_t PRUnichar;
+#else
 typedef PRUint16 PRUnichar;
 #endif
+#endif
 #endif /* MOZ_UNICODE */
 
 /*
 ** WARNING: The undocumented data types PRWord and PRUword are
 ** only used in the garbage collection and arena code.  Do not
 ** use PRWord and PRUword in new code.
 **
 ** A PRWord is an integer that is the same size as a void*.
--- a/pr/src/Makefile.in
+++ b/pr/src/Makefile.in
@@ -176,18 +176,22 @@ ifeq ($(OS_ARCH),UNIXWARE)
 OS_LIBS		= -lsocket -lc
 endif
 
 ifeq ($(OS_ARCH),NEWS-OS)
 OS_LIBS		= -lsocket -lnsl -lgen -lresolv
 endif
 
 ifeq ($(OS_ARCH),WINNT)
+ifdef NS_USE_GCC
+OS_LIBS		= -ladvapi32 -lws2_32
+else
 OS_LIBS		= advapi32.lib wsock32.lib
 endif
+endif
 
 ifeq ($(OS_TARGET),MacOSX)
 OS_LIBS		= -framework CoreServices -framework CoreFoundation
 endif
 
 ifdef GC_LEAK_DETECTOR
 EXTRA_LIBS	= -L$(dist_libdir) -lboehm
 endif
@@ -291,17 +295,21 @@ OBJS += \
 	cplus/$(OBJDIR)/rctime.$(OBJ_SUFFIX)
 endif
 
 ifdef GC_LEAK_DETECTOR
 OBJS += memory/$(OBJDIR)/prgcleak.$(OBJ_SUFFIX)
 endif
 
 ifeq ($(OS_ARCH), WINNT)
+ifdef NS_USE_GCC
+DLLBASE=-Wl,--image-base -Wl,0x30000000
+else
 DLLBASE=/BASE:0x30000000
+endif # GCC
 RES=$(OBJDIR)/nspr.res
 RESNAME=nspr.rc
 endif # WINNT
 
 include $(srcdir)/md/$(PR_MD_ARCH_DIR)/objs.mk
 ifdef USE_BTHREADS
 include $(srcdir)/bthreads/objs.mk
 endif
@@ -330,17 +338,17 @@ PROD = nspr$(MOD_MAJOR_VERSION).$(DLL_SU
 else
 PROD = $(notdir $(SHARED_LIBRARY))
 endif
 
 NOW = $(MOD_DEPTH)/config/$(OBJDIR)/now
 SH_DATE = $(shell date "+%Y-%m-%d %T")
 SH_NOW = $(shell $(NOW))
 
-ifeq ($(OS_ARCH), WINNT)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
 	SUF = i64
 else
 	SUF = LL
 endif
 
 DEFINES		+= -D_NSPR_BUILD_
 
 GARBAGE += $(TINC)
@@ -352,17 +360,17 @@ GARBAGE += $(TINC)
 	    $(ECHO) '#define _BUILD_TIME $(SH_NOW)$(SUF)' >> $(TINC); \
 	else \
 	    true; \
 	fi
 	@$(ECHO) '#define _PRODUCTION "$(PROD)"' >> $(TINC)
 
 
 $(OBJDIR)/prvrsion.$(OBJ_SUFFIX): prvrsion.c $(TINC)
-ifeq ($(OS_ARCH), WINNT)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
 	$(CC) -Fo$@ -c $(CFLAGS) -I$(OBJDIR) $<
 else
 ifeq ($(MOZ_OS2_TOOLS), VACPP)
 	$(CC) -Fo$@ -c $(CFLAGS) -I$(OBJDIR) $<
 else
 	$(CC) -o $@ -c $(CFLAGS) -I$(OBJDIR) $<
 endif
 endif
--- a/pr/src/io/prmapopt.c
+++ b/pr/src/io/prmapopt.c
@@ -41,19 +41,24 @@
  * to use Service Pack 3 extensions), windows.h includes winsock2.h
  * (instead of winsock.h), which doesn't define many socket options
  * defined in winsock.h.
  *
  * We need the socket options defined in winsock.h.  So this file
  * includes winsock.h, with _WIN32_WINNT undefined.
  */
 
-#ifdef WINNT
+#ifdef WIN32
+#ifdef __MINGW32__
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#elif defined(WINNT)
 #include <winsock.h>
 #endif
+#endif
 
 #include "primpl.h"
 
 #if defined(NEXTSTEP)
 /* NEXTSTEP is special: this must come before netinet/tcp.h. */
 #include <netinet/in_systm.h>  /* n_short, n_long, n_time */
 #endif
 
--- a/pr/src/md/windows/Makefile.in
+++ b/pr/src/md/windows/Makefile.in
@@ -103,13 +103,15 @@ DEFINES += -D_NSPR_BUILD_
 
 include $(topsrcdir)/config/rules.mk
 
 export:: $(TARGETS)
 
 # Bug 122433 workaround: disable global optimization (-Og-) on ntio.c.
 ifdef BUILD_OPT
 ifeq ($(OS_TARGET), WINNT)
+ifndef NS_USE_GCC
 $(OBJDIR)/ntio.$(OBJ_SUFFIX): ntio.c
 	@$(MAKE_OBJDIR)
 	$(CC) -Fo$@ -c $(CFLAGS) -Og- $<
 endif
 endif
+endif
--- a/pr/src/md/windows/ntio.c
+++ b/pr/src/md/windows/ntio.c
@@ -94,17 +94,21 @@ static DWORD dirAccessTable[] = {
     FILE_GENERIC_EXECUTE
 };
 
 /*
  * The NSPR epoch (00:00:00 1 Jan 1970 UTC) in FILETIME.
  * We store the value in a PRTime variable for convenience.
  * This constant is used by _PR_FileTimeToPRTime().
  */
+#ifdef __GNUC__
+static const PRTime _pr_filetime_offset = 116444736000000000LL;
+#else
 static const PRTime _pr_filetime_offset = 116444736000000000i64;
+#endif
 
 #define _NEED_351_FILE_LOCKING_HACK
 #ifdef _NEED_351_FILE_LOCKING_HACK
 #define _PR_LOCAL_FILE 1
 #define _PR_REMOTE_FILE 2
 PRBool IsFileLocalInit();
 PRInt32 IsFileLocal(HANDLE hFile);
 #endif /* _NEED_351_FILE_LOCKING_HACK */
@@ -2317,17 +2321,17 @@ PRInt32
             _PR_MD_MAP_READ_ERROR(err);
             return -1;
         }
         return bytes;
     }
 }
 
 PRInt32
-_PR_MD_WRITE(PRFileDesc *fd, void *buf, PRInt32 len)
+_PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
 {
     PRInt32 f = fd->secret->md.osfd;
     PRInt32 bytes;
     int rv, err;
     LONG hiOffset = 0;
     LONG loOffset;
     LARGE_INTEGER offset; /* use for the calculation of the new offset */
 
@@ -2483,17 +2487,17 @@ PRInt32
     if (NULL == fd)
 		PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
 	else
 		PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
     return -1;
 }
 
 PROffset32
-_PR_MD_LSEEK(PRFileDesc *fd, PROffset32 offset, int whence)
+_PR_MD_LSEEK(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence)
 {
     DWORD moveMethod;
     PROffset32 rv;
 
     switch (whence) {
         case PR_SEEK_SET:
             moveMethod = FILE_BEGIN;
             break;
@@ -2516,17 +2520,17 @@ PROffset32
      */
     if (-1 == rv) {
         _PR_MD_MAP_LSEEK_ERROR(GetLastError());
     }
     return rv;
 }
 
 PROffset64
-_PR_MD_LSEEK64(PRFileDesc *fd, PROffset64 offset, int whence)
+_PR_MD_LSEEK64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence)
 {
     DWORD moveMethod;
     LARGE_INTEGER li;
     DWORD err;
 
     switch (whence) {
         case PR_SEEK_SET:
             moveMethod = FILE_BEGIN;
@@ -2815,17 +2819,21 @@ PRInt32
 	}
 }
 
 void
 _PR_FileTimeToPRTime(const FILETIME *filetime, PRTime *prtm)
 {
     PR_ASSERT(sizeof(FILETIME) == sizeof(PRTime));
     CopyMemory(prtm, filetime, sizeof(PRTime));
+#ifdef __GNUC__
+    *prtm = (*prtm - _pr_filetime_offset) / 10LL;
+#else
     *prtm = (*prtm - _pr_filetime_offset) / 10i64;
+#endif
 
 #ifdef DEBUG
     /* Doublecheck our calculation. */
     {
         SYSTEMTIME systime;
         PRExplodedTime etm;
         PRTime cmp; /* for comparison */
         BOOL rv;
@@ -3163,17 +3171,17 @@ PRInt32
 		return 0;
 	} else {
 		_PR_MD_MAP_RENAME_ERROR(GetLastError());
 		return -1;
 	}
 }
 
 PRInt32
-_PR_MD_ACCESS(const char *name, PRIntn how)
+_PR_MD_ACCESS(const char *name, PRAccessHow how)
 {
     PRInt32 rv;
 
     switch (how) {
       case PR_ACCESS_WRITE_OK:
         rv = _access(name, 02);
 		break;
       case PR_ACCESS_READ_OK:
--- a/pr/src/md/windows/ntmisc.c
+++ b/pr/src/md/windows/ntmisc.c
@@ -781,17 +781,17 @@ PRInt32 _PR_MD_ATOMIC_INCREMENT(PRInt32 
 
 #pragma warning(disable: 4035)
 PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 *val)
 {
 #if defined(__GNUC__)
   PRInt32 result;
   asm volatile ("lock ; xadd %0, %1" 
                 : "=r"(result), "=m"(*val)
-                : "0"(1), "m"(*val));
+                : "0"(-1), "m"(*val));
   //asm volatile("lock ; xadd %0, %1" : "=m" (val), "=a" (result) : "-1" (1));
   return result - 1;
 #else
     __asm
     {
         mov ecx, val
         mov eax, 0ffffffffh
         lock xadd dword ptr [ecx], eax
@@ -803,18 +803,18 @@ PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 
 
 #pragma warning(disable: 4035)
 PRInt32 _PR_MD_ATOMIC_ADD(PRInt32 *intp, PRInt32 val)
 {
 #if defined(__GNUC__)
   PRInt32 result;
   //asm volatile("lock ; xadd %1, %0" : "=m" (intp), "=a" (result) : "1" (val));
   asm volatile ("lock ; xadd %0, %1" 
-                : "=r"(result), "=m"(intp)
-                : "0"(val), "m"(intp));
+                : "=r"(result), "=m"(*intp)
+                : "0"(val), "m"(*intp));
   return result + val;
 #else
     __asm
     {
         mov ecx, intp
         mov eax, val
         mov edx, eax
         lock xadd dword ptr [ecx], eax
--- a/pr/tests/Makefile.in
+++ b/pr/tests/Makefile.in
@@ -213,20 +213,25 @@ endif
 
 PROGS = $(addprefix $(OBJDIR)/, $(CSRCS:.c=$(PROG_SUFFIX)))
 
 TARGETS = $(PROGS)
 
 INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
 
 ifeq ($(OS_ARCH), WINNT)
+ifdef NS_USE_GCC
+  EXTRA_LIBS += -lws2_32
+else
+  EXTRA_LIBS += wsock32.lib
   LDOPTS = -NOLOGO -DEBUG -DEBUGTYPE:CV -INCREMENTAL:NO
   ifdef PROFILE                                                                              
     LDOPTS += -PROFILE -MAP                                                                  
   endif # profile
+endif # NS_USE_GCC
 endif
 
 ifeq ($(OS_ARCH),OS2)
 ifeq ($(MOZ_OS2_TOOLS),VACPP)
   LDOPTS = -NOE -DEBUG -nologo -PMTYPE:VIO
 else
 ifeq ($(MOZ_OS2_EMX_OBJECTFORMAT),OMF)
   LDOPTS = -Zlinker /PM:VIO
@@ -474,18 +479,18 @@ ifeq ($(AIX_PRE_4_2),1)
 	rm -f $(AIX_TMP)
 
 else
 
 # All platforms that are not AIX pre-4.2.
 
 $(OBJDIR)/%$(PROG_SUFFIX): $(OBJDIR)/%.$(OBJ_SUFFIX)
 	@$(MAKE_OBJDIR)
-ifeq ($(OS_ARCH), WINNT)
-	link $(LDOPTS) $(EXTRA_LDOPTS) $< $(LIBPLC) $(LIBNSPR) $(EXTRA_LIBS) wsock32.lib -out:$@
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
+	link $(LDOPTS) $(EXTRA_LDOPTS) $< $(LIBPLC) $(LIBNSPR) $(EXTRA_LIBS) -out:$@
 else
 ifeq ($(OS_ARCH),OS2)
 	$(LD) $(EXEFLAGS) $(LDOPTS) $< $(LIBPLC) $(LIBNSPR) $(OS_LIBS) $(EXTRA_LIBS)
 else
 	$(PURE) $(CC) $(XCFLAGS) $< $(LDOPTS) $(LIBPLC) $(LIBNSPR) $(EXTRA_LIBS) -o $@
 endif # OS/2
 endif # WINNT
 endif # AIX_PRE_4_2
--- a/pr/tests/dll/Makefile.in
+++ b/pr/tests/dll/Makefile.in
@@ -59,17 +59,21 @@ OBJS = $(OBJDIR)/mygetval.$(OBJ_SUFFIX) 
 ifeq ($(OS_TARGET), WIN16)
 W16OBJS = $(subst $(space),$(comma)$(space),$(OBJS))
 endif
 
 ifeq ($(OS_ARCH), WINNT)
 ifeq ($(OS_TARGET), WIN16)
 # do nothing
 else
+ifdef NS_USE_GCC
+DLLBASE=-Wl,--image-base -Wl,0x30000000
+else
 DLLBASE=/BASE:0x30000000
+endif
 RES=$(OBJDIR)/my.res
 RESNAME=../../../pr/src/nspr.rc
 endif
 endif
 
 ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
 IMPORT_LIBRARY	= $(OBJDIR)/my.$(LIB_SUFFIX)
 SHARED_LIBRARY	= $(OBJDIR)/my.dll
--- a/pr/tests/runtests.ksh
+++ b/pr/tests/runtests.ksh
@@ -250,17 +250,17 @@ else
 		sleep_pid=0
 		if [ "$TEST_TIMEOUT" -gt 0 ]
 		then
 		(sleep  $TEST_TIMEOUT; kill $test_pid >/dev/null 2>&1 ) &
 		sleep_pid=$!
 		fi
 		wait $test_pid
 		test_rval=$?
-		[ sleep_pid -eq 0 ] || kill $sleep_pid >/dev/null 2>&1
+		[ $sleep_pid -eq 0 ] || kill $sleep_pid >/dev/null 2>&1
 		if [ 0 = $test_rval ] ; then
 			echo "\t\t\tPassed";
 		else
 			echo "\t\t\tFAILED";
 			rval=1
 		fi;
 		echo "\nEND TEST: $prog\n" >> ${LOGFILE} 2>&1
 	done