robertchen
robertchen

Reputation: 461

Use the target name in a target-specific variable

Can I use the target name in a target-specific variable?

program_%: CFILE=path/program_%/do_it.c
                      ^^^^^^^^^^
                       This does not work

So that when doing "make program_xyz", the CFILE will be "path/program_xyz/do_it.c".

Upvotes: 0

Views: 53

Answers (1)

MadScientist
MadScientist

Reputation: 101111

It depends on what you want to use CFILE for. Since you gave us no details about that I'll just answer your exact question: sure, you can do that:

program_% : CFILE = path/program_$*/do_it.c

program_% : ; @echo $(CFILE)

$ make program_foo
path/program_foo/do_it.c

However, my suspicion is you wanted to do more with CFILE besides simply use it inside this recipe. If so, the above solution my not work for what you really want to do...

Upvotes: 1

Related Questions