Make Lab

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.
  1. Download the files and modify the example to create a binary named "hello"
  2. Type "make" to create the binary.
  3. Run the resulting program "hello".
  4. Type "make", again. Why did nothing much happen?
  5. rm hello
  6. make (What got remade, and why?)
  7. rm foo.o
  8. make (What got remade, and why?)
  9. make clean (What did that do?)
  10. make (What got remade, and why?)
  11. ~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.