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