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