removed some dirty physics hacks
[physics.git] / Makefile
CommitLineData
ad9f1fb6 1
26010c4e
PG
2# set this on the command line to get a WIN32 or a FINAL build
3BUILD := DEBUG
d6897213 4
d6897213 5
26010c4e 6ifeq (${BUILD},WIN32)
d6897213
PG
7 LIBGL := -lopengl32 -lglu32
8 LIBSDL := `/usr/mingw32/bin/sdl-config --libs`
9else
10 LIBGL := -lGL -lGLU
11 LIBSDL := `sdl-config --libs`
12endif
5e0713e5 13LIBMY := -lbear
41379c9c 14LIBS := ${LIBSDL} ${LIBGL} ${LIBMY}
44b079f8
PG
15
16OPTFLAGS := -O2
17DBGFLAGS := -ggdb
18PRFFLAGS := ${DBGFLAGS} -pg
a5aefcc6 19MYFLAGS := -Wall -pedantic -ansi
ad9f1fb6 20
00820fda
PG
21RPATH := libs/
22
88e62c4f 23VALFLAGS := --leak-check=full
00820fda 24LNKFLAGS := -Wl,-rpath,${RPATH}
88e62c4f 25
26010c4e
PG
26ifeq (${BUILD},WIN32)
27 CXXFLAGS := ${MYFLAGS} ${OPTFLAGS}
bb552d93 28else
26010c4e
PG
29ifeq (${BUILD},FINAL)
30 CXXFLAGS := ${MYFLAGS} ${OPTFLAGS}
d6897213
PG
31else
32 CXXFLAGS := ${MYFLAGS} ${DBGFLAGS}
33endif
bb552d93 34endif
88e62c4f 35
26010c4e 36ifeq (${BUILD},WIN32)
d6897213
PG
37 CXX := mingw32-g++
38else
39 CXX := g++
40endif
ad9f1fb6 41
00820fda 42DIRS := # := start
0376f786 43
ec424960
PG
44SRCSDIR := src/
45SRCS := # := start
44b079f8 46
26010c4e 47ifeq (${BUILD},WIN32)
d6897213 48 OBJSDIR := objs-mingw32/
bb552d93 49else
26010c4e 50ifeq (${BUILD},FINAL)
d6897213
PG
51 OBJSDIR := objs/
52else
53 OBJSDIR := objsd/
54endif
bb552d93 55endif
d6897213 56OBJS := # := start
16f14459
PG
57
58DEPSDIR := deps/
59DEPS := # := start
60
70468808 61# include all of the dir.mk
07af3cf8
PG
62DIRMK := dir.mk
63include ${SRCSDIR}${DIRMK}
869b3330 64
26010c4e 65ifeq (${BUILD},WIN32)
d6897213 66 WORKINGDIR := bin-mingw32/
bb552d93 67else
26010c4e 68ifeq (${BUILD},FINAL)
d6897213
PG
69 WORKINGDIR := bin/
70else
71 WORKINGDIR := bind/
72endif
bb552d93 73endif
ec424960 74
47b9b09e
PG
75CFGDIRNAME := configs/
76SRCCFGDIR := ${CFGDIRNAME}
77DSTCFGDIR := ${WORKINGDIR}${CFGDIRNAME}
869b3330
PG
78
79CFGS := # := start
80CFGS += keys.cfg
81CFGS := $(addprefix ${DSTCFGDIR},${CFGS})
82
00820fda
PG
83LIBSDIRNAME := libs/
84SRCLIBSDIR := ${LIBSDIRNAME}
26010c4e 85ifeq (${BUILD},WIN32)
5ab56236
PG
86 DSTLIBSDIR := ${WORKINGDIR}
87else
88 DSTLIBSDIR := ${WORKINGDIR}${LIBSDIRNAME}
89endif
47b9b09e 90
bcd46b8f
PG
91LIBSTXT := # := start
92LIBSTXT += COPYING-SDL
93LIBSTXT += README-SDL
94LIBSTXT += VERSION-SDL
95LIBSTXT := $(addprefix ${DSTLIBSDIR},${LIBSTXT})
47b9b09e 96
bcd46b8f 97LIBSCPY := # := start
26010c4e 98ifeq (${BUILD},WIN32)
d6897213 99 LIBSCPY += SDL.dll
5e0713e5 100 LIBSCPY += bear.dll
d6897213 101else
41379c9c 102 LIBSCPY += libSDL-1.2.so.0
5e0713e5 103 LIBSCPY += libbear.so.0
d6897213 104endif
bcd46b8f
PG
105LIBSCPY := $(addprefix ${DSTLIBSDIR},${LIBSCPY})
106
107SRCTXTDIR :=
108DSTTXTDIR := ${WORKINGDIR}
109
110TXT := # := start
111TXT += COPYING
112TXT := $(addprefix ${DSTTXTDIR},${TXT})
47b9b09e 113
26010c4e 114ifeq (${BUILD},WIN32)
d6897213
PG
115 TARGETNAME := run_physics.exe
116else
117 TARGETNAME := run_physics
118endif
9d5863c5 119TARGETTMP := ${OBJSDIR}${TARGETNAME}
ec424960 120TARGET := ${WORKINGDIR}${TARGETNAME}
9d5863c5 121
07af3cf8
PG
122DEPSBLDDIRS := ${DEPSDIR} $(addprefix ${DEPSDIR},${DIRS})
123OBJSBLDDIRS := ${OBJSDIR} $(addprefix ${OBJSDIR},${DIRS})
00820fda
PG
124
125BLDDIRS := # := start
126BLDDIRS += ${OBJSBLDDIRS}
127BLDDIRS += ${DEPSBLDDIRS}
128BLDDIRS += ${WORKINGDIR}
129BLDDIRS += ${DSTCFGDIR}
130BLDDIRS += ${DSTLIBSDIR}
5ab56236 131BLDDIRS := $(sort ${BLDDIRS}) # remove possible duplicates
42f62a75 132
3d1f0813 133INCDIRS := ${SRCSDIR}
f5380bc6 134INCFLAGS := $(addprefix -I, ${INCDIRS})
3d1f0813 135
ad9f1fb6 136
26010c4e 137ifeq (${BUILD},WIN32)
5ab56236
PG
138 PRNTFMT := printf "%-12s: %s\n"
139else
140 PRNTFMT := printf "%-8s: %s\n"
141endif
70468808 142
393654cf
PG
143VERBOSE := 0
144
145ifeq (${VERBOSE},0)
07af3cf8 146 # quiet the printf command
393654cf
PG
147 Q1 := @
148 # quiet the command that is `replaced' by an echo
149 Q2 := @
150else
07af3cf8 151 # EAT the printf command as if it was not there
393654cf
PG
152 Q1 := @true # NOTE: the space between @true and the # is VERY important!!
153 # do not quiet the command output
154 Q2 :=
155endif
ad9f1fb6 156
046b034c 157.PHONY: all
bcd46b8f 158all: ${TARGET} ${CFGS} ${LIBSTXT} ${LIBSCPY} ${TXT}
47b9b09e
PG
159
160# cause the fancy $$ directory rules to work out
161.SECONDEXPANSION:
37a74d97 162
869b3330
PG
163# how to link the main target
164${TARGETTMP}: ${OBJS}
bf7e6563 165 ${Q1}${PRNTFMT} "${CXX}" "$@"
00820fda 166 ${Q2}${CXX} ${CXXFLAGS} ${LNKFLAGS} -o $@ $^ ${LIBS}
ad9f1fb6 167
9d5863c5 168# rule to copy tmp target to working directory
ebea1138 169${TARGET}: ${TARGETTMP} | ${WORKINGDIR}
bf7e6563 170 ${Q1}${PRNTFMT} "cp" "$@"
37a74d97 171 ${Q2}cp $< $@
9d5863c5 172
47b9b09e 173# rule to copy the config files into the working directory
bcd46b8f 174${DSTCFGDIR}%: ${SRCCFGDIR}% | $$(dir $$@)
47b9b09e
PG
175 ${Q1}${PRNTFMT} "cp" "$@"
176 ${Q2}cp $< $@
177
178# rule to copy the library files into the working directory
179${DSTLIBSDIR}%: ${SRCLIBSDIR}% | $$(dir $$@)
180 ${Q1}${PRNTFMT} "cp" "$@"
181 ${Q2}cp $< $@
182
bcd46b8f
PG
183# rule to copy the library files into the working directory
184${DSTTXTDIR}%: ${SRCTXTDIR}% | $$(dir $$@)
185 ${Q1}${PRNTFMT} "cp" "$@"
186 ${Q2}cp $< $@
187
42f62a75
PG
188# how to make a directory
189${BLDDIRS}:
2688190c 190 ${Q1}${PRNTFMT} "mkdir" "$@"
42f62a75
PG
191 ${Q2}mkdir -p $@
192
869b3330 193# rule to make an object file from a .cpp
2688190c 194${OBJSDIR}%.o: ${SRCSDIR}%.cpp | $$(dir $$@)
bf7e6563 195 ${Q1}${PRNTFMT} "${CXX}" "$@"
f5380bc6 196 ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $< ${INCFLAGS}
869b3330 197
a4bb9ac2 198# rule to make a depend file from a .cpp
5f264bf7
PG
199# be clever and escape the / chars in file paths
200# DON'T simply use another sed delimiter or it can't appear in the file paths
2688190c 201${DEPSDIR}%.d: ${SRCSDIR}%.cpp | $$(dir $$@)
bf7e6563 202 ${Q1}${PRNTFMT} "DEP" "$@"
f5380bc6 203 ${Q2}${CXX} -MM ${CXXFLAGS} $< ${INCFLAGS} | \
5f264bf7 204 sed 's/\(^.*\):/$(subst /,\/,${OBJSDIR}\1 $@):/' > $@
ad9f1fb6 205
d6897213
PG
206CLEANCMDS := cleanbin cleanobjs cleandeps clean cleanall
207
47b9b09e
PG
208.PHONY: cleanbin
209cleanbin:
210 ${Q1}${PRNTFMT} "rm" "${WORKINGDIR}"
211 ${Q2}rm -rf ${WORKINGDIR}
212
4537196f
PG
213.PHONY: cleanobjs
214cleanobjs:
70468808
PG
215 ${Q1}${PRNTFMT} "rm" "${OBJSDIR}"
216 ${Q2}rm -rf ${OBJSDIR}
ad9f1fb6 217
4537196f
PG
218.PHONY: cleandeps
219cleandeps:
70468808
PG
220 ${Q1}${PRNTFMT} "rm" "${DEPSDIR}"
221 ${Q2}rm -rf ${DEPSDIR}
4537196f
PG
222
223.PHONY: clean
47b9b09e 224clean: cleanobjs
d6897213
PG
225 ${Q1}${PRNTFMT} "rm" "${TARGET}"
226 ${Q2}rm -rf ${TARGET}
4537196f
PG
227
228.PHONY: cleanall
47b9b09e 229cleanall: clean cleanbin cleandeps
ad9f1fb6 230
d893cce2
PG
231.PHONY: gitclean
232gitclean:
bf7e6563 233 ${Q1}${PRNTFMT} "git clean" "showing; use gitcleanf to force removal"
5f264bf7 234 ${Q2}git clean -nxd
d893cce2
PG
235
236.PHONY: gitcleanf
237gitcleanf:
bf7e6563 238 ${Q1}${PRNTFMT} "git clean" "forcing"
5f264bf7 239 ${Q2}git clean -fxd
d893cce2 240
7adc59fe 241.PHONY: tar
5f264bf7 242tar: physics.tar.bz2
8381f595 243
5f264bf7
PG
244.PHONY: physics.tar.bz2
245physics.tar.bz2:
bf7e6563
PG
246 @${PRNTFMT} "git archive" "Warning, archives HEAD not current"
247 ${Q1}${PRNTFMT} "git archive" "physics.tar.bz2"
248 ${Q2}git archive --prefix=physics/ HEAD | bzip2 > physics.tar.bz2
ad9f1fb6 249
046b034c
PG
250.PHONY: run
251run: all
d6897213
PG
252ifeq (${WIN32},1)
253 cd ${WORKINGDIR}; wine ${TARGETNAME}
254else
67b5017f 255 cd ${WORKINGDIR}; ./${TARGETNAME}
d6897213 256endif
ad9f1fb6 257
6aad402a
PG
258.PHONY: gdb
259gdb: all
67b5017f
PG
260 cd ${WORKINGDIR}; gdb ${TARGETNAME}
261
262.PHONY: cgdb
263cgdb: all
264 cd ${WORKINGDIR}; cgdb ${TARGETNAME}
6aad402a 265
63a52c99
PG
266.PHONY: val
267val: all
823da4ea 268 cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME}
63a52c99
PG
269
270.PHONY: prof
67b5017f 271prof: run
06699cc7
PG
272 cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > prof
273 cd ${WORKINGDIR}; kprof -f prof
ad9f1fb6 274
4e77f48b 275
d6897213
PG
276# Do not include deps files when doing a _single_ clean operation
277ifeq ($(findstring ${MAKECMDGOALS},${CLEANCMDS}),)
278 -include ${DEPS}
279endif