diff --git a/makefile b/makefile
index d31fb0befd519bc8b4de3f88dda110bee4240e34..80f26aa59a21b023523fab10d6b8f0dc568cf43d 100644
--- a/makefile
+++ b/makefile
@@ -4,6 +4,7 @@ CFLAGS = -Wall -Wextra -Werror
 
 # Source files
 SRC = treemap.c
+OBJ = $(SRC:.c=.o)
 HDR = treemap.h place.h
 
 # Output executable
@@ -15,27 +16,42 @@ TEST_TARGET = test-treemap
 
 # Default target
 all: $(TARGET)
-	$(CC) $(CFLAGS) $(SRC) -o $(TARGET)
+	$(CC) $(CFLAGS) $(OBJ) -o $(TARGET)
 
 	./$(TARGET) > whatever.vector
 	chmod +x vector2tex.sh
 	./vector2tex.sh < whatever.vector > whatever.tex
 	pdflatex whatever.tex
-
+	
 	doxygen -g
 	doxygen Doxyfile
 
-# Build the test suite
+$(TARGET): $(OBJ)
+	$(CC) $(CFLAGS) $(OBJ) -o $(TARGET)
+
+%.o: %.c $(HDR)
+	$(CC) $(CFLAGS) -c $< -o $@
+
 test: $(TEST_SRC) $(HDR)
 	$(CC) $(CFLAGS) $(TEST_SRC) $(SRC) -o $(TEST_TARGET)
 	./$(TEST_TARGET)
 
 memcheck: $(TARGET)
 	valgrind --leak-check=full ./$(TARGET) plain.txt
+
+doc:
+	doxygen -g
+	doxygen Doxyfile
+
 	
-# Clean generated files
-clean:
-	rm -f $(TARGET) $(TEST_TARGET) *.o *.tex *.pdf *.aux *.log Doxyfile
+vector: $(TARGET)
+	./$(TARGET) > whatever.vector
+	chmod +x vector2tex.sh
+	./vector2tex.sh < whatever.vector > whatever.tex
+	pdflatex whatever.tex
 
-.PHONY: all test doc memcheck clean
+clean:
+	rm -f $(TARGET) $(TEST_TARGET) $(OBJ) *.o *.tex *.pdf *.aux *.log Doxyfile whatever.vector
+	rm -rf latex html
 
+.PHONY: all test doc memcheck clean vector