Skip to content

Instantly share code, notes, and snippets.

@flowl
Created January 28, 2025 14:05
Show Gist options
  • Save flowl/b7eddd0c71ca82fcf788258d301b4ad5 to your computer and use it in GitHub Desktop.
Save flowl/b7eddd0c71ca82fcf788258d301b4ad5 to your computer and use it in GitHub Desktop.
Listing make targets
# Credit: https://stackoverflow.com/questions/4219255/how-do-you-get-the-list-of-targets-in-a-makefile
# Make > 4.4.1
make --print-targets
# Make <= 4.4.1
.PHONY: list
list:
@LC_ALL=C $(MAKE) -pRrq -f $(firstword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/(^|\n)# Files(\n|$$)/,/(^|\n)# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | grep -E -v -e '^[^[:alnum:]]' -e '^$@$$'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment