From fdc6c4aac69304dc1dbdcb177341f8f8000a2ddf Mon Sep 17 00:00:00 2001 From: Alexander Hinrichs Date: Wed, 15 Jan 2025 07:52:03 +0100 Subject: [PATCH] add autogeneration of help target for Makefile Will aggregate targets and comments behind the target, sort them by target alphabetically and print the output. Removes requirement to update help target everytime something changes. targets without comment will not appear in help output. --- Makefile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 557734d..4e8ca77 100644 --- a/Makefile +++ b/Makefile @@ -7,27 +7,25 @@ GO_CLEAN = $(GO_CMD) clean BUILD_DIR = build BINARY = $(BUILD_DIR)/$(APP_NAME) -.PHONY: build +.PHONY: all build help clean install all: build -build: +build: ## Build the application @echo "Building $(APP_NAME)..." $(GO_BUILD) -o $(BINARY) -install: build +install: build ## Install the application @echo "Installing $(APP_NAME)..." $(GO_INSTALL) -clean: +clean: ## Remove build artifacts @echo "Cleaning up build artifacts..." $(GO_CLEAN) rm -f $(BINARY) -help: +help: ## Print the make targets @echo "Makefile for $(APP_NAME)" - @echo "Usage:" - @echo " make build - Build the application" - @echo " make install - Install the application" - @echo " make clean - Remove build artifacts" - @echo " make - Default target (build)" + @echo "Targets:" + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' +