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