Skip to content

Instantly share code, notes, and snippets.

@gifnksm
Last active August 19, 2023 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gifnksm/ee9ddbad1d638fd90ebce443c5b86597 to your computer and use it in GitHub Desktop.
Save gifnksm/ee9ddbad1d638fd90ebce443c5b86597 to your computer and use it in GitHub Desktop.
Makefile Template
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