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) |
2e58db1a PG |
42 | LINKERNAME := pg.dll |
43 | SONAME := pg.dll | |
44 | REALNAME := pg.dll | |
45 | else | |
46 | LINKERNAME := libpg.so | |
47 | SONAME := libpg.so.0 | |
48 | REALNAME := libpg.so.0.0 | |
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 | |
59 | MYFLAGS := -Wall -pedantic -ansi | |
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 PG |
111 | |
112 | # include all of the dir.mk | |
113 | DIRS := # := start | |
114 | SRCS := # := start | |
115 | OBJS := # := start | |
116 | DEPS := # := start | |
117 | DIRMK := dir.mk | |
118 | include ${SRCSDIR}${DIRMK} | |
119 | ||
120 | ||
121 | DEPSBLDDIRS := ${DEPSDIR} $(addprefix ${DEPSDIR},${DIRS}) | |
122 | OBJSBLDDIRS := ${OBJSDIR} $(addprefix ${OBJSDIR},${DIRS}) | |
123 | ||
124 | BLDDIRS := # := start | |
125 | BLDDIRS += ${OBJSBLDDIRS} | |
126 | BLDDIRS += ${DEPSBLDDIRS} | |
127 | BLDDIRS += ${WORKINGDIR} | |
128 | ||
129 | ||
6da586f4 | 130 | .PHONY: all |
39c02330 | 131 | all: ${TARGET} |
6da586f4 | 132 | |
6b710510 PG |
133 | INSTALL := install |
134 | ||
135 | # HACK install | |
df9cea63 | 136 | install: |
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 |
144 | uninstall: |
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 |
181 | CLEANCMDS := cleanbin cleanobjs cleandeps clean cleanall |
182 | ||
6da586f4 PG |
183 | .PHONY: cleanbin |
184 | cleanbin: | |
185 | ${Q1}${PRNTFMT} "rm" "${WORKINGDIR}" | |
186 | ${Q2}rm -rf ${WORKINGDIR} | |
187 | ||
188 | .PHONY: cleanobjs | |
189 | cleanobjs: | |
190 | ${Q1}${PRNTFMT} "rm" "${OBJSDIR}" | |
191 | ${Q2}rm -rf ${OBJSDIR} | |
192 | ||
193 | .PHONY: cleandeps | |
194 | cleandeps: | |
195 | ${Q1}${PRNTFMT} "rm" "${DEPSDIR}" | |
196 | ${Q2}rm -rf ${DEPSDIR} | |
197 | ||
198 | .PHONY: clean | |
199 | clean: cleanobjs | |
cfe5b22f | 200 | ${Q1}${PRNTFMT} "rm" "${TARGET}" |
17f363e6 | 201 | ${Q2}rm -f ${TARGET} |
6da586f4 PG |
202 | |
203 | .PHONY: cleanall | |
17f363e6 | 204 | cleanall: cleanbin cleanobjs cleandeps |
6da586f4 | 205 | |
cfe5b22f PG |
206 | # Do not include deps files when doing a _single_ clean operation |
207 | ifeq ($(findstring ${MAKECMDGOALS},${CLEANCMDS}),) | |
208 | -include ${DEPS} | |
209 | endif | |
6da586f4 | 210 |