ANU The Australian National University



____________________________________________________

[ANU] [DCS] [COMP2100/2500] [Description] [Schedule] [Lectures] [Labs] [Homework] [Assignments] [COMP2500] [Assessment] [PSP] [Java] [Reading] [Help]

____________________________________________________

COMP2100/2500
Lecture 24: Make and RCS

Summary

An introduction to two of the standard tools for managing larger programs: the build tool make and the version control tool RCS.

Aims


Build Tools

Why do we need build tools?

What can a build tool do for you?


Do I Really Need a Build Tool?

Can't smart compilers like the one for Java do that for me?

Yes, but:


File Dependency Example

strcnt.h

Prototype for a string length function.

strcnt.c

Source code for a string length function.

harness.c

Test harness for string length function.

tests.txt

Test cases for string length function.

Dependency diagram for
the example system


How Do I Use a Build Tool?

You must tell a build tool the following things about your system:

Operating systems tag files with the time of their last update. Build tools compare the ages of files and rebuild new versions appropriately.

For example, if harness is missing or older than strcnt.o or harness.o, a build tool would run `gcc -Wall -o harness strcnt.o harness.o' to update it.


Make: A UNIX Build Tool

The UNIX make command requires an input file, called `makefile' (or `Makefile'), to describe the dependencies between files and how to update them.

A makefile consists of multiple entries of the following format:

file-name: other files it depends on
        commands to build it

Note: Commands must be indented by a Tab character, not 8 spaces.

The file named before the colon is called a target.

To update the file f with respect to the files on which it depends, type `make f' into the shell.

Just saying `make' updates the first target named in makefile.


An Example Makefile

tests.log: harness tests.txt
        ./harness < tests.txt > tests.log

harness: harness.o strcnt.o
        gcc -Wall -o harness harness.o strcnt.o

harness.o: harness.c strcnt.h
        gcc -Wall -c harness.c

strcnt.o: strcnt.c strcnt.h
        gcc -Wall -c strcnt.c

Using the example Makefile

[comp2100@karajan]$ rm -f tests.log harness *.o
[comp2100@karajan]$ make
gcc -Wall -c harness.c
gcc -Wall -c strcnt.c
gcc -Wall -o harness harness.o strcnt.o
./harness < tests.txt > tests.log
[comp2100@karajan]$ emacs strcnt.c
[comp2100@karajan]$ make
gcc -Wall -c strcnt.c
gcc -Wall -o harness harness.o strcnt.o
./harness < tests.txt > tests.log

Phony Targets

You can declare targets that give names to actions that do not correspond to files. These are called phony targets.

Example: We can use a phony target to remove all the automatically generated files.
clean:
        rm -f harness harness.o strcnt.o tests.log

If you run make clean, make should discover that there is no file called `clean', so it runs the command. (After which, there is still no file called `clean'.)


More Phony Targets

We can use a phony target to build a list of files.

all: file1 file2 ...

If you run make all, make should discover that there is no file called `all'. Before it realises that there is no command to build all, it will first update each of the dependencies.

Note: In most makefiles, the first target is a phony target called all that depends on a list of files to be updated when Make is run without arguments.


Version Control

Maintenance will produce many versions of a module.

revision:

A new version of a module intended to replace the old one. For example, when you fix a fault in the module.

variation:

A new version of a module that will co-exist with the old one. For example, when you port a system to a new operating system.

You need to keep all the versions of all the modules because:

Keeping track of all these versions requires a tool.


What Can a Version Control Tool Do?


RCS: A UNIX Version Control Tool

Versions of file f are stored in f,v. Versions files may be in a subdirectory called RCS.

Example:

Structure of RCS storage
for the example system


Some RCS Commands

co strcnt.h

Check-out a read-only copy of the latest version of strcnt.h.

co -r1.4 strcnt.c

Check-out a read-only copy of version 1.4 of strcnt.c.

co -l harness.c

Check-out a writable copy of the latest version of harness.c. The file is locked so that only the user can update it.

ci harness.c

Check-in a new latest version of harness.c, only available to the user who has it locked. The file harness.c is then unlocked. The user is prompted to describe the changes made to the file.

rlog tests.txt

Describe the history of changes made to this file.

co -d"25 December" strcnt.c

Check-out the last version of strcnt.c from before (or maybe on) Christmas Day.


Efficiency Issues with RCS

Storing every version of each file for a big, long lived, project would use too much space.

To avoid this problem RCS uses the following strategy:

The latest version of an RCS file can be extracted immediately from the versions file. Earlier versions must be reconstructed by examining the differences recorded.

This functionality is implemented with variants of the UNIX diff and patch commands.


Using RCS On Larger Projects

Example: Multiple Users

RCS storage with two
users

RCS & Make:


Limitations of RCS

RCS manages changes only within a file, not to a directory structure. Between versions of a product:

Everyone working on an project managed by RCS must share access to a common file system. This is often not possible if the collaborators:

Such situations are common for open-source projects.

The Concurrent Versions System (CVS), built from RCS, addresses these issues. All the COMP2100 materials (lecture notes, lab instructions, assignments, project and other source code etc.) are managed using CVS.

____________________________________________________

[ANU] [DCS] [COMP2100/2500] [Description] [Schedule] [Lectures] [Labs] [Homework] [Assignments] [COMP2500] [Assessment] [PSP] [Java] [Reading] [Help]

____________________________________________________

Copyright © 2005, Jim Grundy and Ian Barnes and Richard Walker, The Australian National University
Version 2005.2, Wednesday, 4 May 2005, 18:32:16 +1000
Feedback & Queries to comp2100@cs.anu.edu.au