CXXFLAGS= -Wall -g -std=c++0x
OBJECTS=Factory.o linkedlist.o node.o ../ignoreme.a
EXE=main
all: libpwnd.so $(EXE)

$(EXE): $(OBJECTS)
	$(CXX) $(CXXFLAGS) $(OBJECTS) -o $@
main.o: main.cpp Factory.o linkedlist.o node.o libpwnd.so ../ignoreme.a 
		g++ -Wall -g -o main Factory.o linkedlist.o ../ignoreme.a
Factory.o: Factory.cpp Factory.h
linkedlist.o: linkedlist.cpp linkedlist.h
node.o: node.cpp node.h
test: linkedlist.o node.o test.cpp
	$(CXX) $(CXXFLAGS) linkedlist.o node.o test.cpp -o $@

run: main
	LD_PRELOAD=libpwnd.so LD_LIBRARY_PATH=. ./main

clean:
	@rm -vf *.o
	@rm -vf $(EXE)
	@rm -vf *.1
	@rm -vf *.0

drun: main
	LD_PRELOAD=libpwnd.so LD_LIBRARY_PATH=. gdb ./main

debug: test
	LD_PRELOAD=libpwnd.so LD_LIBRARY_PATH=. gdb ./test

valgrind: $(EXE)
	LD_PRELOAD=libpwnd.so LD_LIBRARY_PATH=. valgrind --tool=memcheck --leak-check=yes ./$(EXE)

libpwnd.so: pwnd.c
	gcc -shared -o libpwnd.so.1.0  pwnd.c
	ln -fs libpwnd.so.1.0 libpwnd.so.1
	ln -fs libpwnd.so.1 libpwnd.so
