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