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