Search notes:

Vim: building/compiling

General notes about compling vim are found in src/INSTALL.

Clone vim sources

cd p:\ath\to\xyz
git clone https://github.com/vim/vim
cd vim\src

Edit feature.h

Before compiling vim, one might want to edit the preferences in src/feature.h.

Linux

Compiles, but produces E25: GUI cannot be used: not enabled at compile time.
$ ./configure --enable-python3interp --enable-perlinterp --with-x --enable-gui=gtk3 --enable-fontset --disable-xim
Works, but font is ugly:
$ ./configure --enable-python3interp --enable-perlinterp --with-x --enable-gui=auto --enable-fontset --disable-xim
Apparently, make does not create a gvim executable. Instead, it's created as a symlink with make install.
In order to execute vim as GUI, it can be started with the -g command line option.

Windows

It's recommended to build a 32 bit version of vim, even on 64 bit systems. The only advantage of a 64 bit vim is that it can edit files larger than 2GB. (2019-11-25: is this still true???)

MinGW-w64

Apparently, vim cannot be built with MinGW anymore and MinGW-w64 should be used instead.
The makefile requires to have a mkdir in the path that understands the -p option. Unfortunately, the mkdir that comes with cmd.exe does not.
cd src
mingw32-make -f Make_ming.mak

Missing sed

Also, sed is required to determine the of -march option value (see below). If sed is not installed, this value can be specied to the makefile like so:
mingw32-make -f Make_ming.mak ARCH=x86-64
The required value for ARCH can be found with gcc -dumpmachine. It prints something like x86_64-w64-mingw32. The relevant portion is the text before the first hyphen (x86_64).

Rtools / Windows 10

RTools comes with MinGW which can be used if RTools is installed and there is no Visual Studio.
If RTools was installed without adjusting the PATH environment variable, PATH needs to be modified so that make and the GCC compiler are found:
set rtools_root=C:\Rtools
set path=%rtools_root%\bin;%path%
set path=%rtools_root%\mingw_32\bin;%path%
As per instructions in src/Make_cyg_ming.mak, the executables should be built with
make -f Make_ming.mak
However, gui_dwrite.cpp could not be compiled because it tried to include dwrite_2.h which did not exist in the RTools directory. The error message was something like gui_dwrite.cpp:42:23: fatal error: dwrite_2.h: No such file or directory.
I had to turn of colored emoji (which I probably won't need anyway):
make -f Make_ming.mak COLOR_EMOJI=no
Then, the compilation went on smoothly.
However, when trying to link uninstall.exe, I got this error: undefined reference to '_imp__CoTaskMemFree@4'.
In order to fix this, I had to manually add -lole32 in the target uninstal.exe in src\Make_cyg_ming.mak:
uninstal.exe: uninstal.c
            $(CC) $(CFLAGS) -o uninstal.exe uninstal.c $(LIB) -lole32
Update 2019-07-11: The -lole32 is now fixed with my patch 8.1.1662.

Strawberry Perl / Windows 10

Strawberry Perl comes with a gcc compiler.
However, it seems to lack sed which results in the following error message:
'sed' is not recognized as an internal or external command
…
gcc: error: missing argument to '-march='
sed is needed to extract the CPU model from the target triplet in Make_cyg_ming.mak:
ARCH := $(shell $(CC) -dumpmachine | sed -e 's/-.*//' -e 's/_/-/' -e 's/^mingw32$$/i686/')
Thus, ARCH needs to be specified manually when invoking gmake:
gmake -f Make_ming.mak ARCH=x86-64
Note: running gcc -dumpmachine returned x86_64-w64-mingw32 but I had to change the first part of the triple from x86_64 to x86-64.
The value of ARCH seems to be passed directly to the -march gcc option.

Visual Studio 2017 Community Edition on Windows 7

C:\>                         mkdir %userprofile%\build
C:\>                         cd    %userprofile%\build

C:\Users\Rene\build>        \tools\PortableGit\bin\git.exe clone https://github.com/vim/vim.git

C:\Users\Rene\build>         cd vim\src

C:\Users\Rene\build\vim\src> "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"

C:\Users\Rene\build\vim\src> nmake -f Make_mvc.mak GUI=yes

C:\Users\Rene\build\vim\src> copy gvim.exe   %userprofile%\bin
C:\Users\Rene\build\vim\src> copy vimrun.exe %userprofile%\bin

C:\Users\Rene\build\vim\src> cd ..

C:\Users\Rene\build\vim\>    reg add HKCU\Environment /v VIMRUNTIME /d %cd%\runtime

Visual Studio Express 2010 on Windows 7

With Visual Studio Express 2010 on Windows 7:
cd VIMDIR\src
msvc2010.bat
set GUI=yes
set DIRECTX=no
nmake -f Make_mvc.mak
I needed to set DIRECTX to no because otherwise, the compiler didn't find dwrite_2.h.

Create a Vim DLL

In src/Make_cyg_ming.mak, the macro (define) VIMDLL must be set to yes (the line is already commented and needs to be un-commented).
Then, the sources need to be compiled, as outlined above. This will createvim.exe, gvim.exe and vim64.dll (at least when I tried it).
I had some success to execute the DLL in PowerShell like so:
cd P:\ath\to\vim\src

add-type -TypeDefinition @'

using System;
using System.Runtime.InteropServices;

public static class vimDll {

    [DllImport("vim64.dll", EntryPoint = "VimMain", CharSet = CharSet.Ansi
//    , CallingConvention=CallingConvention.Cdecl
     )]
     public static extern int VimMain(
        int argc, 
       [MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPWStr)] string[] argv
     );
}
'@
 

$env:path="$pwd;$env:path"
[string[]] $a = @("This text seems not to be considered at all.")
[vimDll]::VimMain(1,  $a)

Make options

The following lists some variables/options that can be set when the make file.
Specifying the global vimrc file (will be stored in the global variable default_vim_dir
$ make … VIMRCLOC=/etc …
Location of the global runtime files (will be stored in the global variable default_vimruntime_dir):
$ make … VIMRUNTIMEDIR=/usr/share/vim …

Misc

The compiler options with which vim sources were compiled are stored in the global variable all_cflags, the options with which the executable was linked in the global variable all_lflags.

Index