10

I took the plunge today and started out on my quest to build the most recent Emacs master branch developer build -- aka Emacs Trunk -- for MS-Windows.

I found an old blog and went through the procedure, only to be met with an error message telling me that particular method was no longer supported. The error message referred me to read: .../emacs/nt/INSTALL. Well, that is all fine and dandy if the infrastructure for building Emacs has already been installed/configured.

It sure would be handy if there were a step 1, 2, 3 that describes what tools are needed and how to go about installing/configuring them with a specific eye towards building Emacs on MS-Windows.

In the event that anyone would like to prepare a detailed write-up, please feel free to post an answer. If not, I will write one up myself once I figure out how to do it. I was met with additional road-blocks and have submitted a bug report in the interim -- I do not yet know whether it is me, or perhaps a bug: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=21582

I think more people would be inclined to build their own Emacs if there were a "cheat-sheet" that could be used by beginning programmers or hobbyists such as myself (who are not programmers by trade).

4
  • I think you can build Emacs on Windows in more than one way (i.e. most likely MingW / MS VCC, but also possibly clang. You could look here for the list of required libraries (there are a lot of them) emacswiki.org/emacs/BuildingEmacsWithMinGW but this info is surely dated (most likely ten years or so!)
    – wvxvw
    Commented Sep 29, 2015 at 6:56
  • 1
    For a 64 bit build there's a good writeup from emacsbinw64 at sourceforge.net/p/emacsbinw64/wiki/… - it uses MSYS2 and MinGW-w64. Maybe the nt/INSTALL notes should be updated to include this option as well? Commented Dec 11, 2015 at 18:25
  • @bburns.km -- thank you for the link. I was wondering how to build the 64-bit, but didn't have the free-time to invest countless hours figuring it out. In the future, I will definitely check out the link to see if it is something that is a step 1, 2, 3, or just an outline where advanced programmers know how to fill in the blanks that are missing. The instructions like the nt/INSTALL are basically useless for a novice like myself -- it's meaningful to a programmer, but it means virtually nothing to me -- whereas, my 5-easy steps are indeed a true 1, 2, 3 that anyone can follow.
    – lawlist
    Commented Dec 13, 2015 at 5:59
  • @lawlist Yeah it's a good writeup - I tried a year or two ago to do the 32 bit build but something went wrong and/or I got lost in it - like you say it's fairly complex for someone not used to building things from source. But the emacsbinw64 instructions are a bit simpler and worked quite well - just took a few hours to go through it all and get it working. I think I'll ask on the devlist about updating the nt/INSTALL doc - there could be 32 bit and 64 bit sections. I'd started writing up a doc but realized it didn't add too much to the emacsbinw64 instructions, but it could be used there. Commented Dec 13, 2015 at 6:44

2 Answers 2

10

It is recommended that users read the entire ../emacs/nt/INSTALL contained within the Emacs source code.


Quick Start -- 5 Easy Steps:

This answer was tested on WindowsXP--SP3. The installation paths will need to be adjusted based on the individual preferences of the user. In this example:

  • The desktop is: C:\Documents and Settings\lawlist\Desktop

  • The git installation is: C:\git

  • The MinGW installation is: C:\mingw

  • The git download location of Emacs master branch is: C:\Documents and Settings\lawlist\Desktop\emacs

  • The target for Emacs installation is: C:\Documents and Settings\lawlist\Desktop\trunk

Step Number 1: Install git and be sure to select "checkout as-is, commit as-is" during installation:

https://git-scm.com/download/win

Git-2.5.3-32-bit.exe

Run the installer.

Next

Next

Standard installation directory is C:\Program Files\Git, but I chose instead: c:\git

Select components: default is okay, but I chose nothing instead.

Select start menu folder: default is okay, bit I chose not to create a folder instead.

Adjusting your PATH environment: default is okay: Use Git from Bash only.

;; For this next section, pay close attention to the non-default setting -- see Emacs bug #21582.

Configure the line ending conversions: Emacs requires a non-default setting of "checkout as-is, commit as-is"

Configuring the terminal emulator to use with Git Bash: default is okay: Use MinTTY (the default terminal of MSys2)

Configuring experimental performance tweaks: I chose NOT to "Enable file system caching".

Finish [view release notes if so desired]

NOTE: autogen.sh (and perhaps some third-party programs) require the git PATH to be set so that the executable(s) can be called without using the absolute path. The author of this answer has a personal preference for using absolute paths and not modifying the PATH; however, most people seem to prefer modifying the PATH for current and future sessions. On Windows XP, for example, the PATH can be set within Control Panel / System Properties / Advanced tab / Environmental Variables button, and there appears to be two (2) views/opinions regarding whether a user should set the User Variables or the System Variables -- paths are separated by semicolons without spaces. This answer simply sets the PATH for the duration of the session using export set forth hereinbelow. The Emacs autogen.sh looks for the git command on the PATH and complains if it cannot be found.

Step Number 2: Install MinGW

http://www.mingw.org/wiki/Getting_Started

mingw-get-setup.exe

c:\mingw\bin\mingw-get install mingw32-base

c:\mingw\bin\mingw-get install msys-base

c:\mingw\bin\mingw-get install autoconf

c:\mingw\bin\mingw-get install automake

c:\mingw\bin\mingw-get install msys-coreutils

c:\mingw\bin\mingw-get remove mingw32-libiconv

c:\mingw\bin\mingw-get install "libiconv=1.13.1-1"

c:\mingw\msys\1.0\msys.bat

mount c:/mingw /mingw

Step Number 3: Download the following ezwinports zipped packages and extract to the root mingw directory.

https://sourceforge.net/projects/ezwinports/files/

;; unzip all of the following ezwinports packages into c:/mingw, overwriting any duplicates.

cairo-1.12.16-w32-bin.zip

gdk-pixbuf-2.30.2-w32-bin.zip

giflib-5.1.0-w32-bin.zip

glib-2.38.2-w32-bin.zip

gnutls-3.3.11-w32-bin.zip

jpeg-v9a-w32-bin.zip

libpng-1.6.12-w32-bin.zip

librsvg-2.40.1-2-w32-bin.zip

libtasn1-4.2-w32-bin.zip

libxml2-2.7.8-w32-bin.zip

libXpm-3.5.11-2-w32-bin.zip

nettle-2.7.1-w32-bin.zip

p11-kit-0.9-w32-bin.zip

pixman-0.32.4-w32-bin.zip

pkg-config-0.28-w32-bin.zip

tiff-4.0.3-w32-bin.zip

zlib-1.2.8-2-w32-bin.zip

Step Number 4: Download the latest Emacs master branch source files using a git-bash shell.

c:\git\git-bash.exe

cd /c/docume~1/lawlist/desktop/

git clone -b master git://git.sv.gnu.org/emacs.git

exit

Step Number 5: Build the Emacs master branch and copy over the .dll files when done.

;; open generic Command Prompt

c:\mingw\msys\1.0\msys.bat

export PATH=$PATH:/c/git/bin

cd /c/docume~1/lawlist/desktop/emacs

./autogen.sh

./configure --prefix=/c/docume~1/lawlist/desktop/trunk

make

make install

;; copy the following files to the `/bin` directory where `emacs.exe` is located.

cp /c/mingw/bin/libXpm-noX4.dll /c/docume~1/lawlist/desktop/trunk/bin/libXpm-noX4.dll

cp /c/mingw/bin/libpng16-16.dll /c/docume~1/lawlist/desktop/trunk/bin/libpng16-16.dll

cp /c/mingw/bin/libtiff-5.dll /c/docume~1/lawlist/desktop/trunk/bin/libtiff-5.dll

cp /c/mingw/bin/libjpeg-9.dll /c/docume~1/lawlist/desktop/trunk/bin/libjpeg-9.dll

cp /c/mingw/bin/libgif-7.dll /c/docume~1/lawlist/desktop/trunk/bin/libgif-7.dll

cp /c/mingw/bin/librsvg-2-2.dll /c/docume~1/lawlist/desktop/trunk/bin/librsvg-2-2.dll

cp /c/mingw/bin/libgdk_pixbuf-2.0-0.dll /c/docume~1/lawlist/desktop/trunk/bin/libgdk_pixbuf-2.0-0.dll

cp /c/mingw/bin/libglib-2.0-0.dll /c/docume~1/lawlist/desktop/trunk/bin/libglib-2.0-0.dll

cp /c/mingw/bin/libgobject-2.0-0.dll /c/docume~1/lawlist/desktop/trunk/bin/libgobject-2.0-0.dll

cp /c/mingw/bin/libxml2-2.dll /c/docume~1/lawlist/desktop/trunk/bin/libxml2-2.dll

cp /c/mingw/bin/zlib1.dll /c/docume~1/lawlist/desktop/trunk/bin/zlib1.dll

Unzip the entire contents of gnutls-3.3.11-w32-bin.zip to C:\Documents and Settings\lawlist\Desktop\trunk


MANUAL INSTALLATION -- MinGW / MSYS / EZwinports

For those adventurous souls who are interested in doing a manual installation of MinGW/MSYS/EZwinports, the following are the files used by this author on Windows XP to create a successful 32-bit build with the following configuration options enabled by default. The setup and configuration will vary depending upon the individual users personal preferences, and is beyond the scope of this answer.

Configured for 'i686-pc-mingw32'.
Where should the build process find the source code?    .
What compiler should emacs be built with?               gcc -std=gnu99  -g3 -O 2 -gdwarf-2
Should Emacs use the GNU version of malloc?             no
  (The GNU allocators don't work with this system configuration.)
Should Emacs use a relocating allocator for buffers?    no
Should Emacs use mmap(2) for buffer allocation?         yes
What window system should Emacs use?                    w32
What toolkit should Emacs use?                          none
Where do we find X Windows header files?                NONE
Where do we find X Windows libraries?                   NONE
Does Emacs use -lXaw3d?                                 no
Does Emacs use -lXpm?                                   yes
Does Emacs use -ljpeg?                                  yes
Does Emacs use -ltiff?                                  yes
Does Emacs use a gif library?                           yes
Does Emacs use a png library?                           yes
Does Emacs use -lrsvg-2?                                yes
Does Emacs use cairo?                                   no
Does Emacs use imagemagick?                             no
Does Emacs support sound?                               yes
Does Emacs use -lgpm?                                   no
Does Emacs use -ldbus?                                  no
Does Emacs use -lgconf?                                 no
Does Emacs use GSettings?                               no
Does Emacs use a file notification library?             yes (w32)
Does Emacs use access control lists?                    yes
Does Emacs use -lselinux?                               no
Does Emacs use -lgnutls?                                yes
Does Emacs use -lxml2?                                  yes
Does Emacs use -lfreetype?                              no
Does Emacs use -lm17n-flt?                              no
Does Emacs use -lotf?                                   no
Does Emacs use -lxft?                                   no
Does Emacs directly use zlib?                           yes
Does Emacs use toolkit scroll bars?                     yes

EZWINPORTS

cairo-1.12.16-w32-bin.zip
gdk-pixbuf-2.30.2-w32-bin.zip
giflib-5.1.0-w32-bin.zip
glib-2.38.2-w32-bin.zip
gnutls-3.3.11-w32-bin.zip
jpeg-v9a-w32-bin.zip
libXpm-3.5.11-2-w32-bin.zip
libpng-1.6.12-w32-bin.zip
librsvg-2.40.1-2-w32-bin.zip
libtasn1-4.2-w32-bin.zip
libxml2-2.7.8-w32-bin.zip
nettle-2.7.1-w32-bin.zip
p11-kit-0.9-w32-bin.zip
pixman-0.32.4-w32-bin.zip
pkg-config-0.28-w32-bin.zip
tiff-4.0.3-w32-bin.zip
zlib-1.2.8-2-w32-bin.zip

MINGW

autoconf-10-1-mingw32-bin.tar.lzma
autoconf-10-1-mingw32-lic.tar.lzma
autoconf2.1-2.13-4-mingw32-bin.tar.lzma
autoconf2.5-2.68-1-mingw32-bin.tar.lzma
automake-4-1-mingw32-bin.tar.lzma
automake-4-1-mingw32-lic.tar.lzma
automake1.10-1.10.2-1-mingw32-bin.tar.lzma
automake1.11-1.11.1-1-mingw32-bin.tar.lzma
automake1.4-1.4p6-1-mingw32-bin.tar.lzma
automake1.5-1.5-1-mingw32-bin.tar.lzma
automake1.6-1.6.3-1-mingw32-bin.tar.lzma
automake1.7-1.7.9-1-mingw32-bin.tar.lzma
automake1.8-1.8.5-1-mingw32-bin.tar.lzma
automake1.9-1.9.6-3-mingw32-bin.tar.lzma
binutils-2.25.1-1-mingw32-bin.tar.xz
gcc-core-4.8.1-4-mingw32-bin.tar.lzma
gcc-core-4.8.1-4-mingw32-dev.tar.lzma
gcc-core-4.8.1-4-mingw32-dll.tar.lzma
gcc-core-4.8.1-4-mingw32-lic.tar.lzma
gdb-7.6.1-1-mingw32-bin.tar.lzma
gmp-5.1.2-1-mingw32-dll.tar.lzma
libcharset-1.13.1-1-mingw32-dll-1.tar.lzma
libiconv-1.13.1-1-mingw32-bin.tar.lzma
libiconv-1.13.1-1-mingw32-dev.tar.lzma
libiconv-1.13.1-1-mingw32-dll-2.tar.lzma
libiconv-1.13.1-1-mingw32-doc.tar.lzma
libiconv-1.13.1-1-mingw32-lic.tar.lzma
libintl-0.17-1-mingw32-dll-8.tar.lzma
libmpc-1.0.2-mingw32-dll-3.tar.xz
make-3.82.90-2-mingw32-cvs-20120902-bin.tar.lzma
mingwrt-3.21.1-mingw32-dev.tar.xz
mingwrt-3.21.1-mingw32-dll.tar.xz
mpfr-3.1.2-2-mingw32-dll.tar.lzma
pthreads-w32-2.9.1-1-mingw32-dll.tar.lzma
w32api-3.17-2-mingw32-dev.tar.lzma

MSYS

bash-3.1.23-1-msys-1.0.18-bin.tar.xz
bzip2-1.0.6-1-msys-1.0.17-bin.tar.lzma
coreutils-5.97-3-msys-1.0.13-bin.tar.lzma
coreutils-5.97-3-msys-1.0.13-doc.tar.lzma
coreutils-5.97-3-msys-1.0.13-ext.tar.lzma
coreutils-5.97-3-msys-1.0.13-lang.tar.lzma
coreutils-5.97-3-msys-1.0.13-lic.tar.lzma
diffutils-2.8.7.20071206cvs-3-msys-1.0.13-bin.tar.lzma
dos2unix-7.2.3-1-msys-1.0.18-bin.tar.lzma
file-5.04-1-msys-1.0.13-bin.tar.lzma
findutils-4.4.2-2-msys-1.0.13-bin.tar.lzma
gawk-3.1.7-2-msys-1.0.13-bin.tar.lzma
grep-2.5.4-2-msys-1.0.13-bin.tar.lzma
gzip-1.3.12-2-msys-1.0.13-bin.tar.lzma
less-436-2-msys-1.0.13-bin.tar.lzma
libbz2-1.0.6-1-msys-1.0.17-dll-1.tar.lzma
libcrypt-1.1_1-3-msys-1.0.13-dll-0.tar.lzma
libexpat-2.0.1-1-msys-1.0.13-dll-1.tar.lzma
libgdbm-1.8.3-3-msys-1.0.13-dll-3.tar.lzma
libiconv-1.14-1-msys-1.0.17-dll-2.tar.lzma
libintl-0.18.1.1-1-msys-1.0.17-dll-8.tar.lzma
liblzma-5.0.3-1-msys-1.0.17-dll-5.tar.lzma
libmagic-5.04-1-msys-1.0.13-dll-1.tar.lzma
libregex-1.20090805-2-msys-1.0.13-dll-1.tar.lzma
libtermcap-0.20050421_1-2-msys-1.0.13-dll-0.tar.lzma
libxml2-2.7.6-1-msys-1.0.13-dll-2.tar.lzma
m4-1.4.16-2-msys-1.0.17-bin.tar.lzma
make-3.81-3-msys-1.0.13-bin.tar.lzma
msysCORE-1.0.18-1-msys-1.0.18-bin.tar.lzma
msysCORE-1.0.18-1-msys-1.0.18-doc.tar.lzma
msysCORE-1.0.18-1-msys-1.0.18-ext.tar.lzma
msysCORE-1.0.18-1-msys-1.0.18-lic.tar.lzma
perl-5.8.8-1-msys-1.0.17-bin.tar.lzma
sed-4.2.1-2-msys-1.0.13-bin.tar.lzma
tar-1.23-1-msys-1.0.13-bin.tar.lzma
termcap-0.20050421_1-2-msys-1.0.13-bin.tar.lzma
texinfo-4.13a-2-msys-1.0.13-bin.tar.lzma
xz-5.0.3-1-msys-1.0.17-bin.tar.lzma
zlib-1.2.7-1-msys-1.0.17-dll.tar.lzma
2

I had tried the instructions in emacs/nt/INSTALL last year for the 32-bit build but something went wrong (I don't remember what, exactly), so recently I tried the instructions for emacsbinw64 - it worked very well, and it was simpler to get the necessary libraries also. It uses MSYS2 and MinGW-w64 for a 64-bit build - the emacsbinw64 project provides binaries at https://sourceforge.net/projects/emacsbinw64/files/.

So I wrote up some instructions following that outline, with feedback from Eli Zaretski and the author Chris Zheng - the full version is up at http://git.savannah.gnu.org/cgit/emacs.git/plain/nt/INSTALL.W64?h=emacs-25 (just includes building from a release tarball also).

This took about 90 minutes total on an Intel i3 and high speed internet connection - YMMV. Note that most of the work for building on Windows is just setting up the build environment...


Requirements

The total space required is 3GB: 1.8GB for MSYS2 / MinGW-w64 and 1.2GB for Emacs with the full repository.

Download and install MinGW-w64 and MSYS2

Download the x86_64 version of MSYS2 (i.e. msys2-x86_64-.exe) from https://sourceforge.net/projects/msys2/files/Base/x86_64.

Run this file to install MSYS2 in your preferred directory, e.g. the default C:\msys64 -- this will install MinGW-w64 also. Note that directory names containing spaces may cause problems.

Then you'll need to add the following directories to your Windows PATH environment variable:

c:\msys64\usr\bin;c:\msys64\mingw64\bin

you can do this through Control Panel / System and Security / System / Advanced system settings / Environment Variables / Edit path.

Adding these directories to your PATH tells Emacs where to find the DLLs it needs to run, and some optional commands like grep and find. These commands will also be available at the Windows console.

Download and install the necessary packages

Run msys2_shell.bat in your MSYS2 directory and you will see a BASH window opened.

In the BASH prompt, use the following command to install the necessary packages (you can copy and paste it into the shell with Shift + Insert):

pacman -S base-devel \
mingw-w64-x86_64-toolchain \
mingw-w64-x86_64-xpm-nox \
mingw-w64-x86_64-libtiff \
mingw-w64-x86_64-giflib \
mingw-w64-x86_64-libpng \
mingw-w64-x86_64-libjpeg-turbo \
mingw-w64-x86_64-librsvg \
mingw-w64-x86_64-libxml2 \
mingw-w64-x86_64-gnutls

You now have a complete build environment for Emacs.

Install Git (optional) and disable autocrlf

If you don't already have Git on your system, you can install it in your MSYS2 environment with:

pacman -S git

The autocrlf feature of Git may interfere with the configure file, so it is best to disable this feature by running the command:

git config core.autocrlf false

Get the Emacs source code

To download the Git repository, do something like the following -- this will put the Emacs source into C:\emacs\emacs-25:

mkdir /c/emacs
cd /c/emacs
git clone git://git.sv.gnu.org/emacs.git emacs-25

Build Emacs

Now you're ready to build and install Emacs with autogen, configure, make, and make install.

First we need to switch to the MinGW-w64 environment. Exit the MSYS2 BASH console and run mingw64_shell.bat in the C:\msys64 folder, then cd back to your Emacs source directory, e.g.:

cd /c/emacs/emacs-25

Run autogen

If you are building the development sources, run autogen to generate the configure script:

./autogen.sh

Run configure

Now you can run configure, which will build the various Makefiles.

The '--prefix' option specifies a location for the resulting binary files, which 'make install' will use - in this example we set it to C:\emacs\emacs-25. If a prefix is not specified the files will be put in the standard Unix directories located in your C:\msys64 directory, but this is not recommended.

Note also that we need to disable Imagemagick because Emacs does not yet support it on Windows.

PKG_CONFIG_PATH=/mingw64/lib/pkgconfig \
./configure --prefix=/c/emacs/emacs-25 --without-imagemagick

Run make

This will compile Emacs and build the executables, putting them in the src directory:

make

To speed up the process, you can try running

make -jN

where N is the number of cores in your system -- if your MSYS2 make supports parallel execution it will run significantly faster.

Run make install

Now you can run "make install", which will copy the executable and other files to the location specified in the configure step. This will create the bin, libexec, share, and var directories:

make install

You can also say

make install prefix=/c/somewhere

to install them somewhere else.

Test Emacs

To test it out, run

./bin/runemacs.exe -Q

and if all went well, you will have a new 64-bit version of Emacs.

Make a shortcut

To make a shortcut to run the new Emacs, right click on the location where you want to put it, e.g. the Desktop, select New / Shortcut, then select runemacs.exe in the bin folder of the new Emacs, and give it a name.

You can set any command line options by right clicking on the resulting shortcut, select Properties, then add any options to the Target command, e.g. --debug-init.

Credits

Thanks to Chris Zheng for the original build outline as used by the emacsbinw64 project, located at https://sourceforge.net/p/emacsbinw64/wiki/Build%20guideline%20for%20MSYS2-MinGW-w64%20system/.

License

This file is part of GNU Emacs.

GNU Emacs is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see http://www.gnu.org/licenses/.

4
  • Consider adding a step to copy over whatever .dll files that need to be placed in the same directly as the Emacs executable once the build is complete, so that Emacs doesn't need to rely upon on a system-wide defined path to find those files. Also, it is probably necessary to copy over the executable(s) for gnutls into the Emacs executable directory. The last steps should likely be fairly similar to the Emacs 32 build in the alternative answer.
    – lawlist
    Commented Jan 9, 2016 at 20:11
  • Yeah, the original instructions were written that way, but Eli thought it better to use the PATH - lists.gnu.org/archive/html/bug-gnu-emacs/2015-12/msg01476.html. It is another option though - if you wanted to do it that way, you could just copy all the DLLs in the C:\msys64\mingw64\bin to the emacs bin folder - they're only about 32MB - cp /c/msys64/mingw64/bin/*.dll bin. I don't know much about gnutls though - is there a simple way to test it out? Commented Jan 9, 2016 at 20:48
  • In the most general sense without actually using it for email or something, the general test is with the function gnutls-available-p I understand the reason for simplicity when just referring to the system paths, but sometimes people may want to use the Emacs build on a different computer and they will wonder why images and stuff do not work out-of-the-box. There are lots of threads with people asking why pdf files look like gibberish in a regular buffer (i.e., because the lack png support), or why they can't do doc-view or preview in AUCTeX (same reason).
    – lawlist
    Commented Jan 9, 2016 at 21:00
  • Okay, gnutls-available-p returns t using just the PATH setting, so I'll assume it's working for now - I'll submit a patch with the alternative method to copy the DLLs though, and possibly the gnutls exes, if those are needed, and update here later. Commented Jan 9, 2016 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.