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