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

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 212
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 25
16 GNU make
the information in the containing makefile, make should look in another makefile. See
Section 10.5 [Pattern Rules], page 118, for more information on pattern rules.
For example, if you have a makefile called Makefile that says how to make the target
foo (and other targets), you can write a makefile called GNUmakefile that contains:
foo:
frobnicate > foo
%: force
@$(MAKE) -f Makefile $@
force: ;
If you say make foo’, make will find GNUmakefile, read it, and see that to make foo,
it needs to run the recipe frobnicate > foo’. If you say make bar’, make will find no
way to make bar in GNUmakefile, so it will use the recipe from the pattern rule: make
-f Makefile bar’. If Makefile provides a rule for updating bar, make will apply the rule.
And likewise for any other target that GNUmakefile does not say how to make.
The way this works is that the pattern rule has a pattern of just %’, so it matches any
target whatever. The rule specifies a prerequisite force, to guarantee that the recipe will
be run even if the target file already exists. We give the force target an empty recipe to
prevent make from searching for an implicit rule to build it—otherwise it would apply the
same match-anything rule to force itself and create a prerequisite loop!
3.7 How make Reads a Makefile
GNU make does its work in two distinct phases. During the first phase it reads all the make-
files, included makefiles, etc. and internalizes all the variables and their values, implicit and
explicit rules, and constructs a dependency graph of all the targets and their prerequisites.
During the second phase, make uses these internal structures to determine what targets will
need to be rebuilt and to invoke the rules necessary to do so.
It’s important to understand this two-phase approach because it has a direct impact
on how variable and function expansion happens; this is often a source of some confusion
when writing makefiles. Here we will present a summary of the phases in which expansion
happens for different constructs within the makefile. We say that expansion is immediate if
it happens during the first phase: in this case make will expand any variables or functions
in that section of a construct as the makefile is parsed. We say that expansion is deferred if
expansion is not performed immediately. Expansion of a deferred construct is not performed
until either the construct appears later in an immediate context, or until the second phase.
You may not be familiar with some of these constructs yet. You can reference this section
as you become familiar with them, in later chapters.
Variable Assignment
Variable definitions are parsed as follows:
immediate = deferred
immediate ?= deferred
immediate := immediate
immediate ::= immediate
immediate += deferred or immediate
Vista de página 25
1 2 ... 21 22 23 24 25 26 27 28 29 30 31 ... 211 212

Comentários a estes Manuais

Sem comentários