Last active
August 19, 2023 10:01
-
-
Save gifnksm/ee9ddbad1d638fd90ebce443c5b86597 to your computer and use it in GitHub Desktop.
Makefile Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAKEFLAGS += --warn-undefined-variables | |
MAKEFLAGS += --no-builtin-rules | |
MAKEFLAGS += --no-builtin-variables | |
SHELL := bash | |
.SHELLFLAGS := -eu -o pipefail -c | |
.DELETE_ON_ERROR: | |
.SECONDARY: # don't remove intermediate files | |
.SECONDEXPANSION: | |
.PHONY: default | |
default: help | |
## Build the project | |
.PHONY: all | |
all: | |
## Print this message | |
.PHONY: help | |
help: | |
@printf "Available targets:\n\n" | |
@awk '/^[a-zA-Z\-_0-9%:\\]+/ { \ | |
helpMessage = match(lastLine, /^## (.*)/); \ | |
if (helpMessage) { \ | |
helpCommand = $$1; \ | |
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ | |
gsub("\\\\", "", helpCommand); \ | |
gsub(":+$$", "", helpCommand); \ | |
printf " \x1b[32;01m%-24s\x1b[0m %s\n", helpCommand, helpMessage; \ | |
} \ | |
} \ | |
{ \ | |
if ($$0 !~ /^.PHONY/) { \ | |
lastLine = $$0 \ | |
} \ | |
} \ | |
' $(MAKEFILE_LIST) | sort -u | |
@printf "\n" | |
.PHONY: FORCE | |
FORCE: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment