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