893-898.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 129 行
HTML
129 行
<HTML>
<HEAD>
<TITLE>Linux Unleashed, Third Edition:Source Code Control</TITLE>
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0672313723//-->
<!--TITLE=Linux Unleashed, Third Edition//-->
<!--AUTHOR=Tim Parker//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Sams//-->
<!--CHAPTER=56//-->
<!--PAGES=893-898//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch55/890-892.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="898-901.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H2 ALIGN="CENTER"><FONT COLOR="#000077"><I>Part VIII<BR>Advanced Programming Topics
</I></FONT></H2>
<DL>
<DT><B>In This Part</B>
<DT>• Source Code Control
<DT>• Working with the Kernel
<DT>• Writing Device Drivers
<DT>• The Wine Project
<DT>• HylaFAX
<DT>• Games
<DT>• Adabas-D and other Databases
<DT>• StarOffice
<DT>• Lone Star Software’s Lone-Tar
</DL>
<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 56<BR>Source Code Control
</FONT></H2>
<P><I>by Peter MacKinnon and Tim Parker</I></P>
<DL>
<DT><B>In This Chapter</B>
<DT>• make
<DT>• RCS
<DT>• Retrieving version information from an RCS file
<DT>• Administering Access
<DT>• Comparing and merging revisions
<DT>• Tying it all together: working with make and RCS
</DL>
<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:
</P>
<P>“How do I know whether this file of input/output routines that Sue has been working on is the most current one?”</P>
<P>“Oh, no—I have to recompile my application, but I can’t remember which of these 50 files I changed since the last compile!”</P>
<P>Keeping track of which file is most recent and where you put those changes yesterday (or last week) can be more of a job than actual programming.</P>
<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.</P>
<H3><A NAME="Heading2"></A><FONT COLOR="#000077">make</FONT></H3>
<P>Perhaps the most important of all the software development utilities for Linux, <TT>make</TT> 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 <I>update</I> 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, <TT>make</TT> can be your automatic dependency manager, giving you more time to do other important things, such as coding or watching TV.</P>
<P><TT>make</TT> generates commands using a description file known as a <TT>makefile</TT>. These commands are then executed by the shell. The <TT>makefile</TT> is basically a set of rules for <TT>make</TT> 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. <TT>make</TT> can also figure out some things for itself, such as the modification times (or timestamps) when certain files have been changed.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Note: </B><BR><TT>makefile</TT> or <TT>Makefile</TT> is literally the name that the <TT>make</TT> program expects to find in the current directory. You can override the name if you want, but tradition (and who can argue with 30 years of tradition?) dictates that <TT>makefile</TT> is the name programmers should use.<HR></FONT>
</BLOCKQUOTE>
<P><TT>make</TT> is certainly best suited for C programming, but it can also be used with other types of language compilers for Linux, such as assembler or FORTRAN.</P>
<H4 ALIGN="LEFT"><A NAME="Heading3"></A><FONT COLOR="#000077">A Sample makefile</FONT></H4>
<P>Let’s look at a simple application of <TT>make</TT>. The command</P>
<!-- CODE SNIP //-->
<PRE>
$ make someonehappy
</PRE>
<!-- END CODE SNIP //-->
<P>tells Linux that you want to create a new version of <TT>someonehappy</TT>. In this case, <TT>someonehappy</TT> is an executable program; thus, there will be compiling and linking of files. <TT>someonehappy</TT> is referred to as the <I>target</I> of this <TT>make</TT> operation. The object files that are linked together to create the executable are known as <TT>someonehappy</TT>’s <I>dependents</I>. The source code files that are compiled to create these object files are also indirect dependents of <TT>someonehappy</TT>.</P>
<P>The files that are used to build <TT>someonehappy</TT> are the following (the contents of these files are unimportant to the example):</P>
<DL>
<DD>Two C source code files: <TT>main.c</TT>, <TT>dothis.c</TT>
<DD>Three header files: <TT>yes.h</TT>, <TT>no.h</TT>, <TT>maybe.h</TT>
<DD>One library file: <TT>/usr/happy/lib/likeatree.a</TT>
<DD>An assembly language file: <TT>itquick.s</TT>
</DL>
<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 <TT>makefile</TT> for your <TT>someonehappy</TT> project to help automate these tedious tasks.</P>
<P>In your favorite editor, write the following:</P>
<!-- CODE //-->
<PRE>
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/
</PRE>
<!-- END CODE //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch55/890-892.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="898-901.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?