Makefiles

nicolaw 23rd October 2020 at 11:58am
TechnicalNotes

Don't forget that you get a bunch of handy implicit variables for free. Why bother using rm -f in your clean: target, when you could just use $(RM) instead?

.PHONY: as_few as_possible
.DEFAULT_GOAL := blerg

SHELL := $(shell command -v bash || echo /bin/bash)
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules

https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html

http://aegis.sourceforge.net/auug97.pdf

I especially love the question at the end of the paper:

"How can it be possible that we have been misusing make for 20 years?"

Which is quite funny especially because the paper itself is dated 1998, and it's still an issue.


Note to self, double check my use of phony target definitions. I'm pretty sure I've set some targets to be phony when they need not be.


MAKEFILE_REPO_DIR := $(notdir $(patsubst %/,%,$(dir $(realpath $(firstword $(MAKEFILE_LIST))))))