fixed redolent clean rule
[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)
2e58db1a
PG
42 LINKERNAME := pg.dll
43 SONAME := pg.dll
44 REALNAME := pg.dll
45else
46 LINKERNAME := libpg.so
47 SONAME := libpg.so.0
48 REALNAME := libpg.so.0.0
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
59MYFLAGS := -Wall -pedantic -ansi
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
PG
111
112# include all of the dir.mk
113DIRS := # := start
114SRCS := # := start
115OBJS := # := start
116DEPS := # := start
117DIRMK := dir.mk
118include ${SRCSDIR}${DIRMK}
119
120
121DEPSBLDDIRS := ${DEPSDIR} $(addprefix ${DEPSDIR},${DIRS})
122OBJSBLDDIRS := ${OBJSDIR} $(addprefix ${OBJSDIR},${DIRS})
123
124BLDDIRS := # := start
125BLDDIRS += ${OBJSBLDDIRS}
126BLDDIRS += ${DEPSBLDDIRS}
127BLDDIRS += ${WORKINGDIR}
128
129
6da586f4 130.PHONY: all
39c02330 131all: ${TARGET}
6da586f4 132
6b710510
PG
133INSTALL := install
134
135# HACK install
df9cea63 136install:
53054b96
PG
137 ${INSTALL} -d ${includedir}/pg
138 ${INSTALL} -t ${includedir}/pg inc/*
139 ln -sfn ${REALNAME} ${libdir}/${LINKERNAME}
140 ln -sfn ${REALNAME} ${libdir}/${SONAME}
141 ${INSTALL} -t ${libdir} ${WORKINGDIR}${REALNAME}
539650c7 142
6b710510 143# HACK uninstall
539650c7
PG
144uninstall:
145 rm -rf /usr/include/pg
00b5432f
PG
146 rm /usr/lib/${REALNAME}
147 rm /usr/lib/${LINKERNAME}
148 rm /usr/lib/${SONAME}
df9cea63 149
069e9fcf 150# cause the fancy $${@D} directory rules to work out
6da586f4
PG
151.SECONDEXPANSION:
152
153# how to link the main target
069e9fcf 154${TARGETTMP}: ${OBJS} | $${@D}
6da586f4 155 ${Q1}${PRNTFMT} "${CXX}" "$@"
11c73ff2 156 ${Q2}${CXX} ${CXXFLAGS} ${LNKFLAGS} -o $@ $^ ${LIBS}
6da586f4
PG
157
158# rule to copy tmp target to working directory
069e9fcf 159${TARGET}: ${TARGETTMP} | $${@D}
6da586f4
PG
160 ${Q1}${PRNTFMT} "cp" "$@"
161 ${Q2}cp $< $@
162
6da586f4
PG
163# how to make a directory
164${BLDDIRS}:
165 ${Q1}${PRNTFMT} "mkdir" "$@"
166 ${Q2}mkdir -p $@
167
168# rule to make an object file from a .cpp
069e9fcf 169${OBJSDIR}%.o: ${SRCSDIR}%.cpp | $${@D}
6da586f4 170 ${Q1}${PRNTFMT} "${CXX}" "$@"
df9cea63 171 ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $< ${INCFLAGS}
6da586f4
PG
172
173# rule to make a depend file from a .cpp
174# be clever and escape the / chars in file paths
175# DON'T simply use another sed delimiter or it can't appear in the file paths
069e9fcf 176${DEPSDIR}%.d: ${SRCSDIR}%.cpp | $${@D}
6da586f4 177 ${Q1}${PRNTFMT} "DEP" "$@"
df9cea63 178 ${Q2}${CXX} -MM ${CXXFLAGS} $< ${INCFLAGS} | \
6da586f4
PG
179 sed 's/\(^.*\):/$(subst /,\/,${OBJSDIR}\1 $@):/' > $@
180
cfe5b22f
PG
181CLEANCMDS := cleanbin cleanobjs cleandeps clean cleanall
182
6da586f4
PG
183.PHONY: cleanbin
184cleanbin:
185 ${Q1}${PRNTFMT} "rm" "${WORKINGDIR}"
186 ${Q2}rm -rf ${WORKINGDIR}
187
188.PHONY: cleanobjs
189cleanobjs:
190 ${Q1}${PRNTFMT} "rm" "${OBJSDIR}"
191 ${Q2}rm -rf ${OBJSDIR}
192
193.PHONY: cleandeps
194cleandeps:
195 ${Q1}${PRNTFMT} "rm" "${DEPSDIR}"
196 ${Q2}rm -rf ${DEPSDIR}
197
198.PHONY: clean
199clean: cleanobjs
cfe5b22f 200 ${Q1}${PRNTFMT} "rm" "${TARGET}"
17f363e6 201 ${Q2}rm -f ${TARGET}
6da586f4
PG
202
203.PHONY: cleanall
17f363e6 204cleanall: cleanbin cleanobjs cleandeps
6da586f4 205
cfe5b22f
PG
206# Do not include deps files when doing a _single_ clean operation
207ifeq ($(findstring ${MAKECMDGOALS},${CLEANCMDS}),)
208 -include ${DEPS}
209endif
6da586f4 210