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