I've been working on a small game written entirely in C++ using SDL for graphics and audio. Until now all of my source files and headers have been located in the same directory as my executable, but I would like to move these to a ./src and an ./include folder.
However, I am really struggling with makefile syntax and how I would tell the compiler where to find the source and header files.
How can I tell the makefile to find source/headers/objects in subdirectories? Any improvements/mistakes for my makefile?
Here is my current makefile:
OBJS = main.o Window.o Entity.o Player.o Tile.o BoundingBox.o\
MapReader.o Button.o Zombie.o Projectile.o Pathfinder.o
CPP = g++
CPPFLAGS = -c -g
LDFLAGS = -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -mwindows
ZombieAttack: $(OBJS)
$(CPP) -o ZombieAttack $(OBJS) $(LDFLAGS)
main.o: main.cpp
$(CPP) $(CPPFLAGS) main.cpp
Window.o: Window.cpp
$(CPP) $(CPPFLAGS) Window.cpp
Entity.o: Entity.cpp
$(CPP) $(CPPFLAGS) Entity.cpp
Player.o: Player.cpp
$(CPP) $(CPPFLAGS) Player.cpp
Tile.o: Tile.cpp
$(CPP) $(CPPFLAGS) Tile.cpp
BoundingBox.o: BoundingBox.cpp
$(CPP) $(CPPFLAGS) BoundingBox.cpp
MapReader.o: MapReader.cpp
$(CPP) $(CPPFLAGS) MapReader.cpp
Button.o: Button.cpp
$(CPP) $(CPPFLAGS) Button.cpp
Zombie.o: Zombie.cpp
$(CPP) $(CPPFLAGS) Zombie.cpp
Projectile.o: Projectile.cpp
$(CPP) $(CPPFLAGS) Projectile.cpp
Pathfinder.o: Pathfinder.cpp
$(CPP) $(CPPFLAGS) Pathfinder.cpp
clean:
del *.o
I am using mingw for compilation and mingw32-make