The following guidelines described how to compile GNU Emacs with MSYS2/MinGW-w64 combination.

Set up the MSYS2/MinGW-w64 build environment

Download the x86_64 version of MSYS2 in here and install in your preferred directory, e.g. C:\msys64. Note that path containing spaces may causes problems. Run msys2_shell.bat in the C:\msys64 and you will see a BASH window opened. In the BASH prompt, use the following command to install the necessary packages:

1
2
3
4
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

These packages are:
Build required package

  1. base-devel
    • mingw-w64-x86_64-toolchain
      Optional
  2. For various image formats
    • 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
  3. For libxml2
    • mingw-w64-x86_64-libxml2
  4. For GnuTLS
    • mingw-w64-x86_64-gnutls

Get the source code

Follow the instruction in savannah. Or download the release version in gnu ftp. It should be noted that the the autocrlf feature of git may mess up the configure file. Therefore it is better to disable this feature by running the command:

1
git config core.autocrlf false

configure; make; make install

Run mingw64_shell.bat in C:\msys64. This will open a BASH window for MinGW-w64 environment. In the BASH prompt, chdir to the directory of source code. Then run the following commands to build Emacs and install in C:\emacs. If you are building the development version, the first line of the commands will be needed.

1
2
3
4
5
6
7
./autogen.sh
PKG_CONFIG_PATH=/mingw64/lib/pkgconfig ./configure --host=x86_64-w64-mingw32 \
--target=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --with-wide-int --with-jpeg \
--with-xpm --with-png --with-tiff --with-rsvg --with-xml2 --with-gnutls --with-xft \
--without-imagemagick
make
make install prefix=/c/emacs

Note that I disable imagemagick because it breaks the build process.

If all of the above are successfully done, you should have an Emacs installed in C:\emacs. However, it may not work properly since it depends on DLLs in the MinGW-w64 environment. I use the following command to make sure the DLLs are placed with the execution file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cp /mingw64/bin/{libwinpthread-*.dll,libXpm-noX*.dll,libdbus-*.dll} /c/emacs/bin
cp /mingw64/bin/{libgomp-*.dll,libgcc_s_seh-*.dll,libglib-*.dll} /c/emacs/bin
cp /mingw64/bin/{libintl-*.dll,libiconv-*.dll,libgobject-*.dll} /c/emacs/bin
cp /mingw64/bin/{libffi-*.dll,libgdk_pixbuf-*.dll,libgio-*.dll} /c/emacs/bin
cp /mingw64/bin/{libgmodule-*.dll,zlib*.dll,librsvg-*.dll} /c/emacs/bin
cp /mingw64/bin/{libcairo-*.dll,libcroco-*.dll,libpango-*.dll} /c/emacs/bin
cp /mingw64/bin/{libpangocairo-*.dll,libxml2-*.dll,libfontconfig-*.dll} /c/emacs/bin
cp /mingw64/bin/{libfreetype-*.dll,libpixman-*.dll,libpng*.dll} /c/emacs/bin
cp /mingw64/bin/{libpangoft*.dll,libpangowin32-*.dll,liblzma-*.dll} /c/emacs/bin
cp /mingw64/bin/{libexpat-*.dll,libharfbuzz-*.dll,libgnutls-*.dll} /c/emacs/bin
cp /mingw64/bin/{libgnutlsxx-*.dll,libtiff-*.dll,libtiffxx-*.dll} /c/emacs/bin
cp /mingw64/bin/{libjpeg-*.dll,libgif-*.dll,libbz2-*.dll,libjbig-*.dll} /c/emacs/bin
cp /mingw64/bin/{libgmp-*.dll,libhogweed-*.dll,libnettle-*.dll} /c/emacs/bin
cp /mingw64/bin/{libp11-kit-*.dll,libtasn1-*.dll} /c/emacs/bin

If you only run Emacs in your PC and your MinGW-w64 binary folder (e.g. C:\msys64\mingw64\bin) is in PATH the above copy step can be optional.

Run

Double click the runemacs.exe in C:\emacs\bin. If no errors occur, you have successfully builded the 64-Bit version of GNU Emacs.