changed cleaning logic again, added copying of COPYING
[physics.git] / Makefile
1
2 LIBGL  := -lGL -lGLU
3 LIBSDL := `sdl-config --libs`
4 LIBS   := ${LIBSDL} ${LIBGL}
5
6 OPTFLAGS := -O2
7 DBGFLAGS := -ggdb
8 PRFFLAGS := ${DBGFLAGS} -pg
9 MYFLAGS  := -Wall -pedantic -ansi
10
11 VALFLAGS := --leak-check=full
12 CXXFLAGS := ${MYFLAGS} ${DBGFLAGS}
13
14 CXX := g++
15
16 DIRS := # := start
17
18 SRCSDIR := src/
19 SRCS    := # := start
20
21 OBJSDIR := objsd/
22 OBJS    := # := start
23
24 DEPSDIR := deps/
25 DEPS    := # := start
26
27 # include all of the dir.mk
28 DIRMK   := dir.mk
29 include ${SRCSDIR}${DIRMK}
30
31 WORKINGDIR  := bind/
32
33 CFGDIRNAME  := configs/
34 SRCCFGDIR   := ${CFGDIRNAME}
35 DSTCFGDIR   := ${WORKINGDIR}${CFGDIRNAME}
36
37 CFGS := # := start
38 CFGS += keys.cfg
39 CFGS := $(addprefix ${DSTCFGDIR},${CFGS})
40
41 SRCLIBSDIR  := libs/
42 DSTLIBSDIR  := ${WORKINGDIR}
43
44 LIBSTXT     := # := start
45 LIBSTXT     += COPYING-SDL
46 LIBSTXT     += README-SDL
47 LIBSTXT     += VERSION-SDL
48 LIBSTXT     := $(addprefix ${DSTLIBSDIR},${LIBSTXT})
49
50 LIBSCPY     := # := start
51 LIBSCPY     += libSDL.so
52 LIBSCPY     := $(addprefix ${DSTLIBSDIR},${LIBSCPY})
53
54 SRCTXTDIR   :=
55 DSTTXTDIR   := ${WORKINGDIR}
56
57 TXT         := # := start
58 TXT         += COPYING
59 TXT         := $(addprefix ${DSTTXTDIR},${TXT})
60
61 TARGETNAME  := run_physics
62 TARGETTMP   := ${OBJSDIR}${TARGETNAME}
63 TARGET      := ${WORKINGDIR}${TARGETNAME}
64
65 DEPSBLDDIRS := ${DEPSDIR} $(addprefix ${DEPSDIR},${DIRS})
66 OBJSBLDDIRS := ${OBJSDIR} $(addprefix ${OBJSDIR},${DIRS})
67 BLDDIRS     := ${OBJSBLDDIRS} ${DEPSBLDDIRS} ${WORKINGDIR} ${DSTCFGDIR}
68
69 INCDIRS     := ${SRCSDIR}
70
71
72 PRNTFMT := printf "%-5s: %s\n"
73
74 VERBOSE := 0
75
76 ifeq (${VERBOSE},0)
77     # quiet the printf command
78     Q1 := @
79     # quiet the command that is `replaced' by an echo
80     Q2 := @
81 else
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 :=
86 endif
87
88 .PHONY: all
89 all: ${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
138 cleanbin:
139         ${Q1}${PRNTFMT} "rm" "${WORKINGDIR}"
140         ${Q2}rm -rf ${WORKINGDIR}
141
142 .PHONY: cleanobjs
143 cleanobjs:
144         ${Q1}${PRNTFMT} "rm" "${OBJSDIR}"
145         ${Q2}rm -rf ${OBJSDIR}
146
147 .PHONY: cleandeps
148 cleandeps:
149         ${Q1}${PRNTFMT} "rm" "${DEPSDIR}"
150         ${Q2}rm -rf ${DEPSDIR}
151
152 .PHONY: clean
153 clean: cleanobjs
154
155 .PHONY: cleanall
156 cleanall: clean cleanbin cleandeps
157
158 .PHONY: gitclean
159 gitclean:
160         ${Q1}${PRNTFMT} "git clean" "showing; use gitcleanf to force removal"
161         ${Q2}git clean -nxd
162
163 .PHONY: gitcleanf
164 gitcleanf:
165         ${Q1}${PRNTFMT} "git clean" "forcing"
166         ${Q2}git clean -fxd
167
168 .PHONY: tar
169 tar: physics.tar.bz2
170
171 .PHONY: physics.tar.bz2
172 physics.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
178 run: all
179         cd ${WORKINGDIR}; ./${TARGETNAME}
180
181 .PHONY: gdb
182 gdb: all
183         cd ${WORKINGDIR}; gdb ${TARGETNAME}
184
185 .PHONY: cgdb
186 cgdb: all
187         cd ${WORKINGDIR}; cgdb ${TARGETNAME}
188
189 .PHONY: val
190 val: all
191         cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME}
192
193 .PHONY: prof
194 prof: run
195         cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > prof
196         cd ${WORKINGDIR}; kprof -f prof
197
198
199 MINGMAKEARGS := "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
209 mingw32:
210         ${Q1}${PRNTFMT} "make" "mingw32"
211         ${Q2}${MAKE} ${MINGMAKEARGS} cleanbin cleanobjs
212         ${Q2}${MAKE} ${MINGMAKEARGS} all
213
214 FINALMAKEARGS := "CXXFLAGS   := ${OPTFLAGS}" \
215                  "OBJSDIR    := objs/" \
216                  "WORKINGDIR := bin/"
217
218 .PHONY: final
219 final:
220         ${Q1}${PRNTFMT} "make" "final"
221         ${Q2}${MAKE} ${FINALMAKEARGS} cleanbin cleanobjs
222         ${Q2}${MAKE} ${FINALMAKEARGS} all
223
224
225 -include ${DEPS}