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