added -rdynamic flag for better traces
[libbear.git] / Makefile
CommitLineData
6da586f4 1
11c73ff2
PG
2# set this on the command line to get a WIN32 or a FINAL build
3BUILD := DEBUG
2e58db1a 4
2e58db1a 5
6da586f4 6SRCSDIR := src/
edcf57eb
PG
7DEPSDIR := deps/
8INCDIRS := ${SRCSDIR} inc/
6da586f4 9
11c73ff2 10ifeq (${BUILD},WIN32)
2e58db1a
PG
11 OBJSDIR := objs-mingw32/
12else
11c73ff2 13ifeq (${BUILD},FINAL)
2e58db1a
PG
14 OBJSDIR := objs/
15else
16 OBJSDIR := objsd/
17endif
18endif
6da586f4 19
11c73ff2 20ifeq (${BUILD},WIN32)
2e58db1a
PG
21 WORKINGDIR := bin-mingw32/
22else
11c73ff2 23ifeq (${BUILD},FINAL)
2e58db1a
PG
24 WORKINGDIR := bin/
25else
26 WORKINGDIR := bind/
27endif
28endif
29
edcf57eb
PG
30
31ifeq (${BUILD},WIN32)
32 LIBGL := -lopengl32 -lglu32
33 LIBSDL := `/usr/mingw32/bin/sdl-config --libs`
34else
35 LIBGL := -lGL -lGLU
36 LIBSDL := `sdl-config --libs`
37endif
38LIBS := ${LIBSDL} ${LIBGL}
39
40
11c73ff2 41ifeq (${BUILD},WIN32)
7936c2c5
PG
42 LINKERNAME := bear.dll
43 SONAME := bear.dll
44 REALNAME := bear.dll
2e58db1a 45else
7936c2c5
PG
46 LINKERNAME := libbear.so
47 SONAME := libbear.so.0
48 REALNAME := libbear.so.0.0
2e58db1a 49endif
eb6016d8
PG
50
51TARGETTMP := ${OBJSDIR}${REALNAME}
52TARGET := ${WORKINGDIR}${REALNAME}
6da586f4 53
2e58db1a 54
edcf57eb
PG
55OPTFLAGS := -O2
56DBGFLAGS := -ggdb
57PRFFLAGS := ${DBGFLAGS} -pg
58LIBFLAGS := -fPIC
394de68b 59MYFLAGS := -Wall -Wextra -pedantic -ansi
edcf57eb
PG
60INCFLAGS := $(addprefix -I, ${INCDIRS})
61LNKFLAGS := -shared -Wl,-soname,${SONAME}
62
63CXXFLAGS := ${MYFLAGS} ${LIBFLAGS}
64ifeq (${BUILD},WIN32)
65 CXXFLAGS += ${OPTFLAGS}
66else
67ifeq (${BUILD},FINAL)
68 CXXFLAGS += ${OPTFLAGS}
69else
70 CXXFLAGS += ${DBGFLAGS}
71endif
72endif
73
74ifeq (${BUILD},WIN32)
75 CXX := mingw32-g++
76else
77 CXX := g++
78endif
6da586f4 79
6da586f4 80
11c73ff2
PG
81
82ifeq (${BUILD},WIN32)
53054b96
PG
83 prefix := /usr/mingw32
84else
85 prefix := /usr
86endif
87exec_prefix := ${prefix}
88includedir := ${prefix}/include
89libdir := ${exec_prefix}/lib
6da586f4 90
11c73ff2
PG
91ifeq (${BUILD},WIN32)
92 PRNTFMT := printf "%-12s: %s\n"
93else
94 PRNTFMT := printf "%-8s: %s\n"
95endif
6da586f4
PG
96
97VERBOSE := 0
98
99ifeq (${VERBOSE},0)
100 # quiet the printf command
101 Q1 := @
102 # quiet the command that is `replaced' by an echo
103 Q2 := @
104else
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 :=
109endif
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
117all: ${TARGET}
118
119
120# lists populated by dir.mk files in subdirectories
edcf57eb 121SRCS := # := start
630fa680 122DIRS := # := start
edcf57eb
PG
123OBJS := # := start
124DEPS := # := start
630fa680 125
edcf57eb 126DIRMK := dir.mk
630fa680
PG
127
128# include all of the dir.mk files in src
edcf57eb
PG
129include ${SRCSDIR}${DIRMK}
130
131
132DEPSBLDDIRS := ${DEPSDIR} $(addprefix ${DEPSDIR},${DIRS})
133OBJSBLDDIRS := ${OBJSDIR} $(addprefix ${OBJSDIR},${DIRS})
134
135BLDDIRS := # := start
136BLDDIRS += ${OBJSBLDDIRS}
137BLDDIRS += ${DEPSBLDDIRS}
138BLDDIRS += ${WORKINGDIR}
139
140
6b710510
PG
141INSTALL := install
142
143# HACK install
df9cea63 144install:
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 152uninstall:
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
186CLEANCMDS := cleanbin cleanobjs cleandeps clean cleanall
187
6da586f4
PG
188.PHONY: cleanbin
189cleanbin:
190 ${Q1}${PRNTFMT} "rm" "${WORKINGDIR}"
191 ${Q2}rm -rf ${WORKINGDIR}
192
193.PHONY: cleanobjs
194cleanobjs:
195 ${Q1}${PRNTFMT} "rm" "${OBJSDIR}"
196 ${Q2}rm -rf ${OBJSDIR}
197
198.PHONY: cleandeps
199cleandeps:
200 ${Q1}${PRNTFMT} "rm" "${DEPSDIR}"
201 ${Q2}rm -rf ${DEPSDIR}
202
203.PHONY: clean
204clean: cleanobjs
cfe5b22f 205 ${Q1}${PRNTFMT} "rm" "${TARGET}"
17f363e6 206 ${Q2}rm -f ${TARGET}
6da586f4
PG
207
208.PHONY: cleanall
17f363e6 209cleanall: cleanbin cleanobjs cleandeps
6da586f4 210
cfe5b22f
PG
211# Do not include deps files when doing a _single_ clean operation
212ifeq ($(findstring ${MAKECMDGOALS},${CLEANCMDS}),)
213 -include ${DEPS}
214endif
6da586f4 215