I'm trying to write a Makefile where prerequisites using target specific variables
version=
target1: override version=1
target1: package
target2: override version=2
target2: package
package: dir=package-${version}\
package: source
source: src/${version}.c
When i run make the version variable is in target package and source empty.
What I'm doing wrong?
The file name of the target of the rule. If the target is an archive member, then ' $@ ' is the name of the archive file. In a pattern rule that has multiple targets (see Introduction to Pattern Rules), ' $@ ' is the name of whichever target caused the rule's recipe to be run.
An attribute is a specific value on a variable. For instance, the variable Student grade has two attributes: pass and fail . Or, the variable agreement might be defined as having five attributes: 1 = strongly disagree.
A 'make target' is basically a file that you want rebuilt. Make can't divine what you want built, so you have to tell it, implicitly or explicitly, what it should build.
Use Secondary Expansion:
.SECONDEXPANSION:
package: dir=package-$${version}
package: source
source: src/$${version}.c
This answer is wrong, the suggested code won't work because of the reasons explained in the answer to a similar question.
TL;DR: Target-specific variables take their effect based on the target that make is currently building [1]. Second expansion, in turn, takes place right at the end of the read-in phase [2], before building anything.
Thanks to @koniiiik for pointing out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With