Skip to content

Instantly share code, notes, and snippets.

@rpuntaie
Last active January 7, 2022 16:17
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save rpuntaie/8510218 to your computer and use it in GitHub Desktop.
Save rpuntaie/8510218 to your computer and use it in GitHub Desktop.
Build VIM on MinGW/MSYS with support for all interpreters

I recently had to make myself comfortable on a Windows box, which meant installing VIM and python. And being at compiling VIM I compiled it with support for other interpreters as well.

I made a gvim74.exe installation file, like the one you get from http://www.vim.org/download.php, but with the newest batches and the interpreter versions of my choice.

Preparations

  1. I followed all of the steps in

    http://ascend4.org/Setting_up_a_MinGW-w64_build_environment

    just instead of python27_32 I have renamed the 64bit version (python27_64) and set the path accordingly. This is not only for VIM, but for its own sake. With this I have

    • mingw, msys, subversion, nsis, scons, swig, gendef, depends, svn
    • C:\Python27
    • C:\Python27_64
  2. I also installed the 32bit version of

    • C:\Python34

    and copied python.exe and pythonw.exe to python3.exe and pythonw3.exe (pip needs the originals). This way from console I can also start python3.

  3. lua LuaForWindows_v5.1.4-46 from

    http://code.google.com/p/luaforwindows/downloads/list

    and installed it in C:\LUA, but without the 51 subdirectory.

    (http://luabinaries.sourceforge.net/download.html I did not use.)

  4. ruby 1.9.3-p484 from

    http://rubyinstaller.org/downloads/

    I installed at

    C:\Ruby193

    There is a newer version at https://www.ruby-lang.org/en/news/2013/12/25/ruby-2-1-0-is-released/ and there are instruction to compile it, but I didn't go for that.

  5. perl ActivePerl-5.18.1.1800-MSWin32-x86-64int-297570 from

    http://www.activestate.com/activeperl/downloads

    I installed at

    C:\Perl

  6. tcl ActiveTcl8.6.1.0.297577-win32-ix86-threaded from

    http://www.activestate.com/activetcl/downloads

    I installed at

    C:\Tcl

  7. Other tools I use in my vimrc:
  8. I prepended the following to the Windows PATH variable:

    C:\Python27;
    C:\Python27\Scripts;
    C:\Python27\Tools\Scripts;
    C:\Python34;
    C:\Python34\scripts;
    C:\Ruby193\bin;
    C:\Lua;
    C:\Lua\clibs;
    C:\Perl\bin;
    C:\Tcl\bin;
    C:\vim\vim74;
    C:\Mingw\32\bin;
    C:\Mingw\msys\bin;
    C:\Program Files (x86)\Git\cmd;
    C:\Program Files\SlikSvn\bin;
    C:\Program Files (x86)\WordNet\3.0\bin;
    C:\Program Files (x86)\NSIS;

Customary VIM installation file (gvim74.exe)

For VIM I first downloaded and installed the official gvim74.exe in

C:\Vim

This is necessary to get

diff.exe

The MSYS one would need MSYS dlls. Then the installation will generate a _vimrc (unless there is one already) with a set diffexpr=MyDiff(), without which vimdiff will not work on Windows. On Linux this is not necessary.

Replace Executables Only

A usual method to get other interpreters and the newest patches regarding binaries working is to download the sources, compile only those binaries and manually override th according files in the VIM installation directory. My intention was to create a customary gvim74.exe installation file.

The following are shell scripts executable via MSYS with 32 in /etc/fstab unless otherwise mentioned. These will be needed:

mingw-get install mingw32-libpdcurses msys-wget msys-zip msys-unzip msys-sed msys-perl
##later do
##mingw-get remove msys-vim

I made a persistent Windows variable with the path to the root location for these steps:

setx MYVIM "C:\temp\myvim"
mkdir $MYVIM

MinGW Issues?

To use this folder be sure that it is not read-only or has limited access rights (right-click/properties/security) else sed will not work. Also check out http://support.microsoft.com/kb/256614 and possibly do attrib -r -s /s with prompt in that folder.

Microsoft Visual Studio

The basic steps can be done with Microsoft Visual Studio as well by using make_mvc.mak.

Download VIM sources:

cd $MYVIM
hg clone https://vim.googlecode.com/hg/ vim

Make a copy of this VIM folder to allow starting from scratch in case of problems.

The following generates config.cache, config.h, config.log, config.mk, config.status in $MYVIM/vim/src/auto/ and config.mk is needed in the uganda step:

cd $MYVIM/vim
./configure --enable-gui=gtk2 --with-features=big --with-tlib=pdcurses --enable-luainterp=dynamic --enable-perlinterp=dynamic --enable-pythoninterp=dynamic --enable-python3interp=dynamic --enable-rubyinterp=dynamic

Linux Step

A linux step is necessary to generate the .mo files. But are they needed on Windows? I installed without this step and had no problem.

In a linux virtual machine (virtualbox for me) share the windows folder or make $MYVIM be in a shared folder:

#on linux in the vim root folder with the main Makefile (note: pdcurses on msys, ncurses on linux):
./configure --enable-gui=gtk2 --with-features=big --with-tlib=ncurses --enable-luainterp=dynamic --enable-perlinterp=dynamic --enable-pythoninterp=dynamic --enable-python3interp=dynamic --enable-rubyinterp=dynamic
make
#on msys make will not work

Apart from vim and xxd the following .mo files are generated:

af, ca, cs, de, en_GB, eo, es, fi, fr, ga, it, ja, ko, ko.UTF-8, nb, nl,
no, pl, pt_BR, ru, sk, sv, uk, vi, cs.cp1250, ja.euc-jp, ja.sjis,
pl.cp1250, pl.UTF-8, ru.cp1251, sk.cp1250, uk.cp1251, zh_CN.cp936, zh_CN,
zh_CN.UTF-8, zh_TW, zh_TW.UTF-8

if_perl.c is generated in $MYVIM/vim/src/auto/.

Either move the if_perl.c from the linux step into $MYVIM/vim/src or generate it on msys:

cd $MYVIM/vim/src
#empty if_perl.c would lead to error: undefined reference to 'perl_buf_free'
xsubpp -prototypes -typemap /lib/perl5/5.8/ExtUtils/typemap if_perl.xs > if_perl.c

Close MSYS, change 32 to 64 in /etc/fstab (c:\mingw\msys\etc\fstab), open a new MSYS and check via gcc -dumpmachine:

cd $MYVIM/vim/src/GvimExt
make -f Make_ming.mak STATIC_STDCPLUS=yes 
mv gvimext.dll gvimext64.dll
rm *.o
rm *.res

I had to patch Make_ming.mak:

cd $MYVIM/vim/src
sed -i -e"s:#GETTEXT_DYNAMIC=gnu_gettext.dll:DYNAMIC_GETTEXT=DYNAMIC_GETTEXT:g" Make_ming.mak
sed -i -e"s:INTLPATH=\$(GETTEXT)/lib/mingw32:INTLPATH=..:g"  Make_ming.mak
sed -i -e"s:INTLLIB=gnu_gettext:INTLLIB=intl:g"  Make_ming.mak

Get libiconv.dll and libintl.dll:

#!/bin/bash
cd $MYVIM/vim

wget http://sourceforge.net/projects/gettext/files/libiconv-win32/1.9.1/libiconv-1.9.1.bin.woe32.zip/download -O iconv.zip
unzip -d iconv iconv.zip
cp iconv/bin/iconv.dll .

wget http://sourceforge.net/projects/gettext/files/gettext-win32/0.13.1/gettext-runtime-0.13.1.bin.woe32.zip/download -O gettext.zip
unzip -d gettext gettext.zip
cp gettext/bin/intl.dll libintl.dll

mv libintl.dll runtime/
mv iconv.dll runtime/

Close MSYS, change 64 to 32 in /etc/fstab, open a new MSYS and check via gcc -dumpmachine:

##gvimext.dll will be made by the make step
#cd $MYVIM/vim/src/GvimExt
#make -f Make_ming.mak STATIC_STDCPLUS=yes 
#rm *.o
#rm *.res

cd $MYVIM/vim/src

make -f Make_ming.mak clean

#ARCH=x86-64 #for 64 bit build, but then the interpreters would also need to by 64 bit
ARCH=i386 #or i686
VIMINTERPS="PYTHON=C:/Python27 PYTHON_VER=27 PYTHON3=C:/Python34 PYTHON3_VER=34 RUBY=C:/Ruby193 RUBY_VER=19 RUBY_VER_LONG=1.9.1 LUA=C:/LUA LUA_VER=51 PERL=C:/Perl PERL_VER=518 TCL=C:/Tcl TCL_VER=86"
make -f Make_ming.mak FEATURES=big GUI=no STATIC_STDCPLUS=yes ARCH=$ARCH BUILD=x86_64-w64-mingw32 $VIMINTERPS
gcc uninstal.c -o uninstall.exe
mv vim.exe vimw32.exe
mv xxd/xxd.exe xxdw32.exe
mv install.exe installw32.exe
mv uninstall.exe uninstalw32.exe

make -f Make_ming.mak FEATURES=big GUI=yes OLE=yes STATIC_STDCPLUS=yes ARCH=$ARCH BUILD=x86_64-w64-mingw32 $VIMINTERPS 
gcc vimrun.c -o vimrun.exe
cp gvim.exe gvim_ole.exe

In gvim.nsis after the line with libintl.dll add one for iconv.dll:

cd $MYVIM/vim/nsis
sed -i -e"s/\t\tFile \${VIMRT}\\\\libintl\.dll/\t\tFile \${VIMRT}\\\\libintl.dll\n\t\tFile \${VIMRT}\\\\iconv.dll/g" gvim.nsi

Diff.exe from the orginal vim needs to be two levels above the nsis folder (i.e. $MYVIM) Then do:

cd $MYVIM/vim/runtime/doc
make uganda.nsis.txt

cd $MYVIM/vim/nsis

#patch gvim.nsi
sed -i -e's:!define VIMRT "..":!define VIMRT "..\\runtime":g' gvim.nsi

cp ../vimtutor.bat ../runtime/
cp ../Readme.txt ../runtime/

makensis gvim.nsi

#gvim74.exe was created in this folder, if everything went all right

After installing test within vim:

:py print "Hello py"
:py3 print("Hello py3")
:lua print("Hello lua")
:ruby print "Hello ruby"
:perl VIM::Msg("Hello perl")
:tc puts "Hello tcl"

Other Distributed Files

In the maine Makefile there are other files generated (vim74src.zip, vim74rt.zip, vim74.zip, ...), which are provided as separate downloads from the vim homepage. They assume pdb files, i.e. a build with Microsoft Visual Studio. I had problems with permission denied in MSYS. So these steps are better done in Linux with the $MYVIM folder mounted there:

cd $MYVIM/vim #on linux $MYVIM needs to be set with different path

#msys needs to have vim
make dossrc
make dosrt

cp src/*.exe .
cp src/GvimExt/gvimext.dll .
#make dosbin #assumes all steps done as described in Makefile
#else
touch gvim_ole.pdb #just to make it run through 
make dosbin_ole
@anselal
Copy link

anselal commented May 5, 2018

Thank you for documenting the compile procedure.

Can you provide your compiled version with python support ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment