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