Make is a tool that controls the generation of executables and libraries from source codes.
Make utility help you to automatically build and manage your project and make the tedious compiling source files easy, especially when you have several source files to manage.
In this lab, you will be creating Makefile that creates a binary "test" from the following source files: foo.cc, foo.h, and main.cc.
Structure of Makefile
You need a file called a Makefile to tell make what to do.
A makefile consists of a set of rules. The syntax is as follows:
target ...: prereq1 prereq2 ...
[TAB] commands
[TAB] ...
[TAB] ...
where target is the file that will be made and the prerequisites or dependants are names of files that are necessary to create the target.
commands are the system commands that will create the target from the prerequisites.
Here is the example makefile for helloworld in the previous lab.
all: test
test: helloworld.cc
g++ -o test helloworld.cc
Phony Targets
The targets that do not directly represent files are called as phony targets. all: and clean: are one of those.
Adding phony targets on the above examples, we can make it as follows:
all: test
test: helloworld.cc
g++ -o test helloworld.cc
clean:
rm -f test *.o
Now, download the files and follow the instructions below.
Download the files and modify the example to create a binary named "hello"
Type "make" to create the binary.
Run the resulting program "hello".
Type "make", again. Why did nothing much happen?
rm hello
make (What got remade, and why?)
rm foo.o
make (What got remade, and why?)
make clean (What did that do?)
make (What got remade, and why?)
~cs253/bin/checkin L2R# Makefile
Reference: GNU Make Open Book
Grading:
10 points: The submitted Makefile is complete (all/clean/hello).
9 points: Attended but makefile is not complete.
8 points: Makefile is not working.
Note: Please use the exact name given.