0

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.

Community
  • 1
  • 1
Kevin Y.
  • 139
  • 1
  • 6

1 Answers1

2

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.

Community
  • 1
  • 1
Etan Reisner
  • 77,877
  • 8
  • 106
  • 148