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