From c3e9550957724d32f7f04e5c8c8d169a7ffc0afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Str=C3=B6mb=C3=A4ck?= <filip.stromback@liu.se> Date: Sun, 21 Nov 2021 10:37:39 +0100 Subject: [PATCH] Improved makefiles to take dependencies into account. --- .gitignore | 1 + basic/Makefile | 4 ++-- components/Makefile | 17 ++++++++++------- inheritance/Makefile | 17 ++++++++++------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index bc08b84..785af81 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ bin/ build/ *.o +*.d *.aux *.fdb_latexmk diff --git a/basic/Makefile b/basic/Makefile index 39e2fba..2308c59 100644 --- a/basic/Makefile +++ b/basic/Makefile @@ -1,5 +1,5 @@ -CXXFLAGS := -std=c++17 -LDFLAGS := -lsfml-graphics -lsfml-window -lsfml-system +CXXFLAGS := -g -std=c++17 +LDFLAGS := -g -lsfml-graphics -lsfml-window -lsfml-system SOURCES := $(wildcard *.cpp) EXECUTABLES := $(patsubst %.cpp,%,$(SOURCES)) diff --git a/components/Makefile b/components/Makefile index e9258cc..6f38bdf 100644 --- a/components/Makefile +++ b/components/Makefile @@ -1,12 +1,12 @@ -CXXFLAGS := -std=c++17 -Wall -Wextra -LDFLAGS := -lsfml-graphics -lsfml-window -lsfml-system +CXXFLAGS := -g -std=c++17 -Wall -Wextra +LDFLAGS := -g -lsfml-graphics -lsfml-window -lsfml-system SOURCES := $(wildcard *.cpp) OBJECTS := $(patsubst %.cpp,%.o,$(SOURCES)) -# Note: This makefile is not entirely correct, it does not take header dependencies into account. -# It is, however, enough to compile the project here, which is the intended use. If you wish to -# develop the code further, I suggest either mymake or writing a CMake-file. +# Dependencies: +DEPS := $(patsubst %.o,%.d,$(OBJECTS)) +DEPFLAGS := -MMD -MP all: game @@ -14,7 +14,7 @@ pdf: uml.pdf .PHONY: clean clean: - rm -f game $(OBJECTS) + rm -f game $(OBJECTS) $(DEPS) find . -name "uml.*" | grep -Ev "(pdf|tex)$$" | xargs rm -f uml.pdf: uml.tex @@ -24,4 +24,7 @@ game: $(OBJECTS) g++ $(CXXFLAGS) -o game $(OBJECTS) $(LDFLAGS) $(OBJECTS): %.o: %.cpp - g++ $(CXXFLAGS) -c -o $@ $< + g++ $(CXXFLAGS) $(DEPFLAGS) -c -o $@ $< + +# Include dependencies +-include $(DEPS) diff --git a/inheritance/Makefile b/inheritance/Makefile index e9258cc..6f38bdf 100644 --- a/inheritance/Makefile +++ b/inheritance/Makefile @@ -1,12 +1,12 @@ -CXXFLAGS := -std=c++17 -Wall -Wextra -LDFLAGS := -lsfml-graphics -lsfml-window -lsfml-system +CXXFLAGS := -g -std=c++17 -Wall -Wextra +LDFLAGS := -g -lsfml-graphics -lsfml-window -lsfml-system SOURCES := $(wildcard *.cpp) OBJECTS := $(patsubst %.cpp,%.o,$(SOURCES)) -# Note: This makefile is not entirely correct, it does not take header dependencies into account. -# It is, however, enough to compile the project here, which is the intended use. If you wish to -# develop the code further, I suggest either mymake or writing a CMake-file. +# Dependencies: +DEPS := $(patsubst %.o,%.d,$(OBJECTS)) +DEPFLAGS := -MMD -MP all: game @@ -14,7 +14,7 @@ pdf: uml.pdf .PHONY: clean clean: - rm -f game $(OBJECTS) + rm -f game $(OBJECTS) $(DEPS) find . -name "uml.*" | grep -Ev "(pdf|tex)$$" | xargs rm -f uml.pdf: uml.tex @@ -24,4 +24,7 @@ game: $(OBJECTS) g++ $(CXXFLAGS) -o game $(OBJECTS) $(LDFLAGS) $(OBJECTS): %.o: %.cpp - g++ $(CXXFLAGS) -c -o $@ $< + g++ $(CXXFLAGS) $(DEPFLAGS) -c -o $@ $< + +# Include dependencies +-include $(DEPS) -- GitLab