简体   繁体   中英

How to Get a List of Direct Dependencies on a Makefile Target

I am working on a project which has a little complicated Makefile.

It has a lot of function calls and string substitutes to get the list of objects and phony targets.

I am trying to get the direct dependency on an target, eg

FOO_VAR := abc def ghi

test: \
foo \
bar \
$(FOO_VAR) \
whatever

I should get

foo
bar
abc
def
ghi
whatever

Even if these targets have further dependencies.

I have followed

List goals/targets in GNU make that contain variables in their definition

to use make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\\/\\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}' make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\\/\\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'

However it will return all the targets, not just direct dependencies.

Does make -qp | grep 'target:' make -qp | grep 'target:' do what you want?

Or possibly make -qp | grep 'target.*:' make -qp | grep 'target.*:' (in case it isn't the only/last target on that line)?

Also see Eric Melski 's answer for a more efficient (but longer and requires small prep-work) command to run for the make bit of that pipeline.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM