static mode
In makefile, there can be multiple targets in a rule, and the commands defined by the rule are valid for all targets. A rule with multiple goals is equivalent to multiple rules. Using multiple targets can make the makefile file concise. A static mode rule is a rule in which a rule has multiple targets, and a different target can automatically construct a dependent file based on the name of the target file. static mode makes it easier to define multi-objective rules, which can make our rules more resilient and flexible. Let's take a look at the syntax first:<targets: <target-pattern>: <prereq-patterns ...><commands> ... The targets defines a series of target files, which can have wildcard characters. is a collection of targets. Target-parrtern is the pattern that indicates the targets, that is, the target set pattern. Prereq-parrterns is the dependent pattern of the target, which is the definition of a dependent target for the pattern formed by Target-parrtern. A simple explanation: If our <target-parrtern> is defined as "%.o", it means that our <target> collection ends with ". O", and if our <prereq-parrterns > is defined as "%.c", meaning that the target set formed by <target-parrtern> is defined two times, which is calculated by taking the "%" in the <target-parrtern> mode (that is, by removing the [. O] End), and add [. c] To this end, a new set of forms. Therefore, our "target mode" or "dependency mode" should have the "%" character, if you have "%" in the file name, then you can use the backslash "\" to escape, to indicate the real "%" characterSee an example:objects = foo.o bar.oAll : $ (objects)$ (objects):%.o:%.c$ (CC)-C $ (CFLAGS) $<-o [email protected] The above example indicates that our goal is obtained from $object, "%.O" indicates that all targets ending with ". O" are "foo.o bar.o", which is the pattern of the variable $object set, while the dependency mode "%.C" takes the "%" of the Mode "%.O", That is, "foo bar", and add the ". C" suffix, so our target is "foo.c bar.c". The command "$<" and "[email protected]" are automation variables (see [Makefile Notes] seven), "$<" represents all the dependent target set (that is, "foo.c bar.c"), "[Email protected]" Represents the target set (that is, "foo.o bar.o"). Thus, the above rules are expanded to be equivalent to the following rules:foo.o:foo.c$ (CC)-C $ (CFLAGS) Foo.c-o foo.obar.o:bar.c$ (CC)-C $ (CFLAGS) Bar.c-o bar.oImagine, if our "%.O" there are hundreds of, that we just use this very simple "static mode rule" can write a bunch of rules, it is too effective rate.
Can look at:
Http://www.gnu.org/software/make/manual/html_node/Static-Usage.html
We use the examples that we often use:
objects = FOO.O BAR.O
All: $ (objects)
$ (objects):%.o:%.c
$ (CC)-C $ (CFLAGS) $<-o [email protected]
I think it's possible to compare it to a wildcard character. The contents of $ (objects) are in. o format. And each. O is dependent on. C.
Makefile static mode