off loaded including of subdirectories to dir.mk files (fixes dependencies problems)
[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# cause the below directory rules to work out
87.SECONDEXPANSION:
88
89# rule to make an object file from a .cpp
90${OBJSDIR}%.o: ${SRCSDIR}%.cpp | $$(dir $$@)
91 ${Q1}${PRNTFMT} "${CXX}" "$@"
92 ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $< -I "${INCDIRS}"
93
94# rule to make a depend file from a .cpp
95# be clever and escape the / chars in file paths
96# DON'T simply use another sed delimiter or it can't appear in the file paths
97${DEPSDIR}%.d: ${SRCSDIR}%.cpp | $$(dir $$@)
98 ${Q1}${PRNTFMT} "DEP" "$@"
99 ${Q2}${CXX} -MM ${CXXFLAGS} $< -I "${INCDIRS}" | \
100 sed 's/\(^.*\):/$(subst /,\/,${OBJSDIR}\1 $@):/' > $@
101
102# rule to copy the config files into the working directory
103${DSTCFGDIR}%.cfg: ${SRCCFGDIR}%.cfg | $$(dir $$@)
104 ${Q1}${PRNTFMT} "cp" "$@"
105 ${Q2}cp $< $@
106
107
108tags: ${SRCS}
109 ${Q1}${PRNTFMT} "ctags" "$@"
110 ${Q2}ctags $^
111
112
113.PHONY: clean
114clean:
115 ${Q1}${PRNTFMT} "rm" "${OBJSDIR}"
116 ${Q2}rm -rf ${OBJSDIR}
117 ${Q1}${PRNTFMT} "rm" "${TARGET} ${TARGETTMP}"
118 ${Q2}rm -f ${TARGET}
119
120.PHONY: distclean
121distclean: clean
122 ${Q1}${PRNTFMT} "rm" "${DEPSDIR}"
123 ${Q2}rm -rf ${DEPSDIR}
124 ${Q1}${PRNTFMT} "rm" "tags prof gmon.out"
125 ${Q2}rm -f tags prof gmon.out
126
127.PHONY: gitclean
128gitclean:
129 ${Q1}${PRNTFMT} "git clean" "showing; use gitcleanf to force removal"
130 ${Q2}git clean -nxd
131
132.PHONY: gitcleanf
133gitcleanf:
134 ${Q1}${PRNTFMT} "git clean" "forcing"
135 ${Q2}git clean -fxd
136
137.PHONY: tar
138tar: physics.tar.bz2
139
140.PHONY: physics.tar.bz2
141physics.tar.bz2:
142 @${PRNTFMT} "git archive" "Warning, archives HEAD not current"
143 ${Q1}${PRNTFMT} "git archive" "physics.tar.bz2"
144 ${Q2}git archive --prefix=physics/ HEAD | bzip2 > physics.tar.bz2
145
146.PHONY: run
147run: all
148 cd ${WORKINGDIR}; ./${TARGETNAME}
149
150.PHONY: gdb
151gdb: all
152 cd ${WORKINGDIR}; gdb ${TARGETNAME}
153
154.PHONY: cgdb
155cgdb: all
156 cd ${WORKINGDIR}; cgdb ${TARGETNAME}
157
158.PHONY: val
159val: all
160 cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME}
161
162.PHONY: prof
163prof: run
164 cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > prof
165 cd ${WORKINGDIR}; kprof -f prof
166
167
168MINGMAKEARGS := "LIBGL := -lopengl32 -lglu32" \
169 "LIBSDL := `/usr/mingw32/bin/sdl-config --libs`" \
170 "CXXFLAGS := ${OPTFLAGS}" \
171 "CXX := mingw32-g++" \
172 "OBJSDIR := objs-mingw32/" \
173 "WORKINGDIR := bin-mingw32/" \
174 "TARGETNAME := run_physics.exe"
175
176.PHONY: mingw32
177mingw32:
178 ${Q1}${PRNTFMT} "make" "mingw32"
179 ${Q2}${MAKE} ${MINGMAKEARGS} clean all
180
181FINALMAKEARGS := "CXXFLAGS := ${OPTFLAGS}" \
182 "OBJSDIR := objs/" \
183 "WORKINGDIR := bin/"
184
185.PHONY: final
186final:
187 ${Q1}${PRNTFMT} "make" "final"
188 ${Q2}${MAKE} ${FINALMAKEARGS} clean all
189
190
191-include ${DEPS}