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