cleaning of the Makefile
[physics.git] / src / Makefile
index 7ef5006..b9dc85d 100644 (file)
 
-LIBGL = -lGL -lGLU
-LIBSDL = `sdl-config --libs`
-LIBS = ${LIBSDL} ${LIBGL}
+LIBGL  := -lGL -lGLU
+LIBSDL := `sdl-config --libs`
+LIBS   := ${LIBSDL} ${LIBGL}
 
-CXX = g++
-CXXFLAGS = -ggdb -Wall -pedantic
+OPTFLAGS := -O2
+DBGFLAGS := -ggdb
+PRFFLAGS := ${DBGFLAGS} -pg
+MYFLAGS  := -Wall -pedantic -ansi
 
-SRCS := entityManager.cpp
-SRCS += game.cpp
-SRCS += graphics.cpp
-SRCS += main.cpp
-SRCS += mathw.cpp
-SRCS += ticks.cpp
-SRCS += Vector2.cpp
+VALFLAGS := --leak-check=full
+CXXFLAGS := ${MYFLAGS} ${DBGFLAGS}
 
-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
+CXX := g++
 
-SRCS += GameStates/CreatingPolygon.cpp
-SRCS += GameStates/GameState.cpp
-SRCS += GameStates/Paused.cpp
-SRCS += GameStates/Running.cpp
+DIRS := # := start
+DIRS += ./
+DIRS += Entities/
+DIRS += GameStates/
+DIRS += Effects/
+DIRS += config/
+DIRS += input/
+DIRS += graphics/
 
-OBJS = ${SRCS:.cpp=.o}
+SRCS := # := start
+include $(addsuffix /files.mk,${DIRS})
 
-TARGET = ../run_physics
-DEPEND = depend.mk
+WORKINGDIR  := ../bin/
 
+OBJSDIR := ../objs/
+OBJS    := ${SRCS:.cpp=.o}
+OBJS    := $(addprefix ${OBJSDIR},${OBJS})
+
+DEPSDIR := ../deps/
+DEPS    := ${SRCS:.cpp=.d}
+DEPS    := $(addprefix ${DEPSDIR},${DEPS})
+
+CFGDIRNAME := configs/
+SRCCFGDIR  := ../${CFGDIRNAME}
+DSTCFGDIR  := ${WORKINGDIR}${CFGDIRNAME}
+
+CFGS := # := start
+CFGS += keys.cfg
+CFGS := $(addprefix ${DSTCFGDIR},${CFGS})
+
+TARGETNAME  := run_physics
+TARGETTMP   := ${OBJSDIR}${TARGETNAME}
+TARGET                 := ${WORKINGDIR}${TARGETNAME}
+
+DEPSBLDDIRS := $(addprefix ${DEPSDIR},${DIRS})
+OBJSBLDDIRS := $(addprefix ${OBJSDIR},${DIRS})
+BLDDIRS     := ${OBJSBLDDIRS} ${DEPSBLDDIRS} ${WORKINGDIR} ${DSTCFGDIR}
+
+
+VERBOSE := 0
+
+ifeq (${VERBOSE},0)
+    # quiet the echo command
+    Q1 := @
+    # quiet the command that is `replaced' by an echo
+    Q2 := @
+else
+    # EAT the echo command as if it was not there
+    Q1 := @true # NOTE: the space between @true and the # is VERY important!!
+    # do not quiet the command output
+    Q2 :=
+endif
 
 .PHONY: all
-all: ${TARGET}
+all: ${TARGET} ${CFGS}
 
-${TARGET}: ${OBJS}
-       ${CXX} ${CXXFLAGS} -o ${TARGET} $^ ${LIBS}
+# how to link the main target
+${TARGETTMP}: ${OBJS}
+       ${Q1}echo "${CXX}: $@"
+       ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS}
 
-.PHONY: depend
-depend: ${SRCS}
-       ${CXX} -MM $^ > ${DEPEND}
+# rule to copy tmp target to working directory
+${TARGET}: ${TARGETTMP} | ${WORKINGDIR}
+       ${Q1}echo "cp: $@"
+       ${Q2}cp $< $@
 
+# how to make a directory
+${BLDDIRS}:
+       ${Q2}mkdir -p $@
 
-.PHONY: clean
-clean:
-       rm -f ${OBJS} ${TARGET} *~
+# rule to make an object file from a .cpp
+${OBJSDIR}%.o: %.cpp | ${OBJSBLDDIRS}
+       ${Q1}echo "${CXX}: $@"
+       ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $<
+
+# rule to make a depend file from a .cpp
+${DEPSDIR}%.d: %.cpp | ${DEPSBLDDIRS}
+       ${Q1}echo "DEP: $@"
+       ${Q2}${CXX} -MM ${CXXFLAGS} $< | sed 's,\(^.*\):,${OBJSDIR}\1 $@:,' > $@
+
+# rule to copy the config files into the working directory
+${DSTCFGDIR}%.cfg: ${SRCCFGDIR}%.cfg | ${DSTCFGDIR}
+       ${Q1}echo "cp: $@"
+       ${Q2}cp $< $@
 
-.PHONY: distclean
-distclean: clean
-       rm -f tags depend.mk
-       touch depend.mk
 
 tags: ${SRCS}
-       ctags $^
+       ${Q1}echo "ctags: $@"
+       ${Q2}ctags $^
 
-tar: clean
-       cd ..; tar -cjf bluestar.tar.bz2 images/ source/
 
+.PHONY: clean
+clean:
+       ${Q1}echo "CLEAN: OBJS"
+       ${Q2}rm -f ${OBJS}
+       ${Q1}echo "CLEAN: TARGET"
+       ${Q2}rm -f ${TARGET}
+
+.PHONY: distclean
+distclean: clean
+       ${Q1}echo "CLEAN: DEPS"
+       ${Q2}rm -f ${DEPS}
+       ${Q1}echo "CLEAN: tags prof gmon.out"
+       ${Q2}rm -f tags prof gmon.out
+
+.PHONY: gitclean
+gitclean:
+       ${Q1}echo "git-clean: show, use gitcleanf to force"
+       ${Q2}cd ..; git clean -nxd
+
+.PHONY: gitcleanf
+gitcleanf:
+       ${Q1}echo "git-clean: forced"
+       ${Q2}cd ..; git clean -fxd
+
+.PHONY: tar
+tar: ../physics.tar.bz2
+
+.PHONY: ../physics.tar.bz2
+../physics.tar.bz2:
+       @echo "git-archive: Warning, archives HEAD not current"
+       ${Q1}echo "git-archive: ../physics.tar.bz2"
+       ${Q2}cd ..; git-archive --prefix=physics/ HEAD | bzip2 > physics.tar.bz2
 
 .PHONY: run
 run: all
-       ${TARGET}
-
-include ${DEPEND}
-
+       cd ${WORKINGDIR}; ./${TARGETNAME}
+
+.PHONY: gdb
+gdb: all
+       cd ${WORKINGDIR}; gdb ${TARGETNAME}
+
+.PHONY: cgdb
+cgdb: all
+       cd ${WORKINGDIR}; cgdb ${TARGETNAME}
+
+.PHONY: val
+val: all
+       cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME}
+
+.PHONY: prof
+prof: run
+       cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > src/prof
+       kprof -f prof
+
+MINGMAKEARGS := "LIBGL      := -lopengl32 -lglu32" \
+                "LIBSDL     := `/usr/mingw32/bin/sdl-config --libs`" \
+                "CXXFLAGS   := ${OPTFLAGS}" \
+                "CXX        := mingw32-g++" \
+                "OBJSDIR    := ../objs-mingw32/" \
+                "WORKINGDIR := ../bin-mingw32/" \
+                "TARGETNAME := run_physics.exe"
+
+.PHONY: mingw32
+mingw32:
+       ${Q1}echo "make: mingw32"
+       ${Q2}${MAKE} ${MINGMAKEARGS} clean all
+
+-include ${DEPS}