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