Skip to content

Instantly share code, notes, and snippets.

@iNamik
Last active November 17, 2023 12:27
Show Gist options
  • Save iNamik/73fd1081fe299e3bc897d613179e4aee to your computer and use it in GitHub Desktop.
Save iNamik/73fd1081fe299e3bc897d613179e4aee to your computer and use it in GitHub Desktop.
Base Makefile With Ability To List Targets
##
# Base Makefile with ability to list targets
#
.PHONY: help about list targets
ME := $(realpath $(firstword $(MAKEFILE_LIST)))
# Contains trailing '/'
#
PWD := $(dir $(ME))
.DEFAULT_GOAL := help
##
# help
# Displays a (hopefully) useful help screen to the user
#
# NOTE: Keep 'help' as first target in case .DEFAULT_GOAL is not honored
#
help: about list ## This help screen
about:
@echo
@echo "Base Makefile with ability to list targets"
##
# list
# Displays a list of targets, using '##' comment as target description
#
# NOTE: ONLY targets with ## comments are shown
#
list: targets ## see 'targets'
targets: ## Lists targets
@echo
@echo "Make targets:"
@echo
@cat $(ME) | \
sed -n -E 's/^([^.][^: ]+)\s*:(([^=#]*##\s*(.*[^[:space:]])\s*)|[^=].*)$$/ \1 \4/p' | \
sort -u | \
expand -t15
@echo
@rseyf
Copy link

rseyf commented Feb 15, 2023

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment