2
votes

A big project usually has a complicated Makefile system. There are lots of variable definitions and target-prerequisity dependencies scattered in different Makefiles. Any handy way to print all the prerequisites and build rules for a target?

To be specific, two questions:

Question 1

say I have four Makefiles:

Makefile1:

p: a b
    [some rule]

Makefile2:

q: c d
    [some rule]

Makefile3:

r: e f
    [some rule]

Makefile:

all: p q r
    [some rule]

Can I invoke some command to get some output similar to the following?

all: a b c d e f
    [rule 1]
    [rule 2]
    [rule 3]
    ......

Question 2

And, what if the entity I want to examine is just an ordinary binary instead of a target specified in Makefile? For example, how can I get the prerequisites and build rules for sha1sum in coreutils? (It is obvious there is no target named as sha1sum in coreutils' Makefile.)

I have looked into the help and manual of make, but in vain. Maybe I didn't figure out the correct keywords for googling. Can anyone help me? Thanks!

1
I'm not sure this would pick up the prerequisites from other Makefiles but adding this to a target would print the target and prerequisites : @echo $@ : $^user1172023
@cmotley I tried, but the results showed that this rule doesn't pick up prerequisites from other Makefiles. Anyway, thanks! And do you have any ideas on the second question? That is actually what I need.antiAgainst
make -n might be a partial solution. It does lose the specific target info though, and just prints the recipes.Clayton Stanley
@ClaytonStanley Yeah. Now I can use make -n and grep recursively as a partical solution. Thanks!antiAgainst

1 Answers

1
votes

I am a little unclear about the question, but have you tried the -p option. It prints the DAG generated from parsing the makefiles and prints the rules, dependencies and variable values

Any build even a complex one follows the same principles for building the targets. From your example what is unclear is how the dependencies a and b for instance get built. What is the final target.