change how Make triggers cleans
[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
17
18SRCSDIR := src/
19SRCS := # := start
20
21OBJSDIR := objsd/
22OBJS := # := start
23
24DEPSDIR := deps/
25DEPS := # := start
26
27# include all of the dir.mk
28DIRMK := dir.mk
29include ${SRCSDIR}${DIRMK}
30
31WORKINGDIR := bind/
32
33CFGDIRNAME := configs/
34SRCCFGDIR := ${CFGDIRNAME}
35DSTCFGDIR := ${WORKINGDIR}${CFGDIRNAME}
36
37CFGS := # := start
38CFGS += keys.cfg
39CFGS := $(addprefix ${DSTCFGDIR},${CFGS})
40
41TARGETNAME := run_physics
42TARGETTMP := ${OBJSDIR}${TARGETNAME}
43TARGET := ${WORKINGDIR}${TARGETNAME}
44
45DEPSBLDDIRS := ${DEPSDIR} $(addprefix ${DEPSDIR},${DIRS})
46OBJSBLDDIRS := ${OBJSDIR} $(addprefix ${OBJSDIR},${DIRS})
47BLDDIRS := ${OBJSBLDDIRS} ${DEPSBLDDIRS} ${WORKINGDIR} ${DSTCFGDIR}
48
49INCDIRS := ${SRCSDIR}
50
51
52PRNTFMT := printf "%-5s: %s\n"
53
54VERBOSE := 0
55
56ifeq (${VERBOSE},0)
57 # quiet the printf command
58 Q1 := @
59 # quiet the command that is `replaced' by an echo
60 Q2 := @
61else
62 # EAT the printf command as if it was not there
63 Q1 := @true # NOTE: the space between @true and the # is VERY important!!
64 # do not quiet the command output
65 Q2 :=
66endif
67
68.PHONY: all
69all: ${TARGET} ${CFGS}
70
71# how to link the main target
72${TARGETTMP}: ${OBJS}
73 ${Q1}${PRNTFMT} "${CXX}" "$@"
74 ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS}
75
76# rule to copy tmp target to working directory
77${TARGET}: ${TARGETTMP} | ${WORKINGDIR}
78 ${Q1}${PRNTFMT} "cp" "$@"
79 ${Q2}cp $< $@
80
81# how to make a directory
82${BLDDIRS}:
83 ${Q1}${PRNTFMT} "mkdir" "$@"
84 ${Q2}mkdir -p $@
85
86#${SRCSDIR}%.cpp: ${SRCSDIR}%.h
87
88# cause the below directory rules to work out
89.SECONDEXPANSION:
90
91# rule to make an object file from a .cpp
92${OBJSDIR}%.o: ${SRCSDIR}%.cpp | $$(dir $$@)
93 ${Q1}${PRNTFMT} "${CXX}" "$@"
94 ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $< -I "${INCDIRS}"
95
96# rule to make a depend file from a .cpp
97# be clever and escape the / chars in file paths
98# DON'T simply use another sed delimiter or it can't appear in the file paths
99${DEPSDIR}%.d: ${SRCSDIR}%.cpp | $$(dir $$@)
100 ${Q1}${PRNTFMT} "DEP" "$@"
101 ${Q2}${CXX} -MM ${CXXFLAGS} $< -I "${INCDIRS}" | \
102 sed 's/\(^.*\):/$(subst /,\/,${OBJSDIR}\1 $@):/' > $@
103
104# rule to copy the config files into the working directory
105${DSTCFGDIR}%.cfg: ${SRCCFGDIR}%.cfg | $$(dir $$@)
106 ${Q1}${PRNTFMT} "cp" "$@"
107 ${Q2}cp $< $@
108
109.PHONY: cleantargets
110cleantargets:
111 ${Q1}${PRNTFMT} "rm" "${TARGET} ${TARGETTMP}"
112 ${Q2}rm -f ${TARGET}
113
114.PHONY: cleanobjs
115cleanobjs:
116 ${Q1}${PRNTFMT} "rm" "${OBJSDIR}"
117 ${Q2}rm -rf ${OBJSDIR}
118
119.PHONY: cleandeps
120cleandeps:
121 ${Q1}${PRNTFMT} "rm" "${DEPSDIR}"
122 ${Q2}rm -rf ${DEPSDIR}
123
124.PHONY: clean
125clean: cleantargets cleanobjs
126
127.PHONY: cleanall
128cleanall: clean cleandeps
129
130.PHONY: gitclean
131gitclean:
132 ${Q1}${PRNTFMT} "git clean" "showing; use gitcleanf to force removal"
133 ${Q2}git clean -nxd
134
135.PHONY: gitcleanf
136gitcleanf:
137 ${Q1}${PRNTFMT} "git clean" "forcing"
138 ${Q2}git clean -fxd
139
140.PHONY: tar
141tar: physics.tar.bz2
142
143.PHONY: physics.tar.bz2
144physics.tar.bz2:
145 @${PRNTFMT} "git archive" "Warning, archives HEAD not current"
146 ${Q1}${PRNTFMT} "git archive" "physics.tar.bz2"
147 ${Q2}git archive --prefix=physics/ HEAD | bzip2 > physics.tar.bz2
148
149.PHONY: run
150run: all
151 cd ${WORKINGDIR}; ./${TARGETNAME}
152
153.PHONY: gdb
154gdb: all
155 cd ${WORKINGDIR}; gdb ${TARGETNAME}
156
157.PHONY: cgdb
158cgdb: all
159 cd ${WORKINGDIR}; cgdb ${TARGETNAME}
160
161.PHONY: val
162val: all
163 cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME}
164
165.PHONY: prof
166prof: run
167 cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > prof
168 cd ${WORKINGDIR}; kprof -f prof
169
170
171MINGMAKEARGS := "LIBGL := -lopengl32 -lglu32" \
172 "LIBSDL := `/usr/mingw32/bin/sdl-config --libs`" \
173 "CXXFLAGS := ${OPTFLAGS}" \
174 "CXX := mingw32-g++" \
175 "OBJSDIR := objs-mingw32/" \
176 "WORKINGDIR := bin-mingw32/" \
177 "TARGETNAME := run_physics.exe"
178
179.PHONY: mingw32
180mingw32:
181 ${Q1}${PRNTFMT} "make" "mingw32"
182 ${Q2}${MAKE} ${MINGMAKEARGS} clean all
183
184FINALMAKEARGS := "CXXFLAGS := ${OPTFLAGS}" \
185 "OBJSDIR := objs/" \
186 "WORKINGDIR := bin/"
187
188.PHONY: final
189final:
190 ${Q1}${PRNTFMT} "make" "final"
191 ${Q2}${MAKE} ${FINALMAKEARGS} clean all
192
193
194-include ${DEPS}