directory 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
a5aefcc6
PG
9MYFLAGS := -Wall -pedantic -ansi
10CXXFLAGS := ${MYFLAGS} ${DBGFLAGS}
ad9f1fb6 11
88e62c4f
PG
12VALFLAGS := --leak-check=full
13
9d5863c5 14CXX := g++
ad9f1fb6 15
cf116802 16SRCS := # := start
0376f786
PG
17
18DIRS := # := start
e8deb7b6
PG
19DIRS += ./
20DIRS += Entities/
21DIRS += GameStates/
22DIRS += Effects/
23DIRS += config/
24DIRS += input/
25DIRS += graphics/
0376f786
PG
26
27include $(addsuffix /files.mk,${DIRS})
44b079f8 28
f4b779e4 29OBJSDIR := ../objs/
67b5017f
PG
30OBJS := ${SRCS:.cpp=.o}
31OBJS := $(addprefix ${OBJSDIR},${OBJS})
f4b779e4
PG
32
33DEPSDIR := ../deps/
67b5017f
PG
34DEPS := ${SRCS:.cpp=.d}
35DEPS := $(addprefix ${DEPSDIR},${DEPS})
ad9f1fb6 36
9d5863c5
PG
37WORKINGDIR := ../bin/
38TARGETNAME := run_physics
39TARGETTMP := ${OBJSDIR}${TARGETNAME}
40TARGET := ${WORKINGDIR}${TARGETNAME}
41
42BLDDIRS := $(addprefix ${DEPSDIR},${DIRS}) $(addprefix ${OBJSDIR},${DIRS}) ${WORKINGDIR}
42f62a75 43
ad9f1fb6 44
393654cf
PG
45VERBOSE := 0
46
47ifeq (${VERBOSE},0)
48 # quiet the echo command
49 Q1 := @
50 # quiet the command that is `replaced' by an echo
51 Q2 := @
52else
53 # EAT the echo command as if it was not there
54 Q1 := @true # NOTE: the space between @true and the # is VERY important!!
55 # do not quiet the command output
56 Q2 :=
57endif
ad9f1fb6 58
046b034c
PG
59.PHONY: all
60all: ${TARGET}
ad9f1fb6 61
9d5863c5
PG
62# rule to copy tmp target to working directory
63${TARGET}: ${TARGETTMP}
64 ${Q1}echo "cp: $@"
65 ${Q2}cp $^ $@
66
42f62a75 67# how to link the main target
9d5863c5 68${TARGETTMP}: ${OBJS}
393654cf 69 ${Q1}echo "${CXX}: $@"
eb0c55e7 70 ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS}
ad9f1fb6 71
42f62a75
PG
72# how to make a directory
73${BLDDIRS}:
74 ${Q2}mkdir -p $@
75
a4bb9ac2 76# rule to make a depend file from a .cpp
42f62a75 77${DEPSDIR}%.d: %.cpp | ${BLDDIRS}
393654cf 78 ${Q1}echo "DEP: $@"
a68587cf 79 ${Q2}${CXX} -MM ${CXXFLAGS} $< | sed 's,\(^.*\):,${OBJSDIR}\1 $@:,' > $@
ad9f1fb6 80
a4bb9ac2 81# rule to make an object file from a .cpp
42f62a75 82${OBJSDIR}%.o: %.cpp | ${BLDDIRS}
393654cf
PG
83 ${Q1}echo "${CXX}: $@"
84 ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $<
054d658f 85
ad9f1fb6 86
67b5017f
PG
87tags: ${SRCS}
88 ${Q1}echo "ctags: $@"
89 ${Q2}ctags $^
90
91
046b034c 92.PHONY: clean
ad9f1fb6 93clean:
393654cf
PG
94 ${Q1}echo "CLEAN: OBJS"
95 ${Q2}rm -f ${OBJS}
96 ${Q1}echo "CLEAN: TARGET"
97 ${Q2}rm -f ${TARGET}
ad9f1fb6 98
046b034c 99.PHONY: distclean
ad9f1fb6 100distclean: clean
f4b779e4
PG
101 ${Q1}echo "CLEAN: DEPS"
102 ${Q2}rm -f ${DEPS}
393654cf
PG
103 ${Q1}echo "CLEAN: tags prof gmon.out"
104 ${Q2}rm -f tags prof gmon.out
ad9f1fb6 105
d893cce2
PG
106.PHONY: gitclean
107gitclean:
108 ${Q1}echo "git-clean: show, use gitcleanf to force"
109 ${Q2}cd ..; git clean -nxd
110
111.PHONY: gitcleanf
112gitcleanf:
113 ${Q1}echo "git-clean: forced"
114 ${Q2}cd ..; git clean -fxd
115
7adc59fe 116.PHONY: tar
8381f595
PG
117tar: ../physics.tar.bz2
118
119.PHONY: ../physics.tar.bz2
120../physics.tar.bz2:
121 @echo "git-archive: Warning, archives HEAD not current"
a4bb9ac2
PG
122 ${Q1}echo "git-archive: ../physics.tar.bz2"
123 ${Q2}cd ..; git-archive --prefix=physics/ HEAD | bzip2 > physics.tar.bz2
ad9f1fb6 124
046b034c
PG
125.PHONY: run
126run: all
67b5017f 127 cd ${WORKINGDIR}; ./${TARGETNAME}
ad9f1fb6 128
6aad402a
PG
129.PHONY: gdb
130gdb: all
67b5017f
PG
131 cd ${WORKINGDIR}; gdb ${TARGETNAME}
132
133.PHONY: cgdb
134cgdb: all
135 cd ${WORKINGDIR}; cgdb ${TARGETNAME}
6aad402a 136
63a52c99
PG
137.PHONY: val
138val: all
823da4ea 139 cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME}
63a52c99
PG
140
141.PHONY: prof
67b5017f
PG
142prof: run
143 cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > src/prof
63a52c99 144 kprof -f prof
ad9f1fb6 145
9d5863c5
PG
146MINGMAKEARGS := "LIBGL := -lopengl32 -lglu32" \
147 "LIBSDL := `/usr/mingw32/bin/sdl-config --libs`" \
148 "CXXFLAGS := ${OPTFLAGS}" \
149 "CXX := mingw32-g++" \
150 "OBJSDIR := ../objs-mingw32/" \
e8deb7b6 151 "WORKINGDIR := ../bin-mingw32/" \
9d5863c5
PG
152 "TARGETNAME := run_physics.exe"
153
154.PHONY: mingw32
155mingw32:
156 ${Q1}echo "make: mingw32"
157 ${Q2}${MAKE} ${MINGMAKEARGS} clean all
158
f4b779e4 159-include ${DEPS}