Accueil / Blog / Métier / 2017 / Productivity tip: add a Makefile to your project

Productivity tip: add a Makefile to your project

Par Alex Marandon publié 19/04/2017
When you work on projects using different technologies, it can be tricky to remember commands to run tests, build the project, deploy, etc. Providing a Makefile with a generic interface makes it easier to switch between projects.
Productivity tip: add a Makefile to your project

Editing a Makefile

If you often switch between technology stacks, it can be hard to remember commands to run common tasks. Providing a Makefile with generic targets is a cheap way to make it easier to get started with the project, whether it's for a new developer or for your future self. There are a handful of targets that you may find useful for most projects:

  • develop: set up a development environment
  • serve: start a development web server
  • build: build distributable artifacts
  • test: run the automated test suite
  • coverage: produce a test coverage report
  • deploy: push to your staging or production environment

Adding a Makefile that implements those generic targets using the appropriate command lines acts as executable documentation. You can run all those targets as is, but if your particular need is not covered you can also open the Makefile to see how the existing targets are implemented and use them as a starting point for less common tasks. By reading the Makefile, you'll be able to tell which build tool is used by the project and you'll know where to go from there to find more documentation about this tool.

Here is a Makefile you may provide for a JavaScript project:

develop:
        npm install --dev

test:
        npm test

serve:
        npm start

And here is what the Makefile of a Django project may look like:

develop:
        pip install -r requirements.txt
        python manage.py migrate

test: clean
        python manage.py test

coverage:
        coverage run manage.py test
        coverage report

serve:
        python manage.py runserver

Of course, this tip is not only applicable to pure software projects, here is a Makefile for a static web site:

develop:
        pip install -r requirements.txt

build:
        wok

serve:
        wok --server --port=8901

deploy: build
        rsync -avz output/ myserver.example.com:/var/www/homepage

You can also add a Makefile to your presentation slides, your LaTeX resume... as long as you use command lines to manage it, put those commands in a Makefile and it will act as a nice executable reminder of what you can do with the project.

Of course you don't need to implement all targets for all projects. For instance a minify target would be relevant only to frontend projects. But try to use the same target names from project to project for consistency.

Getting into the habit of providing a Makefile with your project will make it easier for your colleagues and your future self to start working on it.

ABONNEZ-VOUS À LA NEWSLETTER !
Voir aussi
Python : Bien configurer son environnement de développement Python : Bien configurer son environnement de développement 07/12/2015

Comment utiliser les bonnes pratiques de développement Python.

Productivity tip: use a better grep 18/01/2017

Improve your life as a developer with a better tool for searching through text files

7 bonnes raisons d’utiliser le logiciel libre 7 bonnes raisons d’utiliser le logiciel libre 01/12/2015

Ensemble, on va plus loin !

Bonnes pratiques pour votre projet Open Source Bonnes pratiques pour votre projet Open Source 05/09/2014

Un recueil des détails qui participent à la qualité d'un projet mis à disposition de l'humanité

Chiffrer les mots de passe dans les fichiers de configuration avec Talend Chiffrer les mots de passe dans les fichiers de configuration avec Talend 19/12/2015

Une des bonnes pratiques de Talend pour faciliter le paramétrage de vos jobs consiste à stocker ...