Copyright 1997 Computer Science 217: Make & RCS Page 38September 14, 1999Make• Typical program development cycle• Potential problemsedit a file, but forget to compile itedit an interface, but forget to compileall the files that depend on itdo more compilation than is necessary• make automates compiling and building a programthinkeditcompile testthinkeditmake testCopyright 1997 Computer Science 217: Make & RCS Page 39September 14, 1999Dependency Graphs• make processes a dependency grapheach node represents a fileeach node is annotated with the command that “makes” the file• To make node Xmake all dependents of X (those modified more recently than X)update X using the associated commandif strset.h or main.c is newer than main.ore-make main.o with lcc -c main.c”uniquemain.cstrset.ostrset.cstrset.hmain.olcc -c main.clcc -c strset.clcc -o unique main.o strset.oCopyright 1997 Computer Science 217: Make & RCS Page 40September 14, 1999Makefiles• makefile or Makefile specifies the dependency graph of maketargets: dependentscommandsunique: main.o strset.olcc -o unique main.o strset.omain.o: main.c strset.hlcc -c main.cstrset.o: strset.c strset.hlcc -c strset.c• To invoke makemake targets ... make strset.omake unique• With no arguments, make makes the first target listed in makefile% makelcc -c main.clcc -c strset.clcc -o unique main.o strset.o% touch strset.c% make strset.olcc -c strset.c% makelcc -o unique main.o strset.oCopyright 1997 Computer Science 217: Make & RCS Page 41September 14, 1999Built-ins and Macros• make contains built-in dependencies and commands a “.o” file is assumed from a “.c” file by the C compilerunique: main.o strset.olcc -o unique main.o strset.omain.o strset.o: strset.h• make has a simple macro facility; macros communicate with built-incommands and simplify makefilesCC=lcc -ACFLAGS=-gLDFLAGS=-gSTRSET=strset0OBJS=main.o $(STRSET).oa.out: $(OBJS)$(CC) $(LDFLAGS) $(OBJS)$(OBJS): strset.h% make -nlcc -A -g -c main.clcc -A -g -c strset0.clcc -A -g main.o strset0.o% make -n STRSET=strset1lcc -A -g -c main.clcc -A -g -c strset1.clcc -A -g main.o strset1.o%setenv STRSET strset1% make -elcc -A -g -c main.clcc -A -g -c strset1.clcc -A -g main.o strset1.o%Copyright 1997 Computer Science 217: Make & RCS Page 42September 14, 1999Dummy Targets, Prefixes, and Built-in Macros• “Dummy” targets for common command sequencesinstall: a.outcp a.out uniquestrip uniqueclean:-rm *.o coreclobber:cleanrm -f a.out uniquemake clean removes “.o” and core files• Dummy targets can be created if only for their modification timeFILES=main.c strset.h strset0 strset1.c...print: $(FILES)@enscript $?@touch print• Use dummy targets for all “program maintenance” tasksclean install printrelease submit test• Don’toveruse dummy targets and macros“-” prefix ignores errors$? macro expands into “younger” dependents“@” prefix suppresses command echoingCopyright 1997 Computer Science 217: Make & RCS Page 43September 14, 1999Version-Control Tools• Software systems evolve — they advance in steps or versions• repair bugs• add performance improvements and new features• add versions for other platforms (SPARC, MIPS, x86, ...)• Might have to retrieve old versions• Version-control tools help maintain versions of programs, or any files• Revision trees1.2.1.11.21.2.2.11.3.1.11.11.3.1.21.3 1.4 1.5Copyright 1997 Computer Science 217: Make & RCS Page 44September 14, 1999Revision Control System• “Checking in” a file creates a new version, including the initial versionci main.ccreates the version file main.c,v that holds main.c as version 1.1deletes main.c• “Checking out” a file retrieves a copy of the latest versionco main.c checks out aread-only copylcc -c main.cco -l main.c checks out a read/write copy, locks main.c,vemacs main.clcc -c main.cci main.c checks in new main.c as version 1.2• Options specify explicit versions for co and cico -r1.2 main.c checks out a read-only copy of version 1.2 main.cco -l1.2 main.c checks out a read/write copy of version 1.2 main.cci -r2 main.c checks in a new “release” of main.cCopyright 1997 Computer Science 217: Make & RCS Page 45September 14, 1999Branching• Branching occurs to fix bugs, enhance old versions, ...•ci main.cco -l main.c; emacs; ... ; ci main.cco -l main.c; emacs; ... ; ci main.cco -l main.c; emacs; ... ; ci -r2 main.cco -l main.c; emacs; ... ; ci main.c• What if you would like to fix and enhance version 1.3?1.11.21.11.31.1 1.22.11.1 1.2 1.32.11.1 1.2 1.3 2.2Copyright 1997 Computer Science 217: Make & RCS Page 46September 14, 1999Branching, cont’d• Create a branch at version 1.3co -l1.3 main.c; emacs; ... ; ci -r1.3.1 main.c• Extra revision number in 1.3.1.1 allows for subsequent revisionsco-l1.3.1 main.c; emacs; ... ; ci -r1.3.1 main.c• See RCS man pages for information on more options, commands, ...2.11.1 1.21.3.1.12.21.32.11.1 1.21.3.1.22.21.31.3.1.1Copyright 1997 Computer Science 217: Make & RCS Page 47September 14, 1999Using RCS with Make• Using RCS with make*.c depends on *.c,vmain.c: main.c,vco main.cRCS automatically looks in the directory RCS for ,v filesmain.c: RCS/main.c,vco main.c“make clobber” should remove .c filesclobber: cleanrm -f wf main.c parse.c table.cor, if rcsclean is availableclobber: cleanrm -f wf; rcsclean *.[ch]• Revised program development cyclethinkeditmake testcheck outcheck inCopyright 1997 Computer Science 217: Make & RCS Page 48September 14, 1999RCS Implementation• Revisions are stored in the version file in differential formif main.c has the revision treemain.c,v holds all of version 1.3edit script to convert 1.3 to 1.2edit script to convert 1.2 to 1.1• RCS revisions are backward deltas . Why?• Other systems,such as SCCS use forward deltasversion file holds all of version 1.1edit script to convert 1.1 to 1.2edit script to convert 1.2 to 1.3• Deltas are computed with “diff”diff -e main.old main.cgenerates ed commands to edit main.old into main.csee Section 5.9 in Kernighan and Pike, The UNIX Programming Environment1.31.1
View Full Document