# Makefile
# CSE 333 Lecture 14 code

CXX = g++
CPPFLAGS = -Wall -g -std=c++17
PROGS = vectorfun vectorcap vectoriterator vectoriterator_2011 vectoralgos listexample mapexample test

# default target builds all executables
all: $(PROGS)

# vector examples
vectorfun: vectorfun.o Tracer.o
	$(CXX) $(CPPFLAGS) -o $@ $^

vectorfun.o: vectorfun.cc Tracer.h
	$(CXX) $(CPPFLAGS) -c $<
	
vectorcap: vectorcap.o Tracer.o
	$(CXX) $(CPPFLAGS) -o $@ $^

vectorcap.o: vectorcap.cc Tracer.h
	$(CXX) $(CPPFLAGS) -c $<

Tracer.o: Tracer.cc Tracer.h
	$(CXX) $(CPPFLAGS) -c $<

# iterator example
vectoriterator: vectoriterator.o Tracer.o
	$(CXX) $(CPPFLAGS) -o $@ $^

vectoriterator.o: vectoriterator.cc Tracer.h
	$(CXX) $(CPPFLAGS) -c $<

# iterator example with auto, range for
vectoriterator_2011: vectoriterator_2011.o Tracer.o
	$(CXX) $(CPPFLAGS) -o $@ $^

vectoriterator_2011.o: vectoriterator_2011.cc Tracer.h
	$(CXX) $(CPPFLAGS) -c $<

# algorithms example (sort, for-each)
vectoralgos: vectoralgos.o Tracer.o
	$(CXX) $(CPPFLAGS) -o $@ $^

vectoralgos.o: vectoralgos.cc Tracer.h
	$(CXX) $(CPPFLAGS) -c $<

# list example
listexample: listexample.o Tracer.o
	$(CXX) $(CPPFLAGS) -o $@ $^

listexample.o: listexample.cc Tracer.h
	$(CXX) $(CPPFLAGS) -c $<

# map example
mapexample: mapexample.o Tracer.o
	$(CXX) $(CPPFLAGS) -o $@ $^

mapexample.o: mapexample.cc Tracer.h
	$(CXX) $(CPPFLAGS) -c $<

# Iterator Question code
test: test.o Tracer.o
	$(CXX) $(CPPFLAGS) -o $@ $^

test.o: test.cc Tracer.h
	$(CXX) $(CPPFLAGS) -c $<

# phony target - remove generated files and backups
clean:
	rm -f *.o $(PROGS)