Presentation is loading. Please wait.

Presentation is loading. Please wait.

Make Make is a system utility that automatically compiles your programs for you Make looks for a file named Makefile (or makefile) in the current directory.

Similar presentations


Presentation on theme: "Make Make is a system utility that automatically compiles your programs for you Make looks for a file named Makefile (or makefile) in the current directory."— Presentation transcript:

1 Make Make is a system utility that automatically compiles your programs for you Make looks for a file named Makefile (or makefile) in the current directory –Describes the relationships among files that comprise you program –Gives the commands for updating each file Using the Makefile, make automatically: –Determines which files need to be recompiled –Issues the commands to recompile them

2 A Simple Program // hello.cpp #include #include “hello.h” using namespace std; int main() { cout << MESSAGE << endl; }

3 The Header File // hello.h #define MESSAGE "Hello World!"

4 Compiling and Running the Program Compiling: –g++ -O2 -o hello hello.cpp Running –./hello Result: –Hello World!

5 Makefile Composed of: –Comments (from a pound sign to the end of a line) # This is a comment –Macros – just like in your program CFLAGS= -O2 –Targets – lists dependencies and rules for updating hello: hello

6 The Makefile # Makefile for hello.cpp CFLAGS = -O2 hello: hello.h hello.cpp g++ $(CFLAGS) -o hello hello.cpp

7 Compiling and Running the Program with Make Compiling: –make Running –./hello Result: –Hello World! Note: make is really unnecessary for such a simple program, but is essential for programs with lots of source files

8 Make - Pitfalls Make is very picky about some things: –Indenting must be done with tabs not spaces –Dependencies must be correct If nothing has changed make will tell you the target is “up to date”

9 A More Complicated Example 5 source files Some shared header files Multiple targets –Make creates the first target by default E.g. make –You can specify others: E,g, make clean

10 Let’s Write a Makefile 3 header files –src1.h – used by src1.cpp –src2.h – used by src2.cpp –global.h – used by src1.cpp, src2.cpp, and main.cpp 4 source files –src1.cpp – routines used by main.cpp –src2.cpp – routines used by main.cpp –src3.cpp – routines used by src2.cpp –main.cpp – main program

11 Questions What will make do if we touch: –global.h? –src1.h? –src2.h? –src3.cpp? –main.cpp?


Download ppt "Make Make is a system utility that automatically compiles your programs for you Make looks for a file named Makefile (or makefile) in the current directory."

Similar presentations


Ads by Google