introduction make is a unix utility for building projects that are comprised of multiple source...

51

Upload: marcia-boone

Post on 30-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that
Page 2: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

IntroductionIntroduction

• make is a UNIX utility for building projects that are comprised of make is a UNIX utility for building projects that are comprised of multiple source files multiple source files

• make takes care of dependencies, and will rebuild the project if one make takes care of dependencies, and will rebuild the project if one or more file is modified or more file is modified

• a file, usually named makefile, contains details of the dependencies, a file, usually named makefile, contains details of the dependencies, and therefore tells make how to build the projectand therefore tells make how to build the project

• Before we go to details and sample make file it will be beneficial to Before we go to details and sample make file it will be beneficial to know about how .exe files are created by compilersknow about how .exe files are created by compilers

Page 3: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

How .exe file is created?How .exe file is created?

Source File

CompileList

errors

NewObj

Correct Errors

Revise Code

otherobj

Linker Linksthe objects

LoadFile

Loader places load file to mem

.exe file in memory

Failed

Success

Page 4: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

target: source [source2] target: source [source2] command command

[command][command]

Dependency NotationDependency Notation

• Target depends on source. If source has changed, execute the Target depends on source. If source has changed, execute the command command

target: target: command command [command][command]

• There are no source files specified, execute command There are no source files specified, execute command

unconditionallyunconditionally

Page 5: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

Dependencies ExampleDependencies Example

• For example, a makefile to build the executable For example, a makefile to build the executable file one from the C/C++ source files one.cpp, file one from the C/C++ source files one.cpp, two.cpp and three.cpp two.cpp and three.cpp

one one one.o one.c one.o one.c // Dependencies// Dependenciesone.h one.h

twotwo two.o two.c two.o two.c two.h two.h

threethree three.o three.c three.o three.c three.h three.h

Page 6: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

example Makefileexample Makefile

one: one.o two.o three.o one: one.o two.o three.o g++g++ -o one one.o two.o three.o -o one one.o two.o three.o

one.o: one.cpp one.h one.o: one.cpp one.h

g++g++ -c one.cpp -c one.cpp

two.o: two.c two.h two.o: two.c two.h

g++g++ -c two.cpp -c two.cpp

three.o: three.cpp three.h three.o: three.cpp three.h

g++g++ -c three.cpp -c three.cpp

Page 7: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

• Makefiles may contain the following five partsMakefiles may contain the following five parts– Explicit RulesExplicit Rules

– Implicit RulesImplicit Rules

– Variable DefinitionsVariable Definitions

– DirectivesDirectives

– Comments Comments

What makefiles containWhat makefiles contain

Page 8: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

• Explicit RulesExplicit Rules say when and how to remake one or more say when and how to remake one or more files, or the targets. It lists the other files that targets files, or the targets. It lists the other files that targets depend on, and may also give commands to use to create depend on, and may also give commands to use to create or update the targets.or update the targets.

• Implicit RulesImplicit Rules say when and how to remake a class of say when and how to remake a class of files based on their names. It describes how a target may files based on their names. It describes how a target may depend on a file with a name similar to the target and depend on a file with a name similar to the target and gives commands to create or update such targetgives commands to create or update such target

What makefiles containWhat makefiles contain

Page 9: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

• Variable DefinitionsVariable Definitions are lines that specify a text string are lines that specify a text string value for a variable that can be substituted in the text later. value for a variable that can be substituted in the text later.

• DirectivesDirectives are commands for make to do something special are commands for make to do something special while reading the makefile. These includewhile reading the makefile. These include– Reading another makefileReading another makefile

– Deciding whether to use or ignore a part of the makefileDeciding whether to use or ignore a part of the makefile

– Defining variable from a verbatim string containing multiple linesDefining variable from a verbatim string containing multiple lines

• CommentsComments start with # in a line of a makefile. The rest of start with # in a line of a makefile. The rest of the line after this # are ignored. the line after this # are ignored.

What makefiles containWhat makefiles contain

Page 10: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

• make has default rules - e.g. the default rule for making make has default rules - e.g. the default rule for making a .o file from a .c file is a .o file from a .c file is

$(CC) $(CFLAGS) -c file.c$(CC) $(CFLAGS) -c file.c

• the macros $(CFLAGS) and $(CC) are predefined by the macros $(CFLAGS) and $(CC) are predefined by makemake

Default make RulesDefault make Rules

Page 11: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

• The name for the make file should be makefile The name for the make file should be makefile or Makefileor Makefile

• Put comments. Comment sign is #Put comments. Comment sign is #

For example:For example:

# This is makefile project3# This is makefile project3• In the command line , you must put a TAB at the beginning In the command line , you must put a TAB at the beginning

of the line. Otherwise you’ll get an error message. Note also of the line. Otherwise you’ll get an error message. Note also that if you copy a makefile, copying usually destroys the tab that if you copy a makefile, copying usually destroys the tab and replaces it with spaces. You must replace the spaces and replaces it with spaces. You must replace the spaces with a tab on all action lines.with a tab on all action lines.

NoteNote

Page 12: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

• Clean the object (.o) filesClean the object (.o) files

For example:For example:

clean:clean:

rm -f *.orm -f *.o

If this is at the end of the makefile, use the command If this is at the end of the makefile, use the command make clean to cause it to execute make clean to cause it to execute

NotesNotes

Page 13: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

• Visual C++ 6.0Visual C++ 6.0– You cannot declare input and output functions as friends. To fix You cannot declare input and output functions as friends. To fix

this don’t use friends or import the std namespace in its entiritythis don’t use friends or import the std namespace in its entirity– Method 1: operator<< …… rather than friendMethod 1: operator<< …… rather than friend– Method 2: include in your source file Method 2: include in your source file

• using std::ostreamusing std::ostream

– Method 3: std::ostream& operator<<(std::ostream & out, const Method 3: std::ostream& operator<<(std::ostream & out, const obj& out)obj& out)

– This is not a bug, however you cannot use <iostream.h> and This is not a bug, however you cannot use <iostream.h> and <iostream> at the same time.<iostream> at the same time.

– Incorrectly handles the scoping of variables declared in the for Incorrectly handles the scoping of variables declared in the for loop initialization expression.loop initialization expression.

Visual C++ Compiler BugsVisual C++ Compiler Bugs

Page 14: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that
Page 15: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

IntroductionIntroduction

• Debugger is allow to see what is happening in your Debugger is allow to see what is happening in your programprogram

• When your program doesn’t behave the way you When your program doesn’t behave the way you accepted, then debugger is used to find out these accepted, then debugger is used to find out these reasons.reasons.

• Unix uses gdb debugger utilityUnix uses gdb debugger utility

Page 16: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

TopicsTopics

• The following topics will be coveredThe following topics will be covered– When do you use gdbWhen do you use gdb– Use of gdbUse of gdb

• Running gdbRunning gdb• Setting gdbSetting gdb• Examine the dataExamine the data• Examine the stackExamine the stack

Page 17: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

GDBGDB

• Use GDB when your program doesn’t behave the Use GDB when your program doesn’t behave the way you expected - catching the bugsway you expected - catching the bugs

• Use GDB when your make files stops on specified Use GDB when your make files stops on specified conditioncondition

• When you want to examine your program logic to When you want to examine your program logic to

see howsee how it worksit works

Page 18: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that
Page 19: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

gdbgdb

Command gdbgdb : starts gdb utility

Syntax:gdbgdb

Shorthand:Shorthand:

Example:gdbgdb

Page 20: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

RunRun

Command runrun : starts your program under gdb

Syntax:runrun program name

Shorthand:Shorthand:

Example:runrun project1.exeproject1.exe

Page 21: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

StepStep

Command stepstep : continues to run until the specific

source line numberSyntax:

stepstep [COUNT]Shorthand:Shorthand:

ssExample:

stepstep

ss

Page 22: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

NextNext

Command Command nextnext : executes the next source line in : executes the next source line in

the current (innermost) stack frame the current (innermost) stack frameSyntax:Syntax:

nextnext [COUNT] [COUNT]Shorthand:Shorthand:

nnExample:Example:

nextnext

nn

Page 23: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

ContinueContinue

Command Command continuecontinue: resumes program execution at the : resumes program execution at the

address where your program last address where your program last stopped stopped

Syntax:Syntax:continuecontinue [IGNORE-COUNT] [IGNORE-COUNT]

Shorthand:Shorthand: cc

Example:Example: continue continue

cc

Page 24: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

FinishFinish

Command finishfinish : continues running until just after

function in the selected stack frame returns

Syntax:finishfinish

Shorthand:Shorthand:

Example:finishfinish

Page 25: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that
Page 26: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

BreakBreak

Command Command breakbreak: makes your program stop whenever : makes your program stop whenever a certain point in the program is a certain point in the program is

reached reached Syntax:Syntax:

breakbreak FUNCTIONFUNCTIONbreakbreak LINENUMLINENUMbreakbreak FUNCTION : LINENUMFUNCTION : LINENUMbreakbreak FILENAME : FUNCTIONFILENAME : FUNCTION

breakbreak … …IF CONDITIONIF CONDITION

Page 27: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

BreakBreak

Shorthand:Shorthand: bb

Example:Example: break break mainmain

b b mainmain

Page 28: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

WatchWatch

Command Command watchwatch: Use it to stop execution whenever the : Use it to stop execution whenever the

value of an expression changes value of an expression changesSyntax:Syntax:

watch watch EXPREXPR

Page 29: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

InfoInfo

Command Command infoinfo: Prints a table of all breakpoints and : Prints a table of all breakpoints and watchpoints with the following columns watchpoints with the following columns for each breakpoint for each breakpoint

Syntax:Syntax:infoinfo break [N]break [N]infoinfo watchpoints [N]watchpoints [N]

Page 30: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

ClearClear

Command Command clearclear: deletes any breakpoints at the next : deletes any breakpoints at the next

instruction to be executed in the instruction to be executed in the selected stack frameselected stack frame

Syntax:Syntax:clear clear FUNCTIONFUNCTION

clear clear FILENAMEFILENAME::FUNCTIONFUNCTIONclear clear LINENUMLINENUMclear clear FILENAMEFILENAME::LINENUMLINENUM

Page 31: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

DeleteDelete

Command Command deletedelete: deletes the breakpoints or watchpoints : deletes the breakpoints or watchpoints

of the numbers specified as arguments. of the numbers specified as arguments. If no number specified, deletes all If no number specified, deletes all breakpointsbreakpoints

Syntax:Syntax:deletedelete [breakpoints][breakpoints] [BNUMS][BNUMS]

Shorthand:Shorthand: dd

Page 32: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that
Page 33: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

PrintPrint

Command Command printprint: prints the value of expression in the : prints the value of expression in the source program source program

Syntax:Syntax:printprint [EXP][EXP] // EXP is an expression// EXP is an expression

Shorthand:Shorthand: // in source code// in source code pp

Page 34: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

DisplayDisplay

Command Command displaydisplay: adds the expression to the list of : adds the expression to the list of

expressions to display each time your expressions to display each time your program stops program stops

Syntax:Syntax:displaydisplay [EXP][EXP]

Shorthand:Shorthand: dispdisp

Page 35: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

ListList

Command Command listlist: prints lines from a source file: prints lines from a source file

Syntax:Syntax:listlist LINENUMLINENUM listlist FUNCTIONFUNCTION listlist // // prints more linesprints more lines listlist -- // prints lines just before // prints lines just before

// the lines last printed// the lines last printedShorthand:Shorthand:

ll

Page 36: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that
Page 37: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

BacktraceBacktrace

Command Command backtracebacktrace: prints a backtrace of the entire : prints a backtrace of the entire

stack stack Syntax:Syntax:

backtracebacktraceShorthand:Shorthand:

btbt

Page 38: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that
Page 39: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

GDB EXAMPLEGDB EXAMPLE

Suppose we have Suppose we have proj1.cppproj1.cpp, , proj1.hproj1.h and and proj1main.cppproj1main.cpp files filesFirst we have to compile our program with –g flagFirst we have to compile our program with –g flag•Now we can start debugger on the proj1main.cppNow we can start debugger on the proj1main.cpp•gdbgdb proj1mainproj1main ( This will start the debugger) ( This will start the debugger)•gdbgdb runrun ( This will start the program) ( This will start the program)•(gdb)(gdb) end proj1mainend proj1main ( Program exited normally) ( Program exited normally)•(gdb)(gdb) break mainbreak main•(gdb)(gdb) runrun•(gdb)(gdb) ss•(gdb)(gdb) quitquit

Page 40: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that
Page 41: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

Submission StepsSubmission Steps

• Create a Create a make filemake file• Construct a Construct a tartar file file• CompressCompress the tar file the tar file• SubmitSubmit the zip file by using the submit command the zip file by using the submit command• In the next slides, let’s see each of them in detailsIn the next slides, let’s see each of them in details

Page 42: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

MakefileMakefile

• Creating a Creating a make file make file is explained in the previous is explained in the previous slides. Follow those instructions to create one. The slides. Follow those instructions to create one. The following is a sample make filefollowing is a sample make file

• Construct a Construct a tartar file file• CompressCompress the tar file the tar file• SubmitSubmit the zip file by using the submit command the zip file by using the submit command• In the next slides, let’s see each of them in detailsIn the next slides, let’s see each of them in details

Page 43: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

Construct tar fileConstruct tar file

• tar file is constructed by using the tar file is constructed by using the tar cftar cf command command• The syntax is as followsThe syntax is as follows

tar cftar cf youruserid.taryouruserid.tar directorydirectory• tar file nametar file name must be your userid must be your userid• the the directorydirectory is the place where your program files is the place where your program files

residesresides

Page 44: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

Construct tar fileConstruct tar file

For example:For example: Let say we have a directory called Let say we have a directory called proj1proj1 where all where all of the program files resides and userid name is of the program files resides and userid name is yabadaba yabadaba then at the system promptthen at the system promptosf1.gmu.edu> osf1.gmu.edu> tar cftar cf yabadaba.taryabadaba.tar proj1proj1will create the tar filewill create the tar file

• Double check to see if all files are present in the tar Double check to see if all files are present in the tar file type the following at the system promptfile type the following at the system promptosf1.gmu.edu> osf1.gmu.edu> tar tvftar tvf yabadaba.taryabadaba.tar

Page 45: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

Compress tar fileCompress tar file

• The tar file is compressed by using the The tar file is compressed by using the gzipgzip commandcommand

• The syntax is as followsThe syntax is as follows

gzipgzip youruserid.taryouruserid.tar • this command deletes the this command deletes the youruserid.taryouruserid.tar file and file and

replaces it with youruserid.tar.gzreplaces it with youruserid.tar.gz

For example:For example:

gzip gzip yabadaba.taryabadaba.tar

Page 46: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

Submit tar fileSubmit tar file

• SubmitSubmit the zip file by using the the zip file by using the submitsubmit command command• There are two sections: Section 03 and Section 04.There are two sections: Section 03 and Section 04.• Each section has its own bin. If you are Section 03 Each section has its own bin. If you are Section 03

then at the system prompt typethen at the system prompt typecd /home/u1/cs31003/classbin cd /home/u1/cs31003/classbin

to change the appropriate classbin directroyto change the appropriate classbin directroy• If you are Section 03 then at the system prompt If you are Section 03 then at the system prompt

typetypecd /home/u1/cs31004/classbincd /home/u1/cs31004/classbin

Page 47: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

Submit tar fileSubmit tar file

• Now we are ready to submit it. Each project has a Now we are ready to submit it. Each project has a submission numbers which are very important to submission numbers which are very important to use the right one. These numbers are giving to you use the right one. These numbers are giving to you by your instructor. Let say submission number is 1by your instructor. Let say submission number is 1

submitsubmit 11 ~/youruserid.tar.gz~/youruserid.tar.gz

Note: Note: ~/ is home directory. You should put the ~/ is home directory. You should put the path where your .gz file resides.path where your .gz file resides.

Page 48: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

Submission ExampleSubmission Example

• This is the scenario: This is the scenario: – Your program files resides in Your program files resides in proj1proj1 directory directory– Your user name is Your user name is yabayaba– Your section number is Your section number is 0303– Project submission number was giving to you as Project submission number was giving to you as 33

• The following is the submission stepsThe following is the submission steps– tar cftar cf yaba.taryaba.tar proj1proj1– tar tvftar tvf yaba.taryaba.tar– gzipgzip yaba.taryaba.tar– cdcd /home/u1/cs310 /home/u1/cs3100303/classbin/classbin– submitsubmit 3 3 ~/yaba.tar.gz~/yaba.tar.gz

• After successful submission, you’ll be notified. Otherwise you’ll After successful submission, you’ll be notified. Otherwise you’ll get an error messageget an error message..

Page 49: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that
Page 50: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

pine Mail Utilitypine Mail Utility

• It is a simple mail utility program. You can send It is a simple mail utility program. You can send and receive e-mails with this utility. Generally the and receive e-mails with this utility. Generally the e-mail addresses are constructed by using the e-mail addresses are constructed by using the firstname and last name combinations. firstname and last name combinations. For example:For example:

If your account user id If your account user id mrcppmrcpp, then this user’s e-, then this user’s e-mail will be mail will be [email protected]@osf1.gmu.eduTo run this program: To run this program: Just type Just type pinepine

Page 51: Introduction make is a UNIX utility for building projects that are comprised of multiple source filesmake is a UNIX utility for building projects that

elm Mail Utilityelm Mail Utility

• It is another simple mail utility program. You can It is another simple mail utility program. You can send and receive e-mails with this utility. send and receive e-mails with this utility.

To run this program: To run this program:

Just type Just type elmelm