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.