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