make clean
[physics.git] / src / Makefile
index 65787c3..d40f145 100644 (file)
@@ -1,7 +1,7 @@
 
-LIBGL := -lGL -lGLU
+LIBGL  := -lGL -lGLU
 LIBSDL := `sdl-config --libs`
-LIBS := ${LIBSDL} ${LIBGL}
+LIBS   := ${LIBSDL} ${LIBGL}
 
 OPTFLAGS := -O2
 DBGFLAGS := -ggdb
@@ -10,62 +10,32 @@ CXXFLAGS := -Wall -pedantic -ansi ${DBGFLAGS}
 
 VALFLAGS := --leak-check=full
 
-TARGET := ../run_physics
+WORKINGDIR  := ..
+TARGETNAME  := run_physics
+TARGET      := ${WORKINGDIR}/${TARGETNAME}
 
-SRCS := # simply to keep every line below the same
-SRCS += game.cpp
-SRCS += main.cpp
-SRCS += mathw.cpp
-SRCS += ticks.cpp
-SRCS += Vector2.cpp
-SRCS += handleSignal.cpp
+SRCS := # := start
 
-SRCS += entityManager.cpp
-SRCS += effectManager.cpp
-SRCS += entityCreator.cpp
-SRCS += collisionHandler.cpp
-SRCS += CollisionInfo.cpp
+DIRS := # := start
+DIRS += .
+DIRS += Entities
+DIRS += GameStates
+DIRS += Effects
+DIRS += config
+DIRS += input
+DIRS += graphics
 
-SRCS += Entities/Ball.cpp
-SRCS += Entities/Entity.cpp
-SRCS += Entities/Line.cpp
-SRCS += Entities/Particle.cpp
-SRCS += Entities/PhysicsEntity.cpp
-SRCS += Entities/Point.cpp
-SRCS += Entities/Polygon.cpp
-SRCS += Entities/WindParticle.cpp
-
-SRCS += GameStates/CreatingPolygon.cpp
-SRCS += GameStates/GameState.cpp
-SRCS += GameStates/Paused.cpp
-SRCS += GameStates/Running.cpp
-
-SRCS += Effects/Effect.cpp
-SRCS += Effects/Gravity.cpp
-SRCS += Effects/GravityWell.cpp
-SRCS += Effects/Screen.cpp
-
-SRCS += config/config.cpp
-
-SRCS += input/inputManager.cpp
-
-SRCS += graphics/graphics.cpp
+include $(addsuffix /files.mk,${DIRS})
 
 OBJSDIR := ../objs/
-OBJS := ${SRCS:.cpp=.o}
-OBJS := $(addprefix ${OBJSDIR},${OBJS})
+OBJS    := ${SRCS:.cpp=.o}
+OBJS    := $(addprefix ${OBJSDIR},${OBJS})
 
 DEPSDIR := ../deps/
-DEPS := ${SRCS:.cpp=.d}
-DEPS := $(addprefix ${DEPSDIR},${DEPS})
-
-HRDS := ${SRCS:.cpp=.h}
-HRDS := $(filter-out main.h,$HRDS) # remove main.h
-HRDS += debug.h
-
-HRDS += graphics/colors.h
+DEPS    := ${SRCS:.cpp=.d}
+DEPS    := $(addprefix ${DEPSDIR},${DEPS})
 
-TARS := ${SRCS} ${HRDS} Makefile
+BLDDIRS := $(addprefix ${DEPSDIR},${DIRS}) $(addprefix ${OBJSDIR},${DIRS})
 
 
 VERBOSE := 0
@@ -85,21 +55,31 @@ endif
 .PHONY: all
 all: ${TARGET}
 
+# how to link the main target
 ${TARGET}: ${OBJS}
        ${Q1}echo "${CXX}: $@"
        ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS}
 
+# how to make a directory
+${BLDDIRS}:
+       ${Q2}mkdir -p $@
+
 # rule to make a depend file from a .cpp
-${DEPSDIR}%.d: %.cpp
+${DEPSDIR}%.d: %.cpp | ${BLDDIRS}
        ${Q1}echo "DEP: $@"
-       ${Q2}${CXX} -M ${CXXFLAGS} $< | sed 's,: , $@: ,' > $@
+       ${Q2}${CXX} -MM ${CXXFLAGS} $< | sed 's,\(^.*\):,${OBJSDIR}\1 $@:,' > $@
 
 # rule to make an object file from a .cpp
-${OBJSDIR}%.o: %.cpp
+${OBJSDIR}%.o: %.cpp | ${BLDDIRS}
        ${Q1}echo "${CXX}: $@"
        ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $<
 
 
+tags: ${SRCS}
+       ${Q1}echo "ctags: $@"
+       ${Q2}ctags $^
+
+
 .PHONY: clean
 clean:
        ${Q1}echo "CLEAN: OBJS"
@@ -124,9 +104,6 @@ gitcleanf:
        ${Q1}echo "git-clean: forced"
        ${Q2}cd ..; git clean -fxd
 
-tags: ${SRCS}
-       ctags $^
-
 .PHONY: tar
 tar: ../physics.tar.bz2
 
@@ -138,20 +115,23 @@ tar: ../physics.tar.bz2
 
 .PHONY: run
 run: all
-       ${TARGET}
+       cd ${WORKINGDIR}; ./${TARGETNAME}
 
 .PHONY: gdb
 gdb: all
-       gdb ${TARGET}
+       cd ${WORKINGDIR}; gdb ${TARGETNAME}
+
+.PHONY: cgdb
+cgdb: all
+       cd ${WORKINGDIR}; cgdb ${TARGETNAME}
 
 .PHONY: val
 val: all
-       valgrind ${VALFLAGS} ${TARGET}
+       cd ${WORKINGDIR}; valgrind ${VALFLAGS} ${TARGETNAME}
 
 .PHONY: prof
-prof: all
-       ${TARGET}
-       gprof -b ${TARGET} > prof
+prof: run
+       cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > src/prof
        kprof -f prof
 
 -include ${DEPS}