rhl51.htm

来自「linux的初学电子书」· HTM 代码 · 共 1,526 行 · 第 1/3 页

HTM
1,526
字号
<HTML>

<HEAD>

<TITLE>Red Hat Linux Unleashed rhl51.htm </TITLE>

<LINK REL="ToC" HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm">

<LINK REL="Index" HREF="htindex.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/htindex.htm">

<LINK REL="Next" HREF="rhl52.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl52.htm">

<LINK REL="Previous" HREF="rhl50.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl50.htm"></HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">

<A NAME="I0"></A>

<H2>Red Hat Linux Unleashed rhl51.htm</H2>

<P ALIGN=LEFT>

<A HREF="rhl50.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl50.htm" TARGET="_self"><IMG SRC="purprev.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>

<A HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm" TARGET="_self"><IMG SRC="purtoc.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>

<A HREF="rhl52.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl52.htm" TARGET="_self"><IMG SRC="purnext.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>


<HR ALIGN=CENTER>

<P>

<UL>

<UL>

<UL>

<LI>

<A HREF="#E68E394" >make</A>

<UL>

<LI>

<A HREF="#E69E518" >A Sample makefile</A>

<LI>

<A HREF="#E69E519" >Basic makefile Format</A>

<LI>

<A HREF="#E69E520" >Building Different Versions of Programs</A>

<LI>

<A HREF="#E69E521" >Forcing Recompiles</A>

<LI>

<A HREF="#E69E522" >Macros</A>

<LI>

<A HREF="#E69E523" >Suffix Rules</A></UL>

<LI>

<A HREF="#E68E395" >RCS</A>

<UL>

<LI>

<A HREF="#E69E524" >Deltas</A>

<LI>

<A HREF="#E69E525" >Creating an RCS File</A>

<LI>

<A HREF="#E69E526" >Retrieving an RCS File</A>

<LI>

<A HREF="#E69E527" >Using Keywords</A></UL>

<LI>

<A HREF="#E68E396" >Retrieving Version Information from an RCS File</A>

<LI>

<A HREF="#E68E397" >Administering Access</A>

<LI>

<A HREF="#E68E398" >Comparing and Merging Revisions</A>

<LI>

<A HREF="#E68E399" >Tying It All Together Working with make and RCS</A>

<LI>

<A HREF="#E68E400" >Summary</A></UL></UL></UL>

<HR ALIGN=CENTER>

<A NAME="E66E51"></A>

<H1 ALIGN=CENTER>

<CENTER>

<FONT SIZE=6 COLOR="#FF0000"><B>51</B></FONT></CENTER></H1>

<BR>

<A NAME="E67E51"></A>

<H2 ALIGN=CENTER>

<CENTER>

<FONT SIZE=6 COLOR="#FF0000"><B>Source Code Control</B></FONT></CENTER></H2>

<BR>

<P>A large-scale software project involving numerous files and programmers can present logistical nightmares if you happen to be the poor soul responsible for managing it:

<BR>

<P>&quot;How do I know whether this file of input/output routines that Sue has been working on is the most current one?&quot;

<BR>

<P>&quot;Oh, no&#151;I have to recompile my application, but I can't remember which of these 50 files I changed since the last compile!&quot;

<BR>

<P>Even small applications typically use more than one source code file. When compiling and linking C applications, you usually must deal with not only source code, but also header files and library files. Fortunately, Linux features a software development 
environment that, for the most part, can greatly simplify these concerns.

<BR>

<P>In this chapter, we will look at the following software development utilities for Linux:

<BR>

<UL>

<LI>make

<BR>

<BR>

<LI>RCS (Revision Control System)

<BR>

<BR>

</UL>

<BR>

<A NAME="E68E394"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>make</B></FONT></CENTER></H3>

<BR>

<P>Perhaps the most important of all the software development utilities for Linux, make is a program that keeps a record of dependencies between files and only updates those files that have been changed since the last update. The term update usually refers 
to a compile or link operation, but it may also involve the removal of temporary files. This updating process can sometimes be repeated dozens of times in the course of a software project. Instead of managing these tasks manually, make can be your 
automatic dependency manager, giving you more time to do other important things such as coding or watching TV.

<BR>

<P>make generates commands using a description file known as a makefile. These commands are then executed by the shell. The makefile is basically a set of rules for make to follow whenever performing an update of your program. These rules usually relate to 
the definition of the dependencies between files. In the case of creating a Linux executable of C code, this usually means compiling source code into object files, and linking those object files together, perhaps with additional library files. make also 
can figure some things out for itself, such as the fact that the modification times (or timestamps) for certain files may have changed.

<BR>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE>makefile or Makefile is literally the name that the make program expects to find in the current directory.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<P>make is certainly best suited for C programming, but it can be used with other types of language compilers for Linux, such as assembler or FORTRAN.

<BR>

<BR>

<A NAME="E69E518"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>A Sample </B><B>makefile</B></FONT></CENTER></H4>

<BR>

<P>Let's look at a simple application of make. The command

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ make someonehappy</FONT></PRE>

<P>tells Linux that you want to create a new version of someonehappy. In this case, someonehappy is an executable program; thus, there will be compiling and linking of files. someonehappy is referred to as the target of this make operation. The object 
files that are linked together to create the executable are known as someonehappy's dependents. The source code files that are compiled to create these object files are also indirect dependents of someonehappy.

<BR>

<P>The files that are used to build someonehappy are the following (the contents of these files are unimportant to the example):

<BR>

<UL>

<UL>

<P>Two C source code files: main.c, dothis.c

<BR>

</UL></UL>

<UL>

<UL>

<P>Three header files: yes.h, no.h, maybe.h

<BR>

</UL></UL>

<UL>

<UL>

<P>One library file: /usr/happy/lib/likeatree.a

<BR>

</UL></UL>

<UL>

<UL>

<P>An assembly language file: itquick.s

<BR>

</UL></UL>

<P>It appears that this is a small project, so you could choose to manually compile and link these files to build your executable. Instead, create a makefile for your someonehappy project to help automate these tedious tasks.

<BR>

<P>In your favorite editor, write the following:

<BR>

<PRE>

<FONT COLOR="#000080">someonehappy: main.o dothis.o itquick.o /usr/happy/lib/likeatree.a

cc -o someonehappy main.o dothis.o itquick.o /usr/happy/lib/likeatree.a

main.o: main.c

cc -c main.c

dothis.o: dothis.c

cc -c dothis.c

itquick.o: itquick.s

as -o itquick.o itquick.s

fresh:

rm *.o

maybe.h: yes.h no.h

cp yes.h no.h /users/sue/</FONT></PRE>

<BR>

<A NAME="E69E519"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Basic </B><B>makefile</B><B> Format</B></FONT></CENTER></H4>

<BR>

<P>So, assuming that these files are in the same directory as the makefile, what do you have? The format of a makefile such as the one you have made is a series of entries. Your makefile has six entries: the first line of an entry is the dependency line, 
which lists the dependencies of the target denoted at the left of the colon; the second line is one or more command lines, which tells make what to do if the target is newer than its dependent (or dependents). An entry basically looks like this:

<BR>

<PRE>

<FONT COLOR="#000080">target: dependents

 (TAB) command list</FONT></PRE>

<P>The space to the left of the command list is actually a tab. This is part of the makefile syntax: each command line must be indented using a tab. A dependency line can have a series of commands associated with it. make executes each command line as if 
the command had its own shell. Thus, the command

<BR>

<PRE>

<FONT COLOR="#000080">cd somewhere

mv *.c anotherwhere</FONT></PRE>

<P>will not behave the way you may have intended. To remedy this kind of situation, you must use the following syntax whenever you need to specify more than one command:

<BR>

<PRE>

<FONT COLOR="#000080">dependency line

command1;command2;command3;...</FONT></PRE>

<P>or

<BR>

<PRE>

<FONT COLOR="#000080">dependency line

command1; \

command2; \

command3;</FONT></PRE>

<P>and so on. If you use a backslash to continue a line, it must be the last character before the end-of-line character.

<BR>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE>You can specify different kinds of dependencies for a target by placing the same target name on different dependency lines.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<P>The first entry in our makefile is the key one for building our executable. It states that someonehappy is to be built if all the dependent object files and library files are present, and if any are newer than the last version of someonehappy. Of 
course, if the executable is not present at all, make merrily performs the compile command listed, but not right away. First, make checks to see which object files need to be recompiled in order to recompile someonehappy. This is a recursive operation as 
make examines the dependencies of each target in the hierarchy, as defined in the makefile.

<BR>

<P>The last entry is a little goofy. It copies the header files yes.h and no.h (somehow related to maybe.h) to the home directories of the user named sue if they have been modified. This is somewhat conceivable if Sue was working on related programs that 
used these header files and needed the most recent copies at all times. More importantly, it illustrates that make can be used to do more than compiling and linking, and that make can execute several commands based on one dependency.

<BR>

<P>The fresh target is another example of a target being used to do more than just compiling. This target lacks any dependents, which is perfectly acceptable to the make program. As long as there are no files in the current directory named fresh, make 
executes the supplied command to remove all object files. This works because make treats any such entry as a target that must be updated.

<BR>

<P>So, if you enter the command

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ make someonehappy</FONT></PRE>

<P>make starts issuing the commands it finds in the makefile for each target that must be updated to achieve the final target. make echoes these commands to the user as it processes them. Simply entering

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ make</FONT></PRE>

<P>would also work in this case, because make always processes the first entry it finds in the makefile. These commands are echoed to the screen, and the make process halts if the compiler finds an error in the code.

<BR>

<P>If all of someonehappy's dependencies are up to date, make does nothing except inform you of the following:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">'someonehappy' is up to date</FONT></PRE>

<P>You can actually supply the name (or names) of any valid target in your makefile on the command line for make. It performs updates in the order that they appear on the command line, but still applies the dependency rules found in the makefile. If you 
supply the name of a fictional target (one that doesn't appear in your makefile and is not the name of a file in the current directory), make will complain something like this:

<BR>

<PRE>

<FONT COLOR="#000080">$ make fiction

make: Don't know how to make fiction. Stop.</FONT></PRE>

<BR>

<A NAME="E69E520"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Building Different Versions of Programs</B></FONT></CENTER></H4>

<BR>

<P>Suppose that you want to have different versions of your someonehappy program that use most of the same code, but require slightly different interface routines. These routines are located in different C files (dothis.c and dothat.c), and they both use 
the code found in main.c. Instead of having separate makefiles for each version, you can simply add targets that do different compiles. Your makefile would look like the following one. Note the first line that has been added. It is a comment about the 
makefile, and is denoted by a # character followed by the comment text.

<BR>

<PRE>

<FONT COLOR="#000080"># A makefile that creates two versions of the someonehappy program

someonehappy1: main.o dothis.o itquick.o /usr/happy/lib/likeatree.a

cc -o someonehappy main.o dothis.o itquick.o /usr/happy/lib/likeatree.a

someonehappy2: main.o dothat.o itquick.o /usr/happy/lib/likeatree.a

cc -o someonehappy main.o dothat.o itquick.o /usr/happy/lib/likeatree.a

main.o: main.c

cc -c main.c

dothis.o: dothis.c

cc -c dothis.c

dothat.o: dothat.c

cc -c dothat.c

itquick.o: itquick.s

as -o itquick.o itquick.s

fresh:

rm *.o

maybe.h: yes.h no.h

⌨️ 快捷键说明

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