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