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

人走茶凉 提交于 2019-12-24 01:12:57

问题


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 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.



来源:https://stackoverflow.com/questions/13727059/how-to-print-all-the-prerequisites-and-build-rules-for-a-target-using-make

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!