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