Skip to content

Commit d738388

Browse files
committed
patch 8.0.0638: cannot build with new MSVC version
Problem: Cannot build with new MSVC version VS2017. Solution: Change the compiler arguments. (Leonardo Manera, closes #1731, closes #1747)
1 parent 21b34b6 commit d738388

3 files changed

Lines changed: 119 additions & 18 deletions

File tree

src/GvimExt/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Makefile for GvimExt, using MSVC
22
# Options:
33
# DEBUG=yes Build debug version (for VC7 and maybe later)
4+
# CPUARG= /arch:IA32/AVX/etc, call from main makefile to set
5+
# automatically from CPUNR
46
#
57

6-
TARGETOS=WINNT
8+
TARGETOS = WINNT
9+
710
!ifndef APPVER
8-
APPVER=5.0
11+
APPVER = 5.01
912
!endif
1013

1114
!if "$(DEBUG)" != "yes"
@@ -37,6 +40,9 @@ CPU = i386
3740
!include <Win32.mak>
3841
!endif
3942

43+
# include CPUARG
44+
cflags = $(cflags) $(CPUARG)
45+
4046
all: gvimext.dll
4147

4248
gvimext.dll: gvimext.obj \

src/Make_mvc.mak

Lines changed: 109 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Makefile for Vim on Win32 (Windows XP/2003/Vista/7/8/10) and Win64,
22
# using the Microsoft Visual C++ compilers. Known to work with VC5, VC6 (VS98),
33
# VC7.0 (VS2002), VC7.1 (VS2003), VC8 (VS2005), VC9 (VS2008), VC10 (VS2010),
4-
# VC11 (VS2012), VC12 (VS2013) and VC14 (VS2015)
4+
# VC11 (VS2012), VC12 (VS2013), VC14 (VS2015) and VC15 (VS2017)
55
#
66
# To build using other Windows compilers, see INSTALLpc.txt
77
#
@@ -108,10 +108,15 @@
108108
#
109109
# Optimization: OPTIMIZE=[SPACE, SPEED, MAXSPEED] (default is MAXSPEED)
110110
#
111-
# Processor Version: CPUNR=[i386, i486, i586, i686, pentium4] (default is
112-
# i386)
111+
# Processor Version: CPUNR=[any, i586, i686, sse, sse2, avx, avx2] (default is
112+
# any)
113+
# avx is available on Visual C++ 2010 and after.
114+
# avx2 is available on Visual C++ 2013 Update 2 and after.
113115
#
114-
# Version Support: WINVER=[0x0501, 0x0600] (default is 0x0501)
116+
# Version Support: WINVER=[0x0501, 0x0502, 0x0600, 0x0601, 0x0602,
117+
# 0x0603, 0x0A00] (default is 0x0501)
118+
# Supported versions depends on your target SDK, check SDKDDKVer.h
119+
# See https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt
115120
#
116121
# Debug version: DEBUG=yes
117122
# Mapfile: MAP=[no, yes or lines] (default is yes)
@@ -270,11 +275,31 @@ MAKEFLAGS_GVIMEXT = DEBUG=yes
270275
!if $(MSVCVER) < 1900
271276
MSVC_MAJOR = ($(MSVCVER) / 100 - 6)
272277
MSVCRT_VER = ($(MSVCVER) / 10 - 60)
278+
# Visual C++ 2017 needs special handling
279+
# it has an _MSC_VER of 1910->14.1, but is actually v15 with runtime v140
280+
!elseif $(MSVCVER) == 1910
281+
MSVC_MAJOR = 15
282+
MSVCRT_VER = 140
273283
!else
274284
MSVC_MAJOR = ($(MSVCVER) / 100 - 5)
275285
MSVCRT_VER = ($(MSVCVER) / 10 - 50)
276286
!endif
277287

288+
# Calculate MSVC_FULL for Visual C++ 8 and up.
289+
!if $(MSVC_MAJOR) >= 8
290+
! if [echo MSVC_FULL=_MSC_FULL_VER> msvcfullver.c && $(CC) /EP msvcfullver.c > msvcfullver.~ 2> nul]
291+
! message *** ERROR
292+
! message Cannot run Visual C to determine its version. Make sure cl.exe is in your PATH.
293+
! message This can usually be done by running "vcvarsall.bat", located in the bin directory where Visual Studio was installed.
294+
! error Make aborted.
295+
! else
296+
! include msvcfullver.~
297+
! if [del msvcfullver.c msvcfullver.~]
298+
! endif
299+
! endif
300+
!endif
301+
302+
278303
# Calculate MSVCRT_VER
279304
!if [(set /a MSVCRT_VER="$(MSVCRT_VER)" > nul) && set MSVCRT_VER > msvcrtver.~] == 0
280305
!include msvcrtver.~
@@ -446,27 +471,95 @@ DEL_TREE = rmdir /s /q
446471
INTDIR=$(OBJDIR)
447472
OUTDIR=$(OBJDIR)
448473

474+
### Validate CPUNR
475+
!ifndef CPUNR
476+
# default to untargeted code
477+
CPUNR = any
478+
!elseif "$(CPUNR)" == "i386" || "$(CPUNR)" == "i486"
479+
# alias i386 and i486 to i586
480+
! message *** WARNING CPUNR=$(CPUNR) is not a valid target architecture.
481+
! message Windows XP is the minimum target OS, with a minimum target
482+
! message architecture of i586.
483+
! message Retargeting to i586
484+
CPUNR = i586
485+
!elseif "$(CPUNR)" == "pentium4"
486+
# alias pentium4 to sse2
487+
! message *** WARNING CPUNR=pentium4 is deprecated in favour of sse2.
488+
! message Retargeting to sse2.
489+
CPUNR = sse2
490+
!elseif "$(CPUNR)" != "any" && "$(CPUNR)" != "i586" && "$(CPUNR)" != "i686" && "$(CPUNR)" != "sse" && "$(CPUNR)" != "sse2" && "$(CPUNR)" != "avx" && "$(CPUNR)" != "avx2"
491+
! error *** ERROR Unknown target architecture "$(CPUNR)". Make aborted.
492+
!endif
493+
449494
# Convert processor ID to MVC-compatible number
450495
!if $(MSVC_MAJOR) < 8
451-
!if "$(CPUNR)" == "i386"
452-
CPUARG = /G3
453-
!elseif "$(CPUNR)" == "i486"
454-
CPUARG = /G4
455-
!elseif "$(CPUNR)" == "i586"
496+
! if "$(CPUNR)" == "i586"
456497
CPUARG = /G5
457-
!elseif "$(CPUNR)" == "i686"
498+
! elseif "$(CPUNR)" == "i686"
458499
CPUARG = /G6
459-
!elseif "$(CPUNR)" == "pentium4"
500+
! elseif "$(CPUNR)" == "sse"
501+
CPUARG = /G6 /arch:SSE
502+
! elseif "$(CPUNR)" == "sse2"
460503
CPUARG = /G7 /arch:SSE2
461-
!else
504+
! elseif "$(CPUNR)" == "avx" || "$(CPUNR)" == "avx2"
505+
! message AVX/AVX2 Instruction Sets are not supported by Visual C++ v$(MSVC_MAJOR)
506+
! message Falling back to SSE2
507+
CPUARG = /G7 /arch:SSE2
508+
! elseif "$(CPUNR)" == "any"
462509
CPUARG =
463-
!endif
510+
! endif
464511
!else
465-
# VC8/9/10 only allows specifying SSE architecture but only for 32bit
466-
!if "$(ASSEMBLY_ARCHITECTURE)" == "i386" && "$(CPUNR)" == "pentium4"
512+
# IA32/SSE/SSE2 are only supported on x86
513+
! if "$(ASSEMBLY_ARCHITECTURE)" == "i386" && ("$(CPUNR)" == "i586" || "$(CPUNR)" == "i686" || "$(CPUNR)" == "any")
514+
# VC<11 generates fp87 code by default
515+
! if $(MSVC_MAJOR) < 11
516+
CPUARG =
517+
# VC>=11 needs explicit insturctions to generate fp87 code
518+
! else
519+
CPUARG = /arch:IA32
520+
! endif
521+
! elseif "$(ASSEMBLY_ARCHITECTURE)" == "i386" && "$(CPUNR)" == "sse"
522+
CPUARG = /arch:SSE
523+
! elseif "$(ASSEMBLY_ARCHITECTURE)" == "i386" && "$(CPUNR)" == "sse2"
467524
CPUARG = /arch:SSE2
525+
! elseif "$(CPUNR)" == "avx"
526+
# AVX is only supported by VC 10 and up
527+
! if $(MSVC_MAJOR) < 10
528+
! message AVX Instruction Set is not supported by Visual C++ v$(MSVC_MAJOR)
529+
! if "$(ASSEMBLY_ARCHITECTURE)" == "i386"
530+
! message Falling back to SSE2
531+
CPUARG = /arch:SSE2
532+
! else
533+
CPUARG =
534+
! endif
535+
! else
536+
CPUARG = /arch:AVX
537+
! endif
538+
! elseif "$(CPUNR)" == "avx2"
539+
# AVX is only supported by VC 10 and up
540+
! if $(MSVC_MAJOR) < 10
541+
! message AVX2 Instruction Set is not supported by Visual C++ v$(MSVC_MAJOR)
542+
! if "$(ASSEMBLY_ARCHITECTURE)" == "i386"
543+
! message Falling back to SSE2
544+
CPUARG = /arch:SSE2
545+
! else
546+
CPUARG =
547+
! endif
548+
# AVX2 is only supported by VC 12U2 and up
549+
# 180030501 is the full version number for Visual Studio 2013/VC 12 Update 2
550+
! elseif $(MSVC_FULL) < 180030501
551+
! message AVX2 Instruction Set is not supported by Visual C++ v$(MSVC_MAJOR)-$(MSVC_FULL)
552+
! message Falling back to AVX
553+
CPUARG = /arch:AVX
554+
! else
555+
CPUARG = /arch:AVX2
556+
! endif
557+
! endif
468558
!endif
469-
!endif
559+
560+
# Pass CPUARG to GVimExt, to avoid using version-dependent defaults
561+
MAKEFLAGS_GVIMEXT = $(MAKEFLAGS_GVIMEXT) CPUARG="$(CPUARG)"
562+
470563

471564
LIBC =
472565
DEBUGINFO = /Zi

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
638,
767769
/**/
768770
637,
769771
/**/

0 commit comments

Comments
 (0)