In an ongoing software development project we are using Makefile tasks to make running long and repetitive commands as easy and as fun as possible to run. They’re like bash aliases, shortcuts to performing recurrent jobs we frequently have to do while writing new code or testing applications. For example, we could define a task that runs unit tests and code standard checks on an application running in a Docker container like so:
test:
echo "Checking application code with PSR2 standards ..."
docker-compose exec -T php phpcs -v --standard=phpcs.xml ./app/src
echo "Running unit tests ..."
docker-compose exec -T php phpunit --colors=always --configuration ./app
and we would run the task with only the following command:
make test
Cool, right? I don’t have to remember all the exact commands to do what I need to do. And even if I forget the right task name (in this case, make test) I can just run the make command in the CLI and I’ll be provided a list of the tasks that I can use for the project.
Now Makefile tasks will run on Unix terminals out of the box. For Windows however, we still have to do some setup before Makefile tasks can run. For my machine at work, I did the following:
- Download and install GnuWin32
- Go to the install folder
C:\Program Files (x86)\GnuWin32\bin - Copy all files inside the bin folder to the root project directory (
libiconv2.dll,libintl3.dll,make.exe) - Add the installation bin directory to the system environment variables
Path
There are other tools that we can use to configure Makefile to run on Windows but this is a quick and easy way to do it. After that we can run make.exe test on the default cmd CLI but on some Unix-like terminals like the Docker Quickstart Terminal we can definitely use make test.