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