1 / 50

Make Utilities

Make Utilities. Introduction. make is a UNIX utility for building projects that are comprised of multiple source files make takes care of dependencies, and will rebuild the project if one or more file is modified

tea
Download Presentation

Make Utilities

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 Utilities

  2. Introduction • make is a UNIX utility for building projects that are comprised of multiple source files • make takes care of dependencies, and will rebuild the project if one or more file is modified • a file, usually named makefile, contains details of the dependencies, and therefore tells make how to build the project • Before we go to details and sample make file it will be beneficial to know about how .exe files are created by compilers

  3. Source File Revise Code Failed Compile List errors Correct Errors Success New Obj other obj Load File Linker Links the objects Loader places load file to mem .exe file in memory How .exe file is created?

  4. Dependency Notation • Target depends on source. If source has changed, execute the command target: source [source2] command [command] • There are no source files specified, execute command unconditionally target: command [command]

  5. Dependencies Example • For example, a makefile to build the executable file one from the C/C++ source files one.cpp, two.cpp and three.cpp one one.o one.c // Dependencies one.h two two.o two.c two.h three three.o three.c three.h

  6. example Makefile one: one.o two.o three.o g++ -o one one.o two.o three.o one.o: one.cpp one.h g++ -c one.cpp two.o: two.c two.h g++ -c two.cpp three.o: three.cpp three.h g++ -c three.cpp

  7. What makefiles contain • Makefiles may contain the following five parts • Explicit Rules • Implicit Rules • Variable Definitions • Directives • Comments

  8. What makefiles contain • Explicit Rules say when and how to remake one or more files, or the targets. It lists the other files that targets depend on, and may also give commands to use to create or update the targets. • Implicit Rules say when and how to remake a class of files based on their names. It describes how a target may depend on a file with a name similar to the target and gives commands to create or update such target

  9. What makefiles contain • Variable Definitions are lines that specify a text string value for a variable that can be substituted in the text later. • Directives are commands for make to do something special while reading the makefile. These include • Reading another makefile • Deciding whether to use or ignore a part of the makefile • Defining variable from a verbatim string containing multiple lines • Comments start with # in a line of a makefile. The rest of the line after this # are ignored.

  10. Default make Rules • make has default rules - e.g. the default rule for making a .o file from a .c file is $(CC) $(CFLAGS) -c file.c • the macros $(CFLAGS) and $(CC) are predefined by make

  11. Note • The name for the make file should be makefile or Makefile • Put comments. Comment sign is # For example: # This is makefile project3 • In the command line , you must put a TAB at the beginning of the line. Otherwise you’ll get an error message. Note also that if you copy a makefile, copying usually destroys the tab and replaces it with spaces. You must replace the spaces with a tab on all action lines.

  12. Notes • Clean the object (.o) files For example: clean: rm -f *.o If this is at the end of the makefile, use the command make clean to cause it to execute

  13. gdb Debugger

  14. Introduction • Debugger is allow to see what is happening in your program • When your program doesn’t behave the way you accepted, then debugger is used to find out these reasons. • Unix uses gdb debugger utility

  15. Topics • The following topics will be covered • When do you use gdb • Use of gdb • Running gdb • Setting gdb • Examine the data • Examine the stack

  16. GDB • Use GDB when your program doesn’t behave the way you expected - catching the bugs • Use GDB when your make files stops on specified condition • When you want to examine your program logic to see howit works

  17. Running/Resuming Commands

  18. gdb Command gdb : starts gdb utility Syntax: gdb Shorthand: Example: gdb

  19. Run Command run : starts your program under gdb Syntax: run program name Shorthand: Example: runproject1.exe

  20. Step Command step : continues to run until the specific source line number Syntax: step [COUNT] Shorthand: s Example: step s

  21. Next Command next : executes the next source line in the current (innermost) stack frame Syntax: next [COUNT] Shorthand: n Example: next n

  22. Continue Command continue: resumes program execution at the address where your program last stopped Syntax: continue [IGNORE-COUNT] Shorthand: c Example: continue c

  23. Finish Command finish : continues running until just after function in the selected stack frame returns Syntax: finish Shorthand: Example: finish

  24. Stopping/Setting Commands

  25. Break Command break: makes your program stop whenever a certain point in the program is reached Syntax: breakFUNCTION breakLINENUM breakFUNCTION : LINENUM breakFILENAME : FUNCTION break …IF CONDITION

  26. Break Shorthand: b Example: break main b main

  27. Watch Command watch: Use it to stop execution whenever the value of an expression changes Syntax: watch EXPR

  28. Info Command info: Prints a table of all breakpoints and watchpoints with the following columns for each breakpoint Syntax: infobreak [N] infowatchpoints [N]

  29. Clear Command clear: deletes any breakpoints at the next instruction to be executed in the selected stack frame Syntax: clear FUNCTION clear FILENAME:FUNCTION clear LINENUM clear FILENAME:LINENUM

  30. Delete Command delete: deletes the breakpoints or watchpoints of the numbers specified as arguments. If no number specified, deletes all breakpoints Syntax: delete[breakpoints][BNUMS] Shorthand: d

  31. Examining Data Commands

  32. Print Command print: prints the value of expression in the source program Syntax: print[EXP] // EXP is an expression Shorthand: // in source code p

  33. Display Command display: adds the expression to the list of expressions to display each time your program stops Syntax: display[EXP] Shorthand: disp

  34. List Command list: prints lines from a source file Syntax: listLINENUM listFUNCTION list // prints more lines list- // prints lines just before // the lines last printed Shorthand: l

  35. Examining Stack Commands

  36. Backtrace Command backtrace: prints a backtrace of the entire stack Syntax: backtrace Shorthand: bt

  37. Example

  38. GDB EXAMPLE • Suppose we have proj1.cpp, proj1.h and proj1main.cpp files • First we have to compile our program with –g flag • Now we can start debugger on the proj1main.cpp • gdbproj1main ( This will start the debugger) • gdbrun ( This will start the program) • (gdb)end proj1main ( Program exited normally) • (gdb)break main • (gdb)run • (gdb)s • (gdb)quit

  39. Submission Process

  40. Submission Steps • Create a make file • Construct a tar file • Compress the tar file • Submit the zip file by using the submit command • In the next slides, let’s see each of them in details

  41. Makefile • Creating a make file is explained in the previous slides. Follow those instructions to create one. The following is a sample make file • Construct a tar file • Compress the tar file • Submit the zip file by using the submit command • In the next slides, let’s see each of them in details

  42. Construct tar file • tar file is constructed by using the tar cf command • The syntax is as follows tar cfyouruserid.tardirectory • tar file name must be your userid • the directory is the place where your program files resides

  43. Construct tar file For example: Let say we have a directory called proj1 where all of the program files resides and userid name is yabadaba then at the system prompt osf1.gmu.edu> tar cfyabadaba.tarproj1 will create the tar file • Double check to see if all files are present in the tar file type the following at the system prompt osf1.gmu.edu> tar tvfyabadaba.tar

  44. Compress tar file • The tar file is compressed by using the gzip command • The syntax is as follows gzipyouruserid.tar • this command deletes the youruserid.tar file and replaces it with youruserid.tar.gz For example: gzip yabadaba.tar

  45. Submit tar file • Submit the zip file by using the submit command • There are two sections: Section 03 and Section 04. • Each section has its own bin. If you are Section 03 then at the system prompt type cd /home/u1/cs31003/classbin to change the appropriate classbin directroy • If you are Section 03 then at the system prompt type cd /home/u1/cs31004/classbin

  46. Submit tar file • Now we are ready to submit it. Each project has a submission numbers which are very important to use the right one. These numbers are giving to you by your instructor. Let say submission number is 1 submit1~/youruserid.tar.gz Note: ~/ is home directory. You should put the path where your .gz file resides.

  47. Submission Example • This is the scenario: • Your program files resides in proj1 directory • Your user name is yaba • Your section number is 03 • Project submission number was giving to you as 3 • The following is the submission steps • tar cfyaba.tarproj1 • tar tvfyaba.tar • gzipyaba.tar • cd /home/u1/cs31003/classbin • submit3 ~/yaba.tar.gz • After successful submission, you’ll be notified. Otherwise you’ll get an error message.

  48. Mail Utility

  49. pine Mail Utility • It is a simple mail utility program. You can send and receive e-mails with this utility. Generally the e-mail addresses are constructed by using the firstname and last name combinations. For example: If your account user id mrcpp, then this user’s e-mail will be mrcpp@osf1.gmu.edu To run this program: Just type pine

  50. elm Mail Utility • It is another simple mail utility program. You can send and receive e-mails with this utility. To run this program: Just type elm

More Related