Reputation: 483
What is the target member name in an archive in a makefile?
It is explained here: https://www.gnu.org/software/make/manual/html_node/Archive-Members.html#Archive-Members but I don't quite understand it since there's not a brief example.
If I have
target(name): name
echo $%
$%
is the automatic variable for target name.
If I use make target
, this won't run
why? What is "target member name" actually?
Upvotes: 2
Views: 2308
Reputation: 189789
The documentation you link to specifically explains this, near the beginning.
This construct is available only in targets and prerequisites, not in recipes! Most programs that you might use in recipes do not support this syntax and cannot act directly on archive members. Only
ar
and other programs specifically designed to operate on archives can do so. Therefore, valid recipes to update an archive member target probably must usear
.
So for example, to create an ar
archive called target
containing name
, the commands would be
touch name
ar cr target name
As a Makefile
, this is
target: name
ar cr $@ $^
name:
touch name
The target(name)
syntax is useful when you want to manipulate the copy of name
which is inside target
. For example, if name
was rebuilt at some point, your Makefile
might want to compare its date stamp against the date stamp of the name
member within target
, to decide whether you need to update the copy inside target
.
target(name): name
ar cr $@ $%
But this doesn't specify how to create target
in the first place; as far as I can tell, you need a recipe like the one at the top of my example for that.
Upvotes: 1