Jump to first page (C) 1998, Arun Lakhotia 1 Software Configuration Management: Build Control Arun Lakhotia University of Southwestern Louisiana Po Box Lafayette, LA 70504, USA
Jump to first page (C) 1998, Arun Lakhotia 2 Software Configuration Management n Practice of handling changes systematically n Three components u Build control u Version control u Change control
Jump to first page (C) 1998, Arun Lakhotia 3 Build control n Maintaining the consistency between components, in particular the derived components. n Derived components u Executables u Hardcopy manuals u Compact Disk u Test results and summaries
Jump to first page (C) 1998, Arun Lakhotia 4 Dynamic dependencies User Requirements Test results Test cases Executable Hardcopy document Code Electronic document
Jump to first page (C) 1998, Arun Lakhotia 5 Need for automated support n Forgettng to create “derived components” leads to incosistent executables, manuals, etc. n Creation of “derived components” manually is tedious, repetituous, and boring. n The relationship (inputs, outputs, transforms) are static n Over time one forgets the mechanisms for transforming inputs to outputs n The same transformation sequence can be applied else where.
Jump to first page (C) 1998, Arun Lakhotia 6 General pattern of deriving components C1 C2 C3 C4 C5 C6 C7 I2 I1 I3 I4 T4 T3 T2 T1 T5T6 D0 Ti: Transformers Ci: Input components Ik: Intermediate components Di: Output (final) component
Jump to first page (C) 1998, Arun Lakhotia 7 Specific example: Deriving executable WordDriver.c WordDriver.h acc WordFile.c WordFile.o WordDriver.o WordFile.h Library WordDriver If any of the.c or.h file changes then WordDriver should be recreated
Jump to first page (C) 1998, Arun Lakhotia 8 Information needed to build components n The sources n The targets n The rules used to create targets from sources n Example u Source: file.c file.h u Target: file.o u Rule: acc -c file.c
Jump to first page (C) 1998, Arun Lakhotia 9 Make: A tool to manage builds n Requires u Components u Dependencies u Transformation rules n Provides u Language to describe the above u Language allows expression of very general rules u Will check for consistency between sources and targets u Will invoke commands necessary to create targets from sources
Jump to first page (C) 1998, Arun Lakhotia 10 Make language Target ‘:’ source1 source2 source3 rule Tab file.o : file.c acc -c file.c Tab WordDrive.o: WordDriver.c WordFile.h acc -c WordDriver.c WordFile.c: WordFile.c WordFile.h acc -c WordFile.c WordDriver: WordDriver.o WordFile.o acc -o WordFile WordDriver.o WordFile.o
Jump to first page (C) 1998, Arun Lakhotia 11 Using Make n Create Makefile. Place the dependencies and generation rles in it. n Run Make u % rm *.o u % make WordDriver Make will invoke the following commands acc -c WordFile.c acc -c WordDriver.c acc -o WordFile WordFile.o WordDriver.o u % make WordDriver Make will say ‘WordDriver’ is up to date. % touch WordFile.c (mark the file as changed) % make WordDriver acc -c WordFile.c acc -o WordFile WordFile.c WordDriver.c
Jump to first page (C) 1998, Arun Lakhotia 12 How make detects change? n Make compares the date of creation of the sources and targets n If a source is more recent than a target, it assumes that the source has changed and that the target should be recreated n What are the drawbacks of this logic?
Jump to first page (C) 1998, Arun Lakhotia 13 Builtin rules n Make has a language to express dependencies based on file extensions.c,.o,.h,.etc n It has some predefined rules to create object files and executable files for various programming languages n So it can do a lot of processing without a Makefile
Jump to first page (C) 1998, Arun Lakhotia 14 Using Built-in rules n Assume Makefile has no rule for Formatter.o % make Formatter.o cc -sun4 -c Formatter.c n How do you say which compiler to use? u Introduce the following line in the Makefile CC= gcc u It says use “gcc” for compiling. n How do you provide compiler options? u Assign option values to CFLAGS CFLAGS= -DFLAG=1 -g
Jump to first page (C) 1998, Arun Lakhotia 15 Using Make variables n CC and CFLAGS are make variables n You can introduce your own make variables n How do you assign value to a variable? VARIABLE= value n How do you USE value of a variable? $(VARIABLE) gives the variables value. n Variables can be used to reduce repetition in Makefiles
Jump to first page (C) 1998, Arun Lakhotia 16 Example Makefile # EXEC gives the name of the executable EXEC = WordDriver # The variable OBJS gives the name of the.o files needed to # create the executable OBJS = WordFile.o WordDriver.o # The following define CC and CFLAGS to be used for compiling # and linking the files CC = gcc CFLAGS = -g # The following rule states how to generate $(EXEC) from $(OBJS) $(EXEC): $(OBJS) $(CC) $(CFLAGS) -o $(EXEC) $(OBJS)
Jump to first page (C) 1998, Arun Lakhotia 17 Using Make for testing n Components u Input file:.dat u Output file:.res n Dependencies: Program “pgm” transforms Input file to Output file n Transformation rule % pgm input.dat > output.res n Test case files: file1.dat, file2.dat, file3.dat … file1.res : file1.dat pgm file1.dat > file1.res file2.res: file2.dat pgm file2.dat > file2.res...
Jump to first page (C) 1998, Arun Lakhotia 18 Introducing transformation rules n Rule for transforming.dat file to.res file. % is a pattern match symbol. %.res matches with any file name with.res extension. The rule says a file “xxx.res” can be created from “xx.dat” $< represents the source represents the target %.res : %.dat pgm $
Jump to first page (C) 1998, Arun Lakhotia 19 Generating filenames in Makefile n You may like to generate the name of.o file from the name of.c file, instead of hardcoding them. n This can be achieved by doing substitution within a pattern match variable, as below. n $(SRC:%.c=%.o) replaces all names with.c to names with.o. The match is performed a “word” at a time. SRC = file1.c file2.c file3.c OBJS = $(SRC:%.c=%.o) EXEC = pgm $(EXEC) : $(OBJS) $(CC) -o $(EXEC) $(OBJS)
Jump to first page (C) 1998, Arun Lakhotia 20 Generating source filenames n Even typing in the name of the source files is not always desirable n One may want the names to be picked up from the directory n This is particularly useful for testcase files n In the following the suffix “:sh” says that execute the value being assigned to TESTCASES as a shell command and assign the output to TESTCASES. n Names of.res files are then generated from the names of.dat files TESTCASES:sh = echo *.dat RESFILES = $(TESTCASES:%.dat=%.res)
Jump to first page (C) 1998, Arun Lakhotia 21 Generating.h dependencies n The.o <--.h dependency can be generated automatically using makedepend. % makedepend f1.c f2.c f3.c … modifies the Makefile and introduces.o/.h dependency. SRCS= f1.c f2.c f3.c makedepend: makedepend $(SRCS) To generate the dependencies introduce the above in your Makefile and give the following command: % make makedepend
Jump to first page (C) 1998, Arun Lakhotia 22 Summary: Make n Make provides a language to describe chains of dependencies and transformation rules to generate derived components n The transformation rules can be written for an individual set of files or for a whole class of files n Its language provides macro variables, mechanism to use pattern match to substitute values in variable, and for assigning output of shell command to a variable.