Implicit rules tell make how to use customary techniques so that you do not have to specify them in detail
when you want to use them.
The built-in implicit rules use several variables in their recipes so that, by changing the values of the
variables, you can change the way the implicit rule works.
For example,the variable CFLAGS controls the flags given to the C compiler by the implicit rule for C compilation.
You can define your own implicit rules by writing pattern rules.
Using Implicit Rules
To allow make to find a customary method for updating a target file, all you have to do is refrain from specifying
recipes yourself.
Either write a rule with no recipe, or don’t write a rule at all.
Then make will figure out which implicit rule to use based on which kind of source file exists or can be made.
foo:foo.o bar.o
cc -o foo foo.o bar.o $(CFLAGS) $(LDFLAGS)
#Because you mention foo.o but do not give a rule for it, make will automatically look for an implicit rule that
#tells how to update it.
#This happens whether or not the file foo.o currently exists.
If an implicit rule is found,it can supply both a recipe and one or more prerequisites(the source files).
You would want to write a rule for foo.o with no recipe if you need to specify additional prerequisites, such as
header files, that the implicit rule cannot supply.
If you do not want an implicit rule to be used for a target that has no recipe, you can give that target an empty
recipe by writing a semicolon.
Catalogue of Built-In Rules
To see the full list of default rules and variables available in your version of GNU make, run ‘make -p’ in a
directory with no makefile.
#可以查看编译时make使用的变量,规则,main是程序名
make -p main > info_file
Variables Used by Implicit Rules
The recipes in built-in implicit rules make liberal use of certain predefined variables.
You can alter the values of these variables in the makefile, with arguments to make, or in the environment to alter
how the implicit rules work without redefining the rules themselves.
For example, the recipe used to compile a C source file actually says ‘$(CC) -c $(CFLAGS) $(CPPFLAGS)’.
Defining and Redefining Pattern Rules
A pattern rule looks like an ordinary rule, except that its target contains the character ‘%’.
The target is considered a pattern for matching file names;the ‘%’ can match any nonempty substring, while other
characters match only themselves.
Note that expansion using ‘%’ in pattern rules occurs after any variable or function expansions, which take place
when the makefile is read.
‘s.%.c’ as a pattern matches any file name that starts with ‘s.’, ends in ‘.c’ and is at least five characters long.
(There must be at least one character to match the ‘%’.)
The substring that the ‘%’ matches is called the stem.
‘%’ in a prerequisite of a pattern rule stands for the same stem that was matched by the ‘%’ in the target.
A pattern rule need not have any prerequisites that contain ‘%’, or in fact any prerequisites at all.
Such a rule is effectively a general wildcard.
https://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html
https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
https://www.gnu.org/software/make/manual/html_node/Pattern-Rules.html