1 / 23

Make and CVS

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

edna
Télécharger la présentation

Make and CVS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Make and CVS Kate Hedstrom October 2001

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

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

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

  5. “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

  6. 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)

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

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

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

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

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

  12. 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 $<

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

  14. 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!

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

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

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

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

  19. # on icehawk % cvs checkout roms % cd roms [make some changes] % cvs commit # on yukon % cd roms % cvs update % make

  20. 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 $

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

  22. Branches • First branch is x.x.1, second is x.x.2 • Can merge branches

  23. 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/)

More Related