Consider a long makefile with numerous targets, all of which are PHONY (meaning that the target name does not represent an existing file).
makefile
I can do either:<
One way to do it:
.PHONY: $(shell sed -n -e '/^$$/ { n ; /^[^ .\#][^ ]*:/ { s/:.*$$// ; p ; } ; }' $(MAKEFILE_LIST))
Works perfectly even for targets mentioned as dependencies.