Configure Git Bash on Windows to run Make

Troy Williams

2021-10-02

Git, Make and Windows

I have developed a Python template repository that contains a number of makefiles for managing repositories. Among the tasks, it can help with constructing virtual environments ($ make venv) and installing all pip dependencies. It can optionally launch Jupyter notebooks ($ make launch). The real power comes from the fact that I can use the same set of commands for the basic management of the Python repositories. It is really very handy on Linux. I do development work on windows and I wanted to be able to use the makefiles there. Unfortunately, there wasn’t an easy way that I really liked. There are options like Cygwin and even WSL for Windows. Both of these options were too heavy to do what I wanted.

The makefiles are relatively straightforward. Besides make not running on windows, the command $ rm -rf that is used to remove the .venv folder does not work either. I don’t want to use a heavy system or something special for something that should be simple. That is when I stumbled on the Bash environment that Git installs on windows to operate. There is a way to get things to work nicely using that environment. The rest of the document will discuss the configuration.

Install Git

Installing Git on windows is pretty easy. Download the latest version and install it. The defaults are usually sufficient. You don’t really need to do anything special.

Modifying Git Bash - Adding More Items

You can find details in this article about installing many different items for support in Git bash. Git on windows, is bundled with the Bash shell. It is a lightweight shell that can run *nix like tools. We will exploit this to get make up and running. Since it is relatively light weight implementation and strictly focused on supporting Git, it doesn’t include all of the tools that I am looking for.

The bash environment has a root folder, that is /. If we download the binaries we want and put them in the correct folders, things should work.

On windows there are two possible locations of root:

  1. C:\Program Files\Git\mingw64\
  2. C:\Users\name\AppData\Local\Programs\Git\mingw64\

The exact location depends on how you installed Git on windows. Did you install it for everyone on the machine? If so, then it is probably location 1. If you installed it for yourself with no admin permissions, it is probably in location 2.

NOTE: You can use the bash terminal to discover the exact location. Type the following commands at the bash terminal:

$ cd /
$ pwd -W

c:/Users/troy.williams/AppData/Local/Git

Once you have the location you can open it in Windows Explorer and navigate to the mingw64 folder and observe a Linux like folder structure. These are the folders where you will need to place the binaries in.

NOTE: Some programs may not work properly with the mintty terminal. Try using the command winpty when calling them. For example $ winpty python.

Install Make

When we install make this way, we are installing make only. Not everything else in the tool chain you may need. If you need those tools, you have to install them separately and make sure they are available on the path.

You can download the files from here. At the time of this writing that was this file:

make-4.1-2-without-guile-w32-bin.zip

NOTE: Download the version without guile.

Once the file is downloaded, extract the contents of the zip file to a temporary folder. Copy the contents of the extracted zip file, files, folders and all to your mingw64 folder (see above for location). When you copy the files over, use the merge option to make sure the files and folders are put into the correct folder.

NOTE: Do not overwrite or replace any existing files. This shouldn’t happen, but is something to watch for.

NOTE: There are many other things you can install. See here for details.

Configure Make - Repo Template

To use the makefiles from the repo template, we need to configure the MakeFile.env. You can use the following as a guide to the modify MakeFile.env correctly:

PYPATH?=/c/tools/python/python_3.9.6
PY?=$(PYPATH)/python
VENV=.venv
BIN?=$(VENV)/Scripts

NOTE: The path to the Python folder cannot have any spaces in it. make doesn’t like spaces at all and will refuse to function.

NOTE: That we don’t specify the .exe. We also don’t have a bin folder on windows, it is Scripts (be mindful of the capitalization)

There are a few conditions to getting this to work properly. But nothing insurmountable.