created a VERBOSE mode for the Makefile
[physics.git] / src / Makefile
index 4a51706..a2702eb 100644 (file)
@@ -1,14 +1,19 @@
 
-LIBGL = -lGL -lGLU
-LIBSDL = `sdl-config --libs`
-LIBS = ${LIBSDL} ${LIBGL}
+LIBGL := -lGL -lGLU
+LIBSDL := `sdl-config --libs`
+LIBS := ${LIBSDL} ${LIBGL}
+
+OPTFLAGS := -O2
+DBGFLAGS := -ggdb
+PRFFLAGS := ${DBGFLAGS} -pg
+
+#CXX := g++
+CXXFLAGS := -Wall -pedantic -ansi ${DBGFLAGS}
 
-CXX = g++
-CXXFLAGS = -ggdb -Wall -pedantic
 
 SRCS := entityManager.cpp
+SRCS += entityCreator.cpp
 SRCS += game.cpp
-SRCS += graphics.cpp
 SRCS += main.cpp
 SRCS += mathw.cpp
 SRCS += ticks.cpp
@@ -30,42 +35,79 @@ SRCS += GameStates/Running.cpp
 
 SRCS += input/inputManager.cpp
 
-OBJS = ${SRCS:.cpp=.o}
+SRCS += graphics/graphics.cpp
+
+OBJS := ${SRCS:.cpp=.o}
+
 
-TARGET = ../run_physics
-DEPEND = depend.mk
+TARGET := ../run_physics
+DEPENDS := ${SRCS:.cpp=.d}
 
+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}
 
 ${TARGET}: ${OBJS}
-       ${CXX} ${CXXFLAGS} -o ${TARGET} $^ ${LIBS}
+       ${Q1}echo "${CXX}: $@"
+       ${Q2}${CXX} ${CXXFLAGS} -o ${TARGET} $^ ${LIBS}
+
+# how to make a depend file from a source file
+%.d: %.cpp
+       ${Q1}echo "DEP: $@"
+       ${Q2}${CXX} -M ${CXXFLAGS} $< | sed 's,: , $@: ,' > $@
+#@${CXX} -M ${CXXFLAGS} $< | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@
 
-.PHONY: depend
-depend: ${SRCS}
-       ${CXX} -MM $^ > ${DEPEND}
+%.o: %.cpp
+       ${Q1}echo "${CXX}: $@"
+       ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $<
 
 
 .PHONY: clean
 clean:
-       rm -f ${OBJS} ${TARGET} *~
+       ${Q1}echo "CLEAN: OBJS"
+       ${Q2}rm -f ${OBJS}
+       ${Q1}echo "CLEAN: TARGET"
+       ${Q2}rm -f ${TARGET}
 
 .PHONY: distclean
 distclean: clean
-       rm -f tags depend.mk
-       touch depend.mk
+       ${Q1}echo "CLEAN: DEPENDS"
+       ${Q2}rm -f ${DEPENDS}
+       ${Q1}echo "CLEAN: tags prof gmon.out"
+       ${Q2}rm -f tags prof gmon.out
 
 tags: ${SRCS}
        ctags $^
 
 tar: clean
-       cd ..; tar -cjf bluestar.tar.bz2 images/ source/
+       cd ..; tar -cjf physics.tar.bz2 src/
 
 
 .PHONY: run
 run: all
        ${TARGET}
 
-include ${DEPEND}
+.PHONY: val
+val: all
+       valgrind ${TARGET}
+
+.PHONY: prof
+prof: all
+       ${TARGET}
+       gprof -b ${TARGET} > prof
+       kprof -f prof
 
+-include ${DEPENDS}