⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 make.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
📖 第 1 页 / 共 4 页
字号:
has ensured that all of the prerequisites of a target areup-to-date and if the target is out-of-date, the commandsassociated with the target entry are executed.If there areno commands listed for the target, the target is treatedas up-to-date.<h5><a name = "tag_001_014_1377_001">&nbsp;</a>Makefile Syntax</h5>A makefile can contain rules, macro definitions (see<xref href=mkmacro><a href="#tag_001_014_1377_004">Macros</a></xref>),and comments.There are two kinds of rules:inference rulesand target rules.The<i>make</i>utility contains a set of built-in inference rules.If the<b>-r</b>option is present, the built-in rules are not used and the suffixlist is cleared.Additional rules of both types can be specified in a makefile.If a rule or macro is defined more than once, the valueof the rule or macro will be that of the last one specified.Comments start with a number sign(#)and continue until an unescapednewline characteris reached.<p>By default, the following files are tried in sequence:<b>./makefile</b>,<b>./Makefile</b>,<b>./s.makefile</b>,<b>SCCS/s.makefile</b>,<b>./s.Makefile</b>,and<b>SCCS/s.Makefile</b>.<p>The<b>-f</b>option directs<i>make</i>to ignore any of these default filesand use the specified argument as a makefile instead.If the "-" argument is specified, standard input will be used.<p>The term<i>makefile</i>is used to refer to any rules provided by theuser, whether in<b>./makefile</b>or its variants,or specified by the<b>-f</b>option.<p>The rules in makefiles consist of the following types of lines:target rules, including special targets (see<xref href=mktarg><a href="#tag_001_014_1377_003">Target Rules</a></xref>);inference rules (see<xref href=infrules><a href="#tag_001_014_1377_005">Inference Rules</a></xref>);macro definitions (see<xref href=mkmacro><a href="#tag_001_014_1377_004">Macros</a></xref>);empty lines;and comments.Comments start with a number sign(#)and continue until an unescapednewline characteris reached.<p>When an escapednewline character(one preceded by a<b>backslash</b>)is found anywhere in the makefile, it is replaced,along with any leading white space on the following line, with a singlespace character.<h5><a name = "tag_001_014_1377_002">&nbsp;</a>Makefile Execution</h5>Command lines are processed one at a timeby writing the command line to the standard output (unlessone of the conditions listed below under "@"suppresses the writing)and executing the commands in the line.A tab character may precede the command to standard output.Commands will be executedby passing the command line to the command interpreter inthe same manner as if the string were the argument tothe <b>XSH</b> specification<i><a href="../xsh/system.html">system()</a></i>function.<p>The environment for the command being executed willcontain all of the variables in the environment of<i>make</i>.The macros from the command line to<i>make</i>will be added to<i>make</i>'senvironment.Other implementation-dependentvariables may also be added to<i>make</i>'senvironment.If any command-line macro has been defined elsewhere, thecommand-line value will overwrite the existing value.If the<i>MAKEFLAGS</i>variable is not set in the environment in which<i>make</i>was invoked, in the makefile or on thecommand line, it will be created by<i>make</i>,and will contain all options specified on the command line except for the<b>-f</b>and<b>-p</b>options.It may also contain implementation-dependent options.<p>By default, when<i>make</i>receives a non-zero status from theexecution of a command, it terminates with an error messageto standard error.<p>Command lines can have one or more of the following prefixes:a hyphen(-),an at sign(@),or a plus sign(+).These modify the way in which<i>make</i>processes the command.When a command is written to standard output,the prefix is not included in the output.<dl compact><dt><b>-</b><dd>If the command prefix contains a hyphen,or the<b>-i</b>option is present, or the special target<b>.IGNORE</b>has either the current target as a prerequisite or has no prerequisites,any error found while executing the command will be ignored.<dt>@<dd>If the command prefix contains an at signand the command-line<b>-n</b>option is not specified, or the<b>-s</b>optionis present, or the special target<b>.SILENT</b>has either the current target as a prerequisite or has no prerequisites,the command will not be written to standard output before it is executed.<dt><b>+</b><dd>If the command prefix contains a plus sign,this indicates a command line that will be executed even if<b>-n</b>,<b>-q</b>or<b>-t</b>is specified.</dl><h5><a name = "tag_001_014_1377_003">&nbsp;</a>Target Rules</h5><xref type="5" name="mktarg"></xref>Target rules are formatted as follows:<pre><code><i>target </i><b>[</b><i>target</i>...<b>]</b>:&nbsp;<b>[</b><i>prerequisite</i>...<b>][;</b><i>command</i><b>][</b>&lt;tab&gt;<i>command</i><b>]</b>&lt;tab&gt;command...<b>]</b><i>line that does not begin with </i>&lt;tab&gt;</code></pre><p>Target entries are specified by ablank-character-separated,non-null list of targets, then a colon, then ablank-character-separated,possibly empty list of prerequisites.Text following a semicolon,if any, and all following lines that begin with atab character,are command lines to be executed to update the target.The first non-empty line that does not begin with atab characteror"#"begins a new entry.An empty or blank line, or a line beginning with"#",may begin a new entry.<p>Applications must select target names from theset of characters consisting solely of periods,underscores, digits and alphabeticsfrom the portable character set (seethe <b>XBD</b> specification, <a href="../xbd/charset.html#tag_001_001"><b>Portable Character Set</b>&nbsp;</a> ).Implementations may allow other charactersin target names as extensions.The interpretation of targets containing the characters "%" and """is implementation-dependent.<p>A target that has prerequisites, but does not have any commands,can be used to add to the prerequisite list for that target.Only one target rule for any given target can contain commands.<p>Lines that begin with one of the following are called<i>special targets</i>and control the operation of<i>make</i>:<dl compact><dt>.DEFAULT<dd>If the makefile uses this special target,it must be specified with commands, butwithout prerequisites.The commands will be used by<i>make</i>if there are no other rulesavailable to build a target.<dt>.IGNORE<dd>Prerequisites of this special target are targets themselves;this will cause errors from commands associated with themto be ignored in the same manner as specified by the<b>-i</b>option.Subsequent occurrences of<b>.IGNORE</b>add to the list of targets ignoring command errors.If no prerequisites are specified,<i>make</i>will behave as if the<b>-i</b>option had been specified and errorsfrom all commands associated with all targets will be ignored.<dt>.POSIX<dd>This special target must be specified without prerequisites or commands.If it appears before the first non-comment line in the makefile,<i>make</i>will process the makefile as specified by this section;otherwise, the behaviour of<i>make</i>is unspecified.<dt>.PRECIOUS<dd>Prerequisites of this special target will not be removed if<i>make</i>receives one of the asynchronous events explicitly described inthe ASYNCHRONOUS EVENTS section.Subsequent occurrences of<b>.PRECIOUS</b>add to the list of precious files.If no prerequisites are specified,all targets in the makefile will be treated as if specified with<b>.PRECIOUS</b>.<dt>.SCCS_GET<dd>This special target must be specified without prerequisites.If this special target is included in amakefile, the commands specified with this targetreplace the default commands associated with thisspecial target.(See<xref href=mkdefr><a href="#tag_001_014_1377_008">Default Rules</a></xref>.)The commands specified with this target are used to get allSCCS files that are not found in the current directory.When source files are named in a dependency list,<i>make</i>treats them just like any other target.Because thesource file is presumed to be present in the directory,there is no need to add an entry for it to the makefile.When a target has no dependencies, but is present in thedirectory,<i>make</i>assumes that that file is up-to-date.If, however, an SCCS file named<b>SCCS/s.</b><i>source_file</i>is found for a target<i>source_file</i>,<i>make</i>does some additional checking to assure that the target is up-to-date.If the target is missing, or if the SCCS file is newer,<i>make</i>automatically issues the commands specifiedfor the<b>.SCCS_GET</b>special target to retrieve the mostrecent version.However, if the target is writable byanyone,<i>make</i>does not retrieve a new version.<dt>.SILENT<dd>Prerequisites of this special target are targets themselves;this causes commands associated with them to not be writtento the standard output before they are executed.Subsequent occurrences of<b>.SILENT</b>add to the list of targets with silent commands.If no prerequisites are specified,<i>make</i>will behave as if the<b>-s</b>option had been specified and no commands or touch messages associated withany target will be written to standard output.<dt>.SUFFIXES<dd>Prerequisites of<b>.SUFFIXES</b>are appended to the listof known suffixes and are usedin conjunction with the inference rules (see<xref href=infrules><a href="#tag_001_014_1377_005">Inference Rules</a></xref>).If<b>.SUFFIXES</b>does not haveany prerequisites, the list of known suffixes will be cleared.Makefiles must not associate commands with<b>.SUFFIXES</b>.</dl><p>Targets with names consisting of a leading period followed bythe upper-case letters<b>POSIX</b>and then any other characters are reserved for future standardisation.Targets with names consisting of a leading period followed byone or more upper-case letters are reserved for implementation extensions.<h5><a name = "tag_001_014_1377_004">&nbsp;</a>Macros</h5><xref type="5" name="mkmacro"></xref>Macro definitions are in the form:<p><dl compact><dt> <dd><i>string1</i>"="<b>[</b><i>string2</i><b>]</b></dl></p><p>The macro named<i>string1</i>is defined as having the value of<i>string2</i>,where<i>string2</i>is defined as all characters,if any, after the equal sign,up to a comment character(#)or an unescapednewlinecharacter.Anyblank charactersimmediately before or after the equal signwill be ignored.<p>Subsequent appearances of<b>$(</b><i>string1</i><b>)</b>or<b>${</b><i>string1</i><b>}</b>are replaced by<i>string2</i>.The parentheses or braces are optional if<i>string1</i>is a single character.The macro$$is replaced by the single character "$".<p>Applications must select macro names from theset of characters consisting solely of periods,underscores, digits and alphabeticsfrom the portable character set (seethe <b>XBD</b> specification, <a href="../xbd/charset.html#tag_001_001"><b>Portable Character Set</b>&nbsp;</a> ).A macro name cannot contain an equal sign.Implementations may allow other charactersin macro names as extensions.<p>Macros can appear anywhere in the makefile.Macros in target lines will be evaluated when the target line is read.Macros in command lines will be evaluated when the command is executed.Macros in macro definition lines will not be evaluateduntil the new macro being defined is used in a rule or command.A macro that has not been defined will evaluate to a null stringwithout causing any error condition.<p>The forms<b>$(</b><i>string1</i><b>[:</b><i>subst1</i><b>=[</b><i>subst2</i><b>]])</b>or<b>${</b><i>string1</i><b>[:</b><i>subst1</i><b>=[</b><i>subst2</i><b>]]}</b>can be used to replaceall occurrences of<i>subst1</i>with<i>subst2</i>when the macro substitution is performed.The<i>subst1</i>to be replaced is recognised when it is a suffixat the end of a word in<i>string1</i>(where a<i>word</i>,in this context, is defined to be a stringdelimited by the beginning of the line, ablank or newline character).<p>Macro assignments will be accepted from the sources listed below,in the order shown.If a macro namealready exists at the time it is being processed, the newer definitionwill replace the existing definition.<ol><p><li>Macros defined in<i>make</i>'sbuilt-in inference rules.<p><li>The contents of the environment,including the variables with null values,in the order defined in the environment.<p><li>Macros defined in the makefiles,processed in the order specified.<p><li>Macros specified on the command line.It is unspecified whether the internal macros defined in<xref href=mkimacs><a href="#tag_001_014_1377_007">Internal Macros</a></xref>are accepted from the command line.<p></ol><p>If the<b>-e</b>option is specified, the order of processing sources items 2 and 3will be reversed.<p>The

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -