Commit | Line | Data |
---|---|---|
ad9f1fb6 | 1 | |
67b5017f | 2 | LIBGL := -lGL -lGLU |
44b079f8 | 3 | LIBSDL := `sdl-config --libs` |
67b5017f | 4 | LIBS := ${LIBSDL} ${LIBGL} |
44b079f8 PG |
5 | |
6 | OPTFLAGS := -O2 | |
7 | DBGFLAGS := -ggdb | |
8 | PRFFLAGS := ${DBGFLAGS} -pg | |
a5aefcc6 | 9 | MYFLAGS := -Wall -pedantic -ansi |
ad9f1fb6 | 10 | |
88e62c4f | 11 | VALFLAGS := --leak-check=full |
4e77f48b | 12 | CXXFLAGS := ${MYFLAGS} ${DBGFLAGS} |
88e62c4f | 13 | |
9d5863c5 | 14 | CXX := g++ |
ad9f1fb6 | 15 | |
0376f786 | 16 | DIRS := # := start |
e8deb7b6 PG |
17 | DIRS += ./ |
18 | DIRS += Entities/ | |
19 | DIRS += GameStates/ | |
20 | DIRS += Effects/ | |
21 | DIRS += config/ | |
22 | DIRS += input/ | |
23 | DIRS += graphics/ | |
3bccd1d7 | 24 | DIRS += locks/ |
0376f786 | 25 | |
ec424960 PG |
26 | SRCSDIR := src/ |
27 | SRCS := # := start | |
44b079f8 | 28 | |
16f14459 PG |
29 | OBJSDIR := objsd/ |
30 | OBJS := # := start | |
31 | ||
32 | DEPSDIR := deps/ | |
33 | DEPS := # := start | |
34 | ||
70468808 PG |
35 | # include all of the dir.mk |
36 | include $(addprefix ${SRCSDIR},$(addsuffix dir.mk,${DIRS})) | |
869b3330 | 37 | |
ec424960 PG |
38 | WORKINGDIR := bind/ |
39 | ||
869b3330 | 40 | CFGDIRNAME := configs/ |
ec424960 | 41 | SRCCFGDIR := ${CFGDIRNAME} |
869b3330 PG |
42 | DSTCFGDIR := ${WORKINGDIR}${CFGDIRNAME} |
43 | ||
44 | CFGS := # := start | |
45 | CFGS += keys.cfg | |
46 | CFGS := $(addprefix ${DSTCFGDIR},${CFGS}) | |
47 | ||
9d5863c5 PG |
48 | TARGETNAME := run_physics |
49 | TARGETTMP := ${OBJSDIR}${TARGETNAME} | |
ec424960 | 50 | TARGET := ${WORKINGDIR}${TARGETNAME} |
9d5863c5 | 51 | |
ebea1138 PG |
52 | DEPSBLDDIRS := $(addprefix ${DEPSDIR},${DIRS}) |
53 | OBJSBLDDIRS := $(addprefix ${OBJSDIR},${DIRS}) | |
869b3330 | 54 | BLDDIRS := ${OBJSBLDDIRS} ${DEPSBLDDIRS} ${WORKINGDIR} ${DSTCFGDIR} |
42f62a75 | 55 | |
ad9f1fb6 | 56 | |
70468808 PG |
57 | PRNTFMT := printf "%-5s: %s\n" |
58 | ||
393654cf PG |
59 | VERBOSE := 0 |
60 | ||
61 | ifeq (${VERBOSE},0) | |
62 | # quiet the echo command | |
63 | Q1 := @ | |
64 | # quiet the command that is `replaced' by an echo | |
65 | Q2 := @ | |
66 | else | |
67 | # EAT the echo command as if it was not there | |
68 | Q1 := @true # NOTE: the space between @true and the # is VERY important!! | |
69 | # do not quiet the command output | |
70 | Q2 := | |
71 | endif | |
ad9f1fb6 | 72 | |
046b034c | 73 | .PHONY: all |
869b3330 | 74 | all: ${TARGET} ${CFGS} |
37a74d97 | 75 | |
869b3330 PG |
76 | # how to link the main target |
77 | ${TARGETTMP}: ${OBJS} | |
bf7e6563 | 78 | ${Q1}${PRNTFMT} "${CXX}" "$@" |
869b3330 | 79 | ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS} |
ad9f1fb6 | 80 | |
9d5863c5 | 81 | # rule to copy tmp target to working directory |
ebea1138 | 82 | ${TARGET}: ${TARGETTMP} | ${WORKINGDIR} |
bf7e6563 | 83 | ${Q1}${PRNTFMT} "cp" "$@" |
37a74d97 | 84 | ${Q2}cp $< $@ |
9d5863c5 | 85 | |
42f62a75 PG |
86 | # how to make a directory |
87 | ${BLDDIRS}: | |
2688190c | 88 | ${Q1}${PRNTFMT} "mkdir" "$@" |
42f62a75 PG |
89 | ${Q2}mkdir -p $@ |
90 | ||
2688190c PG |
91 | # cause the below directory rules to work out |
92 | .SECONDEXPANSION: | |
93 | ||
869b3330 | 94 | # rule to make an object file from a .cpp |
2688190c | 95 | ${OBJSDIR}%.o: ${SRCSDIR}%.cpp | $$(dir $$@) |
bf7e6563 | 96 | ${Q1}${PRNTFMT} "${CXX}" "$@" |
869b3330 PG |
97 | ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $< |
98 | ||
a4bb9ac2 | 99 | # rule to make a depend file from a .cpp |
5f264bf7 PG |
100 | # be clever and escape the / chars in file paths |
101 | # DON'T simply use another sed delimiter or it can't appear in the file paths | |
2688190c | 102 | ${DEPSDIR}%.d: ${SRCSDIR}%.cpp | $$(dir $$@) |
bf7e6563 | 103 | ${Q1}${PRNTFMT} "DEP" "$@" |
5f264bf7 PG |
104 | ${Q2}${CXX} -MM ${CXXFLAGS} $< | \ |
105 | sed 's/\(^.*\):/$(subst /,\/,${OBJSDIR}\1 $@):/' > $@ | |
ad9f1fb6 | 106 | |
869b3330 | 107 | # rule to copy the config files into the working directory |
2688190c | 108 | ${DSTCFGDIR}%.cfg: ${SRCCFGDIR}%.cfg | $$(dir $$@) |
bf7e6563 | 109 | ${Q1}${PRNTFMT} "cp" "$@" |
869b3330 | 110 | ${Q2}cp $< $@ |
054d658f | 111 | |
ad9f1fb6 | 112 | |
67b5017f | 113 | tags: ${SRCS} |
bf7e6563 | 114 | ${Q1}${PRNTFMT} "ctags" "$@" |
67b5017f PG |
115 | ${Q2}ctags $^ |
116 | ||
117 | ||
046b034c | 118 | .PHONY: clean |
ad9f1fb6 | 119 | clean: |
70468808 PG |
120 | ${Q1}${PRNTFMT} "rm" "${OBJSDIR}" |
121 | ${Q2}rm -rf ${OBJSDIR} | |
122 | ${Q1}${PRNTFMT} "rm" "${TARGET} ${TARGETTMP}" | |
393654cf | 123 | ${Q2}rm -f ${TARGET} |
ad9f1fb6 | 124 | |
046b034c | 125 | .PHONY: distclean |
ad9f1fb6 | 126 | distclean: clean |
70468808 PG |
127 | ${Q1}${PRNTFMT} "rm" "${DEPSDIR}" |
128 | ${Q2}rm -rf ${DEPSDIR} | |
129 | ${Q1}${PRNTFMT} "rm" "tags prof gmon.out" | |
393654cf | 130 | ${Q2}rm -f tags prof gmon.out |
ad9f1fb6 | 131 | |
d893cce2 PG |
132 | .PHONY: gitclean |
133 | gitclean: | |
bf7e6563 | 134 | ${Q1}${PRNTFMT} "git clean" "showing; use gitcleanf to force removal" |
5f264bf7 | 135 | ${Q2}git clean -nxd |
d893cce2 PG |
136 | |
137 | .PHONY: gitcleanf | |
138 | gitcleanf: | |
bf7e6563 | 139 | ${Q1}${PRNTFMT} "git clean" "forcing" |
5f264bf7 | 140 | ${Q2}git clean -fxd |
d893cce2 | 141 | |
7adc59fe | 142 | .PHONY: tar |
5f264bf7 | 143 | tar: physics.tar.bz2 |
8381f595 | 144 | |
5f264bf7 PG |
145 | .PHONY: physics.tar.bz2 |
146 | physics.tar.bz2: | |
bf7e6563 PG |
147 | @${PRNTFMT} "git archive" "Warning, archives HEAD not current" |
148 | ${Q1}${PRNTFMT} "git archive" "physics.tar.bz2" | |
149 | ${Q2}git archive --prefix=physics/ HEAD | bzip2 > physics.tar.bz2 | |
ad9f1fb6 | 150 | |
046b034c PG |
151 | .PHONY: run |
152 | run: all | |
67b5017f | 153 | cd ${WORKINGDIR}; ./${TARGETNAME} |
ad9f1fb6 | 154 | |
6aad402a PG |
155 | .PHONY: gdb |
156 | gdb: all | |
67b5017f PG |
157 | cd ${WORKINGDIR}; gdb ${TARGETNAME} |
158 | ||
159 | .PHONY: cgdb | |
160 | cgdb: all | |
161 | cd ${WORKINGDIR}; cgdb ${TARGETNAME} | |
6aad402a | 162 | |
63a52c99 PG |
163 | .PHONY: val |
164 | val: all | |
823da4ea | 165 | cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME} |
63a52c99 PG |
166 | |
167 | .PHONY: prof | |
67b5017f | 168 | prof: run |
06699cc7 PG |
169 | cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > prof |
170 | cd ${WORKINGDIR}; kprof -f prof | |
ad9f1fb6 | 171 | |
4e77f48b | 172 | |
9d5863c5 PG |
173 | MINGMAKEARGS := "LIBGL := -lopengl32 -lglu32" \ |
174 | "LIBSDL := `/usr/mingw32/bin/sdl-config --libs`" \ | |
175 | "CXXFLAGS := ${OPTFLAGS}" \ | |
176 | "CXX := mingw32-g++" \ | |
5f264bf7 PG |
177 | "OBJSDIR := objs-mingw32/" \ |
178 | "WORKINGDIR := bin-mingw32/" \ | |
9d5863c5 PG |
179 | "TARGETNAME := run_physics.exe" |
180 | ||
181 | .PHONY: mingw32 | |
182 | mingw32: | |
bf7e6563 | 183 | ${Q1}${PRNTFMT} "make" "mingw32" |
9d5863c5 PG |
184 | ${Q2}${MAKE} ${MINGMAKEARGS} clean all |
185 | ||
4e77f48b | 186 | FINALMAKEARGS := "CXXFLAGS := ${OPTFLAGS}" \ |
5f264bf7 PG |
187 | "OBJSDIR := objs/" \ |
188 | "WORKINGDIR := bin/" | |
4e77f48b PG |
189 | |
190 | .PHONY: final | |
191 | final: | |
bf7e6563 | 192 | ${Q1}${PRNTFMT} "make" "final" |
4e77f48b PG |
193 | ${Q2}${MAKE} ${FINALMAKEARGS} clean all |
194 | ||
06699cc7 | 195 | |
f4b779e4 | 196 | -include ${DEPS} |