| Fortran Programming Guide |
Program Development
This chapter briefly introduces two powerful program development tools,
makeand SCCS, that can be used very successfully with Fortran programs.A number of good, commercially published books on using
makeand SCCS are currently available, including Managing Projects with make, by Andrew Oram and Steve Talbott, and Applying RCS and SCCS, by Don Bolinger and Tan Bronson. Both are from O'Reilly & Associates.Facilitating Program Builds With the
makeUtilityThe
makeutility applies intelligence to the task of program compilation and linking. Typically, a large application consists of a set of source files andINCLUDEfiles, requiring 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,makeensures that only the files that need recompiling are recompiled and that relinking uses the options and libraries you need to build the executable. The following discussion provides a simple example of how to usemake. For a summary, seemake(1).The Makefile
A file called
makefiletellsmakein a structured manner which source and object files depend on other files. It also defines the commands required to compile and link the files.For example, suppose you have a program of four source files and the makefile:
demo%lsmakefilecommonblockcomputepts.fpattern.fstartupcore.fdemo%Assume both
pattern.fandcomputepts.fhave anINCLUDEofcommonblock, and you wish to compile each.ffile and link the three relocatable files, along with a series of libraries, into a program calledpattern.The makefile looks like this:
The first line of
makefileindicates that makingpatterndepends onpattern.o,computepts.o, andstartupcore.o. The next line and its continuations give the command for makingpatternfrom the relocatable.ofiles and libraries.Each entry in
makefileis a rule expressing a target object's dependencies and the commands needed to make that object. The structure of a rule is:target
:dependencies-listTABbuild-commands
- Dependencies. Each entry starts with a line that names the target file, followed by all the files the target depends on.
- Commands. Each entry has one or more subsequent lines that specify the Bourne shell commands that will build the target file for this entry. Each of these command lines must be indented by a tab character.
makeCommandThe
makecommand can be invoked with no arguments, simply:
demo%makeThe
makeutility looks for a file namedmakefileorMakefilein the current directory and takes its instructions from that file.
- Reads
makefileto determine all the target files it must process, the files they depend on, and the commands needed to build them.- Finds the date and time each file was last changed.
- Rebuilds any target file that is older than any of the files it depends on, using the commands from
makefilefor that target.Macros
The
makeutility's macro facility allows simple, parameterless string substitutions. For example, the list of relocatable files that make up the target programpatterncan be expressed as a single macro string, making it easier to change.A macro string definition has the form:
Use of a macro string is indicated by:
which is replaced by
makewith the actual value of the macro string.This example adds a macro definition naming all the object files to the beginning of
makefile:
OBJ = pattern.o computepts.o startupcore.oNow the macro can be used in both the list of dependencies as well as on the
f77link command for targetpatterninmakefile:
pattern: $(OBJ)f77$(OBJ) -lcore77 -lcore -lsunwindow \-lpixrect -o patternFor macro strings with single-letter names, the parentheses may be omitted.
Overriding of Macro Values
The initial values of
makemacros can be overridden with command-line options tomake. For example:
Now a simple
makecommand without arguments uses the value ofFFLAGSset above. However, this can be overridden from the command line:
demo%make "FFLAGS=-u -O"Here, the definition of the
FFLAGSmacro on themakecommand line overrides themakefileinitialization, and both the-Oflag and the-uflag are passed tof77. Note that"FFLAGS="can also be used on the command to reset the macro to a null string so that it has no effect.Suffix Rules in
makeTo make writing a makefile easier,
makewill use its own default rules depending on the suffix of a target file. Recognizing the.fsuffix,makeuses thef77compiler, passing as arguments any flags specified by theFFLAGSmacro, the-cflag, and the name of the source file to be compiled.The example below demonstrates this rule twice:
makeuses default rules to compilecomputepts.fandstartupcore.f.Similarly, suffix rules for
.f90files will also invoke thef95compiler. However, there are no suffix rules currently defined for.f95Fortran 95 source files or.modFortran 95 module files.Version Tracking and Control With SCCS
SCCS stands for Source Code Control System. SCCS provides a way to:
- Keep track of the evolution of a source file--its change history
- Prevent a source file from being simultaneously changed by other developers
- Keep track of the version number by providing version stamps
The basic three operations of SCCS are:
- Putting files under SCCS control
- Checking out a file for editing
- Checking in a file
This section shows you how to use SCCS to perform these tasks, using the previous program as an example. Only basic SCCS is described and only three SCCS commands are introduced:
create,edit, anddelget.Controlling Files With SCCS
Putting files under SCCS control involves:
- Making the SCCS directory
- Inserting SCCS ID keywords into the files (this is optional)
- Creating the SCCS files
Making the SCCS Directory
To begin, you must create the SCCS subdirectory in the directory in which your program is being developed. Use this command:
demo% mkdir SCCSInserting 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
getordelgetcommand. There are three likely places to put these strings:
- Comment lines
- Parameter statements
- Initialized data
The advantage of using keywords is that the version information appears in the source listing and compiled object program. If preceded by the string @(#), the keywords in the object file can be printed using the
whatcommand.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. In some files, like ASCII data files or makefiles, the SCCS information will appear in comments.
SCCS keywords appear in the form
%keyword%and are expanded into their values by the SCCSgetcommand. The most commonly used keywords are:
%Z%expands to the identifier string@(#)recognized by thewhatcommand.%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.For example, you could identify the makefile with a
makecomment containing these keywords:
# %Z%%M% %I% %E%The source files,
startupcore.f,computepts.f, andpattern.f, can be identified by initialized data of the form:
CHARACTER*50 SCCSIDDATA SCCSID/"%Z%%M% %I% %E%\n"/When this file is processed by SCCS, compiled, and the object file processed by the SCCS
whatcommand, the following is displayed:
demo%f77 -c pattern.f...demo%what patternpattern:pattern.f 1.2 96/06/10You can also create a
PARAMETERnamedCTIMEthat is automatically updated whenever the file is accessed withget.
CHARACTER*(*) CTIMEPARAMETER ( CTIME="%E%")INCLUDE files can be annotated with a Fortran comment containing the SCCS stamp:
C %Z%%M% %I% %E%
Note Use of single letter derived type component names in Fortran 95 source code files can conflict with SCCS keyword recognition. For example, the Fortran 95 structure component referenceX%Y%Zwhen passed through SCCS will becomeXZafter an SCCSget. Care should be taken not to define structure components with single letters when using SCCS on Fortran 95 programs. For example, had the structure reference in the Fortran 95 program been toX%YY%Z, the%YY%would not have been interpreted by SCCS as a keyword reference. Alternatively, the SCCSget -koption will retrieve the file without expanding SCCS keyword IDs.
Creating SCCS Files
Now you can put these files under control of SCCS with the SCCS
createcommand:
demo%sccs create makefile commonblock startupcore.f \computepts.f pattern.fdemo%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.
Check out a file with the
sccseditcommand. For example:
demo%sccs edit computepts.fSCCS then makes a writable copy of
computepts.fin 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.When you have completed your editing, check in the modified file with the
sccsdelgetcommand. For example:
demo%sccs delget computepts.fThis command causes the SCCS system to:
- Make sure that you are the user who checked out the file by comparing login names
- Prompt for a comment from you on the changes
- Make a record of what was changed in this editing session
- Delete the writable copy of
computepts.ffrom the current directory- Replace it by a read-only copy with the SCCS keywords expanded
The
sccsdelgetcommand is a composite of two simpler SCCS commands,deltaandget. Thedeltacommand performs the first three tasks in the list above; thegetcommand performs the last two tasks.
|
Sun Microsystems, Inc. Copyright information. All rights reserved. Feedback |
Library | Contents | Previous | Next | Index |