Program Development |
3 |
![]() |
INCLUDE files, which require linking with a number of libraries. Modifying any one or more of the source files requires recompilation of that part of the program and relinking. You can automate this process by specifying the interdependencies between files that make up the application along with the commands needed to recompile and relink each piece. With these specifications in a file of directives, make insures that only the files that need recompiling are recompiled and that relinking to build the executable uses the options and libraries you want. The following discussion provides a simple example of how to use make. For a summary, see make(1).
For example, suppose you have a program of four source files and the makefile:
demo% ls makefile commonblock computepts.f pattern.f startupcore.f demo% |
Assume both pattern.f and computepts.f have an
INCLUDE of commonblock, and you wish to compile each.f file and link the three relocatable files, along with a series of libraries, into a program called pattern.
The first line of this makefile indicates that making pattern depends on pattern.o, computepts.o, and startupcore.o. The next line and its continuations give the command for making pattern from the relocatable.o files and libraries.
demo% make |
The make utility looks for a file named makefile or Makefile in the current directory and takes its instructions from that file.
A macro string definition has the form:
= string
$(NAME)
This example adds a macro definition naming all the object files to the beginning of makefile:
OBJ = pattern.o computepts.o startupcore.o |
pattern: $(OBJ) f77 $(OBJ) -lcore77 -lcore -lsunwindow \ -lpixrect -o pattern |
For macro strings with single-letter names, the parentheses may be omitted.
Overriding of Macro Values
The initial values of make macros can be overridden with command-line options to make. For example, with the following line to the top of makefile:
FFLAGS=-u |
and the compile-line of computepts.f:
f77 $(FFLAGS) -c computepts.f |
f77 $(FFLAGS) $(OBJ) -lcore77 -lcore -lsunwindow \ lpixrect -o pattern |
demo% make "FFLAGS=-u -O" |
Here, the definition of the FFLAGS macro on the make command line overrides the makefile initialization, and both the -O flag and the -u flag are passed to f77. Note that
"FFLAGS=" can also be used on the command to reset the macro so that it has no effect. Suffix Rules in make
To make writing a makefile easier, make has its own default rules that it will use depending on the suffix of a target file. Recognizing the .f suffix, make uses the f77 compiler passing as arguments any flags specified by the FFLAGS macro, the -c flag, and the name of the source file to be compiled.
make uses default rules to compile computepts.f and startupcore.f.
More Information
A number of good, commercially published books on using make as a program development tool are currently available, including Managing Projects with make, by Oram and Talbott, from O'Reilly & Associates.
Version Tracking and Control With SCCS
SCCS stands for Source Code Control System. SCCS provides a way to:
demo% mkdir SCCS |
SCCS must be in uppercase.
Inserting SCCS ID Keywords
Some developers put one or more SCCS ID keywords into each file, but that is optional. These keywords are later identified with a version number each time the files are checked in with an SCCS get or delget command. There are three likely places to put these strings:
@(#), the keywords in the object file can be printed using the what command.Included header files that contain only parameter and data definition statements do not generate any initialized data, so the keywords for those files usually are put in comments or in parameter statements. Some files, like ASCII data files or makefiles, the SCCS information appears in comments.
SCCS keywords appear in the form
%keyword% and are expanded into their values by the SCCS get command. The most commonly used keywords are:
%Z% expands to the identifier string @(#) recognized by the what command.
%M% expands to the name of the source file.
%I% expands to the version number of this SCCS maintained file.
%E% expands to the current date.
# %Z%%M% %I% %E% |
CHARACTER*50 SCCSID DATA SCCSID/"%Z%%M% %I% %E%\n"/ |
demo% f77 -c pattern.f ... demo% what pattern pattern: pattern.f 1.2 96/06/10 |
CHARACTER*(*) CTIME PARAMETER ( CTIME="%E%") |
INCLUDE files can be annotated with a Fortran comment containing the SCCS stamp:
C %Z%%M% %I% %E% |
Creating SCCS Files
Now you can put these files under control of SCCS with the SCCS create command:
demo% sccs create makefile commonblock startupcore.f \ computepts.f pattern.f demo% |
Checking Files Out and In
Once your source code is under SCCS control, you use SCCS for two main tasks: to check out a file so that you can edit it, and to check in a file you have finished editing.
demo% sccs edit computepts.f |
SCCS then makes a writable copy of computepts.f in the current directory, and records your login name. Other users cannot check the file out while you have it checked out, but they can find out who has checked it out.
demo% sccs delget computepts.f |
This command causes the SCCS system to do the following: