Roland Ver. 4.5 Informações Técnicas Página 121

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 212
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 120
Chapter 10: Using Implicit Rules 111
10 Using Implicit Rules
Certain standard ways of remaking target files are used very often. For example, one
customary way to make an object file is from a C source file using the C compiler, cc.
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. For example, there is an implicit rule
for C compilation. File names determine which implicit rules are run. For example, C
compilation typically takes a .c file and makes a .o file. So make applies the implicit rule
for C compilation when it sees this combination of file name endings.
A chain of implicit rules can apply in sequence; for example, make will remake a .o file
from a .y file by way of a .c file. See Section 10.4 [Chains of Implicit Rules], page 117.
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. See Section 10.3 [Variables Used by Implicit Rules], page 115.
You can define your own implicit rules by writing pattern rules. See Section 10.5 [Defining
and Redefining Pattern Rules], page 118.
Suffix rules are a more limited way to define implicit rules. Pattern rules are more general
and clearer, but suffix rules are retained for compatibility. See Section 10.7 [Old-Fashioned
Suffix Rules], page 125.
10.1 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.
For example, suppose the makefile looks like this:
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.
Each implicit rule has a target pattern and prerequisite patterns. There may be many
implicit rules with the same target pattern. For example, numerous rules make .o files:
one, from a .c file with the C compiler; another, from a .p file with the Pascal compiler;
and so on. The rule that actually applies is the one whose prerequisites exist or can be
made. So, if you have a file foo.c, make will run the C compiler; otherwise, if you have a
file foo.p, make will run the Pascal compiler; and so on.
Of course, when you write the makefile, you know which implicit rule you want make
to use, and you know it will choose that one because you know which possible prerequisite
Vista de página 120
1 2 ... 116 117 118 119 120 121 122 123 124 125 126 ... 211 212

Comentários a estes Manuais

Sem comentários