Skip to content

Instantly share code, notes, and snippets.

@shauninman
Created July 15, 2025 15:37
Show Gist options
  • Save shauninman/3ad5326fe32d4a922722d649522f3eeb to your computer and use it in GitHub Desktop.
Save shauninman/3ad5326fe32d4a922722d649522f3eeb to your computer and use it in GitHub Desktop.
A command to list PHONY build targets in a makefile
# 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