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