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