Fix a typo in DrawQ_RotPic which broke it badly.
[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 cl-debug sdl-debug
72 TARGETS_PROFILE=sv-profile cl-profile sdl-profile
73 TARGETS_RELEASE=sv-release cl-release sdl-release
74 TARGETS_RELEASE_PROFILE=sv-release-profile cl-release-profile sdl-release-profile
75 TARGETS_NEXUIZ=sv-nexuiz cl-nexuiz sdl-nexuiz
76
77 ###### Optional features #####
78 DP_CDDA?=enabled
79 ifeq ($(DP_CDDA), enabled)
80         OBJ_SDLCD=$(OBJ_CD_COMMON) cd_sdl.o
81         OBJ_LINUXCD=$(OBJ_CD_COMMON) cd_linux.o
82         OBJ_BSDCD=$(OBJ_CD_COMMON) cd_bsd.o
83         OBJ_WINCD=$(OBJ_CD_COMMON) cd_win.o
84 else
85         OBJ_SDLCD=$(OBJ_CD_COMMON) $(OBJ_NOCD)
86         OBJ_LINUXCD=$(OBJ_CD_COMMON) $(OBJ_NOCD)
87         OBJ_BSDCD=$(OBJ_CD_COMMON) $(OBJ_NOCD)
88         OBJ_WINCD=$(OBJ_CD_COMMON) $(OBJ_NOCD)
89 endif
90
91 DP_VIDEO_CAPTURE?=enabled
92 ifeq ($(DP_VIDEO_CAPTURE), enabled)
93         CFLAGS_VIDEO_CAPTURE=-DCONFIG_VIDEO_CAPTURE
94         OBJ_VIDEO_CAPTURE= cap_avi.o cap_ogg.o
95 else
96         CFLAGS_VIDEO_CAPTURE=
97         OBJ_VIDEO_CAPTURE=
98 endif
99
100 # Linux configuration
101 ifeq ($(DP_MAKE_TARGET), linux)
102         DEFAULT_SNDAPI=ALSA
103         OBJ_CD=$(OBJ_LINUXCD)
104
105         OBJ_CL=$(OBJ_GLX)
106         OBJ_ICON=
107         OBJ_ICON_NEXUIZ=
108
109         LDFLAGS_CL=$(LDFLAGS_LINUXCL)
110         LDFLAGS_SV=$(LDFLAGS_LINUXSV)
111         LDFLAGS_SDL=$(LDFLAGS_LINUXSDL)
112
113         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
114         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
115         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
116
117         EXE_CL=$(EXE_UNIXCL)
118         EXE_SV=$(EXE_UNIXSV)
119         EXE_SDL=$(EXE_UNIXSDL)
120         EXE_CLNEXUIZ=$(EXE_UNIXCLNEXUIZ)
121         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
122         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
123
124         DP_LINK_ZLIB?=shared
125         DP_LINK_JPEG?=shared
126         DP_LINK_ODE?=dlopen
127         DP_LINK_CRYPTO?=dlopen
128         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
129 endif
130
131 # Mac OS X configuration
132 ifeq ($(DP_MAKE_TARGET), macosx)
133         DEFAULT_SNDAPI=COREAUDIO
134         OBJ_CD=$(OBJ_MACOSXCD)
135
136         OBJ_CL=$(OBJ_AGL)
137         OBJ_ICON=
138         OBJ_ICON_NEXUIZ=
139
140         LDFLAGS_CL=$(LDFLAGS_MACOSXCL)
141         LDFLAGS_SV=$(LDFLAGS_MACOSXSV)
142         LDFLAGS_SDL=$(LDFLAGS_MACOSXSDL)
143
144         SDLCONFIG_CFLAGS=$(SDLCONFIG_MACOSXCFLAGS)
145         SDLCONFIG_LIBS=$(SDLCONFIG_MACOSXLIBS)
146         SDLCONFIG_STATICLIBS=$(SDLCONFIG_MACOSXSTATICLIBS)
147
148         EXE_CL=$(EXE_MACOSXCL)
149         EXE_SV=$(EXE_UNIXSV)
150         EXE_SDL=$(EXE_UNIXSDL)
151         EXE_CLNEXUIZ=$(EXE_MACOSXCLNEXUIZ)
152         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
153         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
154
155         ifeq ($(word 2, $(filter -arch, $(CC))), -arch)
156                 CFLAGS_MAKEDEP=
157         endif
158
159         DP_LINK_ZLIB?=shared
160         DP_LINK_JPEG?=dlopen
161         DP_LINK_ODE?=dlopen
162         DP_LINK_CRYPTO?=dlopen
163         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
164
165         # on OS X, we don't build the CL by default because it uses deprecated
166         # and not-implemented-in-64bit Carbon
167         TARGETS_DEBUG=sv-debug sdl-debug
168         TARGETS_PROFILE=sv-profile sdl-profile
169         TARGETS_RELEASE=sv-release sdl-release
170         TARGETS_RELEASE_PROFILE=sv-release-profile sdl-release-profile
171         TARGETS_NEXUIZ=sv-nexuiz sdl-nexuiz
172 endif
173
174 # SunOS configuration (Solaris)
175 ifeq ($(DP_MAKE_TARGET), sunos)
176         DEFAULT_SNDAPI=BSD
177         OBJ_CD=$(OBJ_SUNOSCD)
178
179         OBJ_CL=$(OBJ_GLX)
180         OBJ_ICON=
181         OBJ_ICON_NEXUIZ=
182
183         CFLAGS_EXTRA=$(CFLAGS_SUNOS)
184
185         LDFLAGS_CL=$(LDFLAGS_SUNOSCL)
186         LDFLAGS_SV=$(LDFLAGS_SUNOSSV)
187         LDFLAGS_SDL=$(LDFLAGS_SUNOSSDL)
188
189         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
190         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
191         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
192
193         EXE_CL=$(EXE_UNIXCL)
194         EXE_SV=$(EXE_UNIXSV)
195         EXE_SDL=$(EXE_UNIXSDL)
196         EXE_CLNEXUIZ=$(EXE_UNIXCLNEXUIZ)
197         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
198         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
199
200         DP_LINK_ZLIB?=shared
201         DP_LINK_JPEG?=shared
202         DP_LINK_ODE?=dlopen
203         DP_LINK_CRYPTO?=dlopen
204         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
205 endif
206
207 # BSD configuration
208 ifeq ($(DP_MAKE_TARGET), bsd)
209 ifeq ($(DP_ARCH),FreeBSD)
210         DEFAULT_SNDAPI=OSS
211 else
212         DEFAULT_SNDAPI=BSD
213 endif
214         OBJ_CD=$(OBJ_BSDCD)
215
216         OBJ_CL=$(OBJ_GLX)
217         OBJ_ICON=
218         OBJ_ICON_NEXUIZ=
219
220         LDFLAGS_CL=$(LDFLAGS_BSDCL)
221         LDFLAGS_SV=$(LDFLAGS_BSDSV)
222         LDFLAGS_SDL=$(LDFLAGS_BSDSDL)
223
224         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
225         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
226         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
227
228         EXE_CL=$(EXE_UNIXCL)
229         EXE_SV=$(EXE_UNIXSV)
230         EXE_SDL=$(EXE_UNIXSDL)
231         EXE_CLNEXUIZ=$(EXE_UNIXCLNEXUIZ)
232         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
233         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
234
235         DP_LINK_ZLIB?=shared
236         DP_LINK_JPEG?=shared
237         DP_LINK_ODE?=dlopen
238         DP_LINK_CRYPTO?=dlopen
239         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
240 endif
241
242 # Win32 configuration
243 ifeq ($(WIN32RELEASE), 1)
244 #       TARGET=i686-pc-mingw32
245 #       CC=$(TARGET)-g++
246 #       WINDRES=$(TARGET)-windres
247         CPUOPTIMIZATIONS=-march=pentium3 -mfpmath=sse -fno-math-errno -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fno-trapping-math
248 #       CPUOPTIMIZATIONS+=-DUSE_WSPIAPI_H -DSUPPORTIPV6
249         LDFLAGS_WINCOMMON=-Wl,--large-address-aware
250 else
251         LDFLAGS_WINCOMMON=
252 endif
253
254 ifeq ($(WIN64RELEASE), 1)
255 #       TARGET=x86_64-pc-mingw32
256 #       CC=$(TARGET)-g++
257 #       WINDRES=$(TARGET)-windres
258 endif
259
260 ifeq ($(D3D), 1)
261         CFLAGS_D3D=-DSUPPORTD3D -DSUPPORTDIRECTX
262         CFLAGS_WARNINGS=-Wall
263         LDFLAGS_D3D=-ld3d9
264 else
265         CFLAGS_D3D=
266         CFLAGS_WARNINGS=-Wall -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement -Wmissing-prototypes
267         LDFLAGS_D3D=
268 endif
269
270
271 ifeq ($(DP_MAKE_TARGET), mingw)
272         DEFAULT_SNDAPI=WIN
273         OBJ_CD=$(OBJ_WINCD)
274
275         OBJ_CL=$(OBJ_WGL)
276         OBJ_ICON=darkplaces.o
277         OBJ_ICON_NEXUIZ=nexuiz.o
278
279         LDFLAGS_CL=$(LDFLAGS_WINCL)
280         LDFLAGS_SV=$(LDFLAGS_WINSV)
281         LDFLAGS_SDL=$(LDFLAGS_WINSDL)
282
283         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS)
284         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS)
285         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS)
286
287         EXE_CL=$(EXE_WINCL)
288         EXE_SV=$(EXE_WINSV)
289         EXE_SDL=$(EXE_WINSDL)
290         EXE_CLNEXUIZ=$(EXE_WINCLNEXUIZ)
291         EXE_SVNEXUIZ=$(EXE_WINSVNEXUIZ)
292         EXE_SDLNEXUIZ=$(EXE_WINSDLNEXUIZ)
293
294         DP_LINK_ZLIB?=dlopen
295         DP_LINK_JPEG?=shared
296         DP_LINK_ODE?=dlopen
297         DP_LINK_CRYPTO?=dlopen
298         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
299 endif
300
301 # set these to "" if you want to use dynamic loading instead
302 # zlib
303 ifeq ($(DP_LINK_ZLIB), shared)
304         CFLAGS_LIBZ=-DLINK_TO_ZLIB
305         LIB_Z=-lz
306 endif
307 ifeq ($(DP_LINK_ZLIB), dlopen)
308         CFLAGS_LIBZ=
309         LIB_Z=
310 endif
311
312 # jpeg
313 ifeq ($(DP_LINK_JPEG), shared)
314         CFLAGS_LIBJPEG=-DLINK_TO_LIBJPEG
315         LIB_JPEG=-ljpeg
316 endif
317 ifeq ($(DP_LINK_JPEG), dlopen)
318         CFLAGS_LIBJPEG=
319         LIB_JPEG=
320 endif
321
322 # ode
323 ifeq ($(DP_LINK_ODE), shared)
324         ODE_CONFIG?=ode-config
325         LIB_ODE=`$(ODE_CONFIG) --libs`
326         CFLAGS_ODE=`$(ODE_CONFIG) --cflags` -DUSEODE -DLINK_TO_LIBODE
327 endif
328 ifeq ($(DP_LINK_ODE), dlopen)
329         LIB_ODE=
330         CFLAGS_ODE=-DUSEODE
331 endif
332
333 # d0_blind_id
334 ifeq ($(DP_LINK_CRYPTO), shared)
335         LIB_CRYPTO=-ld0_blind_id
336         CFLAGS_CRYPTO=-DLINK_TO_CRYPTO
337 endif
338 ifeq ($(DP_LINK_CRYPTO), dlopen)
339         LIB_CRYPTO=
340         CFLAGS_CRYPTO=
341 endif
342 ifeq ($(DP_LINK_CRYPTO_RIJNDAEL), shared)
343         LIB_CRYPTO_RIJNDAEL=-ld0_rijndael
344         CFLAGS_CRYPTO_RIJNDAEL=-DLINK_TO_CRYPTO_RIJNDAEL
345 endif
346 ifeq ($(DP_LINK_CRYPTO_RIJNDAEL), dlopen)
347         LIB_CRYPTO_RIJNDAEL=
348         CFLAGS_CRYPTO_RIJNDAEL=
349 endif
350
351 ##### Sound configuration #####
352
353 ifndef DP_SOUND_API
354         DP_SOUND_API=$(DEFAULT_SNDAPI)
355 endif
356
357 # NULL: no sound
358 ifeq ($(DP_SOUND_API), NULL)
359         OBJ_SOUND=$(OBJ_SND_NULL)
360         LIB_SOUND=$(LIB_SND_NULL)
361 endif
362
363 # OSS: Open Sound System
364 ifeq ($(DP_SOUND_API), OSS)
365         OBJ_SOUND=$(OBJ_SND_OSS)
366         LIB_SOUND=$(LIB_SND_OSS)
367 endif
368
369 # ALSA: Advanced Linux Sound Architecture
370 ifeq ($(DP_SOUND_API), ALSA)
371         OBJ_SOUND=$(OBJ_SND_ALSA)
372         LIB_SOUND=$(LIB_SND_ALSA)
373 endif
374
375 # COREAUDIO: Core Audio
376 ifeq ($(DP_SOUND_API), COREAUDIO)
377         OBJ_SOUND=$(OBJ_SND_COREAUDIO)
378         LIB_SOUND=$(LIB_SND_COREAUDIO)
379 endif
380
381 # BSD: BSD / Sun audio API
382 ifeq ($(DP_SOUND_API), BSD)
383         OBJ_SOUND=$(OBJ_SND_BSD)
384         LIB_SOUND=$(LIB_SND_BSD)
385 endif
386
387 # WIN: DirectX and Win32 WAVE output
388 ifeq ($(DP_SOUND_API), WIN)
389         OBJ_SOUND=$(OBJ_SND_WIN)
390         LIB_SOUND=$(LIB_SND_WIN)
391 endif
392
393 ifeq ($(DP_SOUND_API),3DRAS)
394         OBJ_SOUND=$(OBJ_SND_3DRAS)
395         LIB_SOUND=$(LIB_SND_3DRAS)
396 endif
397
398 ##### Extra CFLAGS #####
399
400 CFLAGS_MAKEDEP?=-MMD
401 ifdef DP_FS_BASEDIR
402         CFLAGS_FS=-DDP_FS_BASEDIR=\"$(DP_FS_BASEDIR)\"
403 else
404         CFLAGS_FS=
405 endif
406
407 CFLAGS_PRELOAD=
408 ifneq ($(DP_MAKE_TARGET), mingw)
409 ifdef DP_PRELOAD_DEPENDENCIES
410 # DP_PRELOAD_DEPENDENCIES: when set, link against the libraries needed using -l
411 # dynamically so they won't get loaded at runtime using dlopen
412         LDFLAGS_CL+=$(LDFLAGS_UNIXCL_PRELOAD)
413         LDFLAGS_SV+=$(LDFLAGS_UNIXSV_PRELOAD)
414         LDFLAGS_SDL+=$(LDFLAGS_UNIXSDL_PRELOAD)
415         CFLAGS_PRELOAD=$(CFLAGS_UNIX_PRELOAD)
416 endif
417 endif
418
419 CFLAGS_NET=
420 # Systems without IPv6 support should uncomment this:
421 #CFLAGS_NET+=-DNOSUPPORTIPV6
422
423 ##### GNU Make specific definitions #####
424
425 DO_LD=$(CC) -o ../../../$@ $^ $(LDFLAGS)
426
427
428 ##### Definitions shared by all makefiles #####
429 include makefile.inc
430
431
432 ##### Dependency files #####
433
434 -include *.d
435
436 # hack to deal with no-longer-needed .h files
437 %.h:
438         @echo
439         @echo "NOTE: file $@ mentioned in dependencies missing, continuing..."
440         @echo "HINT: consider 'make clean'"
441         @echo