Run Makefile on Windows (…kinda)

Run Makefile on Windows (…kinda)

Makefiles are super cool, they help you create an executable process. Why run files manually or update everything when only a few files changed? Established in 1976 and not at all obsolete in 2022, Makefiles still have their place.

Sounds great right? It is, unless you are running windows and don’t have access to a Unix (or Unix-like) operating system. I highly recommend getting a raspberry pi if you need a Unix system. It’s a flexible and light weight solution for most applications, also very affordable. Consider a situation though where you needed to use a windows machine. Maybe you’ve inherited a project you plan to sunset and need to do some testing. How could you use what you have, to work with Make?

To accomplish our task we will need to set up a Unix subsystem on our windows machine and then install make.

Step 1: Turn on the Windows Subsystem for Linux

To get started we need to turn on the Windows Subsystem for Linux. In the start menu type “Turn Windows features on and off”. From this menu, select (you guessed it) “Windows Subsystem for Linux” and click ok.

Step 2: Install Ubuntu for Windows

Now that you are able to install a subsystem, we can find a Ubuntu distribution from the windows store that works very well. I suggest you do a full backup of your machine before adding any subsystem. You can download Ubuntu here.

Once this is installed, launch Ubuntu and set up your user name and administrative password. Make sure you don’t lose this! Once complete, restart your machine.

While you still have to obey Ubuntu rules on file access and commands, you can find the pathway to your home folder under:

C:\Users\user\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\user

This makes it easy to drop files or open items in a text editor.

Step 3: VS Code

Launch VS Code, if you don’t have a copy you can download it for free here.

At the bottom of vs code you’ll see a symbol that allows you to launch VS code from within the subsystem.

Select “New WSL Window” to get started. You can go through the trouble of noticing the error messages and install WSL2, but I haven’t and things have run just fine.

There are a few packages I recommend installing for WSL that make your life a lot easier:

Step 4: Install Make

Now all you need to do is install make which is super easy:

sudo apt install make

Step 5: Install Python (optional)

I have been using Make with Python, to install this bring up a new terminal in VS Code. Then type:

sudo apt-get install python3.8

You can manually select with python distribution you would like, I prefer 3.7 or 3.8.

One important thing I’ll note is that if you have Python on your windows machine you need to manually change the VS code settings to the Ubuntu python distribution to use the debugger or launch code with the “run” button. It will run fine in the terminal, but let’s be honest – no one really does that.

In vs code type ctrl+shift+p and then type settings. Find “Preferences: Open Remove Settings (WSL: Ubuntu).

In this file enter the python pathway as /usr/bin/python3. If that doesn’t work set the python interpreter manually with:

here just paste in /usr/bin/python3 and you are good to go.

If you have installed python, you’ll also need pip which you can easily do with:

sudo apt install python3-pip

One thought on “Run Makefile on Windows (…kinda)

Comments are closed.

Comments are closed.