added using namespace pg to relavent files ... will remove at some point
[physics.git] / Makefile
1
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 LIBMY       := -lpg
17 LIBS        := ${LIBSDL} ${LIBGL} ${LIBMY}
18
19 OPTFLAGS := -O2
20 DBGFLAGS := -ggdb
21 PRFFLAGS := ${DBGFLAGS} -pg
22 MYFLAGS  := -Wall -pedantic -ansi
23
24 RPATH    := libs/
25
26 VALFLAGS := --leak-check=full
27 LNKFLAGS := -Wl,-rpath,${RPATH}
28
29 ifeq (${WIN32},1)
30     CXXFLAGS    := ${OPTFLAGS}
31 else ifeq (${FINAL},1)
32     CXXFLAGS    := ${OPTFLAGS}
33 else
34     CXXFLAGS    := ${MYFLAGS} ${DBGFLAGS}
35 endif
36
37 ifeq (${WIN32},1)
38     CXX := mingw32-g++
39 else
40     CXX := g++
41 endif
42
43 DIRS    := # := start
44
45 SRCSDIR := src/
46 SRCS    := # := start
47
48 ifeq (${WIN32},1)
49     OBJSDIR := objs-mingw32/
50 else ifeq (${FINAL},1)
51     OBJSDIR := objs/
52 else
53     OBJSDIR := objsd/
54 endif
55 OBJS        := # := start
56
57 DEPSDIR := deps/
58 DEPS    := # := start
59
60 # include all of the dir.mk
61 DIRMK   := dir.mk
62 include ${SRCSDIR}${DIRMK}
63
64 ifeq (${WIN32},1)
65     WORKINGDIR  := bin-mingw32/
66 else ifeq (${FINAL},1)
67     WORKINGDIR  := bin/
68 else
69     WORKINGDIR  := bind/
70 endif
71
72 CFGDIRNAME  := configs/
73 SRCCFGDIR   := ${CFGDIRNAME}
74 DSTCFGDIR   := ${WORKINGDIR}${CFGDIRNAME}
75
76 CFGS := # := start
77 CFGS += keys.cfg
78 CFGS := $(addprefix ${DSTCFGDIR},${CFGS})
79
80 LIBSDIRNAME := libs/
81 SRCLIBSDIR  := ${LIBSDIRNAME}
82 DSTLIBSDIR  := ${WORKINGDIR}${LIBSDIRNAME}
83
84 LIBSTXT     := # := start
85 LIBSTXT     += COPYING-SDL
86 LIBSTXT     += README-SDL
87 LIBSTXT     += VERSION-SDL
88 LIBSTXT     := $(addprefix ${DSTLIBSDIR},${LIBSTXT})
89
90 LIBSCPY     := # := start
91 ifeq (${WIN32},1)
92     LIBSCPY += SDL.dll
93 else
94     LIBSCPY += libSDL-1.2.so.0
95     LIBSCPY += libpg.so.0
96 endif
97 LIBSCPY     := $(addprefix ${DSTLIBSDIR},${LIBSCPY})
98
99 SRCTXTDIR   :=
100 DSTTXTDIR   := ${WORKINGDIR}
101
102 TXT         := # := start
103 TXT         += COPYING
104 TXT         := $(addprefix ${DSTTXTDIR},${TXT})
105
106 ifeq (${WIN32},1)
107     TARGETNAME  := run_physics.exe
108 else
109     TARGETNAME  := run_physics
110 endif
111 TARGETTMP   := ${OBJSDIR}${TARGETNAME}
112 TARGET      := ${WORKINGDIR}${TARGETNAME}
113
114 DEPSBLDDIRS := ${DEPSDIR} $(addprefix ${DEPSDIR},${DIRS})
115 OBJSBLDDIRS := ${OBJSDIR} $(addprefix ${OBJSDIR},${DIRS})
116
117 BLDDIRS     := # := start
118 BLDDIRS     += ${OBJSBLDDIRS}
119 BLDDIRS     += ${DEPSBLDDIRS}
120 BLDDIRS     += ${WORKINGDIR}
121 BLDDIRS     += ${DSTCFGDIR}
122 BLDDIRS     += ${DSTLIBSDIR}
123
124 INCDIRS     := ${SRCSDIR}
125 INCFLAGS    := $(addprefix -I, ${INCDIRS})
126
127
128 PRNTFMT := printf "%-5s: %s\n"
129
130 VERBOSE := 0
131
132 ifeq (${VERBOSE},0)
133     # quiet the printf command
134     Q1 := @
135     # quiet the command that is `replaced' by an echo
136     Q2 := @
137 else
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 :=
142 endif
143
144 .PHONY: all
145 all: ${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
193 CLEANCMDS := cleanbin cleanobjs cleandeps clean cleanall
194
195 .PHONY: cleanbin
196 cleanbin:
197         ${Q1}${PRNTFMT} "rm" "${WORKINGDIR}"
198         ${Q2}rm -rf ${WORKINGDIR}
199
200 .PHONY: cleanobjs
201 cleanobjs:
202         ${Q1}${PRNTFMT} "rm" "${OBJSDIR}"
203         ${Q2}rm -rf ${OBJSDIR}
204
205 .PHONY: cleandeps
206 cleandeps:
207         ${Q1}${PRNTFMT} "rm" "${DEPSDIR}"
208         ${Q2}rm -rf ${DEPSDIR}
209
210 .PHONY: clean
211 clean: cleanobjs
212         ${Q1}${PRNTFMT} "rm" "${TARGET}"
213         ${Q2}rm -rf ${TARGET}
214
215 .PHONY: cleanall
216 cleanall: clean cleanbin cleandeps
217
218 .PHONY: gitclean
219 gitclean:
220         ${Q1}${PRNTFMT} "git clean" "showing; use gitcleanf to force removal"
221         ${Q2}git clean -nxd
222
223 .PHONY: gitcleanf
224 gitcleanf:
225         ${Q1}${PRNTFMT} "git clean" "forcing"
226         ${Q2}git clean -fxd
227
228 .PHONY: tar
229 tar: physics.tar.bz2
230
231 .PHONY: physics.tar.bz2
232 physics.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
238 run: all
239 ifeq (${WIN32},1)
240         cd ${WORKINGDIR}; wine ${TARGETNAME}
241 else
242         cd ${WORKINGDIR}; ./${TARGETNAME}
243 endif
244
245 .PHONY: gdb
246 gdb: all
247         cd ${WORKINGDIR}; gdb ${TARGETNAME}
248
249 .PHONY: cgdb
250 cgdb: all
251         cd ${WORKINGDIR}; cgdb ${TARGETNAME}
252
253 .PHONY: val
254 val: all
255         cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME}
256
257 .PHONY: prof
258 prof: 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
264 ifeq ($(findstring ${MAKECMDGOALS},${CLEANCMDS}),)
265     -include ${DEPS}
266 endif