host: Move server perf code to server frame code
[xonotic/darkplaces.git] / makefile
1 #####  DP_MAKE_TARGET autodetection and arch specific variables #####
2
3 ifndef DP_MAKE_TARGET
4
5 # Win32
6 ifdef WINDIR
7         DP_MAKE_TARGET=mingw
8 else
9
10 # UNIXes
11 DP_ARCH:=$(shell uname)
12 ifneq ($(filter %BSD,$(DP_ARCH)),)
13         DP_MAKE_TARGET=bsd
14 else
15 ifeq ($(DP_ARCH), Darwin)
16         DP_MAKE_TARGET=macosx
17 else
18 ifeq ($(DP_ARCH), SunOS)
19         DP_MAKE_TARGET=sunos
20 else
21         DP_MAKE_TARGET=linux
22
23 endif  # ifeq ($(DP_ARCH), SunOS)
24 endif  # ifeq ($(DP_ARCH), Darwin)
25 endif  # ifneq ($(filter %BSD,$(DP_ARCH)),)
26 endif  # ifdef windir
27 endif  # ifndef DP_MAKE_TARGET
28
29 # If we're targeting an x86 CPU we want to enable DP_SSE (CFLAGS_SSE and SSE2)
30 ifeq ($(DP_MAKE_TARGET), mingw)
31         DP_SSE:=1
32 else
33         DP_MACHINE:=$(shell uname -m)
34         ifeq ($(DP_MACHINE),x86_64)
35                 DP_SSE:=1
36         else
37         ifeq ($(DP_MACHINE),i686)
38                 DP_SSE:=1
39         else
40         ifeq ($(DP_MACHINE),i386)
41                 DP_SSE:=1
42         else
43                 DP_SSE:=0
44         endif # ifeq ($(DP_MACHINE),i386)
45         endif # ifeq ($(DP_MACHINE),i686)
46         endif # ifeq ($(DP_MACHINE),x86_64)
47 endif
48
49 # Makefile name
50 MAKEFILE=makefile
51
52 # Commands
53 ifdef windir
54         CMD_RM=del
55         CMD_CP=copy /y
56         CMD_MKDIR=mkdir
57 else
58         CMD_RM=$(CMD_UNIXRM)
59         CMD_CP=$(CMD_UNIXCP)
60         CMD_MKDIR=$(CMD_UNIXMKDIR)
61 endif
62
63 # 64bits AMD CPUs use another lib directory
64 ifeq ($(DP_MACHINE),x86_64)
65         UNIX_X11LIBPATH:=/usr/X11R6/lib64
66 else
67         UNIX_X11LIBPATH:=/usr/X11R6/lib
68 endif
69
70 # default targets
71 TARGETS_DEBUG=sv-debug sdl-debug
72 TARGETS_PROFILE=sv-profile sdl-profile
73 TARGETS_RELEASE=sv-release sdl-release
74 TARGETS_RELEASE_PROFILE=sv-release-profile sdl-release-profile
75 TARGETS_NEXUIZ=sv-nexuiz sdl-nexuiz
76
77 ###### Optional features #####
78 DP_VIDEO_CAPTURE?=enabled
79 ifeq ($(DP_VIDEO_CAPTURE), enabled)
80         CFLAGS_VIDEO_CAPTURE=-DCONFIG_VIDEO_CAPTURE
81         OBJ_VIDEO_CAPTURE=cap_avi.o cap_ogg.o
82 else
83         CFLAGS_VIDEO_CAPTURE=
84         OBJ_VIDEO_CAPTURE=
85 endif
86
87 # Linux configuration
88 ifeq ($(DP_MAKE_TARGET), linux)
89         OBJ_ICON=
90         OBJ_ICON_NEXUIZ=
91
92         LDFLAGS_SV=$(LDFLAGS_LINUXSV)
93         LDFLAGS_SDL=$(LDFLAGS_LINUXSDL)
94
95         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
96         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
97         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
98
99         EXE_SV=$(EXE_UNIXSV)
100         EXE_SDL=$(EXE_UNIXSDL)
101         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
102         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
103
104         DP_LINK_ZLIB?=shared
105         DP_LINK_JPEG?=shared
106         DP_LINK_ODE?=dlopen
107         DP_LINK_CRYPTO?=dlopen
108         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
109         DP_LINK_XMP?=dlopen
110 endif
111
112 # Mac OS X configuration
113 ifeq ($(DP_MAKE_TARGET), macosx)
114         OBJ_ICON=
115         OBJ_ICON_NEXUIZ=
116
117         LDFLAGS_SV=$(LDFLAGS_MACOSXSV)
118         LDFLAGS_SDL=$(LDFLAGS_MACOSXSDL)
119
120         SDLCONFIG_CFLAGS=$(SDLCONFIG_MACOSXCFLAGS)
121         SDLCONFIG_LIBS=$(SDLCONFIG_MACOSXLIBS)
122         SDLCONFIG_STATICLIBS=$(SDLCONFIG_MACOSXSTATICLIBS)
123
124         EXE_SV=$(EXE_UNIXSV)
125         EXE_SDL=$(EXE_UNIXSDL)
126         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
127         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
128
129         ifeq ($(word 2, $(filter -arch, $(CC))), -arch)
130                 CFLAGS_MAKEDEP=
131         endif
132
133         DP_LINK_ZLIB?=shared
134         DP_LINK_JPEG?=dlopen
135         DP_LINK_ODE?=dlopen
136         DP_LINK_CRYPTO?=dlopen
137         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
138         DP_LINK_XMP?=dlopen
139
140         # on OS X, we don't build the CL by default because it uses deprecated
141         # and not-implemented-in-64bit Carbon
142         TARGETS_DEBUG=sv-debug sdl-debug
143         TARGETS_PROFILE=sv-profile sdl-profile
144         TARGETS_RELEASE=sv-release sdl-release
145         TARGETS_RELEASE_PROFILE=sv-release-profile sdl-release-profile
146         TARGETS_NEXUIZ=sv-nexuiz sdl-nexuiz
147 endif
148
149 # SunOS configuration (Solaris)
150 ifeq ($(DP_MAKE_TARGET), sunos)
151         OBJ_ICON=
152         OBJ_ICON_NEXUIZ=
153
154         CFLAGS_EXTRA=$(CFLAGS_SUNOS)
155
156         LDFLAGS_SV=$(LDFLAGS_SUNOSSV)
157         LDFLAGS_SDL=$(LDFLAGS_SUNOSSDL)
158
159         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
160         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
161         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
162
163         EXE_SV=$(EXE_UNIXSV)
164         EXE_SDL=$(EXE_UNIXSDL)
165         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
166         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
167
168         DP_LINK_ZLIB?=shared
169         DP_LINK_JPEG?=shared
170         DP_LINK_ODE?=dlopen
171         DP_LINK_CRYPTO?=dlopen
172         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
173         DP_LINK_XMP?=dlopen
174 endif
175
176 # BSD configuration
177 ifeq ($(DP_MAKE_TARGET), bsd)
178
179         OBJ_ICON=
180         OBJ_ICON_NEXUIZ=
181
182         LDFLAGS_SV=$(LDFLAGS_BSDSV)
183         LDFLAGS_SDL=$(LDFLAGS_BSDSDL)
184
185         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
186         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
187         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
188
189         EXE_SV=$(EXE_UNIXSV)
190         EXE_SDL=$(EXE_UNIXSDL)
191         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
192         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
193
194         DP_LINK_ZLIB?=shared
195         DP_LINK_JPEG?=shared
196         DP_LINK_ODE?=dlopen
197         DP_LINK_CRYPTO?=dlopen
198         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
199         DP_LINK_XMP?=dlopen
200 endif
201
202 # Win32 configuration
203 ifeq ($(WIN32RELEASE), 1)
204 #       TARGET=i686-pc-mingw32
205 #       CC=$(TARGET)-g++
206 #       WINDRES=$(TARGET)-windres
207         CPUOPTIMIZATIONS=-march=pentium3 -mfpmath=sse -fno-math-errno -fno-rounding-math -fno-signaling-nans -fno-trapping-math
208 #       CPUOPTIMIZATIONS+=-DUSE_WSPIAPI_H -DSUPPORTIPV6
209         LDFLAGS_WINCOMMON=-Wl,--large-address-aware
210 else
211         LDFLAGS_WINCOMMON=
212 endif
213
214 ifeq ($(WIN64RELEASE), 1)
215 #       TARGET=x86_64-pc-mingw32
216 #       CC=$(TARGET)-g++
217 #       WINDRES=$(TARGET)-windres
218 endif
219
220 CFLAGS_WARNINGS=-Wall -Winline -Werror=c++-compat -Wshadow -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement -Wmissing-prototypes
221
222
223 ifeq ($(DP_MAKE_TARGET), mingw)
224         OBJ_ICON=darkplaces.o
225         OBJ_ICON_NEXUIZ=nexuiz.o
226
227         LDFLAGS_SV=$(LDFLAGS_WINSV)
228         LDFLAGS_SDL=$(LDFLAGS_WINSDL)
229
230         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS)
231         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS)
232         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS)
233
234         EXE_SV=$(EXE_WINSV)
235         EXE_SDL=$(EXE_WINSDL)
236         EXE_SVNEXUIZ=$(EXE_WINSVNEXUIZ)
237         EXE_SDLNEXUIZ=$(EXE_WINSDLNEXUIZ)
238
239         DP_LINK_ZLIB?=dlopen
240         DP_LINK_JPEG?=shared
241         DP_LINK_ODE?=dlopen
242         DP_LINK_CRYPTO?=dlopen
243         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
244         DP_LINK_XMP?=dlopen
245 endif
246
247 # set these to "" if you want to use dynamic loading instead
248 # zlib
249 ifeq ($(DP_LINK_ZLIB), shared)
250         CFLAGS_LIBZ=-DLINK_TO_ZLIB
251         LIB_Z=-lz
252 endif
253 ifeq ($(DP_LINK_ZLIB), dlopen)
254         CFLAGS_LIBZ=
255         LIB_Z=
256 endif
257
258 # jpeg
259 ifeq ($(DP_LINK_JPEG), shared)
260         CFLAGS_LIBJPEG=-DLINK_TO_LIBJPEG
261         LIB_JPEG=-ljpeg
262 endif
263 ifeq ($(DP_LINK_JPEG), dlopen)
264         CFLAGS_LIBJPEG=
265         LIB_JPEG=
266 endif
267
268 # ode
269 ifeq ($(DP_LINK_ODE), shared)
270         ODE_CONFIG?=ode-config
271         LIB_ODE=`$(ODE_CONFIG) --libs`
272         CFLAGS_ODE=`$(ODE_CONFIG) --cflags` -DUSEODE -DLINK_TO_LIBODE
273 endif
274 ifeq ($(DP_LINK_ODE), dlopen)
275         LIB_ODE=
276         CFLAGS_ODE=-DUSEODE
277 endif
278
279 # d0_blind_id
280 ifeq ($(DP_LINK_CRYPTO), shared)
281         LIB_CRYPTO=-ld0_blind_id
282         CFLAGS_CRYPTO=-DLINK_TO_CRYPTO
283 endif
284 ifeq ($(DP_LINK_CRYPTO), dlopen)
285         LIB_CRYPTO=
286         CFLAGS_CRYPTO=
287 endif
288 ifeq ($(DP_LINK_CRYPTO_RIJNDAEL), shared)
289         LIB_CRYPTO_RIJNDAEL=-ld0_rijndael
290         CFLAGS_CRYPTO_RIJNDAEL=-DLINK_TO_CRYPTO_RIJNDAEL
291 endif
292 ifeq ($(DP_LINK_CRYPTO_RIJNDAEL), dlopen)
293         LIB_CRYPTO_RIJNDAEL=
294         CFLAGS_CRYPTO_RIJNDAEL=
295 endif
296
297 # xmp
298 ifeq ($(DP_LINK_XMP), shared)
299         OBJ_SND_XMP=snd_xmp.o
300         LIB_SND_XMP=-lxmp
301         CFLAGS_SND_XMP=-DUSEXMP -DLINK_TO_LIBXMP
302 endif
303 ifeq ($(DP_LINK_XMP), dlopen)
304         OBJ_SND_XMP=snd_xmp.o
305         LIB_SND_XMP=
306         CFLAGS_SND_XMP=-DUSEXMP
307 endif
308
309
310 ##### Extra CFLAGS #####
311 ifneq ($(CC), tcc)
312         CFLAGS_MAKEDEP?=-MMD
313 endif
314
315 ifdef DP_FS_BASEDIR
316         CFLAGS_FS=-DDP_FS_BASEDIR=\"$(DP_FS_BASEDIR)\"
317 else
318         CFLAGS_FS=
319 endif
320
321 CFLAGS_PRELOAD=
322 ifneq ($(DP_MAKE_TARGET), mingw)
323 ifdef DP_PRELOAD_DEPENDENCIES
324 # DP_PRELOAD_DEPENDENCIES: when set, link against the libraries needed using -l
325 # dynamically so they won't get loaded at runtime using dlopen
326         LDFLAGS_CL+=$(LDFLAGS_UNIXCL_PRELOAD)
327         LDFLAGS_SV+=$(LDFLAGS_UNIXSV_PRELOAD)
328         LDFLAGS_SDL+=$(LDFLAGS_UNIXSDL_PRELOAD)
329         CFLAGS_PRELOAD=$(CFLAGS_UNIX_PRELOAD)
330 endif
331 endif
332
333 CFLAGS_NET=
334 # Systems without IPv6 support should uncomment this:
335 #CFLAGS_NET+=-DNOSUPPORTIPV6
336
337 ##### GNU Make specific definitions #####
338
339 DO_LD=$(CC) -o ../../../$@ $^ $(LDFLAGS)
340
341
342 ##### Definitions shared by all makefiles #####
343 include makefile.inc
344
345
346 ##### Dependency files #####
347
348 -include *.d
349
350 # hack to deal with no-longer-needed .h files
351 %.h:
352         @echo
353         @echo "NOTE: file $@ mentioned in dependencies missing, continuing..."
354         @echo "HINT: consider 'make clean'"
355         @echo