changed cleaning logic again, added copying of COPYING
[physics.git] / Makefile
... / ...
CommitLineData
1
2LIBGL := -lGL -lGLU
3LIBSDL := `sdl-config --libs`
4LIBS := ${LIBSDL} ${LIBGL}
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}
70
71
72PRNTFMT := printf "%-5s: %s\n"
73
74VERBOSE := 0
75
76ifeq (${VERBOSE},0)
77 # quiet the printf command
78 Q1 := @
79 # quiet the command that is `replaced' by an echo
80 Q2 := @
81else
82 # EAT the printf command as if it was not there
83 Q1 := @true # NOTE: the space between @true and the # is VERY important!!
84 # do not quiet the command output
85 Q2 :=
86endif
87
88.PHONY: all
89all: ${TARGET} ${CFGS} ${LIBSTXT} ${LIBSCPY} ${TXT}
90
91# cause the fancy $$ directory rules to work out
92.SECONDEXPANSION:
93
94# how to link the main target
95${TARGETTMP}: ${OBJS}
96 ${Q1}${PRNTFMT} "${CXX}" "$@"
97 ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS}
98
99# rule to copy tmp target to working directory
100${TARGET}: ${TARGETTMP} | ${WORKINGDIR}
101 ${Q1}${PRNTFMT} "cp" "$@"
102 ${Q2}cp $< $@
103
104# rule to copy the config files into the working directory
105${DSTCFGDIR}%: ${SRCCFGDIR}% | $$(dir $$@)
106 ${Q1}${PRNTFMT} "cp" "$@"
107 ${Q2}cp $< $@
108
109# rule to copy the library files into the working directory
110${DSTLIBSDIR}%: ${SRCLIBSDIR}% | $$(dir $$@)
111 ${Q1}${PRNTFMT} "cp" "$@"
112 ${Q2}cp $< $@
113
114# rule to copy the library files into the working directory
115${DSTTXTDIR}%: ${SRCTXTDIR}% | $$(dir $$@)
116 ${Q1}${PRNTFMT} "cp" "$@"
117 ${Q2}cp $< $@
118
119# how to make a directory
120${BLDDIRS}:
121 ${Q1}${PRNTFMT} "mkdir" "$@"
122 ${Q2}mkdir -p $@
123
124# rule to make an object file from a .cpp
125${OBJSDIR}%.o: ${SRCSDIR}%.cpp | $$(dir $$@)
126 ${Q1}${PRNTFMT} "${CXX}" "$@"
127 ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $< -I "${INCDIRS}"
128
129# rule to make a depend file from a .cpp
130# be clever and escape the / chars in file paths
131# DON'T simply use another sed delimiter or it can't appear in the file paths
132${DEPSDIR}%.d: ${SRCSDIR}%.cpp | $$(dir $$@)
133 ${Q1}${PRNTFMT} "DEP" "$@"
134 ${Q2}${CXX} -MM ${CXXFLAGS} $< -I "${INCDIRS}" | \
135 sed 's/\(^.*\):/$(subst /,\/,${OBJSDIR}\1 $@):/' > $@
136
137.PHONY: cleanbin
138cleanbin:
139 ${Q1}${PRNTFMT} "rm" "${WORKINGDIR}"
140 ${Q2}rm -rf ${WORKINGDIR}
141
142.PHONY: cleanobjs
143cleanobjs:
144 ${Q1}${PRNTFMT} "rm" "${OBJSDIR}"
145 ${Q2}rm -rf ${OBJSDIR}
146
147.PHONY: cleandeps
148cleandeps:
149 ${Q1}${PRNTFMT} "rm" "${DEPSDIR}"
150 ${Q2}rm -rf ${DEPSDIR}
151
152.PHONY: clean
153clean: cleanobjs
154
155.PHONY: cleanall
156cleanall: clean cleanbin cleandeps
157
158.PHONY: gitclean
159gitclean:
160 ${Q1}${PRNTFMT} "git clean" "showing; use gitcleanf to force removal"
161 ${Q2}git clean -nxd
162
163.PHONY: gitcleanf
164gitcleanf:
165 ${Q1}${PRNTFMT} "git clean" "forcing"
166 ${Q2}git clean -fxd
167
168.PHONY: tar
169tar: physics.tar.bz2
170
171.PHONY: physics.tar.bz2
172physics.tar.bz2:
173 @${PRNTFMT} "git archive" "Warning, archives HEAD not current"
174 ${Q1}${PRNTFMT} "git archive" "physics.tar.bz2"
175 ${Q2}git archive --prefix=physics/ HEAD | bzip2 > physics.tar.bz2
176
177.PHONY: run
178run: all
179 cd ${WORKINGDIR}; ./${TARGETNAME}
180
181.PHONY: gdb
182gdb: all
183 cd ${WORKINGDIR}; gdb ${TARGETNAME}
184
185.PHONY: cgdb
186cgdb: all
187 cd ${WORKINGDIR}; cgdb ${TARGETNAME}
188
189.PHONY: val
190val: all
191 cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME}
192
193.PHONY: prof
194prof: run
195 cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > prof
196 cd ${WORKINGDIR}; kprof -f prof
197
198
199MINGMAKEARGS := "LIBGL := -lopengl32 -lglu32" \
200 "LIBSDL := `/usr/mingw32/bin/sdl-config --libs`" \
201 "LIBSCPY := $(addprefix bin-mingw32/,SDL.dll)" \
202 "CXXFLAGS := ${OPTFLAGS}" \
203 "CXX := mingw32-g++" \
204 "OBJSDIR := objs-mingw32/" \
205 "WORKINGDIR := bin-mingw32/" \
206 "TARGETNAME := run_physics.exe"
207
208.PHONY: mingw32
209mingw32:
210 ${Q1}${PRNTFMT} "make" "mingw32"
211 ${Q2}${MAKE} ${MINGMAKEARGS} cleanbin cleanobjs
212 ${Q2}${MAKE} ${MINGMAKEARGS} all
213
214FINALMAKEARGS := "CXXFLAGS := ${OPTFLAGS}" \
215 "OBJSDIR := objs/" \
216 "WORKINGDIR := bin/"
217
218.PHONY: final
219final:
220 ${Q1}${PRNTFMT} "make" "final"
221 ${Q2}${MAKE} ${FINALMAKEARGS} cleanbin cleanobjs
222 ${Q2}${MAKE} ${FINALMAKEARGS} all
223
224
225-include ${DEPS}