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