Make

tags
Coding

Make is a build automation tool.

Don’t deal with tabs

I have been annoyed with tabs in Makefiles many times. Some editors or copy-pasting functions automatically convert tabs to space and vice-versa and this can break your Makefile.

With GNU Make 4.0 or later, it is possible to set the prefix to some other fixed token. To use > as a prefix, put this at the beginning of your Makefile:

ifeq ($(origin .RECIPEPREFIX), undefined)
  $(error "This Make does not support .RECIPEPREFIX. \
    Please use GNU Make 4.0 or later")
endif
.RECIPEPREFIX = >

Document a make file for a user

Large Makefiles with lots of recipes can be overwhelming for someone trying your software for the first time. Many conventions exist about which standard recipes should be there, but it is also efficient to document them. This can be done by adding the following recipe to the Makefile (which will be run by default, to change this behavior, remove the first line):

.DEFAULT_GOAL := help
.PHONY: help

help:
  @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
  | sed -n 's/^\(.*\): \(.*\)##\(.*\)/\1|\3/p' \
  | column -t  -s '|'

← Back to Notes