make: Archive Update

1 
1 11.2 Implicit Rule for Archive Member Targets
1 =============================================
1 
1 Recall that a target that looks like 'A(M)' stands for the member named
1 M in the archive file A.
1 
1    When 'make' looks for an implicit rule for such a target, as a
1 special feature it considers implicit rules that match '(M)', as well as
1 those that match the actual target 'A(M)'.
1 
1    This causes one special rule whose target is '(%)' to match.  This
1 rule updates the target 'A(M)' by copying the file M into the archive.
1 For example, it will update the archive member target 'foo.a(bar.o)' by
1 copying the _file_ 'bar.o' into the archive 'foo.a' as a _member_ named
1 'bar.o'.
1 
1    When this rule is chained with others, the result is very powerful.
1 Thus, 'make "foo.a(bar.o)"' (the quotes are needed to protect the '('
1 and ')' from being interpreted specially by the shell) in the presence
1 of a file 'bar.c' is enough to cause the following recipe to be run,
1 even without a makefile:
1 
1      cc -c bar.c -o bar.o
1      ar r foo.a bar.o
1      rm -f bar.o
1 
1 Here 'make' has envisioned the file 'bar.o' as an intermediate file.
1 ⇒Chains of Implicit Rules Chained Rules.
1 
1    Implicit rules such as this one are written using the automatic
1 variable '$%'.  ⇒Automatic Variables.
1 
1    An archive member name in an archive cannot contain a directory name,
1 but it may be useful in a makefile to pretend that it does.  If you
1 write an archive member target 'foo.a(dir/file.o)', 'make' will perform
1 automatic updating with this recipe:
1 
1      ar r foo.a dir/file.o
1 
1 which has the effect of copying the file 'dir/file.o' into a member
1 named 'file.o'.  In connection with such usage, the automatic variables
1 '%D' and '%F' may be useful.
1 

Menu