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

📄 make.html

📁 vxworks相关论文
💻 HTML
📖 第 1 页 / 共 5 页
字号:
</P><PRE>VPATH = src:../headers</PRE><P>specifies a path containing two directories, <TT>`src'</TT> and<TT>`../headers'</TT>, which <CODE>make</CODE> searches in that order.</P><P>With this value of <CODE>VPATH</CODE>, the following rule,</P><PRE>foo.o : foo.c</PRE><P>is interpreted as if it were written like this:</P><PRE>foo.o : src/foo.c</PRE><P>assuming the file <TT>`foo.c'</TT> does not exist in the current directory butis found in the directory <TT>`src'</TT>.</P><H3><A NAME="SEC27" HREF="make_toc.html#TOC27">The <CODE>vpath</CODE> Directive</A></H3><P><A NAME="IDX138"></A></P><P>Similar to the <CODE>VPATH</CODE> variable but more selective is the <CODE>vpath</CODE>directive (note lower case), which allows you to specify a search path for a particular classof file names, those that match a particular pattern.  Thus you can supplycertain search directories for one class of file names and other directories(or none) for other file names.</P><P>There are three forms of the <CODE>vpath</CODE> directive:</P><DL COMPACT><DT><CODE>vpath <VAR>pattern</VAR> <VAR>directories</VAR></CODE><DD>Specify the search path <VAR>directories</VAR> for file names that match<VAR>pattern</VAR>.  The search path, <VAR>directories</VAR>, is a list of directories to besearched, separated by colons or blanks, just like the search path usedin the <CODE>VPATH</CODE> variable.<DT><CODE>vpath <VAR>pattern</VAR></CODE><DD>Clear out the search path associated with <VAR>pattern</VAR>.<DT><CODE>vpath</CODE><DD>Clear all search paths previously specified with <CODE>vpath</CODE> directives.</DL><P>A <CODE>vpath</CODE> pattern is a string containing a <SAMP>`%'</SAMP> character.  Thestring must match the file name of a dependency that is being searchedfor, the <SAMP>`%'</SAMP> character matching any sequence of zero or morecharacters (as in pattern rules; see section <A HREF="make.html#SEC91">Defining and Redefining Pattern Rules</A>).  For example, <CODE>%.h</CODE> matches files thatend in <CODE>.h</CODE>.  (If there is no <SAMP>`%'</SAMP>, the pattern must match thedependency exactly, which is not useful very often.)</P><P><A NAME="IDX139"></A><A NAME="IDX140"></A><A NAME="IDX141"></A><A NAME="IDX142"></A><A NAME="IDX143"></A><SAMP>`%'</SAMP> characters in a <CODE>vpath</CODE> directive's pattern can be quotedwith preceding backslashes (<SAMP>`\'</SAMP>).  Backslashes that would otherwisequote <SAMP>`%'</SAMP> characters can be quoted with more backslashes.Backslashes that quote <SAMP>`%'</SAMP> characters or other backslashes areremoved from the pattern before it is compared to file names.  Backslashesthat are not in danger of quoting <SAMP>`%'</SAMP> characters go unmolested.</P><P>When a dependency fails to exist in the current directory, if the<VAR>pattern</VAR> in a <CODE>vpath</CODE> directive matches the name of thedependency file, then the <VAR>directories</VAR> in that directive are searchedjust like (and before) the directories in the <CODE>VPATH</CODE> variable.  </P><P>For example,</P><PRE>vpath %.h ../headers</PRE><P>tells <CODE>make</CODE> to look for any dependency whose name ends in <TT>`.h'</TT>in the directory <TT>`../headers'</TT> if the file is not found in the currentdirectory.</P><P>If several <CODE>vpath</CODE> patterns match the dependency file's name, then<CODE>make</CODE> processes each matching <CODE>vpath</CODE> directive one by one,searching all the directories mentioned in each directive.  <CODE>make</CODE>handles multiple <CODE>vpath</CODE> directives in the order in which theyappear in the makefile; multiple directives with the same pattern areindependent of each other.</P><P>Thus, </P><PRE>vpath %.c foovpath %   blishvpath %.c bar</PRE><P>will look for a file ending in <SAMP>`.c'</SAMP> in <TT>`foo'</TT>, then<TT>`blish'</TT>, then <TT>`bar'</TT>, while</P><PRE>vpath %.c foo:barvpath %   blish</PRE><P>will look for a file ending in <SAMP>`.c'</SAMP> in <TT>`foo'</TT>, then<TT>`bar'</TT>, then <TT>`blish'</TT>.</P><H3><A NAME="SEC28" HREF="make_toc.html#TOC28">Writing Shell Commands with Directory Search</A></H3><P><A NAME="IDX144"></A><A NAME="IDX145"></A></P><P>When a dependency is found in another directory through directory search,this cannot change the commands of the rule; they will execute as written.Therefore, you must write the commands with care so that they will look forthe dependency in the directory where <CODE>make</CODE> finds it.</P><P>This is done with the <EM>automatic variables</EM> such as <SAMP>`$^'</SAMP>(see section <A HREF="make.html#SEC94">Automatic Variables</A>).  For instance, the value of <SAMP>`$^'</SAMP> is alist of all the dependencies of the rule, including the names ofthe directories in which they were found, and the value of<SAMP>`$@'</SAMP> is the target.  Thus:</P><PRE>foo.o : foo.c        cc -c $(CFLAGS) $^ -o $@</PRE><P>(The variable <CODE>CFLAGS</CODE> exists so you can specify flags for Ccompilation by implicit rules; we use it here for consistency so it willaffect all C compilations uniformly;see section <A HREF="make.html#SEC89">Variables Used by Implicit Rules</A>.)</P><P>Often the dependencies include header files as well, which you do notwant to mention in the commands.  The automatic variable <SAMP>`$&#60;'</SAMP> isjust the first dependency:</P><PRE>VPATH = src:../headersfoo.o : foo.c defs.h hack.h        cc -c $(CFLAGS) $&#60; -o $@</PRE><H3><A NAME="SEC29" HREF="make_toc.html#TOC29">Directory Search and Implicit Rules</A></H3><P><A NAME="IDX146"></A><A NAME="IDX147"></A><A NAME="IDX148"></A><A NAME="IDX149"></A><A NAME="IDX150"></A><A NAME="IDX151"></A><A NAME="IDX152"></A></P><P>The search through the directories specified in <CODE>VPATH</CODE> or with<CODE>vpath</CODE> also happens during consideration of implicit rules(see section <A HREF="make.html#SEC86">Using Implicit Rules</A>).</P><P>For example, when a file <TT>`foo.o'</TT> has no explicit rule, <CODE>make</CODE>considers implicit rules, such as the built-in rule to compile<TT>`foo.c'</TT> if that file exists.  If such a file is lacking in thecurrent directory, the appropriate directories are searched for it.  If<TT>`foo.c'</TT> exists (or is mentioned in the makefile) in any of thedirectories, the implicit rule for C compilation is applied.</P><P>The commands of implicit rules normally use automatic variables as amatter of necessity; consequently they will use the file names found bydirectory search with no extra effort.</P><H3><A NAME="SEC30" HREF="make_toc.html#TOC30">Directory Search for Link Libraries</A></H3><P><A NAME="IDX153"></A><A NAME="IDX154"></A><A NAME="IDX155"></A><A NAME="IDX156"></A><A NAME="IDX157"></A><A NAME="IDX158"></A></P><P>Directory search applies in a special way to libraries used with thelinker.  This special feature comes into play when you write a dependencywhose name is of the form <SAMP>`-l<VAR>name</VAR>'</SAMP>.  (You can tell somethingstrange is going on here because the dependency is normally the name of afile, and the <EM>file name</EM> of the library looks like<TT>`lib<VAR>name</VAR>.a'</TT>, not like <SAMP>`-l<VAR>name</VAR>'</SAMP>.)</P><P>When a dependency's name has the form <SAMP>`-l<VAR>name</VAR>'</SAMP>, <CODE>make</CODE>handles it specially by searching for the file <TT>`lib<VAR>name</VAR>.a'</TT> inthe current directory, in directories specified by matching <CODE>vpath</CODE>search paths and the <CODE>VPATH</CODE> search path, and then in thedirectories <TT>`/lib'</TT>, <TT>`/usr/lib'</TT>, and <TT>`<VAR>prefix</VAR>/lib'</TT>(normally <TT>`/usr/local/lib'</TT>).</P><P>For example,</P><PRE>foo : foo.c -lcurses        cc $^ -o $@</PRE><P>would cause the command </P><PRE>cc foo.c /usr/lib/libcurses.a -o foo</PRE><P>to execute when <TT>`foo'</TT> is older than <TT>`foo.c'</TT> or </P><H2><A NAME="SEC31" HREF="make_toc.html#TOC31">Phony Targets</A></H2><P><A NAME="IDX159"></A><A NAME="IDX160"></A><A NAME="IDX161"></A></P><P>A phony target is one that is not really the name of a file.  It is just aname for some commands to be executed when you make an explicit request.There are two reasons to use a phony target: to avoid a conflict witha file of the same name, and to improve performance.</P><P>If you write a rule whose commands will not create the target file, thecommands will be executed every time the target comes up for remaking.Here is an example:</P><PRE>clean:        rm *.o temp</PRE><P>Because the <CODE>rm</CODE> command does not create a file named <TT>`clean'</TT>,probably no such file will ever exist.  Therefore, the <CODE>rm</CODE> commandwill be executed every time you say <SAMP>`make clean'</SAMP>.<A NAME="IDX162"></A></P><P><A NAME="IDX163"></A>The phony target will cease to work if anything ever does create a filenamed <TT>`clean'</TT> in this directory.  Since it has no dependencies, thefile <TT>`clean'</TT> would inevitably be considered up to date, and itscommands would not be executed.  To avoid this problem, you can explicitlydeclare the target to be phony, using the special target <CODE>.PHONY</CODE>(see section <A HREF="make.html#SEC34">Special Built-in Target Names</A>) as follows:</P><PRE>.PHONY : clean</PRE><P>Once this is done, <SAMP>`make clean'</SAMP> will run the commands regardless ofwhether there is a file named <TT>`clean'</TT>.</P><P>Since it knows that phony targets do not name actual files that could beremade from other files, <CODE>make</CODE> skips the implicit rule search forphony targets (see section <A HREF="make.html#SEC86">Using Implicit Rules</A>).  This is why declaring a targetphony is good for performance, even if you are not worried about theactual file existing.</P><P>Thus, you first write the line that states that <CODE>clean</CODE> is aphony target, then you write the rule, like this:</P><PRE>.PHONY: cleanclean:        rm *.o temp</PRE><P>A phony target should not be a dependency of a real target file; if itis, its commands are run every time <CODE>make</CODE> goes to update thatfile.  As long as a phony target is never a dependency of a realtarget, the phony target commands will be executed only when the phonytarget is a specified goal (see section <A HREF="make.html#SEC80">Arguments to Specify the Goals</A>).</P><P>Phony targets can have dependencies.  When one directory contains multipleprograms, it is most convenient to describe all of the programs in onemakefile <TT>`./Makefile'</TT>.  Since the target remade by default will be thefirst one in the makefile, it is common to make this a phony target named<SAMP>`all'</SAMP> and give it, as dependencies, all the individual programs.  Forexample:</P><PRE>all : prog1 prog2 prog3.PHONY : allprog1 : prog1.o utils.o        cc -o prog1 prog1.o utils.oprog2 : prog2.o        cc -o prog2 prog2.oprog3 : prog3.o sort.o utils.o        cc -o prog3 prog3.o sort.o utils.o</PRE><P>Now you can say just <SAMP>`make'</SAMP> to remake all three programs, or specifyas arguments the ones to remake 

⌨️ 快捷键说明

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