removed all ../ entries and made a basic inc path (dependencies are currently broke)
[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 INCDIRS     := ${SRCSDIR}
57
58
59 PRNTFMT := printf "%-5s: %s\n"
60
61 VERBOSE := 0
62
63 ifeq (${VERBOSE},0)
64     # quiet the echo command
65     Q1 := @
66     # quiet the command that is `replaced' by an echo
67     Q2 := @
68 else
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 :=
73 endif
74
75 .PHONY: all
76 all: ${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
115 tags: ${SRCS}
116         ${Q1}${PRNTFMT} "ctags" "$@"
117         ${Q2}ctags $^
118
119
120 .PHONY: clean
121 clean:
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
128 distclean: 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
135 gitclean:
136         ${Q1}${PRNTFMT} "git clean" "showing; use gitcleanf to force removal"
137         ${Q2}git clean -nxd
138
139 .PHONY: gitcleanf
140 gitcleanf:
141         ${Q1}${PRNTFMT} "git clean" "forcing"
142         ${Q2}git clean -fxd
143
144 .PHONY: tar
145 tar: physics.tar.bz2
146
147 .PHONY: physics.tar.bz2
148 physics.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
154 run: all
155         cd ${WORKINGDIR}; ./${TARGETNAME}
156
157 .PHONY: gdb
158 gdb: all
159         cd ${WORKINGDIR}; gdb ${TARGETNAME}
160
161 .PHONY: cgdb
162 cgdb: all
163         cd ${WORKINGDIR}; cgdb ${TARGETNAME}
164
165 .PHONY: val
166 val: all
167         cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME}
168
169 .PHONY: prof
170 prof: run
171         cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > prof
172         cd ${WORKINGDIR}; kprof -f prof
173
174
175 MINGMAKEARGS := "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
184 mingw32:
185         ${Q1}${PRNTFMT} "make" "mingw32"
186         ${Q2}${MAKE} ${MINGMAKEARGS} clean all
187
188 FINALMAKEARGS := "CXXFLAGS   := ${OPTFLAGS}" \
189                  "OBJSDIR    := objs/" \
190                  "WORKINGDIR := bin/"
191
192 .PHONY: final
193 final:
194         ${Q1}${PRNTFMT} "make" "final"
195         ${Q2}${MAKE} ${FINALMAKEARGS} clean all
196
197
198 -include ${DEPS}