Sure, but when do you want it to spit them out?
To report the name of the target when it runs the rule, put a line in the rule:
foo$(VAR): $(PREREQS)
@echo now making the foo target: $@
do_other_stuff...
To spit them all out at once, you could make a separate PHONY target:
.PHONY: show_vars
show_vars:
@echo foo$(VAR)
@echo bar$(PARAM) blah$(FLAG)
# and so on
And this can be made a prerequisite of your default target:
all: show_vars
...
EDIT:
You want a way to show all possible targets of an arbitrary makefile, which I suppose means non-intrusively. Well...
To do it exactly, and be able to cope with sophisticated makefiles, e.g. involving rules constructed by eval
statements, you'd have to write something close to a Make emulator. Impractical.
To see the targets of the simple rules, you could write a makefile that would act as a makefile scanner, operating on an arbitrary makefile:
- Get all the target names from the makefile using sed.
- `include` the makefile in order to use it to expand variables.
- Use `show_%: ; echo $$*` to print all the targets
This would be an impressive piece of work. Are you sure the goal is worth the effort?