Codes of lecture 5 - virtual.mak

# This is the comment symbol, whenever you want to type a comment
# please put this symbol first.

# Modified feb 3rd 1994. Thor and Pen~a-Mora.

# Here we define some nicknames to be used during compilation

# The CCDEBUG variable defines the flags under which the compiler is
# going to work. The -c flag produce .o (object files) only and not
# linking is done. The -g flag is used for debugging reasons. This flag
# allows debugger such as gdb to use the core file for detecting the bugs.

CCDEBUG = -g


# The INCLUDE variable defines the directories where the compiler
# should search for header files (.h files) 

INCLUDE = 

# To use a nickname we put it inside ${...}

CFLAGS = ${CCDEBUG}

# We set up paths to search for the libraries needed for linking

LIBDIR = -L${ROOT}/${MACHINE}lib -L/mit/atdev/${hosttype}

# Now specify the libraries we want
# m is the math library
# We will also automatically get CC which is the C++ library

LFLAGS = -lm ${CCDEBUG}

# This is a shell script which launches the C++ translator

CC = /mit/cygnus/${hosttype}bin/g++

# The SOURCES variables have all the sources files of your code. If
# you only have one source code just put that one. If you have more than
# one please put as many as you have.

SOURCES =  	virtual.cc

# Macro to create a string with .o files that will have the same name as all
# the .cc files

OBJECTS = ${SOURCES:.cc=.o}

# The PROGS variable is the one that define the program that you are making.

PROGS = virtual

# all is a special name and make tries to make this by default
# this line reads "all depends on ${PROGS}"

all: ${PROGS} 

# The following command explain the compiler how to make the prog filename.
# It also says that filename depends on all the files in the OBJECTS variable.
# The $@ means that put the name of filenmae same than the target as defined
# by all.

virtual: $(OBJECTS) 
	$(CC) $(OBJECTS) -o $@ ${LFLAGS} $(LIBDIR)

# When the compiler try to make filename may find that filename1.o hasn't been
# made. So, the compiler try to make it and the following command explain 
# the compiler how to make it.
# It also says that filename1.o depends on filename1.cc filename1.h
# This is important so that compiler knows that even if filename1.o exists. 
# Its time stamping should be later than filename1.cc filename1.h
# If it is no later, it means that something has changed and the filename1.o
# has to be created again.
# Here you only define as many programs you have and with the name that you give.
# Remeber that filename1 is only a place holder.

virtual.o: virtual.cc virtual.h
	$(CC) $(CFLAGS) $(INCLUDE) -c virtual.cc

# In the case of filename2.o you can see that it depends also in filename1.h
# This tell me that filename2.cc or filename2.h use a function that is 
# declared in filename1.h and is defined in filename1.cc.
# In this case the compiler only needs to know that the function exists.
# At linking time filename1.o that has the function will be merged to 
# filename2.o and everything will be ok.