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

📄 make.html

📁 vxworks相关论文
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<HTML><HEAD><!-- This HTML file has been created by texi2html 1.52     from make.texinfo on 16 March 1999 --><TITLE>GNU make</TITLE></HEAD><BODY><H1>GNU Make</H1><H2>A Program for Directing Recompilation</H2><H2>describing <CODE>make</CODE> Version 3.74.</H2><H2>January 1996</H2><ADDRESS>Richard M. Stallman and Roland McGrath</ADDRESS><P><P><HR><P><P>Copyright (C) 1988, '89, '90, '91, '92, '93, '94, '95 Free Software Foundation, Inc.<P>Published by the Free Software Foundation <BR>675 Massachusetts Avenue, <BR>Cambridge, MA 02139 USA <BR>Printed copies are available for $20 each. <BR></P><P>Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.</P><P>Permission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided that the entireresulting derived work is distributed under the terms of a permissionnotice identical to this one.</P><P>Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions,except that this permission notice may be stated in a translation approvedby the Free Software Foundation.<P>Cover art by Etienne Suvasa.</P><H1><A NAME="SEC1" HREF="make_toc.html#TOC1">Overview of <CODE>make</CODE></A></H1><P>The <CODE>make</CODE> utility automatically determines which pieces of a largeprogram need to be recompiled, and issues commands to recompile them.This manual describes GNU <CODE>make</CODE>, which was implemented by RichardStallman and Roland McGrath.  GNU <CODE>make</CODE> conforms to section 6.2 of<CITE>IEEE Standard 1003.2-1992</CITE> (POSIX.2).<A NAME="IDX1"></A><A NAME="IDX2"></A><A NAME="IDX3"></A></P><P>Our examples show C programs, since they are most common, but you can use<CODE>make</CODE> with any programming language whose compiler can be run with ashell command.  Indeed, <CODE>make</CODE> is not limited to programs.  You canuse it to describe any task where some files must be updated automaticallyfrom others whenever the others change.</P><P>To prepare to use <CODE>make</CODE>, you must write a file calledthe <EM>makefile</EM> that describes the relationships among filesin your program and provides commands for updating each file.In a program, typically, the executable file is updated from objectfiles, which are in turn made by compiling source files.</P><P>Once a suitable makefile exists, each time you change some source files,this simple shell command:</P><PRE>make</PRE><P>suffices to perform all necessary recompilations.  The <CODE>make</CODE> programuses the makefile data base and the last-modification times of the files todecide which of the files need to be updated.  For each of those files, itissues the commands recorded in the data base.</P><P>You can provide command line arguments to <CODE>make</CODE> to control whichfiles should be recompiled, or how.  See section <A HREF="make.html#SEC78">How to Run <CODE>make</CODE></A>.</P><H2><A NAME="SEC2" HREF="make_toc.html#TOC2">How to Read This Manual</A></H2><P>If you are new to <CODE>make</CODE>, or are looking for a generalintroduction, read the first few sections of each chapter, skipping thelater sections.  In each chapter, the first few sections containintroductory or general information and the later sections containspecialized or technical information.The exception is section <A HREF="make.html#SEC4">An Introduction to Makefiles</A>,all of which is introductory.</P><P>If you are familiar with other <CODE>make</CODE> programs, see section <A HREF="make.html#SEC107">Features of GNU <CODE>make</CODE></A>, which lists the enhancements GNU<CODE>make</CODE> has, and section <A HREF="make.html#SEC108">Incompatibilities and Missing<BR> Features</A>, which explains the few things GNU <CODE>make</CODE> lacks thatothers have.</P><P>For a quick summary, see section <A HREF="make.html#SEC85">Summary of Options</A>, section <A HREF="make.html#SEC115">Quick Reference</A>,and section <A HREF="make.html#SEC34">Special Built-in Target Names</A>.</P><H2><A NAME="SEC3" HREF="make_toc.html#TOC3">Problems and Bugs</A></H2><P><A NAME="IDX4"></A><A NAME="IDX5"></A><A NAME="IDX6"></A></P><P>If you have problems with GNU <CODE>make</CODE> or think you've found a bug,please report it to the developers; we cannot promise to do anything butwe might well want to fix it.</P><P>Before reporting a bug, make sure you've actually found a real bug.Carefully reread the documentation and see if it really says you can dowhat you're trying to do.  If it's not clear whether you should be ableto do something or not, report that too; it's a bug in thedocumentation!</P><P>Before reporting a bug or trying to fix it yourself, try to isolate itto the smallest possible makefile that reproduces the problem.  Thensend us the makefile and the exact results <CODE>make</CODE> gave you.  Alsosay what you expected to occur; this will help us decide whether theproblem was really in the documentation.</P><P>Once you've got a precise problem, please send electronic mail eitherthrough the Internet or via UUCP:</P><PRE>Internet address:    bug-gnu-utils@prep.ai.mit.eduUUCP path:    mit-eddie!prep.ai.mit.edu!bug-gnu-utils</PRE><P>Please include the version number of <CODE>make</CODE> you are using.  You canget this information with the command <SAMP>`make --version'</SAMP>.Be sure also to include the type of machine and operating system you areusing.  If possible, include the contents of the file <TT>`config.h'</TT>that is generated by the configuration process.</P><P>Non-bug suggestions are always welcome as well.  If you have questionsabout things that are unclear in the documentation or are just obscurefeatures, send a message to the bug reporting address.  We cannotguarantee you'll get help with your problem, but many seasoned<CODE>make</CODE> users read the mailing list and they will probably try tohelp you out.  The maintainers sometimes answer such questions as well,when time permits. <H1><A NAME="SEC4" HREF="make_toc.html#TOC4">An Introduction to Makefiles</A></H1><P>You need a file called a <EM>makefile</EM> to tell <CODE>make</CODE> what to do.Most often, the makefile tells <CODE>make</CODE> how to compile and link aprogram.<A NAME="IDX7"></A></P><P>In this chapter, we will discuss a simple makefile that describes how tocompile and link a text editor which consists of eight C source filesand three header files.  The makefile can also tell <CODE>make</CODE> how torun miscellaneous commands when explicitly asked (for example, to removecertain files as a clean-up operation).  To see a more complex exampleof a makefile, see section <A HREF="make.html#SEC116">Complex Makefile Example</A>.</P><P>When <CODE>make</CODE> recompiles the editor, each changed C source filemust be recompiled.  If a header file has changed, each C source filethat includes the header file must be recompiled to be safe.  Eachcompilation produces an object file corresponding to the source file.Finally, if any source file has been recompiled, all the object files,whether newly made or saved from previous compilations, must be linkedtogether to produce the new executable editor.<A NAME="IDX8"></A><A NAME="IDX9"></A></P><H2><A NAME="SEC5" HREF="make_toc.html#TOC5">What a Rule Looks Like</A></H2><P><A NAME="IDX10"></A><A NAME="IDX11"></A><A NAME="IDX12"></A></P><P>A simple makefile consists of "rules" with the following shape:</P><P><A NAME="IDX13"></A><A NAME="IDX14"></A><A NAME="IDX15"></A><PRE><VAR>target</VAR> ... : <VAR>dependencies</VAR> ...        <VAR>command</VAR>        ...        ...</PRE><P>A <EM>target</EM> is usually the name of a file that is generated by aprogram; examples of targets are executable or object files.  A targetcan also be the name of an action to carry out, such as <SAMP>`clean'</SAMP>(see section <A HREF="make.html#SEC31">Phony Targets</A>).</P><P>A <EM>dependency</EM> is a file that is used as input to create thetarget.  A target often depends on several files.  </P><P><A NAME="IDX16"></A>A <EM>command</EM> is an action that <CODE>make</CODE> carries out.A rule may have more than one command, each on its own line.<STRONG>Please note:</STRONG> you need to put a tab character at the beginning ofevery command line!  This is an obscurity that catches the unwary.</P><P>Usually a command is in a rule with dependencies and serves to create atarget file if any of the dependencies change.  However, the rule thatspecifies commands for the target need not have dependencies.  Forexample, the rule containing the delete command associated with thetarget <SAMP>`clean'</SAMP> does not have dependencies.</P><P>A <EM>rule</EM>, then, explains how and when to remake certain fileswhich are the targets of the particular rule.  <CODE>make</CODE> carries outthe commands on the dependencies to create or update the target.  Arule can also explain how and when to carry out an action.See section <A HREF="make.html#SEC19">Writing Rules</A>.</P><P>A makefile may contain other text besides rules, but a simple makefileneed only contain rules.  Rules may look somewhat more complicatedthan shown in this template, but all fit the pattern more or less.</P><H2><A NAME="SEC6" HREF="make_toc.html#TOC6">A Simple Makefile</A></H2><P><A NAME="IDX17"></A><A NAME="IDX18"></A></P><P>Here is a straightforward makefile that describes the way anexecutable file called <CODE>edit</CODE> depends on eight object fileswhich, in turn, depend on eight C source and three header files.</P><P>In this example, all the C files include <TT>`defs.h'</TT>, but only thosedefining editing commands include <TT>`command.h'</TT>, and only lowlevel files that change the editor buffer include <TT>`buffer.h'</TT>.</P><PRE>edit : main.o kbd.o command.o display.o \       insert.o search.o files.o utils.o        cc -o edit main.o kbd.o command.o display.o \                   insert.o search.o files.o utils.omain.o : main.c defs.h        cc -c main.ckbd.o : kbd.c defs.h command.h        cc -c kbd.ccommand.o : command.c defs.h command.h        cc -c command.cdisplay.o : display.c defs.h buffer.h        cc -c display.cinsert.o : insert.c defs.h buffer.h        cc -c insert.csearch.o : search.c defs.h buffer.h        cc -c search.cfiles.o : files.c defs.h buffer.h command.h        cc -c files.cutils.o : utils.c defs.h        cc -c utils.cclean :        rm edit main.o kbd.o command.o display.o \           insert.o search.o files.o utils.o</PRE><P>We split each long line into two lines using backslash-newline; this islike using one long line, but is easier to read.<A NAME="IDX19"></A><A NAME="IDX20"></A><A NAME="IDX21"></A><A NAME="IDX22"></A><A NAME="IDX23"></A>To use this makefile to create the executable file called <TT>`edit'</TT>,type:</P><PRE>make</PRE><P>To use this makefile to delete the executable file and all the objectfiles from the directory, type:</P><PRE>make clean</PRE><P>In the example makefile, the targets include the executable file<SAMP>`edit'</SAMP>, and the object files <SAMP>`main.o'</SAMP> and <SAMP>`kbd.o'</SAMP>.  Thedependencies are files such as <SAMP>`main.c'</SAMP> and <SAMP>`defs.h'</SAMP>.In fact, each <SAMP>`.o'</SAMP> file is both a target and a dependency.Commands include <SAMP>`cc -c main.c'</SAMP> and <SAMP>`cc -c kbd.c'</SAMP>.</P><P>When a target is a file, it needs to be recompiled or relinked if anyof its dependencies change.  In addition, any dependencies that arethemselves automatically generated should be updated first.  In thisexample, <TT>`edit'</TT> depends on each of the eight object files; theobject file <TT>`main.o'</TT> depends on the source file <TT>`main.c'</TT> andon the header file <TT>`defs.h'</TT>.  </P><P>A shell command follows each line that contains a target anddependencies.  These shell commands say how to update the target file.A tab character must come at the beginning of every command line todistinguish commands lines from other lines in the makefile.  (Bear inmind that <CODE>make</CODE> does not know anything about how the commandswork.  It is up to you to supply commands that will update the targetfile properly.  All <CODE>make</CODE> does is execute the commands in the ruleyou have specified when the target file needs to be updated.)<A NAME="IDX24"></A></P><P>The target <SAMP>`clean'</SAMP> is not a file, but merely the name of anaction.  Since you normallydo not want to carry out the actions in this rule, <SAMP>`clean'</SAMP> is not a dependency of any other rule.Consequently, <CODE>make</CODE> never does anything with it unless you tellit specifically.  Note that this rule not only is not a dependency, italso does not have any dependencies, so the only purpose of the rule

⌨️ 快捷键说明

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