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