230 likes | 433 Views
Make and CVS. Kate Hedstrom October 2001. make. (Based on a talk by Pete Morreale) Maintains programs based on a description file you provide “make” works by checking the modification times of files and deciding which are out-of-date Only out-of-date files are updated
E N D
Make and CVS Kate Hedstrom October 2001
make • (Based on a talk by Pete Morreale) • Maintains programs based on a description file you provide • “make” works by checking the modification times of files and deciding which are out-of-date • Only out-of-date files are updated • Often used for compiling programs, but can be used for other tasks
Description Files • “make” looks for its description file in the current directory with the name: • You can also tell it what file to use: makefile Makefile s.makefile s.Makefile % make -f Makefile.yukon
Example Makefile • A simple “make” description file, containing four rules: job: main.o func1.o func2.o cc -o job main.o func1.o func2.o main.o: main.c cc -c main.c func1.o: func1.c cc -c func1.c func2.o: func2.c cc -c func2.c
“make” Rules • A “make” rule is the object you want “make” to build for you. Generally, rules are command names, or specific filenames. • target - the object you want “make” to build • dependencies - files the target depends on • commands - list of commands to create the target target : dependencies [TAB] command [TAB] command
Using Macros • A “make” macro is a simple string substitution mechanism • A macro has the following syntax: • Reference a macro with: MACRO_NAME = [substitution string] $(MACRO_NAME)
Macro Conventions • Use upper case for macro names • Define near the top of the Makefile • Use separate macros for commands and the options to those commands: CC = gcc CFLAGS = -O3 LIBDIR = /usr/local/lib LIBS = -L$(LIBDIR) -lnetcdf
Executing “make” % make [options] [target] • Invoke “make” with the following syntax: • If “make” is invoked without a target, the first target will be built • To build another target, specify it on the command line: • A useful option is “-n” to show commands without executing them: % make clean % make -n
Example Macros • A simple Makefile with a macro: • This would expand to: # Compile Fortran 90 sources FC = f90 main.o: main.f [TAB] $(FC) -c main.f f90 -c main.f
Another example, with two macros: • This command expands to: # IBM compiler FC = xlf FFLAGS = -03 -qstrict main.o: main.f [TAB] $(FC) $(FFLAGS) -c main.f xlf -O3 -qstrict -c main.f
Useful “make” Rules • You can add other rules to assist you: • When a target doesn’t have any dependencies, the commands are always executed: clean: rm -r *.o core depend: makedep $(SRCS) % make clean
Implicit Rules • “make” has special rules already built in. Most of these rules deal with compiling programs. Consider this Makefile: • “make” will automatically build the “.o” files using the built-in rule: OBJS = main.o init.o plot.o work.o model: $(OBJS) $(CC) -o model $(OBJS) .c.o: $(CC) $(CFLAGS) -c $<
Dependencies • Say you have the following files, all including “grid.h”: • The Makefile needs to know: • There are tools to produce this information automatically main.c init.c plot.c # include dependencies main.o: grid.h init.o: grid.h plot.o: grid.h
Final Points • “make” is a very powerful tool for program development and other tasks, even web pages • “make” has a portable subset of features, with system-dependent extensions • “gmake” is a full-featured portable solution • Don’t forget those tabs!
Version Control Software • System for managing source files • For groups of people working on the same code • When you need to get back last week’s version • In the old days, there was SCCS and RCS for file-wise management • Current “standard” is CVS • Works with whole directory trees • Has a network option for remote access
Getting Started With CVS • Tell it where to put archive: • Mine is in /allsys, visible to Cray, IBM, SGI • For a new archive: % setenv CVSROOT /myhome/cvsroot or $ CVSROOT=/myhome/cvsroot $ export CVSROOT % cvs init
Main CVS commands • import - bring sources into the repository • checkout - get sources out of the repository • commit - check in changes • update - get changes from other people/directories • tag - label a revision • diff - find out what changed • --help, --help-commands
Example % cd cpp # import whole directory % cvs import cpp der_mouse initial % cd .. % mv cpp cpp_old # want to be working in checked-out copy % cvs checkout cpp % cd cpp [make some changes] % cvs commit % cvs tag version_1_1
# on icehawk % cvs checkout roms % cd roms [make some changes] % cvs commit # on yukon % cd roms % cvs update % make
Revision Numbers • CVS uses RCS files internally • Can see the numbers with “cvs log” • Can get the current revision info into your file with keyword substitution: • Usually put the keywords into a comment or a string $Revision$ -> $Revision: 1.4 $
Tags • In a project, each file has its own independent revision numbers • Want a way to label revisions as belonging together % cvs tag tag_3_5
Branches • First branch is x.x.1, second is x.x.2 • Can merge branches
Learn more • Managing projects with make, by Andrew Oram and Steve Talbott, 1991, O’Reilly • Version Management with CVS, by Per Cederquist, comes with CVS • Practical CVS, parts 1 and 2, by Jeffreys Copeland and Haemer, SunExpert Magazine, 1997 • (http://www.arsc.edu/~kate/Unix_tools/)