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:
If you have bash completion for
make
installed, the completion script will define a function_make_target_extract_script
. This function is meant to create ased
script which can be used to obtain the targets as a list.Use it like this:
This one was helpful to me because I wanted to see the build targets required (and their dependencies) by the make target. I know that make targets cannot begin with a "." character. I don't know what languages are supported, so I went with egrep's bracket expressions.
I usually do:
It would come back with something like:
I hope this helps
Under Bash (at least), this can be done automatically with tab completion:
make
spacetabtabThis is far from clean, but did the job, for me.
I use
make -p
that dumps the internal database, ditch stderr, use a quick and dirtygrep -A 100000
to keep the bottom of the output. Then I clean the output with a couple ofgrep -v
, and finally usecut
to get what's before the colon, namely, the targets.This is enough for my helper scripts on most of my Makefiles.
EDIT: added
grep -v Makefile
that is an internal ruleMy favorite answer to this was posted by Chris Down at Unix & Linux Stack Exchange. I'll quote.
User Brainstone suggests piping to
sort -u
to remove duplicate entries:Source: How to list all targets in make? (Unix&Linux SE)