From 4a84ecfcde206e46114b4375cc338373ce5dc36b Mon Sep 17 00:00:00 2001 From: aldo_bedrij Date: Tue, 23 Apr 2013 18:37:15 -0300 Subject: [PATCH 1/8] Altering directory structure The sources are only for chesspp, so it makes no sense to have another directory. Also `main' is together with the other sources --- src/{chesspp => }/AppState.hpp | 0 src/{chesspp => }/AppStateGame.cpp | 0 src/{chesspp => }/AppStateGame.hpp | 0 src/{chesspp => }/Application.cpp | 0 src/{chesspp => }/Application.hpp | 0 src/{chesspp => }/Exception.hpp | 0 src/{chesspp => }/ResourceManager.hpp | 0 src/{chesspp => }/SFMLEvent.hpp | 0 src/{chesspp => }/TextureManager.hpp | 0 src/{chesspp => }/board/Bishop.cpp | 0 src/{chesspp => }/board/Bishop.hpp | 0 src/{chesspp => }/board/Board.cpp | 0 src/{chesspp => }/board/Board.hpp | 0 src/{chesspp => }/board/King.cpp | 0 src/{chesspp => }/board/King.hpp | 0 src/{chesspp => }/board/Knight.cpp | 0 src/{chesspp => }/board/Knight.hpp | 0 src/{chesspp => }/board/OnValidity.txt | 0 src/{chesspp => }/board/Pawn.cpp | 0 src/{chesspp => }/board/Pawn.hpp | 0 src/{chesspp => }/board/Piece.cpp | 0 src/{chesspp => }/board/Piece.hpp | 0 src/{chesspp => }/board/Position.cpp | 0 src/{chesspp => }/board/Position.hpp | 0 src/{chesspp => }/board/Queen.cpp | 0 src/{chesspp => }/board/Queen.hpp | 0 src/{chesspp => }/board/Rook.cpp | 0 src/{chesspp => }/board/Rook.hpp | 0 src/{chesspp => }/config/Configuration.hpp | 0 src/{chesspp => }/graphics/Graphics.cpp | 0 src/{chesspp => }/graphics/Graphics.hpp | 0 src/{chesspp => }/log/Logger.cpp | 0 src/{chesspp => }/log/Logger.hpp | 0 src/{chesspp => }/util/JsonReader.hpp | 0 34 files changed, 0 insertions(+), 0 deletions(-) rename src/{chesspp => }/AppState.hpp (100%) rename src/{chesspp => }/AppStateGame.cpp (100%) rename src/{chesspp => }/AppStateGame.hpp (100%) rename src/{chesspp => }/Application.cpp (100%) rename src/{chesspp => }/Application.hpp (100%) rename src/{chesspp => }/Exception.hpp (100%) rename src/{chesspp => }/ResourceManager.hpp (100%) rename src/{chesspp => }/SFMLEvent.hpp (100%) rename src/{chesspp => }/TextureManager.hpp (100%) rename src/{chesspp => }/board/Bishop.cpp (100%) rename src/{chesspp => }/board/Bishop.hpp (100%) rename src/{chesspp => }/board/Board.cpp (100%) rename src/{chesspp => }/board/Board.hpp (100%) rename src/{chesspp => }/board/King.cpp (100%) rename src/{chesspp => }/board/King.hpp (100%) rename src/{chesspp => }/board/Knight.cpp (100%) rename src/{chesspp => }/board/Knight.hpp (100%) rename src/{chesspp => }/board/OnValidity.txt (100%) rename src/{chesspp => }/board/Pawn.cpp (100%) rename src/{chesspp => }/board/Pawn.hpp (100%) rename src/{chesspp => }/board/Piece.cpp (100%) rename src/{chesspp => }/board/Piece.hpp (100%) rename src/{chesspp => }/board/Position.cpp (100%) rename src/{chesspp => }/board/Position.hpp (100%) rename src/{chesspp => }/board/Queen.cpp (100%) rename src/{chesspp => }/board/Queen.hpp (100%) rename src/{chesspp => }/board/Rook.cpp (100%) rename src/{chesspp => }/board/Rook.hpp (100%) rename src/{chesspp => }/config/Configuration.hpp (100%) rename src/{chesspp => }/graphics/Graphics.cpp (100%) rename src/{chesspp => }/graphics/Graphics.hpp (100%) rename src/{chesspp => }/log/Logger.cpp (100%) rename src/{chesspp => }/log/Logger.hpp (100%) rename src/{chesspp => }/util/JsonReader.hpp (100%) diff --git a/src/chesspp/AppState.hpp b/src/AppState.hpp similarity index 100% rename from src/chesspp/AppState.hpp rename to src/AppState.hpp diff --git a/src/chesspp/AppStateGame.cpp b/src/AppStateGame.cpp similarity index 100% rename from src/chesspp/AppStateGame.cpp rename to src/AppStateGame.cpp diff --git a/src/chesspp/AppStateGame.hpp b/src/AppStateGame.hpp similarity index 100% rename from src/chesspp/AppStateGame.hpp rename to src/AppStateGame.hpp diff --git a/src/chesspp/Application.cpp b/src/Application.cpp similarity index 100% rename from src/chesspp/Application.cpp rename to src/Application.cpp diff --git a/src/chesspp/Application.hpp b/src/Application.hpp similarity index 100% rename from src/chesspp/Application.hpp rename to src/Application.hpp diff --git a/src/chesspp/Exception.hpp b/src/Exception.hpp similarity index 100% rename from src/chesspp/Exception.hpp rename to src/Exception.hpp diff --git a/src/chesspp/ResourceManager.hpp b/src/ResourceManager.hpp similarity index 100% rename from src/chesspp/ResourceManager.hpp rename to src/ResourceManager.hpp diff --git a/src/chesspp/SFMLEvent.hpp b/src/SFMLEvent.hpp similarity index 100% rename from src/chesspp/SFMLEvent.hpp rename to src/SFMLEvent.hpp diff --git a/src/chesspp/TextureManager.hpp b/src/TextureManager.hpp similarity index 100% rename from src/chesspp/TextureManager.hpp rename to src/TextureManager.hpp diff --git a/src/chesspp/board/Bishop.cpp b/src/board/Bishop.cpp similarity index 100% rename from src/chesspp/board/Bishop.cpp rename to src/board/Bishop.cpp diff --git a/src/chesspp/board/Bishop.hpp b/src/board/Bishop.hpp similarity index 100% rename from src/chesspp/board/Bishop.hpp rename to src/board/Bishop.hpp diff --git a/src/chesspp/board/Board.cpp b/src/board/Board.cpp similarity index 100% rename from src/chesspp/board/Board.cpp rename to src/board/Board.cpp diff --git a/src/chesspp/board/Board.hpp b/src/board/Board.hpp similarity index 100% rename from src/chesspp/board/Board.hpp rename to src/board/Board.hpp diff --git a/src/chesspp/board/King.cpp b/src/board/King.cpp similarity index 100% rename from src/chesspp/board/King.cpp rename to src/board/King.cpp diff --git a/src/chesspp/board/King.hpp b/src/board/King.hpp similarity index 100% rename from src/chesspp/board/King.hpp rename to src/board/King.hpp diff --git a/src/chesspp/board/Knight.cpp b/src/board/Knight.cpp similarity index 100% rename from src/chesspp/board/Knight.cpp rename to src/board/Knight.cpp diff --git a/src/chesspp/board/Knight.hpp b/src/board/Knight.hpp similarity index 100% rename from src/chesspp/board/Knight.hpp rename to src/board/Knight.hpp diff --git a/src/chesspp/board/OnValidity.txt b/src/board/OnValidity.txt similarity index 100% rename from src/chesspp/board/OnValidity.txt rename to src/board/OnValidity.txt diff --git a/src/chesspp/board/Pawn.cpp b/src/board/Pawn.cpp similarity index 100% rename from src/chesspp/board/Pawn.cpp rename to src/board/Pawn.cpp diff --git a/src/chesspp/board/Pawn.hpp b/src/board/Pawn.hpp similarity index 100% rename from src/chesspp/board/Pawn.hpp rename to src/board/Pawn.hpp diff --git a/src/chesspp/board/Piece.cpp b/src/board/Piece.cpp similarity index 100% rename from src/chesspp/board/Piece.cpp rename to src/board/Piece.cpp diff --git a/src/chesspp/board/Piece.hpp b/src/board/Piece.hpp similarity index 100% rename from src/chesspp/board/Piece.hpp rename to src/board/Piece.hpp diff --git a/src/chesspp/board/Position.cpp b/src/board/Position.cpp similarity index 100% rename from src/chesspp/board/Position.cpp rename to src/board/Position.cpp diff --git a/src/chesspp/board/Position.hpp b/src/board/Position.hpp similarity index 100% rename from src/chesspp/board/Position.hpp rename to src/board/Position.hpp diff --git a/src/chesspp/board/Queen.cpp b/src/board/Queen.cpp similarity index 100% rename from src/chesspp/board/Queen.cpp rename to src/board/Queen.cpp diff --git a/src/chesspp/board/Queen.hpp b/src/board/Queen.hpp similarity index 100% rename from src/chesspp/board/Queen.hpp rename to src/board/Queen.hpp diff --git a/src/chesspp/board/Rook.cpp b/src/board/Rook.cpp similarity index 100% rename from src/chesspp/board/Rook.cpp rename to src/board/Rook.cpp diff --git a/src/chesspp/board/Rook.hpp b/src/board/Rook.hpp similarity index 100% rename from src/chesspp/board/Rook.hpp rename to src/board/Rook.hpp diff --git a/src/chesspp/config/Configuration.hpp b/src/config/Configuration.hpp similarity index 100% rename from src/chesspp/config/Configuration.hpp rename to src/config/Configuration.hpp diff --git a/src/chesspp/graphics/Graphics.cpp b/src/graphics/Graphics.cpp similarity index 100% rename from src/chesspp/graphics/Graphics.cpp rename to src/graphics/Graphics.cpp diff --git a/src/chesspp/graphics/Graphics.hpp b/src/graphics/Graphics.hpp similarity index 100% rename from src/chesspp/graphics/Graphics.hpp rename to src/graphics/Graphics.hpp diff --git a/src/chesspp/log/Logger.cpp b/src/log/Logger.cpp similarity index 100% rename from src/chesspp/log/Logger.cpp rename to src/log/Logger.cpp diff --git a/src/chesspp/log/Logger.hpp b/src/log/Logger.hpp similarity index 100% rename from src/chesspp/log/Logger.hpp rename to src/log/Logger.hpp diff --git a/src/chesspp/util/JsonReader.hpp b/src/util/JsonReader.hpp similarity index 100% rename from src/chesspp/util/JsonReader.hpp rename to src/util/JsonReader.hpp From 4306ce91ceb3dca0614327b1e495aec9166d5f52 Mon Sep 17 00:00:00 2001 From: aldo_bedrij Date: Tue, 23 Apr 2013 19:28:54 -0300 Subject: [PATCH 2/8] makefile extracted from http://users.softlab.ece.ntua.gr/~ttsiod/makefile.html Handles dependencies, debug and release --- makefile | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 makefile diff --git a/makefile b/makefile new file mode 100644 index 0000000..7214ca2 --- /dev/null +++ b/makefile @@ -0,0 +1,67 @@ +#CXX = g++ +CPPFLAGS += -std=c++11 -Wall -Wextra -pedantic-errors +INCLUDE = -I. + +ifeq ($(CFG),) +CFG=debug +endif + +ifeq ($(CFG),debug) +CPPFLAGS += -ggdb -DDEBUG +else +CPPFLAGS += -O2 +endif +CPPFLAGS += $(INCLUDE) + + +VPATH=src +TARGET=chesscpp.bin + +SRC = \ + Queen.cpp \ + Board.cpp \ + Pawn.cpp \ + Position.cpp \ + Bishop.cpp \ + King.cpp \ + Rook.cpp \ + Knight.cpp \ + Piece.cpp \ + Logger.cpp \ + Main.cpp \ + Graphics.cpp \ + Application.cpp \ + AppStateGame.cpp + +OBJ = $(patsubst %.cpp, objs.$(CFG)/%.o, ${SRC}) +DEP = $(patsubst %.cpp, deps.$(CFG)/%.d, ${SRC}) + +all: bin.$(CFG)/${TARGET} + +bin.$(CFG)/${TARGET}: ${OBJ} + mkdir -p $(dir $@) + $(CPP) $^ -o $@ + +test: + echo $(OBJ) + +deps.$(CFG)/%.d: %.cpp + mkdir -p $(dir $@) + $(CPP) -MM -MP $(INCLUDE) $< > $@; + +objs.$(CFG)/%.o: %.cpp + mkdir -p $(dir $@) + $(cPP) -c $(CPPFLAGS) $< -o $@ + +.PHONY: clean deps + +clean: + rm -rf objs.$(CFG) bin.$(CFG) + + +# Unless "make clean" is called, include the dependency files +# which are auto-generated. Don't fail if they are missing +# (-include), since they will be missing in the first invocation! +ifneq ($(MAKECMDGOALS),clean) +-include ${DEP} +endif From 0883c5776512f962a07111bfcbb6f7550ebd79b2 Mon Sep 17 00:00:00 2001 From: aldo_bedrij Date: Tue, 23 Apr 2013 19:52:19 -0300 Subject: [PATCH 3/8] Fixed includes Not using relatives. Let the makefile to take care --- src/AppStateGame.hpp | 2 +- src/Main.cpp | 2 +- src/SFMLEvent.hpp | 2 +- src/TextureManager.hpp | 2 +- src/board/Piece.hpp | 2 +- src/config/Configuration.hpp | 6 +++--- src/graphics/Graphics.hpp | 10 +++++----- src/util/JsonReader.hpp | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/AppStateGame.hpp b/src/AppStateGame.hpp index c96407a..523ecb0 100644 --- a/src/AppStateGame.hpp +++ b/src/AppStateGame.hpp @@ -1,6 +1,6 @@ #ifndef _APPSTATEGAME_H #define _APPSTATEGAME_H -#include "../SFML.hpp" +#include "SFML.hpp" #include "TextureManager.hpp" #include "graphics/Graphics.hpp" #include "config/Configuration.hpp" diff --git a/src/Main.cpp b/src/Main.cpp index 3226a3b..94d51d0 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1,6 +1,6 @@ #include -#include "chesspp/Application.hpp" +#include "Application.hpp" int main() { diff --git a/src/SFMLEvent.hpp b/src/SFMLEvent.hpp index a8ace94..3197a9b 100644 --- a/src/SFMLEvent.hpp +++ b/src/SFMLEvent.hpp @@ -1,7 +1,7 @@ #ifndef _EVENT_H #define _EVENT_H -#include "../SFML.hpp" +#include "SFML.hpp" namespace chesspp { diff --git a/src/TextureManager.hpp b/src/TextureManager.hpp index 11a1759..1b00e80 100644 --- a/src/TextureManager.hpp +++ b/src/TextureManager.hpp @@ -1,7 +1,7 @@ #ifndef _TEXTUREMANAGER_H #define _TEXTUREMANAGER_H #include "ResourceManager.hpp" -#include "../SFML.hpp" +#include "SFML.hpp" #ifdef _DEBUG #include diff --git a/src/board/Piece.hpp b/src/board/Piece.hpp index e1da06f..9e09a64 100644 --- a/src/board/Piece.hpp +++ b/src/board/Piece.hpp @@ -9,7 +9,7 @@ // textureX = givenValX // textureY = givenValY + ( this->color == WHITE ? 0 : 80 ) -#include "../log/Logger.hpp" +#include "log/Logger.hpp" // The contigousness of this container does not matter // It could be sorted for std::lower_bound? I don't think time is an issue diff --git a/src/config/Configuration.hpp b/src/config/Configuration.hpp index 28ce72f..0a7c42a 100644 --- a/src/config/Configuration.hpp +++ b/src/config/Configuration.hpp @@ -15,9 +15,9 @@ #endif -#include "../Exception.hpp" -#include "../util/JsonReader.hpp" -#include "../log/logger.hpp" +#include "Exception.hpp" +#include "util/JsonReader.hpp" +#include "log/Logger.hpp" namespace chesspp { diff --git a/src/graphics/Graphics.hpp b/src/graphics/Graphics.hpp index ecdd8e2..96a6d94 100644 --- a/src/graphics/Graphics.hpp +++ b/src/graphics/Graphics.hpp @@ -1,11 +1,11 @@ #ifndef _GRAPHICS_H #define _GRAPHICS_H -#include "../../SFML.hpp" -#include "../TextureManager.hpp" -#include "../config/Configuration.hpp" -#include "../board/Piece.hpp" -#include "../log/Logger.hpp" +#include "SFML.hpp" +#include "TextureManager.hpp" +#include "config/Configuration.hpp" +#include "board/Piece.hpp" +#include "log/Logger.hpp" #ifdef _DEBUG #include diff --git a/src/util/JsonReader.hpp b/src/util/JsonReader.hpp index 70eb354..8f21927 100644 --- a/src/util/JsonReader.hpp +++ b/src/util/JsonReader.hpp @@ -7,7 +7,7 @@ #include #include -#include "../Exception.hpp" +#include "Exception.hpp" namespace chesspp { From 8c55ab1d7a355f9d3059040eea9d7b060b810e65 Mon Sep 17 00:00:00 2001 From: aldo_bedrij Date: Tue, 23 Apr 2013 19:53:19 -0300 Subject: [PATCH 4/8] Handling dependecies --- makefile | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/makefile b/makefile index 7214ca2..527503d 100644 --- a/makefile +++ b/makefile @@ -1,6 +1,7 @@ -#CXX = g++ +CPP = g++ +CC = gcc CPPFLAGS += -std=c++11 -Wall -Wextra -pedantic-errors -INCLUDE = -I. +INCLUDE = -isystem lib/json-parser/ -Isrc ifeq ($(CFG),) CFG=debug @@ -14,7 +15,7 @@ endif CPPFLAGS += $(INCLUDE) -VPATH=src +VPATH=src:src/board/:src/config/:src/graphics/:src/log/:src/util/ TARGET=chesscpp.bin SRC = \ @@ -44,19 +45,22 @@ bin.$(CFG)/${TARGET}: ${OBJ} test: echo $(OBJ) + echo $(DEP) deps.$(CFG)/%.d: %.cpp mkdir -p $(dir $@) - $(CPP) -MM -MP $(INCLUDE) $< > $@; + $(CPP) -MM -MP $(CPPFLAGS) $< > $@; objs.$(CFG)/%.o: %.cpp mkdir -p $(dir $@) - $(cPP) -c $(CPPFLAGS) $< -o $@ + $(CPP) -c $(CPPFLAGS) $< -o $@ .PHONY: clean deps clean: - rm -rf objs.$(CFG) bin.$(CFG) + -rm -r obj.debug deps.debug bin.debug + -rm -r obj.release deps.release bin.release + # Unless "make clean" is called, include the dependency files From 4b86e7447b2711caff438fb5874d924b5a2c3bcf Mon Sep 17 00:00:00 2001 From: aldo_bedrij Date: Tue, 23 Apr 2013 20:06:43 -0300 Subject: [PATCH 5/8] Included libraries json linked statically --- makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index 527503d..faa6720 100644 --- a/makefile +++ b/makefile @@ -3,6 +3,8 @@ CC = gcc CPPFLAGS += -std=c++11 -Wall -Wextra -pedantic-errors INCLUDE = -isystem lib/json-parser/ -Isrc +LIB = `pkg-config --libs sfml-all` lib/json-parser/json.a + ifeq ($(CFG),) CFG=debug endif @@ -41,7 +43,7 @@ all: bin.$(CFG)/${TARGET} bin.$(CFG)/${TARGET}: ${OBJ} mkdir -p $(dir $@) - $(CPP) $^ -o $@ + $(CPP) $^ $(LIBDIR) $(LIB) -o $@ test: echo $(OBJ) From a0bcf53539dc948044e3f0c1789dcf68cacdbe8d Mon Sep 17 00:00:00 2001 From: aldo_bedrij Date: Tue, 23 Apr 2013 21:31:59 -0300 Subject: [PATCH 6/8] Fixed dependencies issues --- makefile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/makefile b/makefile index faa6720..1e3375e 100644 --- a/makefile +++ b/makefile @@ -49,9 +49,10 @@ test: echo $(OBJ) echo $(DEP) + deps.$(CFG)/%.d: %.cpp mkdir -p $(dir $@) - $(CPP) -MM -MP $(CPPFLAGS) $< > $@; + $(CPP) -MM -MP $(CPPFLAGS) $< | perl -pe 's#^(?=.*\.o)#objs.$(CFG)/#' > $@ objs.$(CFG)/%.o: %.cpp mkdir -p $(dir $@) @@ -60,14 +61,12 @@ objs.$(CFG)/%.o: %.cpp .PHONY: clean deps clean: - -rm -r obj.debug deps.debug bin.debug - -rm -r obj.release deps.release bin.release + -rm -r objs.debug deps.debug bin.debug + -rm -r objs.release deps.release bin.release # Unless "make clean" is called, include the dependency files # which are auto-generated. Don't fail if they are missing # (-include), since they will be missing in the first invocation! -ifneq ($(MAKECMDGOALS),clean) -include ${DEP} -endif From 0d1388611670141d166cbc82ec5652e8e13619fe Mon Sep 17 00:00:00 2001 From: aldo_bedrij Date: Tue, 23 Apr 2013 21:41:09 -0300 Subject: [PATCH 7/8] Generating dependencies --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 1e3375e..852271a 100644 --- a/makefile +++ b/makefile @@ -52,7 +52,7 @@ test: deps.$(CFG)/%.d: %.cpp mkdir -p $(dir $@) - $(CPP) -MM -MP $(CPPFLAGS) $< | perl -pe 's#^(?=.*\.o)#objs.$(CFG)/#' > $@ + $(CPP) -MM -MP $(CPPFLAGS) $< | perl -pe 's#^(.*\.o)#deps.$(CFG)/$$1 objs.$(CFG)/$$1#' > $@ objs.$(CFG)/%.o: %.cpp mkdir -p $(dir $@) From 4989a4c10556b719b731e81c8cf66ca720411f76 Mon Sep 17 00:00:00 2001 From: aldo_bedrij Date: Tue, 23 Apr 2013 22:41:32 -0300 Subject: [PATCH 8/8] Usage example --- makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/makefile b/makefile index 852271a..242309e 100644 --- a/makefile +++ b/makefile @@ -1,3 +1,6 @@ +#usage +# make CFG=release + CPP = g++ CC = gcc CPPFLAGS += -std=c++11 -Wall -Wextra -pedantic-errors