Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
    
This doesn't answer your question, but have you considered alternative to GNU Make. I use SCons, which is good for small programs at least. With larger ones it supposedly has performance problems. If you know Python, then that is an even better reason to use it, since SCons build recipes are written in Python. –  Faheem Mitha Sep 26 '11 at 15:21

2 Answers 2

Maybe a dry run is what you are looking for?

make --dry-run fred

The man page gives us this about the dry run:

-n, --just-print, --dry-run, --recon
  Print the commands that would be  executed,  but  do  not 
  execute them.

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.

share|improve this answer

Another possibility, though one that gives you tons more info than you want, is the "print database" option. From the manual:

   ‘-p’
   ‘--print-data-base’
      Print the data base (rules and variable values) that results from reading the
      makefiles; then execute as usual or as otherwise specified. This also prints the
      version information given by the ‘-v’ switch (see below). To print the data base
      without trying to remake any files, use ‘make -qp’. To print the data base of
      predefined rules and variables, use ‘make -p -f /dev/null’. The data base output
      contains file name and line number information for recipe and variable
      definitions, so it can be a useful debugging tool in complex environments.

Fair warning, though: sifting through this mess will be brutal without some post-processing.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.