diff -ruN ..\mirror\emacs-bzr\trunk\src/lisp.h emacs-gnu\src/lisp.h
--- ..\mirror\emacs-bzr\trunk\src/lisp.h	2010-11-18 08:53:04.000000000 +0100
+++ emacs-gnu\src/lisp.h	2010-12-13 21:50:58.000000000 +0100
@@ -124,8 +124,11 @@
 # ifndef DECL_ALIGN
 /* What compiler directive should we use for non-gcc compilers?  -stef  */
 #  if defined (__GNUC__)
-#   define DECL_ALIGN(type, var) \
+#   define DECL_ALIGN(type, var)                                \
      type __attribute__ ((__aligned__ (1 << GCTYPEBITS))) var
+#  elseif defined(_MSC_VER)
+#   define DECL_ALIGN(type, var) \
+     type __declspec(align(1 << GCTYPEBITS)) var
 #  endif
 # endif
 #endif
@@ -1007,7 +1010,11 @@
      2 : it's a localized var, the value is in the `blv' object.
      3 : it's a forwarding variable, the value is in `forward'.
    */
+#ifdef _MSC_VER
+  unsigned short redirect : 3;
+#else
   enum symbol_redirect redirect : 3;
+#endif

   /* Non-zero means symbol is constant, i.e. changing its value
      should signal an error.  If the value is 3, then the var
@@ -1216,7 +1223,11 @@

 struct Lisp_Misc_Any		/* Supertype of all Misc types.  */
 {
+#ifdef _MSC_VER
+  unsigned short type : 16;
+#else
   enum Lisp_Misc_Type type : 16;		/* = Lisp_Misc_??? */
+#endif
   unsigned gcmarkbit : 1;
   int spacer : 15;
   /* Make it as long as "Lisp_Free without padding". */
@@ -1225,7 +1236,11 @@

 struct Lisp_Marker
 {
+#ifdef _MSC_VER
+  unsigned short type : 16;
+#else
   enum Lisp_Misc_Type type : 16;		/* = Lisp_Misc_Marker */
+#endif
   unsigned gcmarkbit : 1;
   int spacer : 13;
   /* This flag is temporarily used in the functions
@@ -1375,7 +1390,11 @@
    I.e. 9words plus 2 bits, 3words of which are for external linked lists.
 */
   {
+#ifdef _MSC_VER
+    unsigned short type : 16;
+#else
     enum Lisp_Misc_Type type : 16;	/* = Lisp_Misc_Overlay */
+#endif
     unsigned gcmarkbit : 1;
     int spacer : 15;
     struct Lisp_Overlay *next;
@@ -1394,7 +1413,11 @@
    This type of object is used in the arg to record_unwind_protect.  */
 struct Lisp_Save_Value
   {
+#ifdef _MSC_VER
+    unsigned short type : 16;
+#else
     enum Lisp_Misc_Type type : 16;	/* = Lisp_Misc_Save_Value */
+#endif
     unsigned gcmarkbit : 1;
     int spacer : 14;
     /* If DOGC is set, POINTER is the address of a memory
@@ -1408,7 +1431,11 @@
 /* A miscellaneous object, when it's on the free list.  */
 struct Lisp_Free
   {
+#ifdef _MSC_VER
+    unsigned short type : 16;
+#else
     enum Lisp_Misc_Type type : 16;	/* = Lisp_Misc_Free */
+#endif
     unsigned gcmarkbit : 1;
     int spacer : 15;
     union Lisp_Misc *chain;
@@ -1800,13 +1827,23 @@

 /* This version of DEFUN declares a function prototype with the right
    arguments, so we can catch errors with maxargs at compile-time.  */
+#ifdef _MSC_VER
 #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc)	\
   Lisp_Object fnname DEFUN_ARGS_ ## maxargs ;				\
   DECL_ALIGN (struct Lisp_Subr, sname) =				\
     { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)),	\
-      { .a ## maxargs = fnname },				\
+      { (Lisp_Object (__cdecl *)(void))fnname },                        \
       minargs, maxargs, lname, intspec, 0};				\
   Lisp_Object fnname
+#else
+#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc)	\
+  Lisp_Object fnname DEFUN_ARGS_ ## maxargs ;				\
+  DECL_ALIGN (struct Lisp_Subr, sname) =				\
+    { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)),	\
+      { .a ## maxargs = fnname },					\
+      minargs, maxargs, lname, intspec, 0};				\
+  Lisp_Object fnname
+#endif

 /* Note that the weird token-substitution semantics of ANSI C makes
    this work for MANY and UNEVALLED.  */
diff -ruN ..\mirror\emacs-bzr\trunk\src/makefile.w32-in emacs-gnu\src/makefile.w32-in
--- ..\mirror\emacs-bzr\trunk\src/makefile.w32-in	2010-11-18 08:53:04.000000000 +0100
+++ emacs-gnu\src/makefile.w32-in	2010-12-13 21:48:10.000000000 +0100
@@ -303,14 +303,14 @@
 	$(MAKE) $(MFLAGS) TAGS-LISP-$(MAKETYPE)

 TAGS-gmake:
-	../lib-src/$(BLD)/etags.exe --include=TAGS-LISP --include=../nt/TAGS \
-	  --regex=@../nt/emacs-src.tags \
-	  $(patsubst $(BLD)%.$(O),$(CURDIR)%.c,$(OBJ0))
-	../lib-src/$(BLD)/etags.exe -a --regex=@../nt/emacs-src.tags \
-	  $(patsubst $(BLD)%.$(O),$(CURDIR)%.c,$(OBJ1))
-	../lib-src/$(BLD)/etags.exe -a --regex=@../nt/emacs-src.tags \
-	  $(patsubst $(BLD)%.$(O),$(CURDIR)%.c,$(OBJ2)) \
-	  $(CURDIR)/*.h
+# ../lib-src/$(BLD)/etags.exe --include=TAGS-LISP --include=../nt/TAGS \
+#   --regex=@../nt/emacs-src.tags \
+#   $(patsubst $(BLD)%.$(O),$(CURDIR)%.c,$(OBJ0))
+# ../lib-src/$(BLD)/etags.exe -a --regex=@../nt/emacs-src.tags \
+#   $(patsubst $(BLD)%.$(O),$(CURDIR)%.c,$(OBJ1))
+# ../lib-src/$(BLD)/etags.exe -a --regex=@../nt/emacs-src.tags \
+#   $(patsubst $(BLD)%.$(O),$(CURDIR)%.c,$(OBJ2)) \
+#   $(CURDIR)/*.h

 TAGS-nmake:
 	echo This target is not supported with NMake
diff -ruN ..\mirror\emacs-bzr\trunk\src/ralloc.c emacs-gnu\src/ralloc.c
--- ..\mirror\emacs-bzr\trunk\src/ralloc.c	2010-11-18 08:53:04.000000000 +0100
+++ emacs-gnu\src/ralloc.c	2010-12-13 21:57:24.000000000 +0100
@@ -651,7 +651,7 @@
       else
 	{
 	  memmove (bloc->new_data, bloc->data, old_size);
-	  memset (bloc->new_data + old_size, 0, size - old_size);
+	  memset ((char *) bloc->new_data + old_size, 0, size - old_size);
 	  *bloc->variable = bloc->data = bloc->new_data;
 	}
     }
diff -ruN ..\mirror\emacs-bzr\trunk\src/regex.c emacs-gnu\src/regex.c
--- ..\mirror\emacs-bzr\trunk\src/regex.c	2010-11-18 08:53:04.000000000 +0100
+++ emacs-gnu\src/regex.c	2010-12-13 16:07:44.000000000 +0100
@@ -569,7 +569,12 @@
 #define MIN(a, b) ((a) < (b) ? (a) : (b))

 /* Type of source-pattern and string chars.  */
+#ifdef _MSC_VER
+/* MSVC barks with double const */
+typedef unsigned char re_char;
+#else
 typedef const unsigned char re_char;
+#endif

 typedef char boolean;
 #define false 0
diff -ruN ..\mirror\emacs-bzr\trunk\src/s/ms-w32.h emacs-gnu\src/s/ms-w32.h
--- ..\mirror\emacs-bzr\trunk\src/s/ms-w32.h	2010-11-18 08:53:04.000000000 +0100
+++ emacs-gnu\src/s/ms-w32.h	2010-12-13 23:20:18.000000000 +0100
@@ -87,6 +87,10 @@
 #define IS_ANY_SEP(_c_) (IS_DIRECTORY_SEP (_c_) || IS_DEVICE_SEP (_c_))

 #include <sys/types.h>
+#ifdef _MSC_VER
+typedef unsigned long sigset_t;
+#endif
+
 struct sigaction {
   int sa_flags;
   void (*sa_handler)(int);
@@ -190,6 +194,12 @@

 #ifdef emacs

+#ifdef _MSC_VER
+#include <sys/timeb.h>
+#include <sys/stat.h>
+#include <signal.h>
+#endif
+
 /* Calls that are emulated or shadowed.  */
 #undef access
 #define access  sys_access
@@ -208,6 +218,9 @@
 #undef dup2
 #define dup2    sys_dup2
 #define fopen   sys_fopen
+#if 1
+#define fstat(a, b)   sys_fstat(a, b)
+#endif
 #define link    sys_link
 #define mkdir   sys_mkdir
 #undef mktemp
@@ -221,9 +234,13 @@
 #define rmdir   sys_rmdir
 #define select  sys_select
 #define sleep   sys_sleep
+#if 1
+#define stat(a, b)   sys_stat(a, b)
+#endif
 #define strerror sys_strerror
 #undef unlink
 #define unlink  sys_unlink
+#define utime   sys_utime
 #undef write
 #define write   sys_write

@@ -325,13 +342,17 @@
 #define _WINSOCK_H

 /* Defines size_t and alloca ().  */
-#ifdef USE_CRT_DLL
+#ifdef emacs
 #define malloc e_malloc
 #define free   e_free
 #define realloc e_realloc
 #define calloc e_calloc
 #endif
+#if 0
 #include <malloc.h>
+#else
+#define alloca _alloca
+#endif

 #include <sys/stat.h>

diff -ruN ..\mirror\emacs-bzr\trunk\src/w32.c emacs-gnu\src/w32.c
--- ..\mirror\emacs-bzr\trunk\src/w32.c	2010-11-18 08:53:04.000000000 +0100
+++ emacs-gnu\src/w32.c	2010-12-13 21:52:37.000000000 +0100
@@ -92,7 +92,10 @@

 #include <tlhelp32.h>
 #include <psapi.h>
+#ifdef _MSC_VER
+#else
 #include <w32api.h>
+#endif
 #if !defined(__MINGW32__) || __W32API_MAJOR_VERSION < 3 || (__W32API_MAJOR_VERSION == 3 && __W32API_MINOR_VERSION < 15)
 /* This either is not in psapi.h or guarded by higher value of
    _WIN32_WINNT than what we use.  w32api suplied with MinGW 3.15
@@ -1541,7 +1544,7 @@
 	 read-only filesystem, like CD-ROM or a write-protected floppy.
 	 The only way to be really sure is to actually create a file and
 	 see if it succeeds.  But I think that's too much to ask.  */
-      if (tmp && _access (tmp, D_OK) == 0)
+      if (tmp && sys_access (tmp, D_OK) == 0)
 	{
 	  char * var = alloca (strlen (tmp) + 8);
 	  sprintf (var, "TMPDIR=%s", tmp);
@@ -1887,6 +1890,8 @@
   return configuration_buffer;
 }

+#define stringer( x ) ( #x )
+
 char *
 get_emacs_configuration_options (void)
 {
@@ -1900,10 +1905,10 @@
     /* configure.bat already sets USER_CFLAGS and USER_LDFLAGS
        with a starting space to save work here.  */
 #ifdef USER_CFLAGS
-    " --cflags", USER_CFLAGS,
+    " --cflags", stringer(USER_CFLAGS),
 #endif
 #ifdef USER_LDFLAGS
-    " --ldflags", USER_LDFLAGS,
+    " --ldflags", stringer(USER_LDFLAGS),
 #endif
     NULL
   };
diff -ruN ..\mirror\emacs-bzr\trunk\src/w32fns.c emacs-gnu\src/w32fns.c
--- ..\mirror\emacs-bzr\trunk\src/w32fns.c	2010-11-18 08:53:04.000000000 +0100
+++ emacs-gnu\src/w32fns.c	2010-12-13 21:59:17.000000000 +0100
@@ -246,7 +246,7 @@
 };

 /* Reportedly, VS 6 does not have this in its headers.  */
-#if defined (_MSC_VER) && _MSC_VER < 1300
+#if defined(_MSC_VER) /* && _MSC_VER < 1300 */
 DECLARE_HANDLE(HMONITOR);
 #endif

diff -ruN ..\mirror\emacs-bzr\trunk\lib-src/movemail.c emacs-gnu\lib-src/movemail.c
--- ..\mirror\emacs-bzr\trunk\lib-src/movemail.c	2010-11-18 08:53:04.000000000 +0100
+++ emacs-gnu\lib-src/movemail.c	2010-12-13 23:21:27.000000000 +0100
@@ -164,6 +164,10 @@
 /* Nonzero means this is name of a lock file to delete on fatal error.  */
 char *delete_lockname;

+#ifdef _MSC_VER
+typedef int ssize_t;
+#endif
+
 int
 main (int argc, char **argv)
 {
diff -ruN ..\mirror\emacs-bzr\trunk\nt/configure.bat emacs-gnu\nt/configure.bat
--- ..\mirror\emacs-bzr\trunk\nt/configure.bat	2010-11-18 08:53:04.000000000 +0100
+++ emacs-gnu\nt/configure.bat	2010-12-13 16:10:24.000000000 +0100
@@ -294,6 +294,18 @@
 rem   Auto-detect compiler if not specified, and validate GCC if chosen.

 :checkcompiler
+
+rem set SDK environment
+if (%noopt%) == (Y) (
+   call "c:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x86 /win7 /Debug
+   set nodebug=N
+)
+
+if (%nodebug%) == (Y) (
+   call "c:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x86 /win7 /Release
+   set noopt=N
+)
+
 if (%COMPILER%)==(cl) goto compilercheckdone
 if (%COMPILER%)==(gcc) goto checkgcc

diff -ruN ..\mirror\emacs-bzr\trunk\nt/makefile.w32-in emacs-gnu\nt/makefile.w32-in
--- ..\mirror\emacs-bzr\trunk\nt/makefile.w32-in	2010-11-18 08:53:04.000000000 +0100
+++ emacs-gnu\nt/makefile.w32-in	2010-12-13 21:43:45.000000000 +0100
@@ -36,6 +36,7 @@

 .PHONY: $(ALL)

+ARCH_CFLAGS	= $(ARCH_CFLAGS) -I../nt/inc -I../src

 addpm:		  stamp_BLD $(BLD)/addpm.exe
 $(BLD)/addpm.exe: $(BLD)/addpm.$(O)
@@ -304,15 +305,15 @@
 	$(MAKE) $(MFLAGS) clean
 	cd ..\doc\lispintro
 	$(MAKE) $(MFLAGS) clean
-	cd ..\doc\lispref
+	cd ..\..\doc\lispref
 	$(MAKE) $(MFLAGS) clean
-	cd ..\leim
+	cd ..\..\leim
 	$(MAKE) $(MFLAGS) clean
 	cd ..\doc\emacs
 	$(MAKE) $(MFLAGS) clean
-	cd ..\doc\misc
+	cd ..\..\doc\misc
 	$(MAKE) $(MFLAGS) clean
-	cd ..\nt
+	cd ..\..\nt

 clean-other-dirs-gmake:
 	$(MAKE) $(MFLAGS) $(XMFLAGS) -C ../lib-src clean
@@ -366,13 +367,13 @@
 	$(MAKE) $(MFLAGS) distclean
 	cd ..\doc\emacs
 	$(MAKE) $(MFLAGS) distclean
-	cd ..\doc\misc
+	cd ..\..\doc\misc
 	$(MAKE) $(MFLAGS) distclean
-	cd ..\doc\lispintro
+	cd ..\..\doc\lispintro
 	$(MAKE) $(MFLAGS) distclean
-	cd ..\doc\lispref
+	cd ..\..\doc\lispref
 	$(MAKE) $(MFLAGS) distclean
-	cd ..\nt
+	cd ..\..\nt

 distclean-other-dirs-gmake:
 	$(MAKE) $(MFLAGS) $(XMFLAGS) -C ../lib-src distclean
@@ -397,13 +398,13 @@
 	$(MAKE) $(MFLAGS) maintainer-clean
 	cd ..\doc\emacs
 	$(MAKE) $(MFLAGS) maintainer-clean
-	cd ..\doc\misc
+	cd ..\..\doc\misc
 	$(MAKE) $(MFLAGS) maintainer-clean
-	cd ..\doc\lispintro
+	cd ..\..\doc\lispintro
 	$(MAKE) $(MFLAGS) maintainer-clean
-	cd ..\doc\lispref
+	cd ..\..\doc\lispref
 	$(MAKE) $(MFLAGS) maintainer-clean
-	cd ..\nt
+	cd ..\..\nt

 maintainer-clean-other-dirs-gmake:
 	$(MAKE) $(MFLAGS) $(XMFLAGS) -C ../lib-src maintainer-clean
@@ -422,9 +423,9 @@

 frc:
 TAGS-gmake: frc
-	../lib-src/$(BLD)/etags $(CURDIR)/*.c
-	$(MAKE) $(MFLAGS) -C ../src TAGS TAGS-LISP
-	$(MAKE) $(MFLAGS) -C ../lib-src TAGS
+# ../lib-src/$(BLD)/etags $(CURDIR)/*.c
+# $(MAKE) $(MFLAGS) -C ../src TAGS TAGS-LISP
+# $(MAKE) $(MFLAGS) -C ../lib-src TAGS

 TAGS-nmake:
 	echo This target is not supported with NMake
diff -ruN ..\mirror\emacs-bzr\trunk\nt/nmake.defs emacs-gnu\nt/nmake.defs
--- ..\mirror\emacs-bzr\trunk\nt/nmake.defs	2010-11-18 08:53:04.000000000 +0100
+++ emacs-gnu\nt/nmake.defs	2010-12-13 16:13:22.000000000 +0100
@@ -110,7 +110,13 @@
 RC_OUT		= -Fo
 RC_INCLUDE	= -i

-libc		= libc.lib
+!ifdef USE_CRT_DLL
+libc		= msvcrt$(D).lib
+XCFLAGS		= -I../nt/inc -I../src -D_DLL -D_MT -DUSE_CRT_DLL=1
+!else
+libc		= libcmt$(D).lib
+XCFLAGS		= -I../nt/inc -I../src -D_MT
+!endif
 baselibs	=
 O		= obj
 A		= lib
@@ -143,11 +149,15 @@
 CHECKING_CFLAGS	=
 !endif

-CFLAGS          = -I. $(ARCH_CFLAGS) \
+CFLAGS          = -I. $(XCFLAGS) $(ARCH_CFLAGS) \
 		  $(DEBUG_CFLAGS) $(CHECKING_CFLAGS) $(USER_CFLAGS) $(LOCAL_FLAGS)
 EMACS_EXTRA_C_FLAGS =

-SYS_LDFLAGS	= -nologo -release -incremental:no -version:3.10 -swaprun:cd -swaprun:net setargv.obj
+!ifdef NOOPT
+SYS_LDFLAGS	= -nologo -manifest -dynamicbase:no -debug -incremental:no -version:3.10 -swaprun:cd -swaprun:net setargv.obj
+!else
+SYS_LDFLAGS	= -nologo -manifest -dynamicbase:no -release -incremental:no -version:3.10 -swaprun:cd -swaprun:net setargv.obj
+!endif

 # see comments in allocate_heap in w32heap.c before changing any of the
 # -stack, -heap, or -base settings.
@@ -183,16 +193,18 @@
 !ifdef NODEBUG
 DEBUG_FLAG =
 DEBUG_LINK =
+D =
 !else
 DEBUG_FLAG = -Zi
-DEBUG_LINK = -debug:full
+DEBUG_LINK = -debug
+D = d
 !endif

 !if "$(ARCH)" == "i386"
 !ifdef NOOPT
-ARCH_CFLAGS     = -nologo -c -Zel -W2 -H63 -Od -G3d -Zp8 $(DEBUG_FLAG)
+ARCH_CFLAGS     = -nologo -D_X86_=1 -c -Zl -Zp8 -W2 -Od -Gd $(DEBUG_FLAG)
 !else
-ARCH_CFLAGS     = -nologo -c -Zel -W2 -H63 -Oxsb2 -Oy- -G6dF -Zp8 $(DEBUG_FLAG)
+ARCH_CFLAGS     = -nologo -D_X86_=1 -c -Zl -Zp8 -W2 -Oi -Ot -Oy- -Ob2 -GF -Gy -Gd $(DEBUG_FLAG)
 !endif
 ARCH_LDFLAGS	= $(SYS_LDFLAGS)

