Makefile self documenting

# max char num in help function TARGET_MAX_CHAR_NUM=20 # the help function enables us to use '## my-comment' syntax above a function to display it in `$ make help` or `$ make` ## Shows this help help: @echo 'command collection for controlling some project related tasks' @echo '' @echo 'usage:' @echo ' ${YELLOW}make${RESET} ${GREEN}<command>${RESET}' @echo '' @echo 'commands:' @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) @echo '' ## Run a test test: @echo "test"

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.