Vim — the editor

Vim: Compiling HowTo

for Vim on Unix-like systems
Last change: 2011-12-24 12:21 UTC
Back to "The Vim Editor"
Back to Welcome page
  1. Once and for all
  2. Every time
  1. Once and for all:
    • Before you compile anything, make sure you have the required software tools. On most Linux distributions, the administrator who installs the Linux software has a choice of "packages" which he may choose to install, or not. In order to be able to compile Vim, you need not only the archive-manipulating tools tar, bzip2 and gzip, a compiler (usually gcc) and its associate linker and libraries, you also need "development" packages for everything that Vim will use. This means, for example, that you cannot compile gvim if the x11-devel package isn't installed (as well as several other packages), that you cannot compile Vim with Python interface if the python-devel package isn't installed, etc. The configure log (see below) will tell you what it couldn't find, it usually means there is a missing "development" package.
    • Create a separate directory structure for development. The text below assumes that this directory structure starts (for Vim) at ~/.build/vim/. Change that prefix whenever it appears below if you use something else.
    • Environment variables: I use environment variables to set configuration options, so I don't need to change any "Vim" files. I believe that this method is "cleaner"; also, since configuration options don't change much from one release to the next, it allows keeping one's configuration even when going from release to release (and the Makefile is downloaded again). For that, I create a shell script, ~/.build/vim/myenviro, which contains as many lines as there are environment variables to set, in the form
      	export variable='value'
      
      There is one difficulty: you cannot just "run" this script (by giving its name to bash as a command name) you must "source" it each time you are ready to start a new compilation. But this actually belongs in a further paragraph, and we shall repeat it there. Here's the sample script I use; it is fairly general, and any features for which you don't have the required "development" packages will be eliminated at configure-time:
      #!/bin/bash
      export CONF_OPT_GUI='--enable-gnome-check'
      export CONF_OPT_PERL='--enable-perlinterp'
      export CONF_OPT_PYTHON='--enable-pythoninterp'
      export CONF_OPT_TCL='--enable-tclinterp --with-tcl=tclsh8.4'
      export CONF_OPT_RUBY='--enable-rubyinterp'
      export CONF_OPT_MZSCHEME='--disable-mzschemeinterp'
      #export CONF_OPT_PLTHOME='--with-plthome=/usr/local/plt'
      export CONF_OPT_CSCOPE='--enable-cscope'
      export CONF_OPT_MULTIBYTE='--enable-multibyte'
      export CONF_OPT_FEAT='--with-features=huge'
      export CONF_OPT_COMPBY='"--with-compiledby=antoine.mechelynck@skynet.be"'
      
      You may use that, except that you will of course have to put your name, not mine, in the last line; and you may or may not have to change the TCL version.
      Note: Starting at Vim 7.2 beta, replace --with-tcl by --with-tclsh — or omit it altogether.
    • If you are using the Xubuntu distribution, you may want to check Taylor Venable's Vim HowTo, especially if you want Vim to interface with MzScheme.
    • Getting the Vim sources: see Getting the Vim source with Mercurial at the Vim Tips wiki.
    • If you want to compile more than one Vim with different feature sets: run make -C src shadow to create a "shadow" directory, which will be named src/shadow and populated with soft links to the contents of src/ ; then immediately rename src/shadow to something else (without changing its location or contents). This way, you can create as many "shadow directories" as you want. Then you will (whenever you compile) cd to the proper shadowdir, source the appropriate environment-setting script, and run make there. You can even run several compilation runs in parallel, each in its own shell, with its own shadowdir and its own configure environment. One line you will probably want to use in this case will be (for instance)
      	export CONF_ARGS='--with-vim-name=vi'
      
      to avoid ending up with several executables all of the same name. Note that you can only have at most one value for each environment variable, but you can concatenate several configure command-line argument (space-separated) in one quoted value, e.g.
      	export CONF_ARGS='--with-vim-name=vim-mod --with-modified-by="John Doe & Mary Roe"'
      
      Notice the use of both single and double quotes in the above example.
  2. Every time:
    1. cd to your top Mercurial directory (the parent of .hg/ src/ runtime/ etc.)
    2. See if there are any changes:
      	hg incoming
      
    3. If there are: get them, either (if you made no changes to the source)
      	(date && hg pull -u) 2>&1 |tee -a ../hgvim.log
      or if you did (and have installed the fetch extension)
      	(date && hg fetch --switch-parent) 2>&1 |tee -a ../hgvim.log
    4. Have a look at the Makefiles (vim71/Makefile and vim71/src/Makefile) and write down any features you might want to change (in the myenviro script mentioned earlier). Make any needed changes, then source the script (it's not enough to just "run" it):
      	source myenviro       
    5. Now's the big one: Let's compile. The current directory is still the "top" directory inside your Mercurial repository (see below if you are compiling in a shadow directory).
      • If you made any changes in the configure options since last time, or if you added or removed software packages:
        	make reconfig 2>&1 |tee ../make-vim.log
        
      • If you didn't, or if this is the first time for this release:
        	make 2>&1 |tee ../make-vim.log
        
    6. The programs we just compiled should end up in the src/ subdirectory. Now let's check that everything went well:
      • less make.log
        — At the end, you should see the make for the .po files (multilingual messages), and above that, the link.
      • ls -l src/vim
        should show you the newly compiled Vim executable, with today's date.
      • src/vim --version |more
        — this will show you the details of the features actually compiled-in. If you miss some feature that is important to you, go back to the configure log (near the top of the make.log), and check what went wrong. As noted earlier, you may need to install some "development" package from your Linux (or other) distribution. (There is another, longer, configure log at src/auto/config.log ).
    7. If everything seems OK, we can "install" the newly-compiled Vim:
      • Close down any running instance of vim or gvim.
      • make install 2>&1 |tee install.log
      • Make sure that the new version will be invoked by default: ls -l `which vim` should show your new Vim executable, dated a few minutes ago. If you see something else, which -a vim will show you all Vim executables in the $PATH, in the order found. You may for instance want to make a soft link in some directory early in the path (let's say as /usr/local/bin/vim) pointing to your new executable. You may also (if it isn't done yet) want to create soft links from the various executable names mentioned at and below ":help ex", all pointing to vim.
    8. That's all folks !
    If you compile in a shadow directory (let's say src/tiny for an executable named vi), the above doesn't change much:
    • Getting the sources and keeping them up-to-date is done only once for all shadow dirs, since all the sources in them are links to the sources in src/, so the following assumes the sources are already up-to-date:
      	cd src/tiny
      		let's source the configure arguments into this shell's environment:
      		this file does not exist by default, you must have set it up
      		like mycfg in the above case, but with the configure arguments for this particular build:
      	source tinycfg.sh
      	make 2>&1 |tee tinymake.log
      		Check that all went well:
      	./vi --version |more
      		and if it looks OK:
      	make installvimbin 2>&1 |tee tinyinst.log
      	ls -l `which vi`
      
    • Since the runtime files are shared by all Vim executables (with a common version and patchlevel but different featuresets), we run make install only once, for the "main" version, which is compiled as above from src/, or maybe from the first shadow directory (src/full or src/default, or whatever suits you).
    • Just like above, you may use make config before plain make to do only the configure part, or make reconfig to reconfigure and recompile. As above, the first time you run make (without arguments) in any particular shadow dir, it will run make config implicitly if it hasn't yet been done there, so be sure to set your environment correctly.

Back to "The Vim Editor" Back to Welcome page