diff --git a/cpp/.gitignore b/cpp/.gitignore index d99efa9..e46b6c0 100644 --- a/cpp/.gitignore +++ b/cpp/.gitignore @@ -29,4 +29,4 @@ # Executables *.exe *.out -*.app \ No newline at end of file +*.appobj/ diff --git a/cpp/Makefile b/cpp/Makefile index 5dc0728..2af4a19 100644 --- a/cpp/Makefile +++ b/cpp/Makefile @@ -1,32 +1,32 @@ -# Compiler flags (add -O2 for optimization, -g for debugging, etc.) -CXXFLAGS = -Wall -O3 +# Add .d to Make's recognized suffixes. +SUFFIXES += .d -# Name of the final executable -TARGET = stickfosh +#We don't need to clean up when we're making these targets +NODEPS:=clean tags svn +#Find all the C++ files in the src/ directory +SOURCES:=$(shell find src/ -name "*.cpp") +OBJFILES := $(patsubst src/%.cpp,obj/%.o,$(SOURCES)) +#These are the dependency files, which make will clean up after it creates them +DEPFILES:=$(patsubst %.cpp,%.d,$(SOURCES)) -# List of source files -SRCS = main.cpp board.cpp +#Don't create dependencies when we're cleaning, for instance +ifeq (0, $(words $(findstring $(MAKECMDGOALS), $(NODEPS)))) + #Chances are, these files don't exist. GMake will create them and + #clean up automatically afterwards + -include $(DEPFILES) +endif -# Automatically generate object file names from source file names -OBJS = $(SRCS:.cpp=.o) +#This is the rule for creating the dependency files +src/%.d: src/%.cpp + $(CXX) $(CXXFLAGS) -MM -MT '$(patsubst src/%.cpp,obj/%.o,$<)' $< -MF $@ -# Default rule: build the target executable -all: $(TARGET) +#This rule does the compilation +obj/%.o: + @mkdir -p $(dir $@) + $(CXX) $(CXXFLAGS) -o $@ -c $< -# Link the object files into the final executable -$(TARGET): $(OBJS) - $(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJS) +main: $(OBJFILES) + $(CXX) $(LDFLAGS) $(OBJFILES) $(LOADLIBES) $(LDLIBS) -o main -# Pattern rule: compile each .cpp file to a .o file -%.o: %.cpp %.hpp - $(CXX) $(CXXFLAGS) -c $< -o $@ - -main.o: board.o -stickfosh: main.o board.o - -# Clean rule to remove built files clean: - rm -f $(TARGET) $(OBJS) - -# Optional: a rule to rebuild everything from scratch -rebuild: clean all + rm -rf obj/* $(DEPFILES) diff --git a/cpp/main b/cpp/main new file mode 100755 index 0000000..986080e Binary files /dev/null and b/cpp/main differ diff --git a/cpp/board.cpp b/cpp/src/board.cpp similarity index 100% rename from cpp/board.cpp rename to cpp/src/board.cpp diff --git a/cpp/board.hpp b/cpp/src/board.hpp similarity index 100% rename from cpp/board.hpp rename to cpp/src/board.hpp diff --git a/cpp/main.cpp b/cpp/src/main.cpp similarity index 100% rename from cpp/main.cpp rename to cpp/src/main.cpp diff --git a/cpp/piece.hpp b/cpp/src/piece.hpp similarity index 100% rename from cpp/piece.hpp rename to cpp/src/piece.hpp diff --git a/cpp/stickfosh.cpp b/cpp/src/stickfosh.cpp similarity index 100% rename from cpp/stickfosh.cpp rename to cpp/src/stickfosh.cpp diff --git a/cpp/tests/fen.cpp b/cpp/tests/fen.cpp index a946ad2..6477926 100644 --- a/cpp/tests/fen.cpp +++ b/cpp/tests/fen.cpp @@ -1,4 +1,4 @@ -#include "../board.cpp" +#include "../board.hpp" #include "lib.hpp" int main() { diff --git a/cpp/tests/lib.hpp b/cpp/tests/lib.hpp index 82db6bb..9e2e994 100644 --- a/cpp/tests/lib.hpp +++ b/cpp/tests/lib.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #define ASSERT_EQUALS(expected, actual) \ { \ if (expected != actual) \