antiAgainst
antiAgainst

Reputation: 43

how to print all the prerequisites and build rules for a target using make

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!

Upvotes: 4

Views: 2300

Answers (1)

Zoro_77
Zoro_77

Reputation: 415

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.

Upvotes: 1

Related Questions