config dir fix
[physics.git] / src / 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
PG
9MYFLAGS := -Wall -pedantic -ansi
10CXXFLAGS := ${MYFLAGS} ${DBGFLAGS}
ad9f1fb6 11
88e62c4f
PG
12VALFLAGS := --leak-check=full
13
9d5863c5 14CXX := g++
ad9f1fb6 15
cf116802 16SRCS := # := start
0376f786
PG
17
18DIRS := # := start
e8deb7b6
PG
19DIRS += ./
20DIRS += Entities/
21DIRS += GameStates/
22DIRS += Effects/
23DIRS += config/
24DIRS += input/
25DIRS += graphics/
0376f786
PG
26
27include $(addsuffix /files.mk,${DIRS})
44b079f8 28
f4b779e4 29OBJSDIR := ../objs/
67b5017f
PG
30OBJS := ${SRCS:.cpp=.o}
31OBJS := $(addprefix ${OBJSDIR},${OBJS})
f4b779e4
PG
32
33DEPSDIR := ../deps/
67b5017f
PG
34DEPS := ${SRCS:.cpp=.d}
35DEPS := $(addprefix ${DEPSDIR},${DEPS})
ad9f1fb6 36
9d5863c5
PG
37WORKINGDIR := ../bin/
38TARGETNAME := run_physics
39TARGETTMP := ${OBJSDIR}${TARGETNAME}
40TARGET := ${WORKINGDIR}${TARGETNAME}
41
37a74d97
PG
42CONFIGDIRNAME := configs/
43CONFIGDIR := ../${CONFIGDIRNAME}
44CONFIGDEST := ${WORKINGDIR}${CONFIGDIRNAME}
45
46CONFIGS := # := start
47CONFIGS += keys.cfg
48CONFIGS := $(addprefix ${CONFIGDEST},${CONFIGS})
49
ebea1138
PG
50DEPSBLDDIRS := $(addprefix ${DEPSDIR},${DIRS})
51OBJSBLDDIRS := $(addprefix ${OBJSDIR},${DIRS})
37a74d97 52BLDDIRS := ${OBJSBLDDIRS} ${DEPSBLDDIRS} ${WORKINGDIR} ${CONFIGDEST}
42f62a75 53
ad9f1fb6 54
393654cf
PG
55VERBOSE := 0
56
57ifeq (${VERBOSE},0)
58 # quiet the echo command
59 Q1 := @
60 # quiet the command that is `replaced' by an echo
61 Q2 := @
62else
63 # EAT the echo command as if it was not there
64 Q1 := @true # NOTE: the space between @true and the # is VERY important!!
65 # do not quiet the command output
66 Q2 :=
67endif
ad9f1fb6 68
046b034c 69.PHONY: all
37a74d97
PG
70all: ${TARGET} ${CONFIGS}
71
72# rule to copy the config files into the working directory
79f36535 73${CONFIGDEST}%.cfg: ${CONFIGDIR}%.cfg | ${CONFIGDEST} ${WORKINGDIR}
37a74d97 74 ${Q1}echo "cp: $@"
79f36535 75 ${Q2}cp $< $@
ad9f1fb6 76
9d5863c5 77# rule to copy tmp target to working directory
ebea1138 78${TARGET}: ${TARGETTMP} | ${WORKINGDIR}
9d5863c5 79 ${Q1}echo "cp: $@"
37a74d97 80 ${Q2}cp $< $@
9d5863c5 81
42f62a75 82# how to link the main target
9d5863c5 83${TARGETTMP}: ${OBJS}
393654cf 84 ${Q1}echo "${CXX}: $@"
eb0c55e7 85 ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS}
ad9f1fb6 86
42f62a75
PG
87# how to make a directory
88${BLDDIRS}:
89 ${Q2}mkdir -p $@
90
a4bb9ac2 91# rule to make a depend file from a .cpp
ebea1138 92${DEPSDIR}%.d: %.cpp | ${DEPSBLDDIRS}
393654cf 93 ${Q1}echo "DEP: $@"
a68587cf 94 ${Q2}${CXX} -MM ${CXXFLAGS} $< | sed 's,\(^.*\):,${OBJSDIR}\1 $@:,' > $@
ad9f1fb6 95
a4bb9ac2 96# rule to make an object file from a .cpp
ebea1138 97${OBJSDIR}%.o: %.cpp | ${OBJSBLDDIRS}
393654cf
PG
98 ${Q1}echo "${CXX}: $@"
99 ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $<
054d658f 100
ad9f1fb6 101
67b5017f
PG
102tags: ${SRCS}
103 ${Q1}echo "ctags: $@"
104 ${Q2}ctags $^
105
106
046b034c 107.PHONY: clean
ad9f1fb6 108clean:
393654cf
PG
109 ${Q1}echo "CLEAN: OBJS"
110 ${Q2}rm -f ${OBJS}
111 ${Q1}echo "CLEAN: TARGET"
112 ${Q2}rm -f ${TARGET}
ad9f1fb6 113
046b034c 114.PHONY: distclean
ad9f1fb6 115distclean: clean
f4b779e4
PG
116 ${Q1}echo "CLEAN: DEPS"
117 ${Q2}rm -f ${DEPS}
393654cf
PG
118 ${Q1}echo "CLEAN: tags prof gmon.out"
119 ${Q2}rm -f tags prof gmon.out
ad9f1fb6 120
d893cce2
PG
121.PHONY: gitclean
122gitclean:
123 ${Q1}echo "git-clean: show, use gitcleanf to force"
124 ${Q2}cd ..; git clean -nxd
125
126.PHONY: gitcleanf
127gitcleanf:
128 ${Q1}echo "git-clean: forced"
129 ${Q2}cd ..; git clean -fxd
130
7adc59fe 131.PHONY: tar
8381f595
PG
132tar: ../physics.tar.bz2
133
134.PHONY: ../physics.tar.bz2
135../physics.tar.bz2:
136 @echo "git-archive: Warning, archives HEAD not current"
a4bb9ac2
PG
137 ${Q1}echo "git-archive: ../physics.tar.bz2"
138 ${Q2}cd ..; git-archive --prefix=physics/ HEAD | bzip2 > physics.tar.bz2
ad9f1fb6 139
046b034c
PG
140.PHONY: run
141run: all
67b5017f 142 cd ${WORKINGDIR}; ./${TARGETNAME}
ad9f1fb6 143
6aad402a
PG
144.PHONY: gdb
145gdb: all
67b5017f
PG
146 cd ${WORKINGDIR}; gdb ${TARGETNAME}
147
148.PHONY: cgdb
149cgdb: all
150 cd ${WORKINGDIR}; cgdb ${TARGETNAME}
6aad402a 151
63a52c99
PG
152.PHONY: val
153val: all
823da4ea 154 cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME}
63a52c99
PG
155
156.PHONY: prof
67b5017f
PG
157prof: run
158 cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > src/prof
63a52c99 159 kprof -f prof
ad9f1fb6 160
9d5863c5
PG
161MINGMAKEARGS := "LIBGL := -lopengl32 -lglu32" \
162 "LIBSDL := `/usr/mingw32/bin/sdl-config --libs`" \
163 "CXXFLAGS := ${OPTFLAGS}" \
164 "CXX := mingw32-g++" \
165 "OBJSDIR := ../objs-mingw32/" \
e8deb7b6 166 "WORKINGDIR := ../bin-mingw32/" \
9d5863c5
PG
167 "TARGETNAME := run_physics.exe"
168
169.PHONY: mingw32
170mingw32:
171 ${Q1}echo "make: mingw32"
172 ${Q2}${MAKE} ${MINGMAKEARGS} clean all
173
f4b779e4 174-include ${DEPS}