From 5ed42eb459c02350d610454d65f12edab10eda8e Mon Sep 17 00:00:00 2001 From: Benji York Date: Wed, 27 Mar 2024 07:48:07 -0500 Subject: [PATCH 1/2] fix errant PHONY, add PHONY linter One of the make PHONY targets was incorrect, so I fixed it and added a linter that would have caught the error. --- Makefile | 10 +++++++--- scripts/lint-make | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 scripts/lint-make diff --git a/Makefile b/Makefile index 69a42be3..d9edc485 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -none: clean +none:clean help: @echo "make test test Ward" @@ -15,13 +15,17 @@ help: setup: poetry install poetry run pre-commit install -.PHONY: requirements +.PHONY: setup format: poetry run pre-commit run --all .PHONY: format -lint: format +lint-make: + python scripts/lint-make +.PHONY: lint-make + +lint: format lint-make .PHONY: lint test: diff --git a/scripts/lint-make b/scripts/lint-make new file mode 100644 index 00000000..b1b54e55 --- /dev/null +++ b/scripts/lint-make @@ -0,0 +1,19 @@ +import sys + +with open('Makefile', 'rt') as makefile: + current_target = None + exit_code = 0 + for line in makefile: + words = line.split() + if not words: + continue + elif words[0] == '.PHONY:': + phony_target = words[1] + if current_target != phony_target: + print(f'Error: make target has wrong phony. Found {phony_target!r}, expected {current_target!r}.') + exit_code = 1 + current_target = None + elif words[0].endswith(':'): + current_target = words[0][:-1] + +sys.exit(exit_code) From 23cf61c7437c01d2afa928212d1c02a89902f532 Mon Sep 17 00:00:00 2001 From: Benji York Date: Wed, 27 Mar 2024 07:48:31 -0500 Subject: [PATCH 2/2] add Makefile preamble; make default target useful This adds a fairly standard Makefile config that is better suited to non-C projects and is safer than the defaults. This also changes the default target to a more standard "build" step instead of "clean". Now the pattern of "make clean; make; make test" works as expected. --- Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d9edc485..78e142e4 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,11 @@ -none:clean +SHELL := bash +.SHELLFLAGS := -eux -o pipefail -c +.DEFAULT_GOAL := setup +.DELETE_ON_ERROR: # If a recipe to build a file exits with an error, delete the file. +.SUFFIXES: # Remove the default suffixes which are for compiling C projects. +.NOTPARALLEL: # Disable use of parallel subprocesses. +MAKEFLAGS += --warn-undefined-variables +MAKEFLAGS += --no-builtin-rules help: @echo "make test test Ward"