Commit | Line | Data |
---|---|---|
6da586f4 | 1 | |
11c73ff2 PG |
2 | # set this on the command line to get a WIN32 or a FINAL build |
3 | BUILD := DEBUG | |
2e58db1a | 4 | |
2e58db1a | 5 | |
6da586f4 | 6 | SRCSDIR := src/ |
edcf57eb PG |
7 | DEPSDIR := deps/ |
8 | INCDIRS := ${SRCSDIR} inc/ | |
6da586f4 | 9 | |
11c73ff2 | 10 | ifeq (${BUILD},WIN32) |
2e58db1a PG |
11 | OBJSDIR := objs-mingw32/ |
12 | else | |
11c73ff2 | 13 | ifeq (${BUILD},FINAL) |
2e58db1a PG |
14 | OBJSDIR := objs/ |
15 | else | |
16 | OBJSDIR := objsd/ | |
17 | endif | |
18 | endif | |
6da586f4 | 19 | |
11c73ff2 | 20 | ifeq (${BUILD},WIN32) |
2e58db1a PG |
21 | WORKINGDIR := bin-mingw32/ |
22 | else | |
11c73ff2 | 23 | ifeq (${BUILD},FINAL) |
2e58db1a PG |
24 | WORKINGDIR := bin/ |
25 | else | |
26 | WORKINGDIR := bind/ | |
27 | endif | |
28 | endif | |
29 | ||
edcf57eb PG |
30 | |
31 | ifeq (${BUILD},WIN32) | |
32 | LIBGL := -lopengl32 -lglu32 | |
33 | LIBSDL := `/usr/mingw32/bin/sdl-config --libs` | |
34 | else | |
35 | LIBGL := -lGL -lGLU | |
36 | LIBSDL := `sdl-config --libs` | |
37 | endif | |
38 | LIBS := ${LIBSDL} ${LIBGL} | |
39 | ||
40 | ||
11c73ff2 | 41 | ifeq (${BUILD},WIN32) |
7936c2c5 PG |
42 | LINKERNAME := bear.dll |
43 | SONAME := bear.dll | |
44 | REALNAME := bear.dll | |
2e58db1a | 45 | else |
7936c2c5 PG |
46 | LINKERNAME := libbear.so |
47 | SONAME := libbear.so.0 | |
48 | REALNAME := libbear.so.0.0 | |
2e58db1a | 49 | endif |
eb6016d8 PG |
50 | |
51 | TARGETTMP := ${OBJSDIR}${REALNAME} | |
52 | TARGET := ${WORKINGDIR}${REALNAME} | |
6da586f4 | 53 | |
2e58db1a | 54 | |
edcf57eb PG |
55 | OPTFLAGS := -O2 |
56 | DBGFLAGS := -ggdb | |
57 | PRFFLAGS := ${DBGFLAGS} -pg | |
58 | LIBFLAGS := -fPIC | |
394de68b | 59 | MYFLAGS := -Wall -Wextra -pedantic -ansi |
edcf57eb PG |
60 | INCFLAGS := $(addprefix -I, ${INCDIRS}) |
61 | LNKFLAGS := -shared -Wl,-soname,${SONAME} | |
62 | ||
63 | CXXFLAGS := ${MYFLAGS} ${LIBFLAGS} | |
64 | ifeq (${BUILD},WIN32) | |
65 | CXXFLAGS += ${OPTFLAGS} | |
66 | else | |
67 | ifeq (${BUILD},FINAL) | |
68 | CXXFLAGS += ${OPTFLAGS} | |
69 | else | |
70 | CXXFLAGS += ${DBGFLAGS} | |
71 | endif | |
72 | endif | |
73 | ||
74 | ifeq (${BUILD},WIN32) | |
75 | CXX := mingw32-g++ | |
76 | else | |
77 | CXX := g++ | |
78 | endif | |
6da586f4 | 79 | |
6da586f4 | 80 | |
11c73ff2 PG |
81 | |
82 | ifeq (${BUILD},WIN32) | |
53054b96 PG |
83 | prefix := /usr/mingw32 |
84 | else | |
85 | prefix := /usr | |
86 | endif | |
87 | exec_prefix := ${prefix} | |
88 | includedir := ${prefix}/include | |
89 | libdir := ${exec_prefix}/lib | |
6da586f4 | 90 | |
11c73ff2 PG |
91 | ifeq (${BUILD},WIN32) |
92 | PRNTFMT := printf "%-12s: %s\n" | |
93 | else | |
94 | PRNTFMT := printf "%-8s: %s\n" | |
95 | endif | |
6da586f4 PG |
96 | |
97 | VERBOSE := 0 | |
98 | ||
99 | ifeq (${VERBOSE},0) | |
100 | # quiet the printf command | |
101 | Q1 := @ | |
102 | # quiet the command that is `replaced' by an echo | |
103 | Q2 := @ | |
104 | else | |
105 | # EAT the printf command as if it was not there | |
106 | Q1 := @true # NOTE: the space between @true and the # is VERY important!! | |
107 | # do not quiet the command output | |
108 | Q2 := | |
109 | endif | |
110 | ||
edcf57eb | 111 | |
630fa680 PG |
112 | # cause the fancy $${@D} directory rules to work out |
113 | .SECONDEXPANSION: | |
114 | ||
72482893 | 115 | # The first and therefor default rule |
630fa680 PG |
116 | .PHONY: all |
117 | all: ${TARGET} | |
118 | ||
119 | ||
120 | # lists populated by dir.mk files in subdirectories | |
edcf57eb | 121 | SRCS := # := start |
630fa680 | 122 | DIRS := # := start |
edcf57eb PG |
123 | OBJS := # := start |
124 | DEPS := # := start | |
630fa680 | 125 | |
edcf57eb | 126 | DIRMK := dir.mk |
630fa680 PG |
127 | |
128 | # include all of the dir.mk files in src | |
edcf57eb PG |
129 | include ${SRCSDIR}${DIRMK} |
130 | ||
131 | ||
132 | DEPSBLDDIRS := ${DEPSDIR} $(addprefix ${DEPSDIR},${DIRS}) | |
133 | OBJSBLDDIRS := ${OBJSDIR} $(addprefix ${OBJSDIR},${DIRS}) | |
134 | ||
135 | BLDDIRS := # := start | |
136 | BLDDIRS += ${OBJSBLDDIRS} | |
137 | BLDDIRS += ${DEPSBLDDIRS} | |
138 | BLDDIRS += ${WORKINGDIR} | |
139 | ||
140 | ||
6b710510 PG |
141 | INSTALL := install |
142 | ||
143 | # HACK install | |
df9cea63 | 144 | install: |
7936c2c5 PG |
145 | ${INSTALL} -d ${includedir}/bear |
146 | ${INSTALL} -t ${includedir}/bear inc/* | |
53054b96 PG |
147 | ln -sfn ${REALNAME} ${libdir}/${LINKERNAME} |
148 | ln -sfn ${REALNAME} ${libdir}/${SONAME} | |
149 | ${INSTALL} -t ${libdir} ${WORKINGDIR}${REALNAME} | |
539650c7 | 150 | |
6b710510 | 151 | # HACK uninstall |
539650c7 | 152 | uninstall: |
7936c2c5 | 153 | rm -rf /usr/include/bear |
00b5432f PG |
154 | rm /usr/lib/${REALNAME} |
155 | rm /usr/lib/${LINKERNAME} | |
156 | rm /usr/lib/${SONAME} | |
df9cea63 | 157 | |
6da586f4 | 158 | # how to link the main target |
069e9fcf | 159 | ${TARGETTMP}: ${OBJS} | $${@D} |
6da586f4 | 160 | ${Q1}${PRNTFMT} "${CXX}" "$@" |
11c73ff2 | 161 | ${Q2}${CXX} ${CXXFLAGS} ${LNKFLAGS} -o $@ $^ ${LIBS} |
6da586f4 PG |
162 | |
163 | # rule to copy tmp target to working directory | |
069e9fcf | 164 | ${TARGET}: ${TARGETTMP} | $${@D} |
6da586f4 PG |
165 | ${Q1}${PRNTFMT} "cp" "$@" |
166 | ${Q2}cp $< $@ | |
167 | ||
6da586f4 PG |
168 | # how to make a directory |
169 | ${BLDDIRS}: | |
170 | ${Q1}${PRNTFMT} "mkdir" "$@" | |
171 | ${Q2}mkdir -p $@ | |
172 | ||
173 | # rule to make an object file from a .cpp | |
069e9fcf | 174 | ${OBJSDIR}%.o: ${SRCSDIR}%.cpp | $${@D} |
6da586f4 | 175 | ${Q1}${PRNTFMT} "${CXX}" "$@" |
df9cea63 | 176 | ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $< ${INCFLAGS} |
6da586f4 PG |
177 | |
178 | # rule to make a depend file from a .cpp | |
179 | # be clever and escape the / chars in file paths | |
180 | # DON'T simply use another sed delimiter or it can't appear in the file paths | |
069e9fcf | 181 | ${DEPSDIR}%.d: ${SRCSDIR}%.cpp | $${@D} |
6da586f4 | 182 | ${Q1}${PRNTFMT} "DEP" "$@" |
df9cea63 | 183 | ${Q2}${CXX} -MM ${CXXFLAGS} $< ${INCFLAGS} | \ |
6da586f4 PG |
184 | sed 's/\(^.*\):/$(subst /,\/,${OBJSDIR}\1 $@):/' > $@ |
185 | ||
cfe5b22f PG |
186 | CLEANCMDS := cleanbin cleanobjs cleandeps clean cleanall |
187 | ||
6da586f4 PG |
188 | .PHONY: cleanbin |
189 | cleanbin: | |
190 | ${Q1}${PRNTFMT} "rm" "${WORKINGDIR}" | |
191 | ${Q2}rm -rf ${WORKINGDIR} | |
192 | ||
193 | .PHONY: cleanobjs | |
194 | cleanobjs: | |
195 | ${Q1}${PRNTFMT} "rm" "${OBJSDIR}" | |
196 | ${Q2}rm -rf ${OBJSDIR} | |
197 | ||
198 | .PHONY: cleandeps | |
199 | cleandeps: | |
200 | ${Q1}${PRNTFMT} "rm" "${DEPSDIR}" | |
201 | ${Q2}rm -rf ${DEPSDIR} | |
202 | ||
203 | .PHONY: clean | |
204 | clean: cleanobjs | |
cfe5b22f | 205 | ${Q1}${PRNTFMT} "rm" "${TARGET}" |
17f363e6 | 206 | ${Q2}rm -f ${TARGET} |
6da586f4 PG |
207 | |
208 | .PHONY: cleanall | |
17f363e6 | 209 | cleanall: cleanbin cleanobjs cleandeps |
6da586f4 | 210 | |
cfe5b22f PG |
211 | # Do not include deps files when doing a _single_ clean operation |
212 | ifeq ($(findstring ${MAKECMDGOALS},${CLEANCMDS}),) | |
213 | -include ${DEPS} | |
214 | endif | |
6da586f4 | 215 |