How can I query prerequisites of a target from a GNU Make makefile?
E.g. if the targets specified like this:
fred: wilma barney betty
I want to print prerequisites of
fred like this:
$ make some_action fred wilma barney betty
Maybe a dry run is what you are looking for?
The man page gives us this about the dry run:
So it will not give you a direct list, but a indirect list since you know that he would like to execute what he depends on.
Another possibility, though one that gives you tons more info than you want, is the "print database" option. From the manual:
Fair warning, though: sifting through this mess will be brutal without some post-processing.
Let's say your Makefile is this:
The latest version of remake has a
In an older version of remake, here is how you could get the dependencies using
$ remake -X -f Makefile GNU Make 4.1+dbg0.91 Built for x86_64-unknown-linux-gnu Copyright (C) 1988-2014 Free Software Foundation, Inc. Copyright (C) 2015 Rocky Bernstein. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Reading makefiles... Updating makefiles.... Updating goal targets.... File 'fred' does not exist. File 'wilma' does not exist. Must remake target 'wilma'. Successfully remade target file 'wilma'. <- (/tmp/??:0) wilma remake<0> target fred depend fred: wilma barney betty remake<1> quit remake: That's all, folks...
If you put those commands issued into a file, say
Then you can run:
I leave as an exercise how to do something more elaborate such as writing program that takes a dependency name and runs the above.