Kevin Y.
Kevin Y.

Reputation: 139

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, e.g.

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]}'

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

Upvotes: 0

Views: 692

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 81042

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

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

Upvotes: 2

Related Questions