Updating a function library file with make
———————————
A library file is a packaged file for an object file (a program-compiled intermediate file). Under UNIX, it is generally the command "AR" to complete the packaging work.
Member of a library file
A function library file consists of multiple files. You can specify the function library file and its composition in the following format:
Archive (Member)
This is not a command, but a definition of a target and a dependency. In general, this usage is basically for the "ar" command to serve. Such as:
Foolib (HACK.O): HACK.O
AR cr foolib HACK.O
If you want to specify more than one member, separate them with spaces, such as:
Foolib (HACK.O kludge.o)
It is equivalent to:
Foolib (HACK.O) foolib (KLUDGE.O)
You can also use the shell's file wildcard characters to define, such as:
Foolib (*.O)
Second, the hidden rules of function library members
When make searches for an implicit rule for a target, a special feature is that if the target is in the form of "A (m)", it will turn the target into "(m)". So, if our members are "%.O" pattern definitions, and if we call makefile in the form of "make FOO.A (BAR.O)", the implied rules go to the "bar.o" rule, and if there is no rule to define BAR.O, then the built-in implication rules take effect, Make will go to the bar.c file to generate the BAR.O, and if you can find it, the command you want to execute is roughly the following:
Cc-c Bar.c-o BAR.O
AR R foo.a bar.o
Rm-f BAR.O
Another variable to note is "$%", which is an automation variable for a proprietary library file, see the "Automation variables" section for instructions.
Third, the suffix rule of the function library file
You can use "suffix rules" and "implied rules" to generate a library package file, such as:
. C.A:
$ (CC) $ (CFLAGS) $ (cppflags)-C $<-O $*.O
$ (AR) R [email protected] $*.o
$ (RM) $*.O
It is equivalent to:
(%.O):%.c
$ (CC) $ (CFLAGS) $ (cppflags)-C $<-O $*.O
$ (AR) R [email protected] $*.o
$ (RM) $*.O
Iv. Matters of note
Be careful with the parallel mechanism of make (the "-j" parameter) when making a library package file generation. If more than one AR command runs on the same library package at the same time, it can corrupt the library file. Therefore, in the make future release, a mechanism should be provided to avoid parallel operations occurring on the function packaging file.
But for now, you should not try to avoid using the "-j" parameter.