off loaded including of subdirectories to dir.mk files (fixes dependencies problems)
[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
0376f786 17
ec424960
PG
18SRCSDIR := src/
19SRCS := # := start
44b079f8 20
16f14459
PG
21OBJSDIR := objsd/
22OBJS := # := start
23
24DEPSDIR := deps/
25DEPS := # := start
26
70468808 27# include all of the dir.mk
07af3cf8
PG
28DIRMK := dir.mk
29include ${SRCSDIR}${DIRMK}
869b3330 30
ec424960
PG
31WORKINGDIR := bind/
32
869b3330 33CFGDIRNAME := configs/
ec424960 34SRCCFGDIR := ${CFGDIRNAME}
869b3330
PG
35DSTCFGDIR := ${WORKINGDIR}${CFGDIRNAME}
36
37CFGS := # := start
38CFGS += keys.cfg
39CFGS := $(addprefix ${DSTCFGDIR},${CFGS})
40
9d5863c5
PG
41TARGETNAME := run_physics
42TARGETTMP := ${OBJSDIR}${TARGETNAME}
ec424960 43TARGET := ${WORKINGDIR}${TARGETNAME}
9d5863c5 44
07af3cf8
PG
45DEPSBLDDIRS := ${DEPSDIR} $(addprefix ${DEPSDIR},${DIRS})
46OBJSBLDDIRS := ${OBJSDIR} $(addprefix ${OBJSDIR},${DIRS})
869b3330 47BLDDIRS := ${OBJSBLDDIRS} ${DEPSBLDDIRS} ${WORKINGDIR} ${DSTCFGDIR}
42f62a75 48
3d1f0813
PG
49INCDIRS := ${SRCSDIR}
50
ad9f1fb6 51
70468808
PG
52PRNTFMT := printf "%-5s: %s\n"
53
393654cf
PG
54VERBOSE := 0
55
56ifeq (${VERBOSE},0)
07af3cf8 57 # quiet the printf command
393654cf
PG
58 Q1 := @
59 # quiet the command that is `replaced' by an echo
60 Q2 := @
61else
07af3cf8 62 # EAT the printf command as if it was not there
393654cf
PG
63 Q1 := @true # NOTE: the space between @true and the # is VERY important!!
64 # do not quiet the command output
65 Q2 :=
66endif
ad9f1fb6 67
046b034c 68.PHONY: all
869b3330 69all: ${TARGET} ${CFGS}
37a74d97 70
869b3330
PG
71# how to link the main target
72${TARGETTMP}: ${OBJS}
bf7e6563 73 ${Q1}${PRNTFMT} "${CXX}" "$@"
869b3330 74 ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS}
ad9f1fb6 75
9d5863c5 76# rule to copy tmp target to working directory
ebea1138 77${TARGET}: ${TARGETTMP} | ${WORKINGDIR}
bf7e6563 78 ${Q1}${PRNTFMT} "cp" "$@"
37a74d97 79 ${Q2}cp $< $@
9d5863c5 80
42f62a75
PG
81# how to make a directory
82${BLDDIRS}:
2688190c 83 ${Q1}${PRNTFMT} "mkdir" "$@"
42f62a75
PG
84 ${Q2}mkdir -p $@
85
2688190c
PG
86# cause the below directory rules to work out
87.SECONDEXPANSION:
88
869b3330 89# rule to make an object file from a .cpp
2688190c 90${OBJSDIR}%.o: ${SRCSDIR}%.cpp | $$(dir $$@)
bf7e6563 91 ${Q1}${PRNTFMT} "${CXX}" "$@"
3d1f0813 92 ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $< -I "${INCDIRS}"
869b3330 93
a4bb9ac2 94# rule to make a depend file from a .cpp
5f264bf7
PG
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
2688190c 97${DEPSDIR}%.d: ${SRCSDIR}%.cpp | $$(dir $$@)
bf7e6563 98 ${Q1}${PRNTFMT} "DEP" "$@"
3d1f0813 99 ${Q2}${CXX} -MM ${CXXFLAGS} $< -I "${INCDIRS}" | \
5f264bf7 100 sed 's/\(^.*\):/$(subst /,\/,${OBJSDIR}\1 $@):/' > $@
ad9f1fb6 101
869b3330 102# rule to copy the config files into the working directory
2688190c 103${DSTCFGDIR}%.cfg: ${SRCCFGDIR}%.cfg | $$(dir $$@)
bf7e6563 104 ${Q1}${PRNTFMT} "cp" "$@"
869b3330 105 ${Q2}cp $< $@
054d658f 106
ad9f1fb6 107
67b5017f 108tags: ${SRCS}
bf7e6563 109 ${Q1}${PRNTFMT} "ctags" "$@"
67b5017f
PG
110 ${Q2}ctags $^
111
112
046b034c 113.PHONY: clean
ad9f1fb6 114clean:
70468808
PG
115 ${Q1}${PRNTFMT} "rm" "${OBJSDIR}"
116 ${Q2}rm -rf ${OBJSDIR}
117 ${Q1}${PRNTFMT} "rm" "${TARGET} ${TARGETTMP}"
393654cf 118 ${Q2}rm -f ${TARGET}
ad9f1fb6 119
046b034c 120.PHONY: distclean
ad9f1fb6 121distclean: clean
70468808
PG
122 ${Q1}${PRNTFMT} "rm" "${DEPSDIR}"
123 ${Q2}rm -rf ${DEPSDIR}
124 ${Q1}${PRNTFMT} "rm" "tags prof gmon.out"
393654cf 125 ${Q2}rm -f tags prof gmon.out
ad9f1fb6 126
d893cce2
PG
127.PHONY: gitclean
128gitclean:
bf7e6563 129 ${Q1}${PRNTFMT} "git clean" "showing; use gitcleanf to force removal"
5f264bf7 130 ${Q2}git clean -nxd
d893cce2
PG
131
132.PHONY: gitcleanf
133gitcleanf:
bf7e6563 134 ${Q1}${PRNTFMT} "git clean" "forcing"
5f264bf7 135 ${Q2}git clean -fxd
d893cce2 136
7adc59fe 137.PHONY: tar
5f264bf7 138tar: physics.tar.bz2
8381f595 139
5f264bf7
PG
140.PHONY: physics.tar.bz2
141physics.tar.bz2:
bf7e6563
PG
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
ad9f1fb6 145
046b034c
PG
146.PHONY: run
147run: all
67b5017f 148 cd ${WORKINGDIR}; ./${TARGETNAME}
ad9f1fb6 149
6aad402a
PG
150.PHONY: gdb
151gdb: all
67b5017f
PG
152 cd ${WORKINGDIR}; gdb ${TARGETNAME}
153
154.PHONY: cgdb
155cgdb: all
156 cd ${WORKINGDIR}; cgdb ${TARGETNAME}
6aad402a 157
63a52c99
PG
158.PHONY: val
159val: all
823da4ea 160 cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME}
63a52c99
PG
161
162.PHONY: prof
67b5017f 163prof: run
06699cc7
PG
164 cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > prof
165 cd ${WORKINGDIR}; kprof -f prof
ad9f1fb6 166
4e77f48b 167
9d5863c5
PG
168MINGMAKEARGS := "LIBGL := -lopengl32 -lglu32" \
169 "LIBSDL := `/usr/mingw32/bin/sdl-config --libs`" \
170 "CXXFLAGS := ${OPTFLAGS}" \
171 "CXX := mingw32-g++" \
5f264bf7
PG
172 "OBJSDIR := objs-mingw32/" \
173 "WORKINGDIR := bin-mingw32/" \
9d5863c5
PG
174 "TARGETNAME := run_physics.exe"
175
176.PHONY: mingw32
177mingw32:
bf7e6563 178 ${Q1}${PRNTFMT} "make" "mingw32"
9d5863c5
PG
179 ${Q2}${MAKE} ${MINGMAKEARGS} clean all
180
4e77f48b 181FINALMAKEARGS := "CXXFLAGS := ${OPTFLAGS}" \
5f264bf7
PG
182 "OBJSDIR := objs/" \
183 "WORKINGDIR := bin/"
4e77f48b
PG
184
185.PHONY: final
186final:
bf7e6563 187 ${Q1}${PRNTFMT} "make" "final"
4e77f48b
PG
188 ${Q2}${MAKE} ${FINALMAKEARGS} clean all
189
06699cc7 190
f4b779e4 191-include ${DEPS}