Created
July 15, 2025 15:37
-
-
Save shauninman/3ad5326fe32d4a922722d649522f3eeb to your computer and use it in GitHub Desktop.
A command to list PHONY build targets in a makefile
This file contains hidden or 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
# add to ~/.zshrc | |
function phony() { | |
local MAKEFILE="makefile" | |
if [[ -n "$1" ]]; then | |
MAKEFILE="$1" | |
if [[ ! -f "$FILE" ]]; then | |
echo "phony: makefile '$MAKEFILE' not found." >&2 | |
return 1 | |
fi | |
fi | |
grep '^\.PHONY:' "$MAKEFILE" \ | |
| sed -E 's/^\.PHONY:[[:space:]]*//' \ | |
| awk -F '##' '{ | |
comment = ($2 ? $2 : "-"); | |
gsub(/^[ \t]+/, "", comment); | |
n = split($1, targets, /[[:space:]]+/); | |
for (i = 1; i <= n; i++) { | |
if (length(targets[i])) { | |
printf "\033[36m%-8s\033[0m %s\n", targets[i], comment; | |
} | |
} | |
}' \ | |
| sort | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment