Last active
September 28, 2023 07:30
-
-
Save odolbeau/d61a35e4767c723de59221234b766828 to your computer and use it in GitHub Desktop.
GNUmakefile - The file I use to define my own tasks without modifying the existing Makefile
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
include Makefile | |
# @See: https://stackoverflow.com/a/14061796 | |
# If you want to pass some arguments directly to your target, add it to the SUPPORTED_COMMANDS right here | |
SUPPORTED_COMMANDS := | |
SUPPORTS_MAKE_ARGS := $(findstring $(firstword $(MAKECMDGOALS)), $(SUPPORTED_COMMANDS)) | |
ifneq "$(SUPPORTS_MAKE_ARGS)" "" | |
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) | |
RUN_ARGS := $(subst :,\:,$(RUN_ARGS)) | |
$(eval $(RUN_ARGS):;@:) | |
endif | |
.DEFAULT_GOAL := custom_help | |
# The help target prints out all targets with their descriptions organized | |
# beneath their categories. The categories are represented by '##@' and the | |
# target descriptions by '##'. | |
# @See: https://www.padok.fr/en/blog/beautiful-makefile-awk | |
.PHONY: custom_help | |
custom_help: | |
@echo "\033[1;36m👇 CUSTOM MAKE COMMANDS 🥰\033[0m" | |
@awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[32m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[33m%s\033[0m\n", substr($$0, 5) } ' GNUmakefile | |
@echo "" | |
@echo "\033[1;36m👇 EXISTING COMMANDS\033[0m" | |
@echo "" | |
@$(MAKE) -sf Makefile | |
##@ CATEGORY DEMO | |
.PHONY: target | |
target: ## This is an example target you can use | |
.PHONY: target-with-deps | |
target-with-deps: target ## Another target | |
##@ ANOTHER EXAMPLE | |
.PHONY: another-task | |
another-task: ## Just another example in another category! 👌 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment