removed all ../ entries and made a basic inc path (dependencies are currently broke)
[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
29OBJSDIR := objsd/
30OBJS := # := start
31
32DEPSDIR := deps/
33DEPS := # := start
34
35# include all of the dir.mk
36include $(addprefix ${SRCSDIR},$(addsuffix dir.mk,${DIRS}))
37
38WORKINGDIR := bind/
39
40CFGDIRNAME := configs/
41SRCCFGDIR := ${CFGDIRNAME}
42DSTCFGDIR := ${WORKINGDIR}${CFGDIRNAME}
43
44CFGS := # := start
45CFGS += keys.cfg
46CFGS := $(addprefix ${DSTCFGDIR},${CFGS})
47
48TARGETNAME := run_physics
49TARGETTMP := ${OBJSDIR}${TARGETNAME}
50TARGET := ${WORKINGDIR}${TARGETNAME}
51
52DEPSBLDDIRS := $(addprefix ${DEPSDIR},${DIRS})
53OBJSBLDDIRS := $(addprefix ${OBJSDIR},${DIRS})
54BLDDIRS := ${OBJSBLDDIRS} ${DEPSBLDDIRS} ${WORKINGDIR} ${DSTCFGDIR}
55
56INCDIRS := ${SRCSDIR}
57
58
59PRNTFMT := printf "%-5s: %s\n"
60
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
74
75.PHONY: all
76all: ${TARGET} ${CFGS}
77
78# how to link the main target
79${TARGETTMP}: ${OBJS}
80 ${Q1}${PRNTFMT} "${CXX}" "$@"
81 ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS}
82
83# rule to copy tmp target to working directory
84${TARGET}: ${TARGETTMP} | ${WORKINGDIR}
85 ${Q1}${PRNTFMT} "cp" "$@"
86 ${Q2}cp $< $@
87
88# how to make a directory
89${BLDDIRS}:
90 ${Q1}${PRNTFMT} "mkdir" "$@"
91 ${Q2}mkdir -p $@
92
93# cause the below directory rules to work out
94.SECONDEXPANSION:
95
96# rule to make an object file from a .cpp
97${OBJSDIR}%.o: ${SRCSDIR}%.cpp | $$(dir $$@)
98 ${Q1}${PRNTFMT} "${CXX}" "$@"
99 ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $< -I "${INCDIRS}"
100
101# rule to make a depend file from a .cpp
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
104${DEPSDIR}%.d: ${SRCSDIR}%.cpp | $$(dir $$@)
105 ${Q1}${PRNTFMT} "DEP" "$@"
106 ${Q2}${CXX} -MM ${CXXFLAGS} $< -I "${INCDIRS}" | \
107 sed 's/\(^.*\):/$(subst /,\/,${OBJSDIR}\1 $@):/' > $@
108
109# rule to copy the config files into the working directory
110${DSTCFGDIR}%.cfg: ${SRCCFGDIR}%.cfg | $$(dir $$@)
111 ${Q1}${PRNTFMT} "cp" "$@"
112 ${Q2}cp $< $@
113
114
115tags: ${SRCS}
116 ${Q1}${PRNTFMT} "ctags" "$@"
117 ${Q2}ctags $^
118
119
120.PHONY: clean
121clean:
122 ${Q1}${PRNTFMT} "rm" "${OBJSDIR}"
123 ${Q2}rm -rf ${OBJSDIR}
124 ${Q1}${PRNTFMT} "rm" "${TARGET} ${TARGETTMP}"
125 ${Q2}rm -f ${TARGET}
126
127.PHONY: distclean
128distclean: clean
129 ${Q1}${PRNTFMT} "rm" "${DEPSDIR}"
130 ${Q2}rm -rf ${DEPSDIR}
131 ${Q1}${PRNTFMT} "rm" "tags prof gmon.out"
132 ${Q2}rm -f tags prof gmon.out
133
134.PHONY: gitclean
135gitclean:
136 ${Q1}${PRNTFMT} "git clean" "showing; use gitcleanf to force removal"
137 ${Q2}git clean -nxd
138
139.PHONY: gitcleanf
140gitcleanf:
141 ${Q1}${PRNTFMT} "git clean" "forcing"
142 ${Q2}git clean -fxd
143
144.PHONY: tar
145tar: physics.tar.bz2
146
147.PHONY: physics.tar.bz2
148physics.tar.bz2:
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
152
153.PHONY: run
154run: all
155 cd ${WORKINGDIR}; ./${TARGETNAME}
156
157.PHONY: gdb
158gdb: all
159 cd ${WORKINGDIR}; gdb ${TARGETNAME}
160
161.PHONY: cgdb
162cgdb: all
163 cd ${WORKINGDIR}; cgdb ${TARGETNAME}
164
165.PHONY: val
166val: all
167 cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME}
168
169.PHONY: prof
170prof: run
171 cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > prof
172 cd ${WORKINGDIR}; kprof -f prof
173
174
175MINGMAKEARGS := "LIBGL := -lopengl32 -lglu32" \
176 "LIBSDL := `/usr/mingw32/bin/sdl-config --libs`" \
177 "CXXFLAGS := ${OPTFLAGS}" \
178 "CXX := mingw32-g++" \
179 "OBJSDIR := objs-mingw32/" \
180 "WORKINGDIR := bin-mingw32/" \
181 "TARGETNAME := run_physics.exe"
182
183.PHONY: mingw32
184mingw32:
185 ${Q1}${PRNTFMT} "make" "mingw32"
186 ${Q2}${MAKE} ${MINGMAKEARGS} clean all
187
188FINALMAKEARGS := "CXXFLAGS := ${OPTFLAGS}" \
189 "OBJSDIR := objs/" \
190 "WORKINGDIR := bin/"
191
192.PHONY: final
193final:
194 ${Q1}${PRNTFMT} "make" "final"
195 ${Q2}${MAKE} ${FINALMAKEARGS} clean all
196
197
198-include ${DEPS}