Support MSVC build with newer versions of Visual Studio.
authorEli Zaretskii <eliz@gnu.org>
Sat, 5 Nov 2011 11:34:56 +0000 (13:34 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sat, 5 Nov 2011 11:34:56 +0000 (13:34 +0200)
Small portions of the changes by Fabrice Popineau <fabrice.popineau@supelec.fr>.

 src/makefile.w32-in (TAGS-gmake): Don't use $(patsubst ...), as
 Nmake barfs on that.  Use $(OBJ*_c) variables instead, defined on
 nt/gmake.defs.
 src/lisp.h (ENUM_BF): New macro, for enumerated types in bitfields,
 which are not supported by MSVC.
 (Lisp_Symbol, Lisp_Misc_Any, Lisp_Marker, Lisp_Misc_Overlay)
 (Lisp_Save_Value, Lisp_Free): Use ENUM_BF for enumerated types in
 bitfields.
 (Lisp_Object) [USE_LISP_UNION_TYPE]: Use ENUM_BF for enumerated
 types in bitfields.
 (DEFUN) [_MSC_VER]: Define in a different way for MSVC.
 src/w32fns.c [_MSC_VER]: DECLARE_HANDLE for any MSVC version.
 src/w32.c: Don't include w32api.h for MSVC.
 (init_environment) [_MSC_VER]: Call sys_access, not _access.
 src/s/ms-w32.h <sigset_t, ssize_t> [_MSC_VER]: Typedefs for MSVC.
 [_MSC_VER]: Include sys/timeb.h, sys/stat.h, and signal.h.
 (fstat, stat, utime) [_MSC_VER]: Redirect to their sys_* cousins.
 (malloc, free, realloc, calloc) [_MSC_VER]: Always redirect to the
 e_* cousins.
 (alloca) [_MSC_VER]: Define to _alloca.
 src/lisp.h (DECL_ALIGN) [_MSC_VER]: Define for MSVC.
 src/regex.c <re_char> [_MSC_VER]: A separate definition for MSVC.
 nt/makefile.w32-in (clean-other-dirs-nmake)
 (distclean-other-dirs-nmake, maintainer-clean-other-dirs-nmake):
 Update for current structure of doc/ subdirectories.
 nt/gmake.defs (OBJ0_c, OBJ1_c, OBJ2_c): New variables.
 nt/INSTALL: Update for newer versions of MSVC.
 lib/makefile.w32-in (FRC): New dummy target.
 (TAGS): Depend on FRC.

Fixes: debbugs:9960

14 files changed:
ChangeLog
lib/makefile.w32-in
nt/ChangeLog
nt/INSTALL
nt/gmake.defs
nt/makefile.w32-in
nt/nmake.defs
src/ChangeLog
src/lisp.h
src/makefile.w32-in
src/regex.c
src/s/ms-w32.h
src/w32.c
src/w32fns.c

index f41fe08..68f5042 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-11-05  Eli Zaretskii  <eliz@gnu.org>
+
+       * lib/makefile.w32-in (FRC): New dummy target.
+       (TAGS): Depend on FRC.
+
 2011-11-04  Glenn Morris  <rgm@gnu.org>
 
        * configure.in: Increase minimum GnuTLS version to 2.6.6. (Bug#9929)
index 6b451dd..d530425 100644 (file)
@@ -50,7 +50,9 @@ all:          stamp_BLD $(ALL)
 
 ### TAGS ###
 
-TAGS:
+FRC:
+
+TAGS: FRC
         ../lib-src/$(BLD)/etags.exe *.c *.h
 
 ### DEPENDENCIES ###
index 55535c4..21ab0c4 100644 (file)
@@ -1,3 +1,21 @@
+2011-11-05  Eli Zaretskii  <eliz@gnu.org>
+
+       Support MSVC build with newer versions of Visual Studio.
+       * makefile.w32-in (clean-other-dirs-nmake)
+       (distclean-other-dirs-nmake, maintainer-clean-other-dirs-nmake):
+       Update for current structure of doc/ subdirectories.
+
+       * gmake.defs (OBJ0_c, OBJ1_c, OBJ2_c): New variables.
+
+       * INSTALL: Update for newer versions of MSVC.
+
+2011-11-05  Fabrice Popineau  <fabrice.popineau@supelec.fr> (tiny change)
+
+       Support MSVC build with newer versions of Visual Studio.
+       * nmake.defs (USE_CRT_DLL): Define to 1.
+       (libc, EMACS_EXTRA_C_FLAGS, SYS_LDFLAGS, ARCH_CFLAGS): Update values.
+       (D): New variable.
+
 2011-11-04  Eli Zaretskii  <eliz@gnu.org>
 
        * runemacs.c (ensure_unicows_dll): New function, tries to load
index 6136108..6328504 100644 (file)
 
        cd nt
 
-  2. Run configure.bat.  From the COMMAND.COM/CMD.EXE command prompt:
+  2. Run configure.bat.
+
+  2a.If you use MSVC, set up the build environment by running the
+     SetEnv.cmd batch file from the appropriate SDK directory.  (Skip
+     this step if you are using MinGW.)  For example:
+
+       "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x86 /Debug
+
+      if you are goiung to compile a debug version, or
+
+       "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x86 /Release
+
+      if you are going to compile an optimized version.
+
+  2b.From the COMMAND.COM/CMD.EXE command prompt type:
 
        configure
 
-     from a Unixy shell prompt:
+     From a Unixy shell prompt:
 
        cmd /c configure.bat
      or
        command.com /c configure.bat
 
   3. Run the Make utility suitable for your environment.  If you build
-     with the Microsoft's Visual C compiler (but see notes about using
-     VC++ 8.0 and later below):
+     with the Microsoft's Visual C compiler:
 
        nmake
 
 * Supported development environments
 
   To compile Emacs, you will need either Microsoft Visual C++ 2.0, or
-  later up to 7.0, and nmake, or a Windows port of GCC 2.95 or later
-  with MinGW and W32 API support and a port of GNU Make.  You can use
-  the Cygwin ports of GCC, but Emacs requires the MinGW headers and
-  libraries to build (latest versions of the Cygwin toolkit, at least
-  since v1.3.3, include the MinGW headers and libraries as an integral
-  part).
-
-  Note that building Emacs with Visual Studio 2005 (VC++ 8.0) and
-  later is not supported at this time, due to changes introduced by
-  Microsoft into the libraries shipped with the compiler.
+  later and nmake, or a Windows port of GCC 2.95 or later with MinGW
+  and W32 API support and a port of GNU Make.  You can use the Cygwin
+  ports of GCC, but Emacs requires the MinGW headers and libraries to
+  build (latest versions of the Cygwin toolkit, at least since v1.3.3,
+  include the MinGW headers and libraries as an integral part).
 
   The rest of this file assumes you have a working development
-  environment.  If you just installed  such an environment, try
+  environment.  If you just installed such an environment, try
   building a trivial C "Hello world" program, and see if it works.  If
   it doesn't work, resolve that problem first!  If you use Microsoft
   Visual Studio .NET 2003, don't forget to run the VCVARS32.BAT batch
   file from the `Bin' subdirectory of the directory where you have
-  installed VS.NET.
+  installed VS.NET.  With other versions of MSVC, run the SetEnv.cmd
+  batch file from the `Bin' subdirectory of the directory where you
+  have the SDK installed.
 
   If you use the MinGW port of GCC and GNU Make to build Emacs, there
   are some compatibility issues wrt Make and the shell that is run by
index bbb5602..46d4acf 100644 (file)
@@ -193,6 +193,11 @@ OLE32              = -lole32
 UNISCRIBE      = -lusp10
 UUID           = -luuid
 
+# Used by src/makefile.w32-in, since Nmake barfs on $(func SOMETHING)
+OBJ0_c         = $(patsubst $(BLD)%.$(O),$(CURDIR)%.c,$(OBJ0))
+OBJ1_c         = $(patsubst $(BLD)%.$(O),$(CURDIR)%.c,$(OBJ1))
+OBJ2_c         = $(patsubst $(BLD)%.$(O),$(CURDIR)%.c,$(OBJ2))
+
 ifdef NOOPT
 DEBUG_CFLAGS   = -DEMACSDEBUG
 else
index 0563185..194f075 100644 (file)
@@ -313,15 +313,15 @@ clean-other-dirs-nmake:
        $(MAKE) $(MFLAGS) clean\r
        cd ..\doc\lispintro\r
        $(MAKE) $(MFLAGS) clean\r
-       cd ..\doc\lispref\r
+       cd ..\lispref\r
        $(MAKE) $(MFLAGS) clean\r
-       cd ..\leim\r
+       cd ..\..\leim\r
        $(MAKE) $(MFLAGS) clean\r
        cd ..\doc\emacs\r
        $(MAKE) $(MFLAGS) clean\r
-       cd ..\doc\misc\r
+       cd ..\misc\r
        $(MAKE) $(MFLAGS) clean\r
-       cd ..\nt\r
+       cd ..\..\nt\r
 \r
 clean-other-dirs-gmake:\r
        $(MAKE) $(MFLAGS) $(XMFLAGS) -C ../lib clean\r
@@ -381,13 +381,13 @@ distclean-other-dirs-nmake:
        $(MAKE) $(MFLAGS) distclean\r
        cd ..\doc\emacs\r
        $(MAKE) $(MFLAGS) distclean\r
-       cd ..\doc\misc\r
+       cd ..\misc\r
        $(MAKE) $(MFLAGS) distclean\r
-       cd ..\doc\lispintro\r
+       cd ..\lispintro\r
        $(MAKE) $(MFLAGS) distclean\r
-       cd ..\doc\lispref\r
+       cd ..\lispref\r
        $(MAKE) $(MFLAGS) distclean\r
-       cd ..\nt\r
+       cd ..\..\nt\r
 \r
 distclean-other-dirs-gmake:\r
        $(MAKE) $(MFLAGS) $(XMFLAGS) -C ../lib distclean\r
@@ -415,13 +415,13 @@ maintainer-clean-other-dirs-nmake:
        $(MAKE) $(MFLAGS) maintainer-clean\r
        cd ..\doc\emacs\r
        $(MAKE) $(MFLAGS) maintainer-clean\r
-       cd ..\doc\misc\r
+       cd ..\misc\r
        $(MAKE) $(MFLAGS) maintainer-clean\r
-       cd ..\doc\lispintro\r
+       cd ..\lispintro\r
        $(MAKE) $(MFLAGS) maintainer-clean\r
-       cd ..\doc\lispref\r
+       cd ..\lispref\r
        $(MAKE) $(MFLAGS) maintainer-clean\r
-       cd ..\nt\r
+       cd ..\..\nt\r
 \r
 maintainer-clean-other-dirs-gmake:\r
        $(MAKE) $(MFLAGS) $(XMFLAGS) -C ../lib maintainer-clean\r
index 6c0922d..4a7d93d 100644 (file)
@@ -109,7 +109,15 @@ RC         = rc
 RC_OUT         = -Fo\r
 RC_INCLUDE     = -i\r
 \r
-libc           = libc.lib\r
+USE_CRT_DLL    = 1\r
+\r
+!ifdef USE_CRT_DLL\r
+libc           = msvcrt$(D).lib\r
+EMACS_EXTRA_C_FLAGS= -D_DLL -D_MT -DUSE_CRT_DLL=1\r
+!else\r
+libc           = libcmt$(D).lib\r
+EMACS_EXTRA_C_FLAGS= -D_MT\r
+!endif\r
 baselibs       =\r
 O              = obj\r
 A              = lib\r
@@ -146,9 +154,13 @@ CFLAGS          = -I. $(ARCH_CFLAGS) \
                  $(DEBUG_CFLAGS) $(CHECKING_CFLAGS) $(USER_CFLAGS) $(LOCAL_FLAGS)\r
 ESC_CFLAGS      = -I. $(ARCH_CFLAGS) \\r
                  $(DEBUG_CFLAGS) $(CHECKING_CFLAGS) $(ESC_USER_CFLAGS) $(LOCAL_FLAGS)\r
-EMACS_EXTRA_C_FLAGS =\r
 \r
-SYS_LDFLAGS    = -nologo -release -incremental:no -version:3.10 -swaprun:cd -swaprun:net setargv.obj\r
+#SYS_LDFLAGS   = -nologo -release -incremental:no -version:3.10 -swaprun:cd -swaprun:net setargv.obj\r
+!ifdef NOOPT\r
+SYS_LDFLAGS    = -nologo -manifest -dynamicbase:no -debug -incremental:no -version:3.10 -swaprun:cd -swaprun:net setargv.obj\r
+!else\r
+SYS_LDFLAGS    = -nologo -manifest -dynamicbase:no -release -incremental:no -version:3.10 -swaprun:cd -swaprun:net setargv.obj\r
+!endif\r
 \r
 # see comments in allocate_heap in w32heap.c before changing any of the\r
 # -stack, -heap, or -base settings.\r
@@ -184,16 +196,20 @@ DEL_TREE  = rm -r
 !ifdef NODEBUG\r
 DEBUG_FLAG =\r
 DEBUG_LINK =\r
+D =\r
 !else\r
 DEBUG_FLAG = -Zi\r
-DEBUG_LINK = -debug:full\r
+DEBUG_LINK = -debug\r
+D = d\r
 !endif\r
 \r
 !if "$(ARCH)" == "i386"\r
 !ifdef NOOPT\r
-ARCH_CFLAGS     = -nologo -c -Zel -W2 -H63 -Od -G3d -Zp8 $(DEBUG_FLAG)\r
+#ARCH_CFLAGS     = -nologo -c -Zel -W2 -H63 -Od -G3d -Zp8 $(DEBUG_FLAG)\r
+ARCH_CFLAGS     = -nologo -D_X86_=1 -c -Zl -Zp8 -W2 -Od -Gd $(DEBUG_FLAG)\r
 !else\r
-ARCH_CFLAGS     = -nologo -c -Zel -W2 -H63 -Oxsb2 -Oy- -G6dF -Zp8 $(DEBUG_FLAG)\r
+#ARCH_CFLAGS     = -nologo -c -Zel -W2 -H63 -Oxsb2 -Oy- -G6dF -Zp8 $(DEBUG_FLAG)\r
+ARCH_CFLAGS     = -nologo -D_X86_=1 -c -Zl -Zp8 -W2 -Oi -Ot -Oy- -Ob2 -GF -Gy -Gd $(DEBUG_FLAG)\r
 !endif\r
 ARCH_LDFLAGS   = $(SYS_LDFLAGS)\r
 \r
index 624ad71..83e6154 100644 (file)
@@ -1,3 +1,38 @@
+2011-11-05  Eli Zaretskii  <eliz@gnu.org>
+
+       Support MSVC build with newer versions of Visual Studio.
+       * makefile.w32-in (TAGS-gmake): Don't use $(patsubst ...), as
+       Nmake barfs on that.  Use $(OBJ*_c) variables instead, defined on
+       nt/gmake.defs.
+
+       * lisp.h (ENUM_BF): New macro, for enumerated types in bitfields,
+       which are not supported by MSVC.
+       (Lisp_Symbol, Lisp_Misc_Any, Lisp_Marker, Lisp_Misc_Overlay)
+       (Lisp_Save_Value, Lisp_Free): Use ENUM_BF for enumerated types in
+       bitfields.
+       (Lisp_Object) [USE_LISP_UNION_TYPE]: Use ENUM_BF for enumerated
+       types in bitfields.
+       (DEFUN) [_MSC_VER]: Define in a different way for MSVC.
+
+       * w32fns.c [_MSC_VER]: DECLARE_HANDLE for any MSVC version.
+
+2011-11-05  Fabrice Popineau  <fabrice.popineau@supelec.fr> (tiny change)
+
+       Support MSVC build with newer versions of Visual Studio.
+       * w32.c: Don't include w32api.h for MSVC.
+       (init_environment) [_MSC_VER]: Call sys_access, not _access.
+
+       * s/ms-w32.h <sigset_t, ssize_t> [_MSC_VER]: Typedefs for MSVC.
+       [_MSC_VER]: Include sys/timeb.h, sys/stat.h, and signal.h.
+       (fstat, stat, utime) [_MSC_VER]: Redirect to their sys_* cousins.
+       (malloc, free, realloc, calloc) [_MSC_VER]: Always redirect to the
+       e_* cousins.
+       (alloca) [_MSC_VER]: Define to _alloca.
+
+       * lisp.h (DECL_ALIGN) [_MSC_VER]: Define for MSVC.
+
+       * regex.c <re_char> [_MSC_VER]: A separate definition for MSVC.
+
 2011-11-04  Eli Zaretskii  <eliz@gnu.org>
 
        * xdisp.c (note_mouse_highlight): If either of
index df8812f..f3c704b 100644 (file)
@@ -168,6 +168,9 @@ extern int suppress_checking EXTERNALLY_VISIBLE;
 #  if HAVE_ATTRIBUTE_ALIGNED
 #   define DECL_ALIGN(type, var) \
      type __attribute__ ((__aligned__ (1 << GCTYPEBITS))) var
+#  elif defined(_MSC_VER)
+#   define DECL_ALIGN(type, var) \
+     type __declspec(align(1 << GCTYPEBITS)) var
 #  else
      /* What directives do other compilers use?  */
 #  endif
@@ -225,6 +228,15 @@ extern int suppress_checking EXTERNALLY_VISIBLE;
 # endif
 #endif
 
+/* Stolen from GDB.  The only known compiler that doesn't support
+   enums in bitfields is MSVC.  */
+#ifdef _MSC_VER
+#define ENUM_BF(TYPE) unsigned int
+#else
+#define ENUM_BF(TYPE) enum TYPE
+#endif
+
+
 enum Lisp_Type
   {
     /* Integer.  XINT (obj) is the integer value.  */
@@ -315,12 +327,12 @@ union Lisp_Object
        /* Use explict signed, the signedness of a bit-field of type
           int is implementation defined.  */
        signed EMACS_INT val  : VALBITS;
-       enum Lisp_Type type : GCTYPEBITS;
+       ENUM_BF (Lisp_Type) type : GCTYPEBITS;
       } s;
     struct
       {
        EMACS_UINT val : VALBITS;
-       enum Lisp_Type type : GCTYPEBITS;
+       ENUM_BF (Lisp_Type) type : GCTYPEBITS;
       } u;
   }
 Lisp_Object;
@@ -336,14 +348,14 @@ union Lisp_Object
 
     struct
       {
-       enum Lisp_Type type : GCTYPEBITS;
+       ENUM_BF (Lisp_Type) type : GCTYPEBITS;
        /* Use explict signed, the signedness of a bit-field of type
           int is implementation defined.  */
        signed EMACS_INT val  : VALBITS;
       } s;
     struct
       {
-       enum Lisp_Type type : GCTYPEBITS;
+       ENUM_BF (Lisp_Type) type : GCTYPEBITS;
        EMACS_UINT val : VALBITS;
       } u;
   }
@@ -1096,7 +1108,7 @@ struct Lisp_Symbol
      1 : it's a varalias, the value is really in the `alias' symbol.
      2 : it's a localized var, the value is in the `blv' object.
      3 : it's a forwarding variable, the value is in `forward'.  */
-  enum symbol_redirect redirect : 3;
+  ENUM_BF (symbol_redirect) redirect : 3;
 
   /* Non-zero means symbol is constant, i.e. changing its value
      should signal an error.  If the value is 3, then the var
@@ -1309,7 +1321,7 @@ struct Lisp_Hash_Table
 
 struct Lisp_Misc_Any           /* Supertype of all Misc types.  */
 {
-  enum Lisp_Misc_Type type : 16;               /* = Lisp_Misc_??? */
+  ENUM_BF (Lisp_Misc_Type) type : 16;          /* = Lisp_Misc_??? */
   unsigned gcmarkbit : 1;
   int spacer : 15;
   /* Make it as long as "Lisp_Free without padding".  */
@@ -1318,7 +1330,7 @@ struct Lisp_Misc_Any              /* Supertype of all Misc types.  */
 
 struct Lisp_Marker
 {
-  enum Lisp_Misc_Type type : 16;               /* = Lisp_Misc_Marker */
+  ENUM_BF (Lisp_Misc_Type) type : 16;          /* = Lisp_Misc_Marker */
   unsigned gcmarkbit : 1;
   int spacer : 13;
   /* This flag is temporarily used in the functions
@@ -1468,7 +1480,7 @@ struct Lisp_Overlay
    I.e. 9words plus 2 bits, 3words of which are for external linked lists.
 */
   {
-    enum Lisp_Misc_Type type : 16;     /* = Lisp_Misc_Overlay */
+    ENUM_BF (Lisp_Misc_Type) type : 16;        /* = Lisp_Misc_Overlay */
     unsigned gcmarkbit : 1;
     int spacer : 15;
     struct Lisp_Overlay *next;
@@ -1487,7 +1499,7 @@ struct Lisp_Kboard_Objfwd
    This type of object is used in the arg to record_unwind_protect.  */
 struct Lisp_Save_Value
   {
-    enum Lisp_Misc_Type type : 16;     /* = Lisp_Misc_Save_Value */
+    ENUM_BF (Lisp_Misc_Type) type : 16;        /* = Lisp_Misc_Save_Value */
     unsigned gcmarkbit : 1;
     int spacer : 14;
     /* If DOGC is set, POINTER is the address of a memory
@@ -1501,7 +1513,7 @@ struct Lisp_Save_Value
 /* A miscellaneous object, when it's on the free list.  */
 struct Lisp_Free
   {
-    enum Lisp_Misc_Type type : 16;     /* = Lisp_Misc_Free */
+    ENUM_BF (Lisp_Misc_Type) type : 16;        /* = Lisp_Misc_Free */
     unsigned gcmarkbit : 1;
     int spacer : 15;
     union Lisp_Misc *chain;
@@ -1896,13 +1908,23 @@ typedef struct {
 
 /* This version of DEFUN declares a function prototype with the right
    arguments, so we can catch errors with maxargs at compile-time.  */
-#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \
-  Lisp_Object fnname DEFUN_ARGS_ ## maxargs ;                          \
-  static DECL_ALIGN (struct Lisp_Subr, sname) =                                \
-    { PVEC_SUBR,                                                       \
-      { .a ## maxargs = fnname },                              \
-      minargs, maxargs, lname, intspec, 0};                            \
-  Lisp_Object fnname
+#ifdef _MSC_VER
+#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc)    \
+   Lisp_Object fnname DEFUN_ARGS_ ## maxargs ;                         \
+   static DECL_ALIGN (struct Lisp_Subr, sname) =                       \
+     { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)),   \
+      { (Lisp_Object (__cdecl *)(void))fnname },                        \
+       minargs, maxargs, lname, intspec, 0};                           \
+   Lisp_Object fnname
+#else  /* not _MSC_VER */
+#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc)    \
+   Lisp_Object fnname DEFUN_ARGS_ ## maxargs ;                         \
+   static DECL_ALIGN (struct Lisp_Subr, sname) =                       \
+     { PVEC_SUBR,                                                      \
+      { .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.  */
index 53cb5f8..bee8576 100644 (file)
@@ -348,11 +348,11 @@ TAGS-LISP: $(OBJ0) $(OBJ1) $(OBJ2)
 TAGS-gmake:
        ../lib-src/$(BLD)/etags.exe --include=TAGS-LISP --include=../nt/TAGS \
          --regex=@../nt/emacs-src.tags \
-         $(patsubst $(BLD)%.$(O),$(CURDIR)%.c,$(OBJ0))
+         $(OBJ0_c)
        ../lib-src/$(BLD)/etags.exe -a --regex=@../nt/emacs-src.tags \
-         $(patsubst $(BLD)%.$(O),$(CURDIR)%.c,$(OBJ1))
+         $(OBJ1_c)
        ../lib-src/$(BLD)/etags.exe -a --regex=@../nt/emacs-src.tags \
-         $(patsubst $(BLD)%.$(O),$(CURDIR)%.c,$(OBJ2)) \
+         $(OBJ2_c) \
          $(CURDIR)/*.h $(CURDIR)/m/intel386.h $(CURDIR)/s/ms-w32.h
 
 TAGS-nmake:
index 8033ab9..ccbad58 100644 (file)
@@ -530,7 +530,11 @@ init_syntax_once (void)
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 
 /* Type of source-pattern and string chars.  */
+#ifdef _MSC_VER
+typedef unsigned char re_char;
+#else
 typedef const unsigned char re_char;
+#endif
 
 typedef char boolean;
 #define false 0
index 813c3ce..519f6e7 100644 (file)
@@ -86,6 +86,12 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #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;
+typedef int ssize_t;
+#endif
+
 struct sigaction {
   int sa_flags;
   void (*sa_handler)(int);
@@ -181,6 +187,12 @@ struct sigaction {
 
 #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
@@ -270,6 +282,15 @@ typedef int pid_t;
 #define utime    _utime
 #endif
 
+#ifdef _MSC_VER
+/* MSVC gets link-time errors without these redirections.  */
+#define fstat(a, b) sys_fstat(a, b)
+#define stat(a, b)  sys_stat(a, b)
+#if _MSC_VER >= 1400
+#define utime       sys_utime
+#endif
+#endif
+
 /* This is hacky, but is necessary to avoid warnings about macro
    redefinitions using the SDK compilers.  */
 #ifndef __STDC__
@@ -317,13 +338,17 @@ extern char *get_emacs_configuration_options (void);
 #define _WINSOCK_H
 
 /* Defines size_t and alloca ().  */
-#ifdef USE_CRT_DLL
+#if (defined(_MSC_VER) && defined(emacs)) || defined(USE_CRT_DLL)
 #define malloc e_malloc
 #define free   e_free
 #define realloc e_realloc
 #define calloc e_calloc
 #endif
+#ifdef _MSC_VER
+#define alloca _alloca
+#else
 #include <malloc.h>
+#endif
 
 #include <sys/stat.h>
 
index 42546fc..f17e987 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -94,7 +94,9 @@ typedef struct _MEMORY_STATUS_EX {
 
 #include <tlhelp32.h>
 #include <psapi.h>
+#ifndef _MSC_VER
 #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 supplied with MinGW 3.15
@@ -1547,7 +1549,12 @@ init_environment (char ** argv)
         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.  */
+#ifdef _MSC_VER
+      /* MSVC's _access crashes with D_OK.  */
+      if (tmp && sys_access (tmp, D_OK) == 0)
+#else
       if (tmp && _access (tmp, D_OK) == 0)
+#endif
        {
          char * var = alloca (strlen (tmp) + 8);
          sprintf (var, "TMPDIR=%s", tmp);
index f7ba1c5..6380a87 100644 (file)
@@ -140,8 +140,8 @@ struct MONITOR_INFO
     DWORD   dwFlags;
 };
 
-/* Reportedly, VS 6 does not have this in its headers.  */
-#if defined (_MSC_VER) && _MSC_VER < 1300
+/* Reportedly, MSVC does not have this in its headers.  */
+#ifdef _MSC_VER
 DECLARE_HANDLE(HMONITOR);
 #endif