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} | |
88 | DSTLIBSDIR := ${WORKINGDIR}${LIBSDIRNAME} | |
47b9b09e | 89 | |
bcd46b8f PG |
90 | LIBSTXT := # := start |
91 | LIBSTXT += COPYING-SDL | |
92 | LIBSTXT += README-SDL | |
93 | LIBSTXT += VERSION-SDL | |
94 | LIBSTXT := $(addprefix ${DSTLIBSDIR},${LIBSTXT}) | |
47b9b09e | 95 | |
bcd46b8f | 96 | LIBSCPY := # := start |
d6897213 PG |
97 | ifeq (${WIN32},1) |
98 | LIBSCPY += SDL.dll | |
99 | else | |
41379c9c PG |
100 | LIBSCPY += libSDL-1.2.so.0 |
101 | LIBSCPY += libpg.so.0 | |
d6897213 | 102 | endif |
bcd46b8f PG |
103 | LIBSCPY := $(addprefix ${DSTLIBSDIR},${LIBSCPY}) |
104 | ||
105 | SRCTXTDIR := | |
106 | DSTTXTDIR := ${WORKINGDIR} | |
107 | ||
108 | TXT := # := start | |
109 | TXT += COPYING | |
110 | TXT := $(addprefix ${DSTTXTDIR},${TXT}) | |
47b9b09e | 111 | |
d6897213 PG |
112 | ifeq (${WIN32},1) |
113 | TARGETNAME := run_physics.exe | |
114 | else | |
115 | TARGETNAME := run_physics | |
116 | endif | |
9d5863c5 | 117 | TARGETTMP := ${OBJSDIR}${TARGETNAME} |
ec424960 | 118 | TARGET := ${WORKINGDIR}${TARGETNAME} |
9d5863c5 | 119 | |
07af3cf8 PG |
120 | DEPSBLDDIRS := ${DEPSDIR} $(addprefix ${DEPSDIR},${DIRS}) |
121 | OBJSBLDDIRS := ${OBJSDIR} $(addprefix ${OBJSDIR},${DIRS}) | |
00820fda PG |
122 | |
123 | BLDDIRS := # := start | |
124 | BLDDIRS += ${OBJSBLDDIRS} | |
125 | BLDDIRS += ${DEPSBLDDIRS} | |
126 | BLDDIRS += ${WORKINGDIR} | |
127 | BLDDIRS += ${DSTCFGDIR} | |
128 | BLDDIRS += ${DSTLIBSDIR} | |
42f62a75 | 129 | |
3d1f0813 | 130 | INCDIRS := ${SRCSDIR} |
f5380bc6 | 131 | INCFLAGS := $(addprefix -I, ${INCDIRS}) |
3d1f0813 | 132 | |
ad9f1fb6 | 133 | |
70468808 PG |
134 | PRNTFMT := printf "%-5s: %s\n" |
135 | ||
393654cf PG |
136 | VERBOSE := 0 |
137 | ||
138 | ifeq (${VERBOSE},0) | |
07af3cf8 | 139 | # quiet the printf command |
393654cf PG |
140 | Q1 := @ |
141 | # quiet the command that is `replaced' by an echo | |
142 | Q2 := @ | |
143 | else | |
07af3cf8 | 144 | # EAT the printf command as if it was not there |
393654cf PG |
145 | Q1 := @true # NOTE: the space between @true and the # is VERY important!! |
146 | # do not quiet the command output | |
147 | Q2 := | |
148 | endif | |
ad9f1fb6 | 149 | |
046b034c | 150 | .PHONY: all |
bcd46b8f | 151 | all: ${TARGET} ${CFGS} ${LIBSTXT} ${LIBSCPY} ${TXT} |
47b9b09e PG |
152 | |
153 | # cause the fancy $$ directory rules to work out | |
154 | .SECONDEXPANSION: | |
37a74d97 | 155 | |
869b3330 PG |
156 | # how to link the main target |
157 | ${TARGETTMP}: ${OBJS} | |
bf7e6563 | 158 | ${Q1}${PRNTFMT} "${CXX}" "$@" |
00820fda | 159 | ${Q2}${CXX} ${CXXFLAGS} ${LNKFLAGS} -o $@ $^ ${LIBS} |
ad9f1fb6 | 160 | |
9d5863c5 | 161 | # rule to copy tmp target to working directory |
ebea1138 | 162 | ${TARGET}: ${TARGETTMP} | ${WORKINGDIR} |
bf7e6563 | 163 | ${Q1}${PRNTFMT} "cp" "$@" |
37a74d97 | 164 | ${Q2}cp $< $@ |
9d5863c5 | 165 | |
47b9b09e | 166 | # rule to copy the config files into the working directory |
bcd46b8f | 167 | ${DSTCFGDIR}%: ${SRCCFGDIR}% | $$(dir $$@) |
47b9b09e PG |
168 | ${Q1}${PRNTFMT} "cp" "$@" |
169 | ${Q2}cp $< $@ | |
170 | ||
171 | # rule to copy the library files into the working directory | |
172 | ${DSTLIBSDIR}%: ${SRCLIBSDIR}% | $$(dir $$@) | |
173 | ${Q1}${PRNTFMT} "cp" "$@" | |
174 | ${Q2}cp $< $@ | |
175 | ||
bcd46b8f PG |
176 | # rule to copy the library files into the working directory |
177 | ${DSTTXTDIR}%: ${SRCTXTDIR}% | $$(dir $$@) | |
178 | ${Q1}${PRNTFMT} "cp" "$@" | |
179 | ${Q2}cp $< $@ | |
180 | ||
42f62a75 PG |
181 | # how to make a directory |
182 | ${BLDDIRS}: | |
2688190c | 183 | ${Q1}${PRNTFMT} "mkdir" "$@" |
42f62a75 PG |
184 | ${Q2}mkdir -p $@ |
185 | ||
869b3330 | 186 | # rule to make an object file from a .cpp |
2688190c | 187 | ${OBJSDIR}%.o: ${SRCSDIR}%.cpp | $$(dir $$@) |
bf7e6563 | 188 | ${Q1}${PRNTFMT} "${CXX}" "$@" |
f5380bc6 | 189 | ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $< ${INCFLAGS} |
869b3330 | 190 | |
a4bb9ac2 | 191 | # rule to make a depend file from a .cpp |
5f264bf7 PG |
192 | # be clever and escape the / chars in file paths |
193 | # DON'T simply use another sed delimiter or it can't appear in the file paths | |
2688190c | 194 | ${DEPSDIR}%.d: ${SRCSDIR}%.cpp | $$(dir $$@) |
bf7e6563 | 195 | ${Q1}${PRNTFMT} "DEP" "$@" |
f5380bc6 | 196 | ${Q2}${CXX} -MM ${CXXFLAGS} $< ${INCFLAGS} | \ |
5f264bf7 | 197 | sed 's/\(^.*\):/$(subst /,\/,${OBJSDIR}\1 $@):/' > $@ |
ad9f1fb6 | 198 | |
d6897213 PG |
199 | CLEANCMDS := cleanbin cleanobjs cleandeps clean cleanall |
200 | ||
47b9b09e PG |
201 | .PHONY: cleanbin |
202 | cleanbin: | |
203 | ${Q1}${PRNTFMT} "rm" "${WORKINGDIR}" | |
204 | ${Q2}rm -rf ${WORKINGDIR} | |
205 | ||
4537196f PG |
206 | .PHONY: cleanobjs |
207 | cleanobjs: | |
70468808 PG |
208 | ${Q1}${PRNTFMT} "rm" "${OBJSDIR}" |
209 | ${Q2}rm -rf ${OBJSDIR} | |
ad9f1fb6 | 210 | |
4537196f PG |
211 | .PHONY: cleandeps |
212 | cleandeps: | |
70468808 PG |
213 | ${Q1}${PRNTFMT} "rm" "${DEPSDIR}" |
214 | ${Q2}rm -rf ${DEPSDIR} | |
4537196f PG |
215 | |
216 | .PHONY: clean | |
47b9b09e | 217 | clean: cleanobjs |
d6897213 PG |
218 | ${Q1}${PRNTFMT} "rm" "${TARGET}" |
219 | ${Q2}rm -rf ${TARGET} | |
4537196f PG |
220 | |
221 | .PHONY: cleanall | |
47b9b09e | 222 | cleanall: clean cleanbin cleandeps |
ad9f1fb6 | 223 | |
d893cce2 PG |
224 | .PHONY: gitclean |
225 | gitclean: | |
bf7e6563 | 226 | ${Q1}${PRNTFMT} "git clean" "showing; use gitcleanf to force removal" |
5f264bf7 | 227 | ${Q2}git clean -nxd |
d893cce2 PG |
228 | |
229 | .PHONY: gitcleanf | |
230 | gitcleanf: | |
bf7e6563 | 231 | ${Q1}${PRNTFMT} "git clean" "forcing" |
5f264bf7 | 232 | ${Q2}git clean -fxd |
d893cce2 | 233 | |
7adc59fe | 234 | .PHONY: tar |
5f264bf7 | 235 | tar: physics.tar.bz2 |
8381f595 | 236 | |
5f264bf7 PG |
237 | .PHONY: physics.tar.bz2 |
238 | physics.tar.bz2: | |
bf7e6563 PG |
239 | @${PRNTFMT} "git archive" "Warning, archives HEAD not current" |
240 | ${Q1}${PRNTFMT} "git archive" "physics.tar.bz2" | |
241 | ${Q2}git archive --prefix=physics/ HEAD | bzip2 > physics.tar.bz2 | |
ad9f1fb6 | 242 | |
046b034c PG |
243 | .PHONY: run |
244 | run: all | |
d6897213 PG |
245 | ifeq (${WIN32},1) |
246 | cd ${WORKINGDIR}; wine ${TARGETNAME} | |
247 | else | |
67b5017f | 248 | cd ${WORKINGDIR}; ./${TARGETNAME} |
d6897213 | 249 | endif |
ad9f1fb6 | 250 | |
6aad402a PG |
251 | .PHONY: gdb |
252 | gdb: all | |
67b5017f PG |
253 | cd ${WORKINGDIR}; gdb ${TARGETNAME} |
254 | ||
255 | .PHONY: cgdb | |
256 | cgdb: all | |
257 | cd ${WORKINGDIR}; cgdb ${TARGETNAME} | |
6aad402a | 258 | |
63a52c99 PG |
259 | .PHONY: val |
260 | val: all | |
823da4ea | 261 | cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME} |
63a52c99 PG |
262 | |
263 | .PHONY: prof | |
67b5017f | 264 | prof: run |
06699cc7 PG |
265 | cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > prof |
266 | cd ${WORKINGDIR}; kprof -f prof | |
ad9f1fb6 | 267 | |
4e77f48b | 268 | |
d6897213 PG |
269 | # Do not include deps files when doing a _single_ clean operation |
270 | ifeq ($(findstring ${MAKECMDGOALS},${CLEANCMDS}),) | |
271 | -include ${DEPS} | |
272 | endif |