If there is no response to an urgent issue, you can escalate to the general security mailing list for advice. Development of Make, and GNU in general, is a volunteer effort, and you can contribute. For information, please read How to help GNU.
If you'd like to get involved, it's a good idea to join the discussion mailing list see above. We defend the rights of all software users. There are also other ways to contact the FSF. GNU Make GNU Make is a tool which controls the generation of executables and other non-source files of a program from the program's source files. Capabilities of Make Make enables the end user to build and install your package without knowing the details of how that is done -- because these details are recorded in the makefile that you supply.
Make figures out automatically which files it needs to update, based on which source files have changed. It also automatically determines the proper order for updating files, in case one non-source file depends on another non-source file. Make is not limited to any particular language. For each non-source file in the program, the makefile specifies the shell commands to compute it.
These shell commands can run a compiler to produce an object file, the linker to produce an executable, ar to update a library, or TeX or Makeinfo to format documentation. Make is not limited to building a package. You can also use Make to control installing or deinstalling a package, generate tags tables for it, or anything else you want to do often enough to make it worth while writing down how to do it. Make Rules and Targets A rule in the makefile tells Make how to execute a series of commands in order to build a target file from source files.
Here is what a simple rule looks like: target: dependencies The other way in which make processes recipes is by expanding any variable references in them see Basics of Variable References.
This occurs after make has finished reading all the makefiles and the target is determined to be out of date; so, the recipes for targets which are not rebuilt are never expanded.
Variable and function references in recipes have identical syntax and semantics to references elsewhere in the makefile. Normally make prints each line of the recipe before it is executed. We call this echoing because it gives the appearance that you are typing the lines yourself. Typically you would use this for a command whose only effect is to print something, such as an echo command to indicate progress through the makefile:. See Summary of Options.
This flag is useful for finding out which recipes make thinks are necessary without actually doing them. A rule in the makefile for the special target. When it is time to execute recipes to update a target, they are executed by invoking a new sub-shell for each line of the recipe, unless the. Please note: this implies that setting shell variables and invoking shell commands such as cd that set a context local to each process will not affect the following lines in the recipe. Then make will invoke one shell to run the entire line, and the shell will execute the statements in sequence.
Sometimes you would prefer that all the lines in the recipe be passed to a single invocation of the shell.
There are generally two situations where this is useful: first, it can improve performance in makefiles where recipes consist of many command lines, by avoiding extra processes. Second, you might want newlines to be included in your recipe command for example perhaps you are using a very different interpreter as your SHELL.
ONESHELL special target appears anywhere in the makefile then all recipe lines for each target will be provided to a single invocation of the shell. Newlines between recipe lines will be preserved. This feature is intended to allow existing makefiles to add the. Since the special prefix characters are not legal at the beginning of a line in a POSIX shell script this is not a loss in functionality.
For example, this works as expected:. Even with this special feature, however, makefiles with. For example, normally if any line in the recipe fails, that causes the rule to fail and no more recipe lines are processed. You can modify. Ultimately you may need to harden your recipe lines to allow them to work with. The argument s passed to the shell are taken from the variable.
The default value of. This is because the SHELL environment variable is used to specify your personal choice of shell program for interactive use. It would be very bad for personal choices like this to affect the functioning of makefiles. See Variables from the Environment. Furthermore, when you do set SHELL in your makefile that value is not exported in the environment to recipe lines that make invokes. You can override this behavior by explicitly exporting SHELL see Communicating Variables to a Sub- make , forcing it to be passed in the environment to recipe lines.
The stock shell, command. In every directory it examines, make will first look for the specific file sh in the example above.
If this is not found, it will also look in that directory for that file with one of the known extensions which identify executable files. For example. If any of these attempts is successful, the value of SHELL will be set to the full pathname of the shell as found. However, if none of these is found, the value of SHELL will not be changed, and thus the line that sets it will be effectively ignored.
This is so make will only support features specific to a Unix-style shell if such a shell is actually installed on the system where make runs. Note that this extended search for the shell is limited to the cases where SHELL is set from the Makefile; if it is set in the environment or command line, you are expected to set it to the full pathname of the shell, exactly as things are on Unix.
GNU make knows how to execute several recipes at once. Normally, make will execute only one recipe at a time, waiting for it to finish before executing the next. You can inhibit parallelism in a particular makefile with the. The default number of job slots is one, which means serial execution one thing at a time. Handling recursive make invocations raises issues for parallel execution.
For more information on this, see Communicating Options to a Sub- make. If a recipe fails is killed by a signal or exits with a nonzero status , and errors are not ignored for that recipe see Errors in Recipes , the remaining recipe lines to remake the same target will not be run. If make terminates for any reason including a signal with child processes running, it waits for them to finish before actually exiting. When the system is heavily loaded, you will probably want to run fewer jobs than when it is lightly loaded.
When running several recipes in parallel the output from each recipe appears as soon as it is generated, with the result that messages from different recipes may be interspersed, sometimes even appearing on the same line. This can make reading the output very difficult. This option instructs make to save the output from the commands it invokes and print it all once the commands are completed.
Additionally, if there are multiple recursive make invocations running in parallel, they will communicate so that only one of them is generating output at a time. There are four levels of granularity when synchronizing output, specified by giving an argument to the option e.
This is the default: all output is sent directly as it is generated and no synchronization is performed. Output from each individual line of the recipe is grouped and printed as soon as that line is complete. If a recipe consists of multiple lines, they may be interspersed with lines from other recipes. Output from the entire recipe for each target is grouped and printed once the target is complete.
This is the default if the --output-sync or -O option is given with no argument. Output from each recursive invocation of make is grouped and printed once the recursive invocation is complete. Regardless of the mode chosen, the total build time will be the same. The only difference is in how the output appears.
The difference between them is in how recipes that contain recursive invocations of make are treated see Recursive Use of make. This ensures output from all the targets built by a given recursive make instance are grouped together, which may make the output easier to understand.
However it also leads to long periods of time during the build where no output is seen, followed by large bursts of output. If you are not watching the build as it proceeds, but instead viewing a log of the build after the fact, this may be the best option for you.
If you are watching the output, the long gaps of quiet during the build can be frustrating. The recursive make will perform the synchronization for its targets and the output from each will be displayed immediately when it completes.
Be aware that output from recursive lines of the recipe are not synchronized for example if the recursive line prints a message before running make , that message will not be synchronized. For example, many programs that can display colorized output will not do so if they determine they are not writing to a terminal.
Two processes cannot both take input from the same device at the same time. To make sure that only one recipe tries to take input from the terminal at once, make will invalidate the standard input streams of all but one running recipe.
It is unpredictable which recipe will have a valid standard input stream which will come from the terminal, or wherever you redirect the standard input of make. The first recipe run will always get it first, and the first recipe started after that one finishes will get it next, and so on. We will change how this aspect of make works if we find a better alternative. In the mean time, you should not rely on any recipe using standard input at all if you are using the parallel execution feature; but if you are not using this feature, then standard input works normally in all recipes.
After each shell invocation returns, make looks at its exit status. If the shell completed successfully the exit status is zero , the next line in the recipe is executed in a new shell; after the last line is finished, the rule is finished. If there is an error the exit status is nonzero , make gives up on the current rule, and perhaps on all rules. Sometimes the failure of a certain recipe line does not indicate a problem.
For example, you may use the mkdir command to ensure that a directory exists. If the directory already exists, mkdir will report an error, but you probably want make to continue regardless. This is less flexible but sometimes useful.
When an error happens that make has not been told to ignore, it implies that the current target cannot be correctly remade, and neither can any other that depends on it either directly or indirectly.
No further recipes will be executed for these targets, since their preconditions have not been achieved. Normally make gives up immediately in this circumstance, returning a nonzero status. The usual behavior assumes that your purpose is to get the specified targets up to date; once make learns that this is impossible, it might as well report the failure immediately.
Usually when a recipe line fails, if it has changed the target file at all, the file is corrupted and cannot be used—or at least it is not completely updated. The situation is just the same as when the shell is killed by a signal; see Interrupts.
So generally the right thing to do is to delete the target file if the recipe fails after beginning to change the file. This is almost always what you want make to do, but it is not historical practice; so for compatibility, you must explicitly request it.
If make gets a fatal signal while a shell is executing, it may delete the target file that the recipe was supposed to update. The purpose of deleting the target is to make sure that it is remade from scratch when make is next run. Why is this? Suppose you type Ctrl-c while a compiler is running, and it has begun to write an object file foo.
The Ctrl-c kills the compiler, resulting in an incomplete file whose last-modification time is newer than the source file foo. But make also receives the Ctrl-c signal and deletes this incomplete file. If make did not do this, the next invocation of make would think that foo. You can prevent the deletion of a target file in this way by making the special target. Before remaking a target, make checks to see whether it appears on the prerequisites of. Some reasons why you might do this are that the target is updated in some atomic fashion, or exists only to record a modification-time its contents do not matter , or must exist at all times to prevent other sorts of trouble.
Although make does its best to clean up there are certain situations in which cleanup is impossible. For example, make may be killed by an uncatchable signal. Or, one of the programs make invokes may be killed or crash, leaving behind an up-to-date but corrupt target file: make will not realize that this failure requires the target to be cleaned.
Or make itself may encounter a bug and crash. Most commonly these recipes create temporary files rather than updating the target directly, then rename the temporary file to the final target name. Recursive use of make means using make as a command in a makefile. This technique is useful when you want separate makefiles for various subsystems that compose a larger system.
You can do it by writing this:. You can write recursive make commands just by copying this example, but there are many things to know about how they work and why, and about how the sub- make relates to the top-level make.
This value is never touched by make again: in particular note that if you include files from other directories the value of CURDIR does not change. The value has the same precedence it would have if it were set in the makefile by default, an environment variable CURDIR will not override this value. Note that setting this variable has no impact on the operation of make it does not cause make to change its working directory, for example. The value of this variable is the file name with which make was invoked.
If you use a special version of make to run the top-level makefile, the same special version will be executed for recursive invocations.
See Instead of Executing the Recipes. This special feature is only enabled if the MAKE variable appears directly in the recipe: it does not apply if the MAKE variable is referenced through expansion of another variable. Recipe lines containing MAKE are executed normally despite the presence of a flag that causes most recipes not to be run. Variable values of the top-level make can be passed to the sub- make through the environment by explicit request.
To pass down, or export , a variable, make adds the variable and its value to the environment for running each line of the recipe. The sub- make , in turn, uses the environment to initialize its table of variable values. Except by explicit request, make exports a variable only if it is either defined in the environment initially or set on the command line, and if its name consists only of letters, numbers, and underscores. Some shells cannot cope with environment variable names consisting of characters other than letters, numbers, and underscores.
See Choosing the Shell. Variables are not normally passed down if they were created by default by make see Variables Used by Implicit Rules. The sub- make will define these for itself. If you want to export specific variables to a sub- make , use the export directive, like this:. If you want to prevent a variable from being exported, use the unexport directive, like this:. In both of these forms, the arguments to export and unexport are expanded, and so could be variables or functions which expand to a list of variable names to be un exported.
You may notice that the export and unexport directives work in make in the same way they work in the shell, sh. This tells make that variables which are not explicitly mentioned in an export or unexport directive should be exported. Any variable given in an unexport directive will still not be exported.
If you use export by itself to export variables by default, variables whose names contain characters other than alphanumerics and underscores will not be exported unless specifically mentioned in an export directive. The behavior elicited by an export directive by itself was the default in older versions of GNU make.
If your makefiles depend on this behavior and you want to be compatible with old versions of make , you can write a rule for the special target. This will be ignored by old make s, while the export directive will cause a syntax error. Likewise, you can use unexport by itself to tell make not to export variables by default. Since this is the default behavior, you would only need to do this if export had been used by itself earlier in an included makefile, perhaps.
You cannot use export and unexport by themselves to have variables exported for some recipes and not for others. The last export or unexport directive that appears by itself determines the behavior for the entire run of make. The incrementation happens when make sets up the environment for a recipe.
This variable, if defined in the outer-level makefile, is passed down through the environment; then it serves as a list of extra makefiles for the sub- make to read before the usual or specified ones. This variable is set up automatically by make to contain the flag letters that make received.
In response, it takes the flags from that value and processes them as if they had been given as arguments. See Overriding Variables. This is not usually useful to do.
You probably do not care about this. If you want your makefiles to be compatible with old make programs, use this technique; it will work fine with more modern make versions too. That variable is set only for compatibility; make does not interpret a value you set for it in any way. If you do put MAKEFLAGS in your environment, you should be sure not to include any options that will drastically affect the actions of make and undermine the purpose of makefiles and of make itself.
When the same sequence of commands is useful in making various targets, you can define it as a canned sequence with the define directive, and refer to the canned sequence from the recipes for those targets. The canned sequence is actually a variable, so the name must not conflict with other variable names. Here run-yacc is the name of the variable being defined; endef marks the end of the definition; the lines in between are the commands. See Defining Multi-Line Variables , for a complete explanation of define.
The first command in this example runs Yacc on the first prerequisite of whichever rule uses the canned sequence. The output file from Yacc is always named y. To use the canned sequence, substitute the variable into the recipe of a rule. You can substitute it like any other variable see Basics of Variable References. Because variables defined by define are recursively expanded variables, all the variable references you wrote inside the define are expanded now.
This is a realistic example, but this particular one is not needed in practice because make has an implicit rule to figure out these commands based on the file names involved see Using Implicit Rules.
In recipe execution, each line of a canned sequence is treated just as if the line appeared on its own in the rule, preceded by a tab. In particular, make invokes a separate sub-shell for each line. For example, using this canned sequence:. But it will echo the following two recipe lines. On the other hand, prefix characters on the recipe line that refers to a canned sequence apply to every line in the sequence.
So the rule:. It is sometimes useful to define recipes which do nothing. This is done simply by giving a recipe that consists of nothing but whitespace. You could also use a line beginning with a recipe prefix character to define an empty recipe, but this would be confusing because such a line looks empty. You may be wondering why you would want to define a recipe that does nothing. One reason this is useful is to prevent a target from getting implicit recipes from implicit rules or the.
You may be inclined to define empty recipes for targets that are not actual files, but only exist so that their prerequisites can be remade. However, this is not the best way to do that, because the prerequisites may not be remade properly if the target file actually does exist. See Phony Targets , for a better way to do this. These values are substituted by explicit request into targets, prerequisites, recipes, and other parts of the makefile.
In some other versions of make , variables are called macros. Variables can represent lists of file names, options to pass to compilers, programs to run, directories to look in for source files, directories to write output in, or anything else you can imagine. However, variable names containing characters other than letters, numbers, and underscores should be considered carefully, as in some shells they cannot be passed through the environment to a sub- make see Communicating Variables to a Sub- make.
Variable names are case-sensitive. It is traditional to use upper case letters in variable names, but we recommend using lower case letters for variable names that serve internal purposes in the makefile, and reserving upper case for parameters that control implicit rules or for parameters that the user should override with command options see Overriding Variables. A few variables have names that are a single punctuation character or just a few characters.
These are the automatic variables , and they have particular specialized uses. See Automatic Variables. Variable references can be used in any context: targets, prerequisites, recipes, most directives, and new variable values. Here is an example of a common case, where a variable holds the names of all the object files in a program:. A dollar sign followed by a character other than a dollar sign, open-parenthesis or open-brace treats that single character as the variable name.
However, this practice can lead to confusion e. One place where readability is often improved is automatic variables see Automatic Variables. There are two ways that a variable in GNU make can have a value; we call them the two flavors of variables. The two flavors are distinguished in how they are defined and in what they do when expanded. The first flavor of variable is a recursively expanded variable. The value you specify is installed verbatim; if it contains references to other variables, these references are expanded whenever this variable is substituted in the course of expanding some other string.
When this happens, it is called recursive expansion. This flavor of variable is the only sort supported by most other versions of make. It has its advantages and its disadvantages.
An advantage most would say is that:. A major disadvantage is that you cannot append something on the end of a variable, as in. Actually make detects the infinite loop and reports an error. Another disadvantage is that any functions see Functions for Transforming Text referenced in the definition will be executed every time the variable is expanded.
This makes make run slower; worse, it causes the wildcard and shell functions to give unpredictable results because you cannot easily control when they are called, or even how many times. To avoid all the problems and inconveniences of recursively expanded variables, there is another flavor: simply expanded variables. The value of a simply expanded variable is scanned once and for all, expanding any references to other variables and functions, when the variable is defined.
The actual value of the simply expanded variable is the result of expanding the text that you write. It does not contain any references to other variables; it contains their values as of the time this variable was defined.
See The shell Function. Simply expanded variables generally make complicated makefile programming more predictable because they work like variables in most programming languages.
They allow you to redefine a variable using its own value or its value processed in some way by one of the expansion functions and to use the expansion functions much more efficiently see Functions for Transforming Text.
You can also use them to introduce controlled leading whitespace into variable values. Leading whitespace characters are discarded from your input before substitution of variable references and function calls; this means you can include leading spaces in a variable value by protecting them with variable references, like this:. Here the value of the variable space is precisely one space. Since trailing space characters are not stripped from variable values, just a space at the end of the line would have the same effect but be rather hard to read.
If you put whitespace at the end of a variable value, it is a good idea to put a comment like that at the end of the line to make your intent clear. Conversely, if you do not want any whitespace characters at the end of your variable value, you must remember not to put a random comment on the end of the line after some whitespace, such as this:.
This is called a conditional variable assignment operator, because it only has an effect if the variable is not yet defined. This statement:. This section describes some advanced features you can use to reference variables in more flexible ways. A substitution reference substitutes the value of a variable with alterations that you specify. See Setting Variables.
We provide substitution references as well as patsubst for compatibility with other implementations of make. Another type of substitution reference lets you use the full power of the patsubst function. See Functions for String Substitution and Analysis , for a description of the patsubst function.
Computed variable names are a complicated concept needed only for sophisticated makefile programming. For most purposes you need not consider them, except to know that making a variable with a dollar sign in its name might have strange results.
However, if you are the type that wants to understand everything, or you are actually interested in what they do, read on. Variables may be referenced inside the name of a variable. This is called a computed variable name or a nested variable reference. The previous example shows two levels of nesting, but any number of levels is possible. For example, here are three levels:. References to recursively-expanded variables within a variable name are re-expanded in the usual fashion.
Nested variable references can also contain modified references and function invocations see Functions for Transforming Text , just like any other reference. For example, using the subst function see Functions for String Substitution and Analysis :. A computed variable name need not consist entirely of a single variable reference. It can contain several variable references, as well as some invariant text.
The only restriction on this sort of use of nested variable references is that they cannot specify part of the name of a function to be called. This is because the test for a recognized function name is done before the expansion of nested references.
This restriction could be removed in the future if that change is shown to be a good idea. You can also use computed variable names in the left-hand side of a variable assignment, or in a define directive, as in:. Note that nested variable references are quite different from recursively expanded variables see The Two Flavors of Variables , though both are used together in complex ways when doing makefile programming. See The Two Flavors of Variables.
The variable name may contain function and variable references, which are expanded when the line is read to find the actual variable name to use. There is no limit on the length of the value of a variable except the amount of memory on the computer. You can split the value of a variable into multiple physical lines for readability see Splitting Long Lines.
Most variable names are considered to have the empty string as a value if you have never set them. Several variables have built-in initial values that are not empty, but you can set them in the usual ways see Variables Used by Implicit Rules. Several special variables are set automatically to a new value for each rule; these are called the automatic variables see Automatic Variables.
This operator first evaluates the right-hand side, then passes that result to the shell for execution. If the result of the execution ends in a newline, that one newline is removed; all other newlines are replaced by spaces. The resulting string is then placed into the named recursively-expanded variable. Alternatively, you can set a simply expanded variable to the result of running a program using the shell function call.
As with the shell function, the exit status of the just-invoked shell script is stored in the. Often it is useful to add more text to the value of a variable already defined. See The Two Flavors of Variables , for an explanation of the two flavors of variables. In fact,. Recall that when you define a recursively-expanded variable, make does not expand the value you set for variable and function references immediately.
Instead it stores the text verbatim, and saves these variable and function references to be expanded later, when you refer to the new variable see The Two Flavors of Variables. Take this common example:. Thus, includes need not be defined yet for its value to take effect. This is pretty close, but not quite what we want. If a variable has been set with a command argument see Overriding Variables , then ordinary assignments in the makefile are ignored.
If you want to set the variable in the makefile even though it was set with a command argument, you can use an override directive, which is a line that looks like this:. Variable assignments marked with the override flag have a higher priority than all other assignments, except another override. Subsequent assignments or appends to this variable which are not marked override will be ignored. The override directive was not invented for escalation in the war between makefiles and command arguments.
It was invented so you can alter and add to values that the user specifies with command arguments. You could use this override directive:. You can also use override directives with define directives. This is done as you might expect:.
Another way to set the value of a variable is to use the define directive. This directive has an unusual syntax which allows newline characters to be included in the value, which is convenient for defining both canned sequences of commands see Defining Canned Recipes , and also sections of makefile syntax to use with eval see Eval Function.
The define directive is followed on the same line by the name of the variable being defined and an optional assignment operator, and nothing more. The value to give the variable appears on the following lines. The end of the value is marked by a line containing just the word endef. Aside from this difference in syntax, define works just like any other variable definition.
The variable name may contain function and variable references, which are expanded when the directive is read to find the actual variable name to use. The final newline before the endef is not included in the value; if you want your value to contain a trailing newline you must include a blank line.
For example in order to define a variable that contains a newline character you must use two empty lines, not one:. You may omit the variable assignment operator if you prefer. You may nest define directives: make will keep track of nested directives and report an error if they are not all properly closed with endef.
Note that lines beginning with the recipe prefix character are considered part of a recipe, so any define or endef strings appearing on such a line will not be considered make directives.
However, note that using two separate lines means make will invoke the shell twice, running an independent sub-shell for each line. If you want variable definitions made with define to take precedence over command-line variable definitions, you can use the override directive together with define :.
If you want to clear a variable, setting its value to empty is usually sufficient. Expanding such a variable will yield the same result empty string regardless of whether it was set or not. However, if you are using the flavor see Flavor Function and origin see Origin Function functions, there is a difference between a variable that was never set and a variable with an empty value.
In such situations you may want to use the undefine directive to make a variable appear as if it was never set. If you want to undefine a command-line variable definition, you can use the override directive together with undefine , similar to how this is done for variable definitions:.
Variables in make can come from the environment in which make is run. Every environment variable that make sees when it starts up is transformed into a make variable with the same name and value. However, an explicit assignment in the makefile, or with a command argument, overrides the environment. But this is not recommended practice.
Thus, by setting the variable CFLAGS in your environment, you can cause all C compilations in most makefiles to use the compiler switches you prefer. This is safe for variables with standard or conventional meanings because you know that no makefile will use them for other things. Note this is not totally reliable; some makefiles set CFLAGS explicitly and therefore are not affected by the value in the environment.
When make runs a recipe, variables defined in the makefile are placed into the environment of each shell. This allows you to pass values to sub- make invocations see Recursive Use of make. By default, only variables that came from the environment or the command line are passed to recursive invocations.
You can use the export directive to pass other variables. See Communicating Variables to a Sub- make , for full details. Other use of variables from the environment is not recommended.
It is not wise for makefiles to depend for their functioning on environment variables set up outside their control, since this would cause different users to get different results from the same makefile. This is against the whole purpose of most makefiles. It would be very undesirable for this choice to affect make ; so, make handles the SHELL environment variable in a special way; see Choosing the Shell. One exception to that is automatic variables see Automatic Variables. The other exception is target-specific variable values.
This feature allows you to define different values for the same variable, based on the target that make is currently building. Target-specific variable assignments can be prefixed with any or all of the special keywords export , override , or private ; these apply their normal behavior to this instance of the variable only.
Multiple target values create a target-specific variable value for each member of the target list individually. All variables that appear within the variable-assignment are evaluated within the context of the target: thus, any previously-defined target-specific variable values will be in effect.
Target-specific variables have the same priority as any other makefile variable. Specifying the override directive will allow the target-specific variable value to be preferred. There is one more special feature of target-specific variables: when you define a target-specific variable that variable value is also in effect for all prerequisites of this target, and all their prerequisites, etc.
So, for example, a statement like this:. Be aware that a given prerequisite will only be built once per invocation of make, at most. If the same file is a prerequisite of multiple targets, and each of those targets has a different value for the same target-specific variable, then the first target to be built will cause that prerequisite to be built and the prerequisite will inherit the target-specific value from the first target.
It will ignore the target-specific values from any other targets. In addition to target-specific variable values see Target-specific Variable Values , GNU make supports pattern-specific variable values.
In this form, the variable is defined for any target that matches the pattern specified. As with target-specific variable values, multiple pattern values create a pattern-specific variable value for each pattern individually. The variable-assignment can be any valid form of assignment. Any command line variable setting will take precedence, unless override is specified. If a target matches more than one pattern, the matching pattern-specific variables with longer stems are interpreted first.
This results in more specific variables taking precedence over the more generic ones, for example:. Pattern-specific variables which result in the same stem length are considered in the order in which they were defined in the makefile. Pattern-specific variables are searched after any target-specific variables defined explicitly for that target, and before target-specific variables defined for the parent target. As described in previous sections, make variables are inherited by prerequisites.
This capability allows you to modify the behavior of a prerequisite based on which targets caused it to be rebuilt. Sometimes, however, you may not want a variable to be inherited. For these situations, make provides the private modifier. PHONY is good for performance, even if you are not worried about the actual file existing. A phony target should not be a prerequisite of a real target file; if it is, its recipe will be run every time make goes to update that file.
As long as a phony target is never a prerequisite of a real target, the phony target recipe will be executed only when the phony target is a specified goal see Arguments to Specify the Goals. Phony targets can have prerequisites. When one directory contains multiple programs, it is most convenient to describe all of the programs in one makefile. For example:. Phoniness is not inherited: the prerequisites of a phony target are not themselves phony, unless explicitly declared to be so.
When one phony target is a prerequisite of another, it serves as a subroutine of the other. PHONY : all prog1 : prog1.
0コメント