Quantcast
Channel: Nomad Software » Gotcha
Viewing all articles
Browse latest Browse all 4

Compiling Vim and GVim 64bit on Windows 7

$
0
0

This post was prompted by trying to compile Vim as a 64 bit executable on Windows7 using only freely available tools. To be honest it has been a total pain in the arse and taken a lot of experimentation so i’d though i’d share how i eventually did it.

Get the Vim source code

The source code for Vim is freely available from the website however it’s best to download it using Mercurial that way you get all the latest patches. Mercurial is a source code manager which you will need to install first from http://mercurial.selenic.com. Once Mercurial is installed, open a Windows command prompt and CD to a directory where you would like to place the Vim source and issue the following command.

hg clone https://vim.googlecode.com/hg/ vim

This will download the latest Vim sources from the online Mercurial repository.

Install the necessary tools

The following tools are needed for successfully compiling a 64 bit executable. The SDK contains scripts to setup a correct environment and the earlier versions of Visual Studio Express didn’t contain tools to compile a 64bit executable (which incidentally was a great deal of fun investigating, …not). So the new Visual Studio 2012 Express for Windows Desktop version will need installing. Click the links below to download the installers.

  1. Visual Studio 2012 Express for Windows Desktop
  2. Microsoft Windows SDK for Windows 7 and .NET Framework 4

Hack The Make Files

Yes this is the ugly part, we need to alter the make files that come with the Vim source to support the new Visual Studio 2012 Express version. Not only that but introduce a path variable so a particular file in the SDK can be found. This path variable is probably not needed if the environment was set up correctly but i couldn’t find a script to do that so this simple hack works.

Open this file  vim\src\GvimExt\Makefile  which is inside the Vim source code and change it according to this diff. (The minuses are lines removed and the pluses are lines added.) Here we are just adding the SDK path as a variable.

@@ -10,7 +10,7 @@
 NODEBUG = 1
 !endif

-!include <win32.mak>
+!include $(SDK_INCLUDE_DIR)\Win32.mak

 all: gvimext.dll

Once that is done open the file located at  vim\src\Make_mvc.mak  and make the following changes. Here we are adding the SDK path again and adding support for the new version of Visual Studio Express.

@@ -227,7 +227,7 @@

 # Get all sorts of useful, standard macros from the Platform SDK.

-!include <Win32.mak>
+!include $(SDK_INCLUDE_DIR)\Win32.mak

 # Flag to turn on Win64 compatibility warnings for VC7.x and VC8.
 WP64CHECK = /Wp64
@@ -395,6 +395,9 @@
 !if "$(_NMAKE_VER)" == "10.00.30319.01"
 MSVCVER = 10.0
 !endif
+!if "$(_NMAKE_VER)" == "11.00.50727.1"
+MSVCVER = 11.0
+!endif
 !endif

 # Abort bulding VIM if version of VC is unrecognised.
@@ -409,7 +412,7 @@
 !endif

 # Convert processor ID to MVC-compatible number
-!if ("$(MSVCVER)" != "8.0") && ("$(MSVCVER)" != "9.0") && ("$(MSVCVER)" != "10.0")
+!if ("$(MSVCVER)" != "8.0") && ("$(MSVCVER)" != "9.0") && ("$(MSVCVER)" != "10.0") && ("$(MSVCVER)" != "11.0")
 !if "$(CPUNR)" == "i386"
 CPUARG = /G3
 !elseif "$(CPUNR)" == "i486"
@@ -443,7 +446,7 @@
 OPTFLAG = /Ox
 !endif

-!if ("$(MSVCVER)" == "8.0") || ("$(MSVCVER)" == "9.0") || ("$(MSVCVER)" == "10.0")
+!if ("$(MSVCVER)" == "8.0") || ("$(MSVCVER)" == "9.0") || ("$(MSVCVER)" == "10.0") || ("$(MSVCVER)" == "11.0")
 # Use link time code generation if not worried about size
 !if "$(OPTIMIZE)" != "SPACE"
 OPTFLAG = $(OPTFLAG) /GL
@@ -908,7 +911,7 @@

 # Report link time code generation progress if used.
 !ifdef NODEBUG
-!if ("$(MSVCVER)" == "8.0") || ("$(MSVCVER)" == "9.0") || ("$(MSVCVER)" == "10.0")
+!if ("$(MSVCVER)" == "8.0") || ("$(MSVCVER)" == "9.0") || ("$(MSVCVER)" == "10.0") || ("$(MSVCVER)" == "11.0")
 !if "$(OPTIMIZE)" != "SPACE"
 LINKARGS1 = $(LINKARGS1) /LTCG:STATUS
 !endif

Create a compile batch file

Once all the above make files have been altered create a file called  compile.bat  and place in the  vim\src\  directory. Edit that file and add the following to it. 1

@ECHO OFF
SET SDK_INCLUDE_DIR=C:\Program Files\Microsoft SDKs\Windows\v7.1\Include
SET VC_DIR="C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC

ECHO "Setting up compiler..."
CALL %VC_DIR%\vcvarsall.bat" x86_amd64

ECHO "Setting up environment variables..."
SET CPUNR=i686
SET WINVER=0x500
SET CPU=AMD64
SET GUI=yes
SET NETBEANS=no
SET FEATURES=HUGE
SET OPTIMIZE=MAXSPEED

ECHO "Start compiling..."
CALL %VC_DIR%\bin\nmake" -f Make_mvc.mak

Once this has been saved, open a command prompt (if you haven’t got one open) CD to the vim\src\  directory within the Vim source code and issue the following command to execute the compile batch file.

compile.bat

This will setup the compiler environment for 64 bit, set up optional environment variables to control Vim’s compilation and then kick off the compilation process.

If the batch file is left as above it will (or should) compile a 64 bit GVim executable. To create a Vim executable you simply alter the  SET GUI=yes  line to  SET GUI=no  and compile again. A full list of compiler options for the batch file can be found here.

Downloads

If you don’t want to do the above or it’s not working, here’s a download link which includes the above hacked make files and compiled executables (compiled with python3 support).

Vim 7.3.661 64bit for Windows (with Python3 support)


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles



Latest Images