Getting Makefiles Working on Windows 10

     

Windows 10 running emacs, golang and make

As you might know from some posts on here, I've been getting into 3D programming - AR / VR / spatial computing as well as dabbling in machine learning and parallel algorithms using GPUs. For the past few years, I've been doing this on hardware from like 2011. I needed an upgrade, and I couldn't find an offering from Apple that fit the bill.

So I've had to byte the bullet and leave the Apple ecosystem for the first time since… what… 2003. I'll probably wind up on Linux, but for now I am using Windows 10 - at least until after I play Valve's Half Life: Alyx.

Since I've lived in the POSIX world for so long, all my pet projects use Makefiles and bash scripts. Those don't work on Windows out of the box. This is how I got something working.

Note: Before you go through all this, you might be able to get away with Ubuntu on windows. You can install it from the Microsoft store free. It gives you a nice little Ubuntu shell. What I am doing, however, requires access to Windows shared libraries - like SDL2, Opengl - and I don't think you can access those libraries from within the Ubuntu shell. This setup seems to be the best of both worlds - albeit with some setup.

Chocolatey

So this will get a bit weird because you'll need to use a few different package managers. The first one is called Chocolatey. This will install programs into “the Windows world”: https://chocolatey.org/install

msys2 & mingw

These are poorly named apps that have over lap, and that makes things confusing. What I am about to say is not exactly correct, but for our purposes think of msys2 as your shell (aka bash), and mingw as a bunch of extra shell applications (like make, gcc, etc)

Install both of these apps into the windows world using Chocolatey via PowerShell via Run As Administrator:

choco install msys2 mingw

If you don't need make, you can probably get away with just msys2. It has gcc and a few other apps. However, if you need a real version of make

Getting Make Working

Now that we have both of those installed we'll need link them together. They are in their own worlds at the moment. Start up msys2 from within C:\tools\msys64 (that's the default location).

You'll want to edit the /etc/fstab file and mount the mingw tools. Edit /etc/fstab by adding the line:

C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64 /mingw64

If you don't have an editor in the default shell you could just do

sudo echo "C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64 /mingw64" >> /etc/fstab

Once that edit is made, close the shell and open it again (or just remount).

Now, add the new /mingw64 path to your shell's PATH variable. For example, add something like the following (inside msys2) to your ~/.bashrc file:

GOPATH=/c/Users/robro/go
PATH=/mingw64/bin:${PATH}:/c/Go/bin:'/c/Program Files/Git/cmd':${GOPATH}/bin

reload the file

source ~/.bashrc

And you should now be able to run mingw32-make.exe and should get the ol’ “*** No targets specified and no makefile found. Stop.". Almost there…

This works, but if you have any kind of make files that spawn other shells and run more make files, the system wont know what's going on. So we need to make a quick symlink:

cd /usr/bin
ln -s /mingw64/bin/mingw32-make.exe make

You don't want to make an alias for make because /bin/sh shells won't understand aliases.

After that, you should have a, normal, working make command you can run from anywhere.

(While you're here, I'd recommend you do the same process with: C:/tools /tools, /etc/fstab, add to your path, yadda)

Getting Automake

Some projects I have also use Automake. To get that you need to use the package mananager inside of msys2. It's called pacman and it's the same one used on Arch Linux (if you're looking for documentation).

To get automake, from within the msys2 shell:

pacman -Syu automake

You can add any tools you're missing this way as well. For example, a lame editor:

pacman -Syu vim

Or the clangd lsp server thing for C completion (via llvm):

pacman -Syu llvm

Windows 10 running lsp-mode and clangd in emacs

http://releases.llvm.org/download.html but that's a whole other post.

I didn't take the best notes while doing this, so a few things might be missing.

Good luck!