Gnu make output_option

Posted: samprof Date of post: 30.05.2017

Go to the first , previous , next , last section, table of contents.

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. So make applies the implicit rule for C compilation when it sees this combination of file name endings. See section Chains of Implicit Rules. The built-in implicit rules use several variables in their commands 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 Variables Used by Implicit Rules. You can define your own implicit rules by writing pattern rules. See section Defining and Redefining Pattern Rules. 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 Old-Fashioned Suffix Rules. To allow make to find a customary method for updating a target file, all you have to do is refrain from specifying commands yourself.

Either write a rule with no command lines, 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. If an implicit rule is found, it can supply both commands and one or more prerequisites the source files. Each implicit rule has a target pattern and prerequisite patterns.

There may be many implicit rules with the same target pattern. The rule that actually applies is the one whose prerequisites exist or can be made. 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 files are supposed to exist.

See section Catalogue of Implicit Rules , for a catalogue of all the predefined implicit rules. Above, we said an implicit rule applies if the required prerequisites "exist or can be made". A file "can be made" if it is mentioned explicitly in the makefile as a target or a prerequisite, or if an implicit rule can be recursively found for how to make it. When an implicit prerequisite is the result of another implicit rule, we say that chaining is occurring.

In general, make searches for an implicit rule for each target, and for each double-colon rule, that has no commands. A file that is mentioned only as a prerequisite is considered a target whose rule specifies nothing, so implicit rule search happens for it. See section Implicit Rule Search Algorithm , for the details of how the search is done.

Note that explicit prerequisites do not influence implicit rule search.

Internal Server Error

For example, consider this explicit rule:. If you do not want an implicit rule to be used for a target that has no commands, you can give that target empty commands by writing a semicolon see section Using Empty Commands.

Here is a catalogue of predefined implicit rules which are always available unless the makefile explicitly overrides or cancels them. See section Canceling Implicit Rules , for information on canceling or overriding an implicit rule. Many of the predefined implicit rules are implemented in make as suffix rules, so which ones will be defined depends on the suffix list the list of prerequisites of the special target. The default suffix list is: All of the implicit rules described below whose prerequisites have one of these suffixes are actually suffix rules.

If you modify the suffix list, the only predefined suffix rules in effect will be those named by one or two of the suffixes that are on the list you specify; rules whose suffixes fail to be on the list are disabled.

See section Old-Fashioned Suffix Rules , for full details on suffix rules. Usually, you want to change only the variables listed in the table above, which are documented in the following section.

However, the commands in built-in implicit rules actually use variables such as COMPILE.

S , whose values contain the commands listed above. If you use such a system, and use VPATH , some compilations will put their output in the wrong place. The commands in built-in implicit rules make liberal use of certain predefined variables. You can alter 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. The variables used in implicit rules fall into two classes: The "name of a program" may also contain some command arguments, but it must start with an actual executable program name.

If a variable value contains more than one argument, separate them with spaces. Here is a table of variables whose values are additional arguments for the programs above. The default values for all of these is the empty string, unless otherwise noted. Sometimes a file can be made by a sequence of implicit rules.

Such a sequence is called a chain. Once make has decided to use the intermediate file, it is entered in the data base as if it had been mentioned in the makefile, along with the implicit rule that says how to create it. Intermediate files are remade using their rules just like all other files. But intermediate files are treated differently in two ways.

The first difference is what happens if the intermediate file does not exist. If an ordinary file b does not exist, and make considers a target that depends on b , it invariably creates b and then updates the target from b.

But if b is an intermediate file, then make can leave well enough alone. It won't bother updating b , or the ultimate target, unless some prerequisite of b is newer than that target or there is some other reason to update that target. The second difference is that if make does create b in order to update something else, it deletes b later on after it is no longer needed.

Therefore, an intermediate file which did not exist before make also does not exist after make.

Ordinarily, a file cannot be intermediate if it is mentioned in the makefile as a target or prerequisite. However, you can explicitly mark a file as intermediate by listing it as a prerequisite of the special target. This takes effect even if the file is mentioned explicitly in some other way. You can prevent automatic deletion of an intermediate file by marking it as a secondary file.

gnu make output_option

To do this, list it as a prerequisite of the special target. When a file is secondary, make will not create the file merely because it does not already exist, but make does not automatically delete the file.

Marking a file as secondary also marks it as intermediate. PRECIOUS to preserve intermediate files made by implicit rules whose target patterns match that file's name; see section Interrupting or Killing make. A chain can involve more than two implicit rules.

No single implicit rule can appear more than once in a chain. This constraint has the added benefit of preventing any infinite loop in the search for an implicit rule chain. There are some special implicit rules to optimize certain cases that would otherwise be handled by rule chains.

But what actually happens is that a special rule for this case does the compilation and linking with a single cc command. The optimized rule is used in preference to the step-by-step chain because it comes earlier in the ordering of rules.

You define an implicit rule by writing a pattern rule. See section How to Use Variables , and section Functions for Transforming Text. In order for the pattern rule to apply, its target pattern must match the file name under consideration, and its prerequisite patterns must name files that exist or can be made. These files become prerequisites of the target. These unvarying prerequisites are useful occasionally. Such a rule is effectively a general wildcard.

It provides a way to make any file that matches the target pattern. See section Defining Last-Resort Default Rules. Pattern rules may have more than one target. Unlike normal rules, this does not act as many different rules with the same prerequisites and commands. If a pattern rule has multiple targets, make knows that the rule's commands are responsible for making all of the targets.

The commands are executed only once to make all the targets. When searching for a pattern rule to match a target, the target patterns of a rule other than the one that matches the target in need of a rule are incidental: However, when this file's commands are run, the other targets are marked as having been updated themselves.

The order in which pattern rules appear in the makefile is important since this is the order in which they are considered. Of equally applicable rules, only the first one found is used. The rules you write take precedence over those that are built in. Note however, that a rule whose prerequisites actually exist or are mentioned always takes priority over a rule with prerequisites that must be made by chaining other implicit rules.

Here are some examples of pattern rules actually predefined in make. The double colon makes the rule terminal , which means that its prerequisite may not be an intermediate file see section Match-Anything Pattern Rules. You cannot write the name in the command, because the name is different each time the implicit rule is applied. What you do is use a special feature of make , the automatic variables. These variables have values computed afresh for each rule that is executed, based on the target and prerequisites of the rule.

This rule copies just the changed object files into the archive:. Of the variables listed above, four have values that are single file names, and three have values that are lists of file names.

These seven have variants that get just the file's directory name or just the file name within the directory. These variants are semi-obsolete in GNU make since the functions dir and notdir can be used to get a similar effect see section Functions for File Names.

Here is a table of the variants:. We think this convention looks more natural in this special case. The pattern matches a file name only if the file name starts with the prefix and ends with the suffix, without overlap. The text between the prefix and the suffix is called the stem. When the target pattern does not contain a slash and it usually does not , directory names in the file names are removed from the file name before it is compared with the target prefix and suffix.

After the comparison of the file name to the target pattern, the directory names, along with the slash that ends them, are added on to the prerequisite file names generated from the pattern rule's prerequisite patterns and the file name. The directories are ignored only for the purpose of finding an implicit rule to use, not in the application of that rule. We call these rules match-anything rules.

They are very useful, but it can take a lot of time for make to think about them, because it must consider every such rule for each file name listed either as a target or as a prerequisite.

But these possibilities are so numerous that make would run very slowly if it had to consider them. To gain speed, we have put various constraints on the way make considers match-anything rules. There are two different constraints that can be applied, and each time you define a match-anything rule you must choose one or the other for that rule.

GNU make: Catalogue of Rules

One choice is to mark the match-anything rule as terminal by defining it with a double colon. When a rule is terminal, it does not apply unless its prerequisites actually exist. Prerequisites that could be made with other implicit rules are not good enough.

In other words, no further chaining is allowed beyond a terminal rule. RCS and SCCS files are generally ultimate source files, which should not be remade from any other files; therefore, make can save time by not looking for ways to remake them. If you do not mark the match-anything rule as terminal, then it is nonterminal. A nonterminal match-anything rule cannot apply to a file name that indicates a specific type of data. A file name indicates a specific type of data if some non-match-anything implicit rule target matches it.

The motivation for this constraint is that nonterminal match-anything rules are used for making files containing specific types of data such as executable files and a file name with a recognized suffix indicates some other specific type of data such as a C source file. Special built-in dummy pattern rules are provided solely to recognize certain file names so that nonterminal match-anything rules will not be considered.

These dummy rules have no prerequisites and no commands, and they are ignored for all other purposes. For example, the built-in implicit rule. You can override a built-in implicit rule or one you have defined yourself by defining a new pattern rule with the same target and prerequisites, but different commands. When the new rule is defined, the built-in one is replaced. The new rule's position in the sequence of implicit rules is determined by where you write the new rule.

You can cancel a built-in implicit rule by defining a pattern rule with the same target and prerequisites, but no commands. For example, the following would cancel the rule that runs the assembler:. You can define a last-resort implicit rule by writing a terminal match-anything pattern rule with no prerequisites see section Match-Anything Pattern Rules.

This is just like any other pattern rule; the only thing special about it is that it will match any target. So such a rule's commands are used for all targets and prerequisites that have no commands of their own and for which no other implicit rule applies. For example, when testing a makefile, you might not care if the source files contain real data, only that they exist.

Then you might do this:. You can instead define commands to be used for targets for which there are no rules at all, even ones which don't specify commands. You do this by writing a rule for the target. Such a rule's commands are used for all prerequisites which do not appear as targets in any explicit rule, and for which no implicit rule applies. Naturally, there is no. DEFAULT rule unless you write one. Then make acts as if you had never defined.

If you do not want a target to get the commands from a match-anything pattern rule or. DEFAULT , but you also do not want any commands to be run for the target, you can give it empty commands see section Using Empty Commands.

Not Found

You can use a last-resort rule to override part of another makefile. See section Overriding Part of Another Makefile. Suffix rules are the old-fashioned way of defining implicit rules for make. Suffix rules are obsolete because pattern rules are more general and clearer.

They are supported in GNU make for compatibility with old makefiles. They come in two kinds: A double-suffix rule is defined by a pair of suffixes: It matches any file whose name ends with the target suffix. The corresponding implicit prerequisite is made by replacing the target suffix with the source suffix in the file name. A single-suffix rule is defined by a single suffix, which is the source suffix. It matches any file name, and the corresponding implicit prerequisite name is made by appending the source suffix.

Suffix rule definitions are recognized by comparing each rule's target against a defined list of known suffixes. When make sees a rule whose target is a known suffix, this rule is considered a single-suffix rule. When make sees a rule whose target is two known suffixes concatenated, this rule is taken as a double-suffix rule. Here is the old-fashioned way to define the rule for compiling a C source file:. Suffix rules cannot have any prerequisites of their own. If they have any, they are treated as normal files with funny names, not as suffix rules.

Suffix rules with no commands are also meaningless. They do not remove previous rules as do pattern rules with no commands see section Canceling Implicit Rules. They simply enter the suffix or pair of suffixes concatenated as a target in the data base. The known suffixes are simply the names of the prerequisites of the special target.

gnu make output_option

You can add your own suffixes by writing a rule for. SUFFIXES that adds more prerequisites, as in:. If you wish to eliminate the default known suffixes instead of just adding to them, write a rule for.

SUFFIXES with no prerequisites. By special dispensation, this eliminates all existing prerequisites of. You can then write another rule to add the suffixes you want. The variable SUFFIXES is defined to the default list of suffixes before make reads any makefiles.

GCC and Make - A Tutorial on how to compile, link and build C/C++ applications

You can change the list of suffixes with a rule for the special target. SUFFIXES , but that does not alter this variable. Here is the procedure make uses for searching for an implicit rule for a target t. This procedure is followed for each double-colon rule with no commands, for each target of ordinary rules none of which have commands, and for each prerequisite that is not the target of any rule. It is also followed recursively for prerequisites that come from implicit rules, in the search for a chain of rules.

Suffix rules are not mentioned in this algorithm because suffix rules are converted to equivalent pattern rules once the makefiles have been read in. After these commands are executed, each of these stored file names are entered into the data base and marked as having been updated and having the same update status as the file t. When the commands of a pattern rule are executed for t , the automatic variables are set corresponding to the target and prerequisites.

See section Automatic Variables.

inserted by FC2 system