1 / 35

第四单元 make 和 SCCS 工具集合

第四单元 make 和 SCCS 工具集合. What is This Unit is About. This unit introduces the basic features of the UNIX make and SCCS (Source Code Control system) facility.

latoya
Download Presentation

第四单元 make 和 SCCS 工具集合

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和SCCS工具集合 中山大学-AIX应用程序开发

  2. What is This Unit is About This unit introduces the basic features of the UNIX make and SCCS (Source Code Control system) facility. Since make is found on most UNIX systems, as well as DOS and OS/2 systems, there is a chance that you might already be familiar with the general concepts of make. This unit describes how make works in AIX. Targets, dependencies, and action lines are discussed. The construction of the makefile is explained, and make macros are introduced. The second part of this unit discusses about SCCS. At the conclusion of this unit and lab, you should be able to create makefiles of intermediate complexity to handle typical application scenarios. You should also be able to use SCCS to maintain your source files.

  3. What You Should Be Able to Do After completing this unit, you should be able to: Create a makefile that properly lists the targets and dependencies for a typical C application. Use the make command to bring an executable file up to date. Create and execute pseudo-targets in a makefile. Code and use macros from within a makefile and from the command line. Use SCCS to maintain source code.

  4. How You Will Check Your Progress You can check your progress by completing Lab exercise 3

  5. References AIX 5L online documentation

  6. Unit Objectives After completing this unit, you should be able to: Create a makefile that properly lists the targets and dependencies for a typical C application. Use the make command to bring an executable file up to date. Create and execute pseudo targets in a makefile. Code and use macros from within a makefile and from the command line. Use SCCS to maintain source code.

  7. 4.1 The make facility Unit 4. The make and SCCS Facility

  8. An application example

  9. Targets and dependencies One can determine an order of dependency based on the diagram from the previous figure,Examples: If a change is made to the hcrep.c source file, what other source code files need to be recompiled? What object files need to be relinked? If the hclab.h file changed, what source files need to be recompiled? What object files need to be relinked? The make utility useds a list of targets and dependencies to automate the process of bringing executables up to date. The make utility compares”last modification” dates of sources, include, object, and executable files for an entire project.

  10. The makefile The make utility uses a file, usually named makefile or Makefile, to describe targets and dependencies. Makefile lines are either: Dependency lines –Lists target and its dependencies. Action lines – Must begin with <Tab>; actual command used to compile or link dependencies. chip: hcdbmaint.o hcrep.o hconline.o cc -o chip hcdbccmaint.o hcrep.o hconline.o hcdbmaint.o: hcdbmaint.c hcrec.h cc -c -O hcdbmaint.c hcrep.o: hcrep.c hcrec.h hclab.h cc -c -O hcrep.c hconline.o: hconline.c hcrec.h cc -c -O hconline.c When make runs, the action line is executed for every dependency line where the last modification date of any dependency if later than the target file.

  11. makefile Action Lines Action lines: Must immediately follow the dependency line they apply to Must begin with a <Tab> Can specify any command to execute chip: hcdbmaint.o hcrep.o hconline.o @ echo "Creating the chip executable" @cc -o chip hcdmaint.o hcrep.o hconline.o ... Normally, each exectued action line is echoed to the screen as it runs. The @ symbol can be placed at the beginning of an action line to have the line run “silently”.

  12. Makefile Action Lines(2 of 2) chip: hcdbmaint.o hcrep.o hconline.o @ echo "Creating the chip executable" # Saving the old chip program @-mv chip chip.old @cc -o chip hcdbmaint.o hcrep.o hconline.o ... The # symbol indicates a comment: When it is at the start of a line, it makes the entire line a comment. When it is within a line, it makes all text to the right of it a comment. Normally, makefile action lines report an error if they fail and the make operation stops. The – symbol at the start of the action line ignores the error and does not print a message. Long action lines may use the \ symbol for line continuation.

  13. 4.2 Using make Unit 4. The make and SCCS Facility

  14. Using the make command The make command looks for the file makefile in the current directory. If makefile is not found, it looks for Makefile in the current directory. You may specify a different makefile by issuing the make command with the –f option: $ make –f myfile You can tell make to run silently (same as preceding action lines with @) by using the –s option: $ make –s –f mymake You can tell make to ignore errors in action lines (same as preceding action lines with -) by using the –i option: $ make –i -s –f mymake

  15. Using the make command(2 of 2) If no dependency files have been modified since the last modification of the target file, the following messages is reported: ‘target file’ is up to date’

  16. Make with command Line targets A single makefile could be used to manage many projects. To keep control over which target files are checked, the desired target file name (first parameter of the dependency line) can be issued as an argument to the make command: $ make –f mymake myprog

  17. Pseudo Targets Make files can contain pseudo targets: Name on left side of colon on depencency line Not associated with an actual file Have non depencency list Are always assumed to be “out of date” by make Have associated actions cleanup: @-rm hcdbmaint.o hcrep.o hconline.o @echo "Object files removed" print_all: #print all source files @-pr *.c | lp @-pr *.h | lp

  18. makefile Macros(1 of 2) Macros (variables) can be defined within a makefile: Simplifies lists of file names or long expressions Convenient for handling compilation options Improves readability of makefile Definition syntax: var_name=string_value Referencing the variable within the makefile: $(var_name)

  19. Makefile Macros (2 of 2) Example: OBJS=hcdbmaint.o hcrep.o hconline.o CFLAGS=-O chip: $(OBJS) @echo "Creating the chip executable" # Saving the old chip program @-mv chip chip.old @cc -o chip $(CFLAGS) $(OBJS) …

  20. Command Line Macros Values can be assigned to variables from the command line when make is executed. This assignment supersedes any assignment made to that variable from within the makefile. Example: $ make –f mymake chip CFLAGS=-g Craeting the chip executable. $__ • This example creates the chip executable if needed, but with the –g option of the cc command instead of –O.

  21. Internal Macros $@ Name of the current target file $$@ Label name on the dependency line $? Names of files more recent that target $* Name of the current parent file without suffix $< File name of the out-of-date file that caused a target to be created

  22. 4.2 Make rules Unit 4. The make and SCCS Facility

  23. Inference rules Default rules for make Based on file suffixes Default rules file:/usr/ccs/lib/aix.mk Format: rule: <Tab> command where rule is a single suffix(.c) or a double suffix(.c.o) File may be overridden on command line by MAKERULES variable. Rules may be added to makefile

  24. Exmaple Rules File .SUFFIXES: .o .c .c~ ... #PRESET VARIABLES MAKE=make LD=ld LDFLAGS= CC=cc CFLAGS=-O FC=xlf FFLAGS=-O AS=as ASFLAGS= GET=get GFLAGS= #SINGLE SUFFIX RULES .c: $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ .c~: $(GET) $(GFLAGS) -p $< > $*.c $(CC) $(CFLAGS) $(LDFLAGS) $*.c -o $* -rm -f $*.c ... #DOUBLE SUFFIX RULES .c.o: $(CC) $(CFLAGS) -c $< .c~.o: $(GET) $(GFLAGS) -p $< > $*.c $(CC) $(CFLAGS) -c $*.c -rm -f $*.c .c~.c: $(GET) $(GFLAGS) -p $< > $*.c ...

  25. 4.4 Source Code Control System (SCCS) Unit 4. The make and SCCS Facility

  26. What is SCCS? • A collection of commands used to control and track changes to text files. • Facilities provided include: • Storing and retrieving various versions of text files • Recording the history of changes • Identifying the version of each source file from which a program was created • Controlling who has privileges to update files

  27. SCCS Terminology

  28. Creating a SCCS file • Use the admin command to put a file under the control of SCCS • Syntax admin –iorig_filename s.filename -orig_filename follows –i(no spaces) -s.filename is the sccs file to store the file orig_filename. • The original file should be renamed or removed so that is does nt interfere with the operation of SCCS.

  29. get Command The get command • Retrieves a copy of a source file from SCCS • The retrieved copy is read-only by default • To retrieve a copy for editing and to lock others from retrieving a writable copy, use the –e option.

  30. delta command The delta command • Records changes made to the source file that was retrieved by get –e • Can add a comment about the change made. • Removes the p. file and makes the source file available for someone else for editing.

  31. unget command The unget command: • Prevents the creation of a delta after retrieving a writable copy of the source file using the get command. • Removes the writable copy of source file and the p. file without affecting the version control.

  32. ID keywords • Used to automatically embed information about the source file into the s. file • Place the ID keywords in a comment or declaration line, so that it does not interfere with the source code itself. • The keywords are expanded when a get operation on the file is performed. • Some common keywords: • %M% The module name( name of file) • %I% the SID • %z% the string @(#) as used by the what command • %W% Embed %Z%%M<Tab>%I% together • The what command: • -Searches specified files for the @(#) string. • -Prints text following the @(#) string until a double quote is reached.

  33. Other Helpful SCCS Commands • The prs command prints information about s.files managed by SCCS. • The rmdel command removes a delta. • The sact command reports outstanding get –e operations. • The get command uses the –x option to excluding deltas. Multiple deltas can be excluded.

  34. Unit Summary • An application example • Targets and dependencies • The makefile • The make command • Pseudo targets • make Macros • Using SCCS

  35. Thank You !

More Related