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