Revert "Make cdda optional, server does not need to play music" because it
[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 not on compiling for Win32, we need additional information
30 ifneq ($(DP_MAKE_TARGET), mingw)
31         DP_ARCH:=$(shell uname)
32         DP_MACHINE:=$(shell uname -m)
33 endif
34
35
36 # Command used to delete files
37 ifdef windir
38         CMD_RM=del
39 else
40         CMD_RM=$(CMD_UNIXRM)
41 endif
42
43 # 64bits AMD CPUs use another lib directory
44 ifeq ($(DP_MACHINE),x86_64)
45         UNIX_X11LIBPATH:=/usr/X11R6/lib64
46 else
47         UNIX_X11LIBPATH:=/usr/X11R6/lib
48 endif
49
50 # default targets
51 TARGETS_DEBUG=sv-debug cl-debug sdl-debug
52 TARGETS_PROFILE=sv-profile cl-profile sdl-profile
53 TARGETS_RELEASE=sv-release cl-release sdl-release
54 TARGETS_RELEASE_PROFILE=sv-release-profile cl-release-profile sdl-release-profile
55 TARGETS_NEXUIZ=sv-nexuiz cl-nexuiz sdl-nexuiz
56
57 # Linux configuration
58 ifeq ($(DP_MAKE_TARGET), linux)
59         DEFAULT_SNDAPI=ALSA
60         OBJ_CD=$(OBJ_LINUXCD)
61
62         OBJ_CL=$(OBJ_GLX)
63         OBJ_ICON=
64         OBJ_ICON_NEXUIZ=
65
66         LDFLAGS_CL=$(LDFLAGS_LINUXCL)
67         LDFLAGS_SV=$(LDFLAGS_LINUXSV)
68         LDFLAGS_SDL=$(LDFLAGS_LINUXSDL)
69
70         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
71         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
72         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
73
74         EXE_CL=$(EXE_UNIXCL)
75         EXE_SV=$(EXE_UNIXSV)
76         EXE_SDL=$(EXE_UNIXSDL)
77         EXE_CLNEXUIZ=$(EXE_UNIXCLNEXUIZ)
78         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
79         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
80
81         DP_LINK_ZLIB?=shared
82         DP_LINK_JPEG?=shared
83         DP_LINK_ODE?=dlopen
84 endif
85
86 # Mac OS X configuration
87 ifeq ($(DP_MAKE_TARGET), macosx)
88         DEFAULT_SNDAPI=COREAUDIO
89         OBJ_CD=$(OBJ_MACOSXCD)
90
91         OBJ_CL=$(OBJ_AGL)
92         OBJ_ICON=
93         OBJ_ICON_NEXUIZ=
94
95         LDFLAGS_CL=$(LDFLAGS_MACOSXCL)
96         LDFLAGS_SV=$(LDFLAGS_MACOSXSV)
97         LDFLAGS_SDL=$(LDFLAGS_MACOSXSDL)
98
99         SDLCONFIG_CFLAGS=$(SDLCONFIG_MACOSXCFLAGS)
100         SDLCONFIG_LIBS=$(SDLCONFIG_MACOSXLIBS)
101         SDLCONFIG_STATICLIBS=$(SDLCONFIG_MACOSXSTATICLIBS)
102
103         EXE_CL=$(EXE_MACOSXCL)
104         EXE_SV=$(EXE_UNIXSV)
105         EXE_SDL=$(EXE_UNIXSDL)
106         EXE_CLNEXUIZ=$(EXE_MACOSXCLNEXUIZ)
107         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
108         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
109
110         ifeq ($(word 2, $(filter -arch, $(CC))), -arch)
111                 CFLAGS_MAKEDEP=
112         endif
113
114         DP_LINK_ZLIB?=shared
115         DP_LINK_JPEG?=shared
116         DP_LINK_ODE?=dlopen
117
118         # on OS X, we don't build the CL by default because it uses deprecated
119         # and not-implemented-in-64bit Carbon
120         TARGETS_DEBUG=sv-debug sdl-debug
121         TARGETS_PROFILE=sv-profile sdl-profile
122         TARGETS_RELEASE=sv-release sdl-release
123         TARGETS_RELEASE_PROFILE=sv-release-profile sdl-release-profile
124         TARGETS_NEXUIZ=sv-nexuiz sdl-nexuiz
125 endif
126
127 # SunOS configuration (Solaris)
128 ifeq ($(DP_MAKE_TARGET), sunos)
129         DEFAULT_SNDAPI=BSD
130         OBJ_CD=$(OBJ_SUNOSCD)
131
132         OBJ_CL=$(OBJ_GLX)
133         OBJ_ICON=
134         OBJ_ICON_NEXUIZ=
135
136         CFLAGS_EXTRA=$(CFLAGS_SUNOS)
137
138         LDFLAGS_CL=$(LDFLAGS_SUNOSCL)
139         LDFLAGS_SV=$(LDFLAGS_SUNOSSV)
140         LDFLAGS_SDL=$(LDFLAGS_SUNOSSDL)
141
142         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
143         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
144         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
145
146         EXE_CL=$(EXE_UNIXCL)
147         EXE_SV=$(EXE_UNIXSV)
148         EXE_SDL=$(EXE_UNIXSDL)
149         EXE_CLNEXUIZ=$(EXE_UNIXCLNEXUIZ)
150         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
151         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
152
153         DP_LINK_ZLIB?=shared
154         DP_LINK_JPEG?=shared
155         DP_LINK_ODE?=dlopen
156 endif
157
158 # BSD configuration
159 ifeq ($(DP_MAKE_TARGET), bsd)
160 ifeq ($(DP_ARCH),FreeBSD)
161         DEFAULT_SNDAPI=OSS
162 else
163         DEFAULT_SNDAPI=BSD
164 endif
165         OBJ_CD=$(OBJ_BSDCD)
166
167         OBJ_CL=$(OBJ_GLX)
168         OBJ_ICON=
169         OBJ_ICON_NEXUIZ=
170
171         LDFLAGS_CL=$(LDFLAGS_BSDCL)
172         LDFLAGS_SV=$(LDFLAGS_BSDSV)
173         LDFLAGS_SDL=$(LDFLAGS_BSDSDL)
174
175         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
176         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
177         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
178
179         EXE_CL=$(EXE_UNIXCL)
180         EXE_SV=$(EXE_UNIXSV)
181         EXE_SDL=$(EXE_UNIXSDL)
182         EXE_CLNEXUIZ=$(EXE_UNIXCLNEXUIZ)
183         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
184         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
185
186         DP_LINK_ZLIB?=shared
187         DP_LINK_JPEG?=shared
188         DP_LINK_ODE?=dlopen
189 endif
190
191 # Win32 configuration
192 ifeq ($(WIN32RELEASE), 1)
193 #       TARGET=i686-pc-mingw32
194 #       CC=$(TARGET)-g++
195 #       WINDRES=$(TARGET)-windres
196         CPUOPTIMIZATIONS=-march=i686 -fno-math-errno -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fno-trapping-math
197 #       CPUOPTIMIZATIONS+=-DUSE_WSPIAPI_H -DSUPPORTIPV6
198         LDFLAGS_WINCOMMON=-Wl,--large-address-aware
199 else
200         LDFLAGS_WINCOMMON=
201 endif
202
203 ifeq ($(WIN64RELEASE), 1)
204 #       TARGET=x86_64-pc-mingw32
205 #       CC=$(TARGET)-g++
206 #       WINDRES=$(TARGET)-windres
207 endif
208
209 ifeq ($(D3D), 1)
210         CFLAGS_D3D=-DSUPPORTD3D -DSUPPORTDIRECTX
211         CFLAGS_WARNINGS=-Wall
212         LDFLAGS_D3D=-ld3d9
213 else
214         CFLAGS_D3D=
215         CFLAGS_WARNINGS=-Wall -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement -Wmissing-prototypes
216         LDFLAGS_D3D=
217 endif
218
219
220 ifeq ($(DP_MAKE_TARGET), mingw)
221         DEFAULT_SNDAPI=WIN
222         OBJ_CD=$(OBJ_WINCD)
223
224         OBJ_CL=$(OBJ_WGL)
225         OBJ_ICON=darkplaces.o
226         OBJ_ICON_NEXUIZ=nexuiz.o
227
228         LDFLAGS_CL=$(LDFLAGS_WINCL)
229         LDFLAGS_SV=$(LDFLAGS_WINSV)
230         LDFLAGS_SDL=$(LDFLAGS_WINSDL)
231
232         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS)
233         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS)
234         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS)
235
236         EXE_CL=$(EXE_WINCL)
237         EXE_SV=$(EXE_WINSV)
238         EXE_SDL=$(EXE_WINSDL)
239         EXE_CLNEXUIZ=$(EXE_WINCLNEXUIZ)
240         EXE_SVNEXUIZ=$(EXE_WINSVNEXUIZ)
241         EXE_SDLNEXUIZ=$(EXE_WINSDLNEXUIZ)
242
243         DP_LINK_ZLIB?=dlopen
244         DP_LINK_JPEG?=shared
245         DP_LINK_ODE?=dlopen
246 endif
247
248 # set these to "" if you want to use dynamic loading instead
249 # zlib
250 ifeq ($(DP_LINK_ZLIB), shared)
251         CFLAGS_LIBZ=-DLINK_TO_ZLIB
252         LIB_Z=-lz
253 endif
254 ifeq ($(DP_LINK_ZLIB), dlopen)
255         CFLAGS_LIBZ=
256         LIB_Z=
257 endif
258
259 # jpeg
260 ifeq ($(DP_LINK_JPEG), shared)
261         CFLAGS_LIBJPEG=-DLINK_TO_LIBJPEG
262         LIB_JPEG=-ljpeg
263 endif
264 ifeq ($(DP_LINK_JPEG), dlopen)
265         CFLAGS_LIBJPEG=
266         LIB_JPEG=
267 endif
268
269 # ode
270 ifeq ($(DP_LINK_ODE), shared)
271         ODE_CONFIG?=ode-config
272         LIB_ODE=`$(ODE_CONFIG) --libs`
273         CFLAGS_ODE=`$(ODE_CONFIG) --cflags` -DUSEODE -DLINK_TO_LIBODE
274 endif
275 ifeq ($(DP_LINK_ODE), dlopen)
276         LIB_ODE=
277         CFLAGS_ODE=-DUSEODE
278 endif
279
280 # d0_blind_id
281 # most distros do not have d0_blind_id package, dlopen will used by default
282 # LIB_CRYPTO=-ld0_blind_id
283 # CFLAGS_CRYPTO=-DLINK_TO_CRYPTO
284 # LIB_CRYPTO_RIJNDAEL=-ld0_rijndael
285 # CFLAGS_CRYPTO_RIJNDAEL=-DLINK_TO_CRYPTO_RIJNDAEL
286 LIB_CRYPTO=
287 CFLAGS_CRYPTO=
288 LIB_CRYPTO_RIJNDAEL=
289 CFLAGS_CRYPTO_RIJNDAEL=
290
291 ##### Sound configuration #####
292
293 ifndef DP_SOUND_API
294         DP_SOUND_API=$(DEFAULT_SNDAPI)
295 endif
296
297 # NULL: no sound
298 ifeq ($(DP_SOUND_API), NULL)
299         OBJ_SOUND=$(OBJ_SND_NULL)
300         LIB_SOUND=$(LIB_SND_NULL)
301 endif
302
303 # OSS: Open Sound System
304 ifeq ($(DP_SOUND_API), OSS)
305         OBJ_SOUND=$(OBJ_SND_OSS)
306         LIB_SOUND=$(LIB_SND_OSS)
307 endif
308
309 # ALSA: Advanced Linux Sound Architecture
310 ifeq ($(DP_SOUND_API), ALSA)
311         OBJ_SOUND=$(OBJ_SND_ALSA)
312         LIB_SOUND=$(LIB_SND_ALSA)
313 endif
314
315 # COREAUDIO: Core Audio
316 ifeq ($(DP_SOUND_API), COREAUDIO)
317         OBJ_SOUND=$(OBJ_SND_COREAUDIO)
318         LIB_SOUND=$(LIB_SND_COREAUDIO)
319 endif
320
321 # BSD: BSD / Sun audio API
322 ifeq ($(DP_SOUND_API), BSD)
323         OBJ_SOUND=$(OBJ_SND_BSD)
324         LIB_SOUND=$(LIB_SND_BSD)
325 endif
326
327 # WIN: DirectX and Win32 WAVE output
328 ifeq ($(DP_SOUND_API), WIN)
329         OBJ_SOUND=$(OBJ_SND_WIN)
330         LIB_SOUND=$(LIB_SND_WIN)
331 endif
332
333 ifeq ($(DP_SOUND_API),3DRAS)
334         OBJ_SOUND=$(OBJ_SND_3DRAS)
335         LIB_SOUND=$(LIB_SND_3DRAS)
336 endif
337
338 ##### Extra CFLAGS #####
339
340 CFLAGS_MAKEDEP?=-MMD
341 ifdef DP_FS_BASEDIR
342         CFLAGS_FS=-DDP_FS_BASEDIR='\"$(DP_FS_BASEDIR)\"'
343 else
344         CFLAGS_FS=
345 endif
346
347 CFLAGS_PRELOAD=
348 ifneq ($(DP_MAKE_TARGET), mingw)
349 ifdef DP_PRELOAD_DEPENDENCIES
350 # DP_PRELOAD_DEPENDENCIES: when set, link against the libraries needed using -l
351 # dynamically so they won't get loaded at runtime using dlopen
352         LDFLAGS_CL+=$(LDFLAGS_UNIXCL_PRELOAD)
353         LDFLAGS_SV+=$(LDFLAGS_UNIXSV_PRELOAD)
354         LDFLAGS_SDL+=$(LDFLAGS_UNIXSDL_PRELOAD)
355         CFLAGS_PRELOAD=$(CFLAGS_UNIX_PRELOAD)
356 endif
357 endif
358
359 ##### GNU Make specific definitions #####
360
361 DO_LD=$(CC) -o $@ $^ $(LDFLAGS)
362
363
364 ##### Definitions shared by all makefiles #####
365 include makefile.inc
366
367
368 ##### Dependency files #####
369
370 -include *.d
371
372 # hack to deal with no-longer-needed .h files
373 %.h:
374         @echo
375         @echo "NOTE: file $@ mentioned in dependencies missing, continuing..."
376         @echo "HINT: consider 'make clean'"
377         @echo