Created
May 30, 2021 13:25
-
-
Save Thesola10/c6d118d8c29670297ca135c004d2eb31 to your computer and use it in GitHub Desktop.
Useful resources for pretty makefiles.
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
GREEN := $(shell tput setaf 2 2>/dev/null) | |
YELLOW := $(shell tput setaf 3 2>/dev/null) | |
BOLD := $(shell tput bold 2>/dev/null) | |
RESET := $(shell tput sgr0 2>/dev/null) | |
define rich_echo | |
printf "${BOLD}$(1)${RESET}\t$(2)\n" | |
endef | |
TARGET_MAX_CHAR_NUM=20 | |
## Show this message | |
help: | |
@echo '' | |
@echo 'Usage:' | |
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}' | |
@echo '' | |
@echo 'Targets:' | |
@awk '/^[a-zA-Z\-_0-9]+:/ { \ | |
helpMessage = match(lastLine, /^## (.*)/); \ | |
if (helpMessage) { \ | |
helpCommand = substr($$1, 0, index($$1, ":")-1); \ | |
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ | |
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \ | |
} \ | |
} \ | |
{ lastLine = $$0 }' $(MAKEFILE_LIST) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment