How to become more productive using Makefile
Tags: make, python, django, productivity
Published: 2020-06-27 06:59:13


---
title: "How to become more productive using Makefile"
published: true
description: "How to become more productive using Makefile"
tags: make, python, django, productivity
cover_image: https://images.unsplash.com/photo-1560088032-d21fe602f4bc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80
---

Originally posted on [my blog](https://rapidpython.com/how-to-become-more-productive-using-makefile/)

## Introduction

You want to become more productive, automate your workflow, there are many tools to help you achieve your goal.

**make** gives you the flexibility to run and compile a program from source.
In this guide, we will use it to automate our development workflow.
Note: I will use Django as an example, but the technics are applicable to other technologies.
In this guide, I will use Makefile to automate many things in Django like database migration, superuser, deployment, and more.
At the end of the guide, you'll be more productive in your development.
Before you continue, ensure that **make** is installed in your system.

## Installation

In Order to use **make** we need two(2) things one(1) we need to install it in our system and finally we need to create a file called **Makefile**.

To install **make** in your system you can follow these links :
[OSX](https://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/)
[Windows](http://gnuwin32.sourceforge.net/packages/make.htm)

## Basic examples

To explore **make** let's begin with this simple program, go to any directory, and create a **Makefile**.
Note: Don't give it an extension.

```shell
$ mkdir test_make && cd test_make
$ touch Makefile
```

Open the file with your text editor and put this

```make
say_hello:
        echo "Hello world"
```

run the file by typing **make** inside the directory **test_make**

```shell
$ make
```

What is the output?
Here is what I get.

```shell
echo "Hello world"
Hello world
```

## Django integration

If you're a **Django** developer, you know how tedious is to repeat again and again these commands :

```shell
python manage.py runserver
python manage.py makemigrations
python manage.py migrate
...
```

Let's automate them with **make**

Clone the example project [here](https://github.com/xarala221/consume-restfull-api-with-django) and follow the **README** guide.

```shell
git clone https://github.com/xarala221/consume-restfull-api-with-django && cd consume-restfull-api-with-django
```

Run the application to ensure that everything is working fine.

```shell
python manage.py migrate
python manage.py runserver
```

Open your browser and go to [http://localhost:8000](http://localhost:8000/).

Inside the project, folder created a file called **Makefile** and add these lines.

```shell
touch Makefile
```

The final file will look like this

```Makefile
SHELL := /bin/bash

help:
	@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'

install:
	pipenv install

activate:
	pipenv shell

run:
	python manage.py runserver

migration:
	python manage.py makemigrations

migrate:
	python manage.py migrate

superuser:
	python manage.py createsuperuser

heroku:
	git push heroku master

deploy:
	docker-compose build
	docker-compose up -d

down:
	docker-compose down

```

you'll be more productive with these tips.

## Conclusion

Become more productive and make things done is very important, in this guide you've learned how to automate your workflow by using **make**.

What do you think about this? Let us know in the comment section.