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