How to get the list of targets in a makefile

gnu-makemakefiletargets

I've used rake a bit (a Ruby make program), and it has an option to get a list of all the available targets, eg

> rake --tasks
rake db:charset      # retrieve the charset for your data...
rake db:collation    # retrieve the collation for your da...
rake db:create       # Creates the databases defined in y...
rake db:drop         # Drops the database for your curren...
...

but there seems to be no option to do this in GNU make.

Apparently the code is almost there for it, as of 2007 – http://www.mail-archive.com/help-make@gnu.org/msg06434.html.

Anyway, I made little hack to extract the targets from a makefile, which you can include in a makefile.

list:
    @grep '^[^#[:space:]].*:' Makefile

It will give you a list of the defined targets. It's just a start – it doesn't filter out the dependencies, for instance.

> make list
list:
copy:
run:
plot:
turnin:

Best Answer

Under Bash (at least), this can be done automatically with tab completion:

make spacetabtab