From a6fc3b5c539c0a35e4447a12cc395294952d7561 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 5 Nov 2011 13:34:56 +0200 Subject: [PATCH] Support MSVC build with newer versions of Visual Studio. Small portions of the changes by Fabrice Popineau . 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 [_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 [_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 --- ChangeLog | 5 ++++ lib/makefile.w32-in | 4 +++- nt/ChangeLog | 18 +++++++++++++++ nt/INSTALL | 42 +++++++++++++++++++++------------- nt/gmake.defs | 5 ++++ nt/makefile.w32-in | 24 +++++++++---------- nt/nmake.defs | 28 ++++++++++++++++++----- src/ChangeLog | 35 ++++++++++++++++++++++++++++ src/lisp.h | 56 +++++++++++++++++++++++++++++++-------------- src/makefile.w32-in | 6 ++--- src/regex.c | 4 ++++ src/s/ms-w32.h | 27 +++++++++++++++++++++- src/w32.c | 7 ++++++ src/w32fns.c | 4 ++-- 14 files changed, 207 insertions(+), 58 deletions(-) diff --git a/ChangeLog b/ChangeLog index f41fe08d87..68f5042d7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-11-05 Eli Zaretskii + + * lib/makefile.w32-in (FRC): New dummy target. + (TAGS): Depend on FRC. + 2011-11-04 Glenn Morris * configure.in: Increase minimum GnuTLS version to 2.6.6. (Bug#9929) diff --git a/lib/makefile.w32-in b/lib/makefile.w32-in index 6b451dd14e..d530425887 100644 --- a/lib/makefile.w32-in +++ b/lib/makefile.w32-in @@ -50,7 +50,9 @@ all: stamp_BLD $(ALL) ### TAGS ### -TAGS: +FRC: + +TAGS: FRC ../lib-src/$(BLD)/etags.exe *.c *.h ### DEPENDENCIES ### diff --git a/nt/ChangeLog b/nt/ChangeLog index 55535c460f..21ab0c477b 100644 --- a/nt/ChangeLog +++ b/nt/ChangeLog @@ -1,3 +1,21 @@ +2011-11-05 Eli Zaretskii + + 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 (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 * runemacs.c (ensure_unicows_dll): New function, tries to load diff --git a/nt/INSTALL b/nt/INSTALL index 613610890a..63285047a6 100644 --- a/nt/INSTALL +++ b/nt/INSTALL @@ -21,19 +21,32 @@ 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 @@ -101,24 +114,21 @@ * 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 diff --git a/nt/gmake.defs b/nt/gmake.defs index bbb560264c..46d4acf76d 100644 --- a/nt/gmake.defs +++ b/nt/gmake.defs @@ -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 diff --git a/nt/makefile.w32-in b/nt/makefile.w32-in index 05631855f6..194f0759bb 100644 --- a/nt/makefile.w32-in +++ b/nt/makefile.w32-in @@ -313,15 +313,15 @@ clean-other-dirs-nmake: $(MAKE) $(MFLAGS) clean cd ..\doc\lispintro $(MAKE) $(MFLAGS) clean - cd ..\doc\lispref + cd ..\lispref $(MAKE) $(MFLAGS) clean - cd ..\leim + cd ..\..\leim $(MAKE) $(MFLAGS) clean cd ..\doc\emacs $(MAKE) $(MFLAGS) clean - cd ..\doc\misc + cd ..\misc $(MAKE) $(MFLAGS) clean - cd ..\nt + cd ..\..\nt clean-other-dirs-gmake: $(MAKE) $(MFLAGS) $(XMFLAGS) -C ../lib clean @@ -381,13 +381,13 @@ distclean-other-dirs-nmake: $(MAKE) $(MFLAGS) distclean cd ..\doc\emacs $(MAKE) $(MFLAGS) distclean - cd ..\doc\misc + cd ..\misc $(MAKE) $(MFLAGS) distclean - cd ..\doc\lispintro + cd ..\lispintro $(MAKE) $(MFLAGS) distclean - cd ..\doc\lispref + cd ..\lispref $(MAKE) $(MFLAGS) distclean - cd ..\nt + cd ..\..\nt distclean-other-dirs-gmake: $(MAKE) $(MFLAGS) $(XMFLAGS) -C ../lib distclean @@ -415,13 +415,13 @@ maintainer-clean-other-dirs-nmake: $(MAKE) $(MFLAGS) maintainer-clean cd ..\doc\emacs $(MAKE) $(MFLAGS) maintainer-clean - cd ..\doc\misc + cd ..\misc $(MAKE) $(MFLAGS) maintainer-clean - cd ..\doc\lispintro + cd ..\lispintro $(MAKE) $(MFLAGS) maintainer-clean - cd ..\doc\lispref + cd ..\lispref $(MAKE) $(MFLAGS) maintainer-clean - cd ..\nt + cd ..\..\nt maintainer-clean-other-dirs-gmake: $(MAKE) $(MFLAGS) $(XMFLAGS) -C ../lib maintainer-clean diff --git a/nt/nmake.defs b/nt/nmake.defs index 6c0922d78b..4a7d93d40d 100644 --- a/nt/nmake.defs +++ b/nt/nmake.defs @@ -109,7 +109,15 @@ RC = rc RC_OUT = -Fo RC_INCLUDE = -i -libc = libc.lib +USE_CRT_DLL = 1 + +!ifdef USE_CRT_DLL +libc = msvcrt$(D).lib +EMACS_EXTRA_C_FLAGS= -D_DLL -D_MT -DUSE_CRT_DLL=1 +!else +libc = libcmt$(D).lib +EMACS_EXTRA_C_FLAGS= -D_MT +!endif baselibs = O = obj A = lib @@ -146,9 +154,13 @@ CFLAGS = -I. $(ARCH_CFLAGS) \ $(DEBUG_CFLAGS) $(CHECKING_CFLAGS) $(USER_CFLAGS) $(LOCAL_FLAGS) ESC_CFLAGS = -I. $(ARCH_CFLAGS) \ $(DEBUG_CFLAGS) $(CHECKING_CFLAGS) $(ESC_USER_CFLAGS) $(LOCAL_FLAGS) -EMACS_EXTRA_C_FLAGS = -SYS_LDFLAGS = -nologo -release -incremental:no -version:3.10 -swaprun:cd -swaprun:net setargv.obj +#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. @@ -184,16 +196,20 @@ DEL_TREE = rm -r !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 -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 -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) diff --git a/src/ChangeLog b/src/ChangeLog index 624ad71379..83e6154fb5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,38 @@ +2011-11-05 Eli Zaretskii + + 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 (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 [_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 [_MSC_VER]: A separate definition for MSVC. + 2011-11-04 Eli Zaretskii * xdisp.c (note_mouse_highlight): If either of diff --git a/src/lisp.h b/src/lisp.h index df8812f73b..f3c704bc76 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -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. */ diff --git a/src/makefile.w32-in b/src/makefile.w32-in index 53cb5f857a..bee857694e 100644 --- a/src/makefile.w32-in +++ b/src/makefile.w32-in @@ -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: diff --git a/src/regex.c b/src/regex.c index 8033ab9eda..ccbad58abb 100644 --- a/src/regex.c +++ b/src/regex.c @@ -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 diff --git a/src/s/ms-w32.h b/src/s/ms-w32.h index 813c3cef11..519f6e7bc6 100644 --- a/src/s/ms-w32.h +++ b/src/s/ms-w32.h @@ -86,6 +86,12 @@ along with GNU Emacs. If not, see . */ #define IS_ANY_SEP(_c_) (IS_DIRECTORY_SEP (_c_) || IS_DEVICE_SEP (_c_)) #include + +#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 +#include +#include +#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 +#endif #include diff --git a/src/w32.c b/src/w32.c index 42546fc8d4..f17e987f43 100644 --- a/src/w32.c +++ b/src/w32.c @@ -94,7 +94,9 @@ typedef struct _MEMORY_STATUS_EX { #include #include +#ifndef _MSC_VER #include +#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); diff --git a/src/w32fns.c b/src/w32fns.c index f7ba1c59e7..6380a87098 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -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 -- 2.20.1