moved makefile up to root
[physics.git] / Makefile
... / ...
CommitLineData
1
2LIBGL := -lGL -lGLU
3LIBSDL := `sdl-config --libs`
4LIBS := ${LIBSDL} ${LIBGL}
5
6OPTFLAGS := -O2
7DBGFLAGS := -ggdb
8PRFFLAGS := ${DBGFLAGS} -pg
9MYFLAGS := -Wall -pedantic -ansi
10
11VALFLAGS := --leak-check=full
12CXXFLAGS := ${MYFLAGS} ${DBGFLAGS}
13
14CXX := g++
15
16DIRS := # := start
17DIRS += ./
18DIRS += Entities/
19DIRS += GameStates/
20DIRS += Effects/
21DIRS += config/
22DIRS += input/
23DIRS += graphics/
24DIRS += locks/
25
26SRCSDIR := src/
27SRCS := # := start
28
29# include all of the files.mk
30include $(addprefix ${SRCSDIR},$(addsuffix files.mk,${DIRS}))
31
32WORKINGDIR := bind/
33
34OBJSDIR := objsd/
35OBJS := ${SRCS:.cpp=.o}
36OBJS := $(addprefix ${OBJSDIR},${OBJS})
37
38DEPSDIR := deps/
39DEPS := ${SRCS:.cpp=.d}
40DEPS := $(addprefix ${DEPSDIR},${DEPS})
41
42CFGDIRNAME := configs/
43SRCCFGDIR := ${CFGDIRNAME}
44DSTCFGDIR := ${WORKINGDIR}${CFGDIRNAME}
45
46CFGS := # := start
47CFGS += keys.cfg
48CFGS := $(addprefix ${DSTCFGDIR},${CFGS})
49
50TARGETNAME := run_physics
51TARGETTMP := ${OBJSDIR}${TARGETNAME}
52TARGET := ${WORKINGDIR}${TARGETNAME}
53
54DEPSBLDDIRS := $(addprefix ${DEPSDIR},${DIRS})
55OBJSBLDDIRS := $(addprefix ${OBJSDIR},${DIRS})
56BLDDIRS := ${OBJSBLDDIRS} ${DEPSBLDDIRS} ${WORKINGDIR} ${DSTCFGDIR}
57
58
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
72
73.PHONY: all
74all: ${TARGET} ${CFGS}
75
76# how to link the main target
77${TARGETTMP}: ${OBJS}
78 ${Q1}echo "${CXX}: $@"
79 ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS}
80
81# rule to copy tmp target to working directory
82${TARGET}: ${TARGETTMP} | ${WORKINGDIR}
83 ${Q1}echo "cp: $@"
84 ${Q2}cp $< $@
85
86# how to make a directory
87${BLDDIRS}:
88 ${Q2}mkdir -p $@
89
90# rule to make an object file from a .cpp
91${OBJSDIR}%.o: ${SRCSDIR}%.cpp | ${OBJSBLDDIRS}
92 ${Q1}echo "${CXX}: $@"
93 ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $<
94
95# rule to make a depend file from a .cpp
96${DEPSDIR}%.d: ${SRCSDIR}%.cpp | ${DEPSBLDDIRS}
97 ${Q1}echo "DEP: $@"
98 ${Q2}${CXX} -MM ${CXXFLAGS} $< | sed 's,\(^.*\):,${OBJSDIR}\1 $@:,' > $@
99
100# rule to copy the config files into the working directory
101${DSTCFGDIR}%.cfg: ${SRCCFGDIR}%.cfg | ${DSTCFGDIR}
102 ${Q1}echo "cp: $@"
103 ${Q2}cp $< $@
104
105
106tags: ${SRCS}
107 ${Q1}echo "ctags: $@"
108 ${Q2}ctags $^
109
110
111.PHONY: clean
112clean:
113 ${Q1}echo "CLEAN: OBJS"
114 ${Q2}rm -f ${OBJS}
115 ${Q1}echo "CLEAN: TARGET"
116 ${Q2}rm -f ${TARGET}
117
118.PHONY: distclean
119distclean: clean
120 ${Q1}echo "CLEAN: DEPS"
121 ${Q2}rm -f ${DEPS}
122 ${Q1}echo "CLEAN: tags prof gmon.out"
123 ${Q2}rm -f tags prof gmon.out
124
125.PHONY: gitclean
126gitclean:
127 ${Q1}echo "git-clean: show, use gitcleanf to force"
128 ${Q2}cd ..; git clean -nxd
129
130.PHONY: gitcleanf
131gitcleanf:
132 ${Q1}echo "git-clean: forced"
133 ${Q2}cd ..; git clean -fxd
134
135.PHONY: tar
136tar: ../physics.tar.bz2
137
138.PHONY: ../physics.tar.bz2
139../physics.tar.bz2:
140 @echo "git-archive: Warning, archives HEAD not current"
141 ${Q1}echo "git-archive: ../physics.tar.bz2"
142 ${Q2}cd ..; git-archive --prefix=physics/ HEAD | bzip2 > physics.tar.bz2
143
144.PHONY: run
145run: all
146 cd ${WORKINGDIR}; ./${TARGETNAME}
147
148.PHONY: gdb
149gdb: all
150 cd ${WORKINGDIR}; gdb ${TARGETNAME}
151
152.PHONY: cgdb
153cgdb: all
154 cd ${WORKINGDIR}; cgdb ${TARGETNAME}
155
156.PHONY: val
157val: all
158 cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME}
159
160.PHONY: prof
161prof: run
162 cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > src/prof
163 kprof -f prof
164
165
166MINGMAKEARGS := "LIBGL := -lopengl32 -lglu32" \
167 "LIBSDL := `/usr/mingw32/bin/sdl-config --libs`" \
168 "CXXFLAGS := ${OPTFLAGS}" \
169 "CXX := mingw32-g++" \
170 "OBJSDIR := ../objs-mingw32/" \
171 "WORKINGDIR := ../bin-mingw32/" \
172 "TARGETNAME := run_physics.exe"
173
174.PHONY: mingw32
175mingw32:
176 ${Q1}echo "make: mingw32"
177 ${Q2}${MAKE} ${MINGMAKEARGS} clean all
178
179FINALMAKEARGS := "CXXFLAGS := ${OPTFLAGS}" \
180 "OBJSDIR := ../objs/" \
181 "WORKINGDIR := ../bin/"
182
183.PHONY: final
184final:
185 ${Q1}echo "make: final"
186 ${Q2}${MAKE} ${FINALMAKEARGS} clean all
187
188-include ${DEPS}