510 likes | 664 Views
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
E N D
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
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?
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]
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
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
What makefiles contain • Makefiles may contain the following five parts • Explicit Rules • Implicit Rules • Variable Definitions • Directives • Comments
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
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.
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
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.
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
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
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
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
gdb Command gdb : starts gdb utility Syntax: gdb Shorthand: Example: gdb
Run Command run : starts your program under gdb Syntax: run program name Shorthand: Example: runproject1.exe
Step Command step : continues to run until the specific source line number Syntax: step [COUNT] Shorthand: s Example: step s
Next Command next : executes the next source line in the current (innermost) stack frame Syntax: next [COUNT] Shorthand: n Example: next n
Continue Command continue: resumes program execution at the address where your program last stopped Syntax: continue [IGNORE-COUNT] Shorthand: c Example: continue c
Finish Command finish : continues running until just after function in the selected stack frame returns Syntax: finish Shorthand: Example: finish
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
Break Shorthand: b Example: break main b main
Watch Command watch: Use it to stop execution whenever the value of an expression changes Syntax: watch EXPR
Info Command info: Prints a table of all breakpoints and watchpoints with the following columns for each breakpoint Syntax: infobreak [N] infowatchpoints [N]
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
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
Print Command print: prints the value of expression in the source program Syntax: print[EXP] // EXP is an expression Shorthand: // in source code p
Display Command display: adds the expression to the list of expressions to display each time your program stops Syntax: display[EXP] Shorthand: disp
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
Backtrace Command backtrace: prints a backtrace of the entire stack Syntax: backtrace Shorthand: bt
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
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
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
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
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
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
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
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.
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.
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
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