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