Site icon Random Thoughts

Building the Development Version of Emacs on Windows (mingw edition)

Some days ago, I gave a brief write-up on how to build the development version of Emacs on Windows under Cygwin. Cygwin is all well and nice, but some prefer the fully native mingw-w64 version, so here’s the howto for that.

The first four steps are identical with the previous recipe, so let’s just skip to 5):

5) Install msys2 by clicking the “Download the installer” link, and then going through the installer.

6) You can now go back to the sofa where you’re no doubt lounging with your Linux laptop (I may just be speaking for myself here), and ssh in:

You can copy and paste the rest of this into your ssh session:

c:\msys64\usr\bin\bash
sed -i -E 's/^Match Group administrators|AuthorizedKeysFile __PROGRAMDATA__/#&/' c:/ProgramData/ssh/sshd_config
powershell -command "restart-service sshd"
pacman -Syu --noconfirm
# Will exit, so restart:
c:\msys64\usr\bin\bash
pacman --noconfirm -Su 
pacman --noconfirm -S git make autoconf
pacman --noconfirm -S --needed base-devel mingw-w64-x86_64-toolchain
pacman --noconfirm -S `pacman -Si mingw-w64-i686-emacs | sed -E ':a ; $!N ; s/\n\s+/ / ; ta ; P ; D' | grep Dep | sed 's/^[^:]*://'`
MSYSTEM=MINGW64 bash -l
git clone https://git.savannah.gnu.org/git/emacs.git
cd emacs
make -j4
./src/emacs

Man, that was painful to figure out, because apparently nobody has ever tried to build anything via ssh before, because all the recipes say “and then you start the mingw shell” (C:\msys64\mingw64.exe), which pops up a window on the Window machine, and is therefore useless. But the MSYSTEM=MINGW64 thing seems to work fine? I’m not sure, though — I don’t know nothing from no Windows.

In any case, a different way to start the shell in MINGW mode is:

c:\msys64\usr\bin\env MSYSTEM=MINGW64 c:\msys64\usr\bin\bash

OK, do this in Powershell:

$oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
$newpath = "$oldpath;c:\msys64\mingw64\bin"
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath

Now search for “runemacs.exe”, and click it, and then Emacs starts as it should, and you can edit c:\foo.bar. So I guess it worked! It’s a native Emacs.

That’s still a whole bunch of steps… anybody know a shorter recipe? I really can’t believe that pacman is this primitive… no equivalent of “apt build-dep”? All the build dependencies are kept in PKGBUILD scripts instead of a database?

Dude.

But look!

But more importantly, it works via ssh, too:

./src/emacs -nw

Exit mobile version