more makefile cleaning
[physics.git] / src / Makefile
CommitLineData
ad9f1fb6 1
67b5017f 2LIBGL := -lGL -lGLU
44b079f8 3LIBSDL := `sdl-config --libs`
67b5017f 4LIBS := ${LIBSDL} ${LIBGL}
44b079f8
PG
5
6OPTFLAGS := -O2
7DBGFLAGS := -ggdb
8PRFFLAGS := ${DBGFLAGS} -pg
44b079f8 9CXXFLAGS := -Wall -pedantic -ansi ${DBGFLAGS}
ad9f1fb6 10
88e62c4f
PG
11VALFLAGS := --leak-check=full
12
67b5017f
PG
13WORKINGDIR := ..
14TARGETNAME := run_physics
15TARGET := ${WORKINGDIR}/${TARGETNAME}
ad9f1fb6 16
a4bb9ac2 17SRCS := # simply to keep every line below the same
0376f786
PG
18
19DIRS := # := start
20DIRS += .
21DIRS += Entities
22DIRS += GameStates
23DIRS += Effects
24DIRS += config
25DIRS += input
26DIRS += graphics
27
28include $(addsuffix /files.mk,${DIRS})
44b079f8 29
f4b779e4 30OBJSDIR := ../objs/
67b5017f
PG
31OBJS := ${SRCS:.cpp=.o}
32OBJS := $(addprefix ${OBJSDIR},${OBJS})
f4b779e4
PG
33
34DEPSDIR := ../deps/
67b5017f
PG
35DEPS := ${SRCS:.cpp=.d}
36DEPS := $(addprefix ${DEPSDIR},${DEPS})
ad9f1fb6 37
ad9f1fb6 38
393654cf
PG
39VERBOSE := 0
40
41ifeq (${VERBOSE},0)
42 # quiet the echo command
43 Q1 := @
44 # quiet the command that is `replaced' by an echo
45 Q2 := @
46else
47 # EAT the echo command as if it was not there
48 Q1 := @true # NOTE: the space between @true and the # is VERY important!!
49 # do not quiet the command output
50 Q2 :=
51endif
ad9f1fb6 52
046b034c
PG
53.PHONY: all
54all: ${TARGET}
ad9f1fb6 55
046b034c 56${TARGET}: ${OBJS}
393654cf 57 ${Q1}echo "${CXX}: $@"
eb0c55e7 58 ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS}
ad9f1fb6 59
a4bb9ac2 60# rule to make a depend file from a .cpp
f4b779e4 61${DEPSDIR}%.d: %.cpp
393654cf 62 ${Q1}echo "DEP: $@"
a68587cf 63 ${Q2}${CXX} -MM ${CXXFLAGS} $< | sed 's,\(^.*\):,${OBJSDIR}\1 $@:,' > $@
ad9f1fb6 64
a4bb9ac2 65# rule to make an object file from a .cpp
f4b779e4 66${OBJSDIR}%.o: %.cpp
393654cf
PG
67 ${Q1}echo "${CXX}: $@"
68 ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $<
054d658f 69
ad9f1fb6 70
67b5017f
PG
71tags: ${SRCS}
72 ${Q1}echo "ctags: $@"
73 ${Q2}ctags $^
74
75
046b034c 76.PHONY: clean
ad9f1fb6 77clean:
393654cf
PG
78 ${Q1}echo "CLEAN: OBJS"
79 ${Q2}rm -f ${OBJS}
80 ${Q1}echo "CLEAN: TARGET"
81 ${Q2}rm -f ${TARGET}
ad9f1fb6 82
046b034c 83.PHONY: distclean
ad9f1fb6 84distclean: clean
f4b779e4
PG
85 ${Q1}echo "CLEAN: DEPS"
86 ${Q2}rm -f ${DEPS}
393654cf
PG
87 ${Q1}echo "CLEAN: tags prof gmon.out"
88 ${Q2}rm -f tags prof gmon.out
ad9f1fb6 89
d893cce2
PG
90.PHONY: gitclean
91gitclean:
92 ${Q1}echo "git-clean: show, use gitcleanf to force"
93 ${Q2}cd ..; git clean -nxd
94
95.PHONY: gitcleanf
96gitcleanf:
97 ${Q1}echo "git-clean: forced"
98 ${Q2}cd ..; git clean -fxd
99
7adc59fe 100.PHONY: tar
8381f595
PG
101tar: ../physics.tar.bz2
102
103.PHONY: ../physics.tar.bz2
104../physics.tar.bz2:
105 @echo "git-archive: Warning, archives HEAD not current"
a4bb9ac2
PG
106 ${Q1}echo "git-archive: ../physics.tar.bz2"
107 ${Q2}cd ..; git-archive --prefix=physics/ HEAD | bzip2 > physics.tar.bz2
ad9f1fb6 108
046b034c
PG
109.PHONY: run
110run: all
67b5017f 111 cd ${WORKINGDIR}; ./${TARGETNAME}
ad9f1fb6 112
6aad402a
PG
113.PHONY: gdb
114gdb: all
67b5017f
PG
115 cd ${WORKINGDIR}; gdb ${TARGETNAME}
116
117.PHONY: cgdb
118cgdb: all
119 cd ${WORKINGDIR}; cgdb ${TARGETNAME}
6aad402a 120
63a52c99
PG
121.PHONY: val
122val: all
67b5017f 123 cd ${WORKINGDIR}; valgrind ${VALFLAGS} ${TARGETNAME}
63a52c99
PG
124
125.PHONY: prof
67b5017f
PG
126prof: run
127 cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > src/prof
63a52c99 128 kprof -f prof
ad9f1fb6 129
f4b779e4 130-include ${DEPS}