]> git.xonotic.org Git - xonotic/darkplaces.git/blob - makefile
Merge PR 'Muffle sounds when the player is under water'
[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 ifeq ($(OS),Windows_NT)
33         ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
34                 DP_SSE:=1
35         else ifeq ($(PROCESSOR_ARCHITEW6432),AMD64)
36                 DP_SSE:=1
37         else ifeq ($(PROCESSOR_ARCHITECTURE),x86)
38                 DP_SSE:=1
39         else
40                 DP_SSE:=0
41         endif
42 else
43         DP_MACHINE:=$(shell uname -m)
44         ifeq ($(DP_MACHINE),x86_64)
45                 DP_SSE:=1
46         else ifeq ($(DP_MACHINE),i686)
47                 DP_SSE:=1
48         else ifeq ($(DP_MACHINE),i386)
49                 DP_SSE:=1
50         else
51                 DP_SSE:=0
52         endif
53 endif
54
55 # Makefile name
56 MAKEFILE=makefile
57
58 # Commands
59 ifdef windir
60         CMD_RM=del
61         CMD_CP=copy /y
62         CMD_MKDIR=mkdir
63 else
64         CMD_RM=$(CMD_UNIXRM)
65         CMD_CP=$(CMD_UNIXCP)
66         CMD_MKDIR=$(CMD_UNIXMKDIR)
67 endif
68
69 # default targets
70 TARGETS_DEBUG=sv-debug sdl-debug
71 TARGETS_PROFILE=sv-profile sdl-profile
72 TARGETS_RELEASE=sv-release sdl-release
73 TARGETS_RELEASE_PROFILE=sv-release-profile sdl-release-profile
74 TARGETS_NEXUIZ=sv-nexuiz sdl-nexuiz
75
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_SDL?=shared
105         DP_LINK_ZLIB?=shared
106         DP_LINK_JPEG?=shared
107         DP_LINK_ODE?=
108         DP_LINK_CRYPTO?=dlopen
109         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
110         DP_LINK_XMP?=dlopen
111 endif
112
113 # Mac OS X configuration
114 ifeq ($(DP_MAKE_TARGET), macosx)
115         OBJ_ICON=
116         OBJ_ICON_NEXUIZ=
117
118         LDFLAGS_SV=$(LDFLAGS_MACOSXSV)
119         LDFLAGS_SDL=$(LDFLAGS_MACOSXSDL)
120
121         SDLCONFIG_CFLAGS=$(SDLCONFIG_MACOSXCFLAGS)
122         SDLCONFIG_LIBS=$(SDLCONFIG_MACOSXLIBS)
123         SDLCONFIG_STATICLIBS=$(SDLCONFIG_MACOSXSTATICLIBS)
124
125         EXE_SV=$(EXE_UNIXSV)
126         EXE_SDL=$(EXE_UNIXSDL)
127         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
128         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
129
130         ifeq ($(word 2, $(filter -arch, $(CC))), -arch)
131                 CFLAGS_MAKEDEP=
132         endif
133
134         DP_LINK_SDL?=shared
135         DP_LINK_ZLIB?=shared
136         DP_LINK_JPEG?=dlopen
137         DP_LINK_ODE?=
138         DP_LINK_CRYPTO?=dlopen
139         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
140         DP_LINK_XMP?=dlopen
141
142         # on OS X, we don't build the CL by default because it uses deprecated
143         # and not-implemented-in-64bit Carbon
144         TARGETS_DEBUG=sv-debug sdl-debug
145         TARGETS_PROFILE=sv-profile sdl-profile
146         TARGETS_RELEASE=sv-release sdl-release
147         TARGETS_RELEASE_PROFILE=sv-release-profile sdl-release-profile
148         TARGETS_NEXUIZ=sv-nexuiz sdl-nexuiz
149 endif
150
151 # SunOS configuration (Solaris)
152 ifeq ($(DP_MAKE_TARGET), sunos)
153         OBJ_ICON=
154         OBJ_ICON_NEXUIZ=
155
156         CFLAGS_EXTRA=$(CFLAGS_SUNOS)
157
158         LDFLAGS_SV=$(LDFLAGS_SUNOSSV)
159         LDFLAGS_SDL=$(LDFLAGS_SUNOSSDL)
160
161         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
162         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
163         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
164
165         EXE_SV=$(EXE_UNIXSV)
166         EXE_SDL=$(EXE_UNIXSDL)
167         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
168         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
169
170         DP_LINK_SDL?=shared
171         DP_LINK_ZLIB?=shared
172         DP_LINK_JPEG?=shared
173         DP_LINK_ODE?=
174         DP_LINK_CRYPTO?=dlopen
175         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
176         DP_LINK_XMP?=dlopen
177 endif
178
179 # BSD configuration
180 ifeq ($(DP_MAKE_TARGET), bsd)
181
182         OBJ_ICON=
183         OBJ_ICON_NEXUIZ=
184
185         LDFLAGS_SV=$(LDFLAGS_BSDSV)
186         LDFLAGS_SDL=$(LDFLAGS_BSDSDL)
187
188         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
189         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
190         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
191
192         EXE_SV=$(EXE_UNIXSV)
193         EXE_SDL=$(EXE_UNIXSDL)
194         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
195         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
196
197         DP_LINK_SDL?=shared
198         DP_LINK_ZLIB?=shared
199         DP_LINK_JPEG?=shared
200         DP_LINK_ODE?=
201         DP_LINK_CRYPTO?=dlopen
202         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
203         DP_LINK_XMP?=dlopen
204 endif
205
206 # Win32 configuration
207 ifeq ($(DP_MAKE_TARGET), mingw)
208         OBJ_ICON=darkplaces.o
209         OBJ_ICON_NEXUIZ=nexuiz.o
210
211         LDFLAGS_SV=$(LDFLAGS_WINSV)
212         LDFLAGS_SDL=$(LDFLAGS_WINSDL)
213
214         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS)
215         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS)
216         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS)
217
218         EXE_SV=$(EXE_WINSV)
219         EXE_SDL=$(EXE_WINSDL)
220         EXE_SVNEXUIZ=$(EXE_WINSVNEXUIZ)
221         EXE_SDLNEXUIZ=$(EXE_WINSDLNEXUIZ)
222
223         DP_LINK_SDL?=shared
224         DP_LINK_ZLIB?=dlopen
225         DP_LINK_JPEG?=shared
226         DP_LINK_ODE?=
227         DP_LINK_CRYPTO?=dlopen
228         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
229         DP_LINK_XMP?=dlopen
230 endif
231
232
233 ##### Library linking #####
234 # SDL2
235 SDL_CONFIG?=sdl2-config
236 SDLCONFIG_UNIXCFLAGS?=`$(SDL_CONFIG) --cflags`
237 SDLCONFIG_UNIXCFLAGS_X11?=
238 SDLCONFIG_UNIXLIBS?=`$(SDL_CONFIG) --libs`
239 SDLCONFIG_UNIXLIBS_X11?=-lX11
240 SDLCONFIG_UNIXSTATICLIBS?=`$(SDL_CONFIG) --static-libs`
241 SDLCONFIG_UNIXSTATICLIBS_X11?=-lX11
242 SDLCONFIG_MACOSXCFLAGS=$(SDLCONFIG_UNIXCFLAGS)
243 SDLCONFIG_MACOSXLIBS=$(SDLCONFIG_UNIXLIBS)
244 SDLCONFIG_MACOSXSTATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS)
245 ifeq ($(DP_LINK_SDL), shared)
246         SDL_LIBS=$(SDLCONFIG_LIBS)
247 else ifeq ($(DP_LINK_SDL), static)
248         SDL_LIBS=$(SDLCONFIG_STATICLIBS)
249 else ifeq ($(DP_LINK_SDL), dlopen)
250   $(error libSDL2 can only be used with shared or static linking)
251 endif
252
253 # zlib
254 ifeq ($(DP_LINK_ZLIB), shared)
255         CFLAGS_LIBZ=-DLINK_TO_ZLIB
256         LIB_Z=-lz
257 else ifeq ($(DP_LINK_ZLIB), static)
258         CFLAGS_LIBZ=-DLINK_TO_ZLIB
259         LIB_Z=-l:libz.a
260 else ifeq ($(DP_LINK_ZLIB), dlopen)
261         CFLAGS_LIBZ=
262         LIB_Z=
263 endif
264
265 # jpeg
266 ifeq ($(DP_LINK_JPEG), shared)
267         CFLAGS_LIBJPEG=-DLINK_TO_LIBJPEG
268         LIB_JPEG=-ljpeg
269 else ifeq ($(DP_LINK_JPEG), static)
270         CFLAGS_LIBJPEG=-DLINK_TO_LIBJPEG
271         LIB_JPEG=-l:libjpeg.a
272 else ifeq ($(DP_LINK_JPEG), dlopen)
273         CFLAGS_LIBJPEG=
274         LIB_JPEG=
275 endif
276
277 # ode
278 ifeq ($(DP_LINK_ODE), shared)
279         ODE_CONFIG?=ode-config
280         LIB_ODE=`$(ODE_CONFIG) --libs`
281         CFLAGS_ODE=`$(ODE_CONFIG) --cflags` -DUSEODE -DLINK_TO_LIBODE
282 else ifeq ($(DP_LINK_ODE), static)
283         # This is the configuration from Xonotic
284         ODE_CONFIG?=ode-config
285         LIB_ODE=-l:libode.a -lstdc++ -pthread
286         CFLAGS_ODE=-DUSEODE -DLINK_TO_LIBODE -DdDOUBLE
287 else ifeq ($(DP_LINK_ODE), dlopen)
288         LIB_ODE=
289         CFLAGS_ODE=-DUSEODE
290 endif
291
292 # d0_blind_id
293 ifeq ($(DP_LINK_CRYPTO), shared)
294         LIB_CRYPTO=-ld0_blind_id
295         CFLAGS_CRYPTO=-DLINK_TO_CRYPTO
296 else ifeq ($(DP_LINK_CRYPTO), static)
297         LIB_CRYPTO=-l:libd0_blind_id.a -lgmp
298         CFLAGS_CRYPTO=-DLINK_TO_CRYPTO
299 else ifeq ($(DP_LINK_CRYPTO), static_inc_gmp)
300         LIB_CRYPTO=-l:libd0_blind_id.a -l:libgmp.a
301         CFLAGS_CRYPTO=-DLINK_TO_CRYPTO
302 else ifeq ($(DP_LINK_CRYPTO), dlopen)
303         LIB_CRYPTO=
304         CFLAGS_CRYPTO=
305 endif
306
307 # d0_rijndael
308 ifeq ($(DP_LINK_CRYPTO_RIJNDAEL), shared)
309         LIB_CRYPTO_RIJNDAEL=-ld0_rijndael
310         CFLAGS_CRYPTO_RIJNDAEL=-DLINK_TO_CRYPTO_RIJNDAEL
311 else ifeq ($(DP_LINK_CRYPTO_RIJNDAEL), static)
312         LIB_CRYPTO_RIJNDAEL=-l:libd0_rijndael.a
313         CFLAGS_CRYPTO_RIJNDAEL=-DLINK_TO_CRYPTO_RIJNDAEL
314 else ifeq ($(DP_LINK_CRYPTO_RIJNDAEL), dlopen)
315         LIB_CRYPTO_RIJNDAEL=
316         CFLAGS_CRYPTO_RIJNDAEL=
317 endif
318
319 # xmp
320 ifeq ($(DP_LINK_XMP), shared)
321         OBJ_SND_XMP=snd_xmp.o
322         LIB_SND_XMP=-lxmp
323         CFLAGS_SND_XMP=-DUSEXMP -DLINK_TO_LIBXMP
324 else ifeq ($(DP_LINK_XMP), static)
325         OBJ_SND_XMP=snd_xmp.o
326         LIB_SND_XMP=-l:libxmp.a
327         CFLAGS_SND_XMP=-DUSEXMP -DLINK_TO_LIBXMP
328 else ifeq ($(DP_LINK_XMP), dlopen)
329         OBJ_SND_XMP=snd_xmp.o
330         LIB_SND_XMP=
331         CFLAGS_SND_XMP=-DUSEXMP
332 endif
333
334
335 ##### Extra CFLAGS #####
336 ifdef DP_FS_BASEDIR
337         CFLAGS_FS=-DDP_FS_BASEDIR=\"$(DP_FS_BASEDIR)\"
338 else
339         CFLAGS_FS=
340 endif
341
342 CFLAGS_PRELOAD=
343 ifneq ($(DP_MAKE_TARGET), mingw)
344 ifdef DP_PRELOAD_DEPENDENCIES
345 # DP_PRELOAD_DEPENDENCIES: when set, link against the libraries needed using -l
346 # dynamically so they won't get loaded at runtime using dlopen
347         LDFLAGS_CL+=$(LDFLAGS_UNIXCL_PRELOAD)
348         LDFLAGS_SV+=$(LDFLAGS_UNIXSV_PRELOAD)
349         LDFLAGS_SDL+=$(LDFLAGS_UNIXSDL_PRELOAD)
350         CFLAGS_PRELOAD=$(CFLAGS_UNIX_PRELOAD)
351 endif
352 endif
353
354 CFLAGS_NET=
355 # Systems without IPv6 support should uncomment this:
356 #CFLAGS_NET+=-DNOSUPPORTIPV6
357
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