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