-->
Previous Table of Contents Next


Part VIII
Advanced Programming Topics

In This Part
•   Source Code Control
•   Working with the Kernel
•   Writing Device Drivers
•   The Wine Project
•   HylaFAX
•   Games
•   Adabas-D and other Databases
•   StarOffice
•   Lone Star Software’s Lone-Tar

Chapter 56
Source Code Control

by Peter MacKinnon and Tim Parker

In This Chapter
•   make
•   RCS
•   Retrieving version information from an RCS file
•   Administering Access
•   Comparing and merging revisions
•   Tying it all together: working with make and RCS

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:

“How do I know whether this file of input/output routines that Sue has been working on is the most current one?”

“Oh, no—I have to recompile my application, but I can’t remember which of these 50 files I changed since the last compile!”

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.

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.

make

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.

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 can also figure out some things for itself, such as the modification times (or timestamps) when certain files have been changed.


Note:  
makefile or Makefile is literally the name that the make 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 makefile is the name programmers should use.

make 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.

A Sample makefile

Let’s look at a simple application of make. The command


$ make someonehappy

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.

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

Two C source code files: main.c, dothis.c
Three header files: yes.h, no.h, maybe.h
One library file: /usr/happy/lib/likeatree.a
An assembly language file: itquick.s

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.

In your favorite editor, write the following:


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/


Previous Table of Contents Next