# CSC 270H                         Project 4                    Makefile
#
# A makefile you can use to ease the task of compilation, especially when it
# has to be repeated many times.  Remember that, though it's just a way of
# organizing commands that you would use anyway, it does sometimes provide
# its own error messages in place of the compiler's or the Unix shell's, and
# these may possibly increase your confusion.  If you don't understand or
# believe an error message from a "make" command, try typing the original
# compile command yourself, on the Unix command line.

# First, we define the program to be used to compile our code.
CC = g++ -c

# Now define the program to link the objects
LD = g++

# Now, some compiler flags.
CFLAGS = -Wall -ansi -pedantic

# The non-standard libraries.   You may want some functions from the math
# library so we better include it.
LDFLAGS = -lm

# Flags we can set for debugging.  Unless we're in serious difficulty, we'll
# just use the -g flag, which allows us to use the "gdb" debugger if needed.
DEBUGFLAGS = -g
CFLAGS += $(DEBUGFLAGS)

# Object files that the main program depends on.
# *** ADD APPROPRIATE OBJECT FILENAMES HERE! ***
# the "\" is used to split a line 
OBJS = trafficsim.o shortest_path.o random_numbers.o \
       queues.o network.o graph.o cars.o

# Name of the final executable file.
TARGET = trafficsim

# Finally, we're ready to define things we can get "make" to do.

# If you just give the command "make", with no further words on the command
# line, you get whatever is listed for "default".
default: $(TARGET)

# "make trafficsim" compiles the main program
$(TARGET): $(OBJS)
	$(LD) -o $(TARGET) $(OBJS) $(LDFLAGS)
## The first character on the line above should be a TAB! ##

# "make clean" gets rid of object (.o) and executable files.
clean:
	rm -f core *.o $(TARGET)
## The first character on the line above should be a TAB! ##

# Now we list the commands to compile each file.
# Each file has two lines.  The first line lists the dependencies.  These are
# the file and all of its includes.  Anytime a dependency is updated, make
# will recompile the code.
#
# The second line is the compile command.
# *** ADD APPROPRIATE DEPENDENCIES HERE! ***

trafficsim.o: trafficsim.cpp network.h cars.h random_numbers.h queues.h graph.h
	$(CC) $(CFLAGS) trafficsim.cpp

network.o: network.cpp network.h graph.h queues.h shortest_paths.h \
			random_numbers.h
	$(CC) $(CFLAGS) network.cpp

cars.o: cars.cpp cars.h random_numbers.h
	$(CC) $(CFLAGS) cars.cpp

shortest_path.o: shortest_path.cpp shortest_paths.h graph.h
	$(CC) $(CFLAGS) shortest_path.cpp

random_numbers.o: random_numbers.cpp random_numbers.h
	$(CC) $(CFLAGS) random_numbers.cpp

queues.o: queues.cpp queues.h
	$(CC) $(CFLAGS) queues.cpp

graph.o: graph.cpp graph.h
	$(CC) $(CFLAGS) graph.cpp
