Re: Multiple rules for same target: what is the order of prerequisites in $^ and what does $< expand to?

Paul Smith <[email protected]>
Newsgroups gmane.comp.gnu.make.general
Organization GNU's Not UNIX!
Message-ID <[email protected]>
On Mon, 2023-10-02 at 11:48 -0700, Bahman Movaqar wrote:
> my-target : foo
> my-target :
>         @echo 'my-target: $$(<) is $(<)'

This is an unusual way to construct this rule.  Normally it would be:

  my-target : foo
            @echo 'my-target: $$< is $<'

whereupon the value of $< is reliably "foo" regardless of anything else
in the makefile.

> That brings me to the natural question:  why would anyone ever use
> `$(<)'?  In other words, what is an appropriate usecase for that
> variable?

You have to use automatic variables, including $<, when you write
implicit rules.  There is no other option.

I agree that if you're writing a rule with a recipe and you DO NOT
provide at least one prerequisite, it's probably a bad idea to use $<
in the recipe since you have no idea what it will be.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.