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