]> git.xonotic.org Git - xonotic/darkplaces.git/blob - makefile
Makefile: support explicit static linking of all configurable libraries
[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 # 64bits AMD CPUs use another lib directory
70 ifeq ($(DP_MACHINE),x86_64)
71         UNIX_X11LIBPATH:=/usr/X11R6/lib64
72 else
73         UNIX_X11LIBPATH:=/usr/X11R6/lib
74 endif
75
76 # default targets
77 TARGETS_DEBUG=sv-debug sdl-debug
78 TARGETS_PROFILE=sv-profile sdl-profile
79 TARGETS_RELEASE=sv-release sdl-release
80 TARGETS_RELEASE_PROFILE=sv-release-profile sdl-release-profile
81 TARGETS_NEXUIZ=sv-nexuiz sdl-nexuiz
82
83 ###### Optional features #####
84 DP_VIDEO_CAPTURE?=enabled
85 ifeq ($(DP_VIDEO_CAPTURE), enabled)
86         CFLAGS_VIDEO_CAPTURE=-DCONFIG_VIDEO_CAPTURE
87         OBJ_VIDEO_CAPTURE=cap_avi.o cap_ogg.o
88 else
89         CFLAGS_VIDEO_CAPTURE=
90         OBJ_VIDEO_CAPTURE=
91 endif
92
93 # Linux configuration
94 ifeq ($(DP_MAKE_TARGET), linux)
95         OBJ_ICON=
96         OBJ_ICON_NEXUIZ=
97
98         LDFLAGS_SV=$(LDFLAGS_LINUXSV)
99         LDFLAGS_SDL=$(LDFLAGS_LINUXSDL)
100
101         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
102         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
103         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
104
105         EXE_SV=$(EXE_UNIXSV)
106         EXE_SDL=$(EXE_UNIXSDL)
107         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
108         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
109
110         DP_LINK_SDL?=shared
111         DP_LINK_ZLIB?=shared
112         DP_LINK_JPEG?=shared
113         DP_LINK_ODE?=
114         DP_LINK_CRYPTO?=dlopen
115         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
116         DP_LINK_XMP?=dlopen
117 endif
118
119 # Mac OS X configuration
120 ifeq ($(DP_MAKE_TARGET), macosx)
121         OBJ_ICON=
122         OBJ_ICON_NEXUIZ=
123
124         LDFLAGS_SV=$(LDFLAGS_MACOSXSV)
125         LDFLAGS_SDL=$(LDFLAGS_MACOSXSDL)
126
127         SDLCONFIG_CFLAGS=$(SDLCONFIG_MACOSXCFLAGS)
128         SDLCONFIG_LIBS=$(SDLCONFIG_MACOSXLIBS)
129         SDLCONFIG_STATICLIBS=$(SDLCONFIG_MACOSXSTATICLIBS)
130
131         EXE_SV=$(EXE_UNIXSV)
132         EXE_SDL=$(EXE_UNIXSDL)
133         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
134         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
135
136         ifeq ($(word 2, $(filter -arch, $(CC))), -arch)
137                 CFLAGS_MAKEDEP=
138         endif
139
140         DP_LINK_SDL?=shared
141         DP_LINK_ZLIB?=shared
142         DP_LINK_JPEG?=dlopen
143         DP_LINK_ODE?=
144         DP_LINK_CRYPTO?=dlopen
145         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
146         DP_LINK_XMP?=dlopen
147
148         # on OS X, we don't build the CL by default because it uses deprecated
149         # and not-implemented-in-64bit Carbon
150         TARGETS_DEBUG=sv-debug sdl-debug
151         TARGETS_PROFILE=sv-profile sdl-profile
152         TARGETS_RELEASE=sv-release sdl-release
153         TARGETS_RELEASE_PROFILE=sv-release-profile sdl-release-profile
154         TARGETS_NEXUIZ=sv-nexuiz sdl-nexuiz
155 endif
156
157 # SunOS configuration (Solaris)
158 ifeq ($(DP_MAKE_TARGET), sunos)
159         OBJ_ICON=
160         OBJ_ICON_NEXUIZ=
161
162         CFLAGS_EXTRA=$(CFLAGS_SUNOS)
163
164         LDFLAGS_SV=$(LDFLAGS_SUNOSSV)
165         LDFLAGS_SDL=$(LDFLAGS_SUNOSSDL)
166
167         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
168         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
169         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
170
171         EXE_SV=$(EXE_UNIXSV)
172         EXE_SDL=$(EXE_UNIXSDL)
173         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
174         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
175
176         DP_LINK_SDL?=shared
177         DP_LINK_ZLIB?=shared
178         DP_LINK_JPEG?=shared
179         DP_LINK_ODE?=
180         DP_LINK_CRYPTO?=dlopen
181         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
182         DP_LINK_XMP?=dlopen
183 endif
184
185 # BSD configuration
186 ifeq ($(DP_MAKE_TARGET), bsd)
187
188         OBJ_ICON=
189         OBJ_ICON_NEXUIZ=
190
191         LDFLAGS_SV=$(LDFLAGS_BSDSV)
192         LDFLAGS_SDL=$(LDFLAGS_BSDSDL)
193
194         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
195         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
196         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
197
198         EXE_SV=$(EXE_UNIXSV)
199         EXE_SDL=$(EXE_UNIXSDL)
200         EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
201         EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
202
203         DP_LINK_SDL?=shared
204         DP_LINK_ZLIB?=shared
205         DP_LINK_JPEG?=shared
206         DP_LINK_ODE?=
207         DP_LINK_CRYPTO?=dlopen
208         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
209         DP_LINK_XMP?=dlopen
210 endif
211
212 # Win32 configuration
213 ifeq ($(WIN32RELEASE), 1)
214 #       TARGET=i686-pc-mingw32
215 #       CC=$(TARGET)-g++
216 #       WINDRES=$(TARGET)-windres
217         CPUOPTIMIZATIONS=-march=pentium3 -mfpmath=sse -fno-math-errno -fno-rounding-math -fno-signaling-nans -fno-trapping-math
218 #       CPUOPTIMIZATIONS+=-DUSE_WSPIAPI_H -DSUPPORTIPV6
219         LDFLAGS_WINCOMMON=-Wl,--large-address-aware
220 else
221         LDFLAGS_WINCOMMON=
222 endif
223
224 ifeq ($(WIN64RELEASE), 1)
225 #       TARGET=x86_64-pc-mingw32
226 #       CC=$(TARGET)-g++
227 #       WINDRES=$(TARGET)-windres
228 endif
229
230 CFLAGS_WARNINGS=-Wall -Winline -Werror=vla -Werror=c++-compat -Wwrite-strings -Wshadow -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement -Wmissing-prototypes
231
232
233 ifeq ($(DP_MAKE_TARGET), mingw)
234         OBJ_ICON=darkplaces.o
235         OBJ_ICON_NEXUIZ=nexuiz.o
236
237         LDFLAGS_SV=$(LDFLAGS_WINSV)
238         LDFLAGS_SDL=$(LDFLAGS_WINSDL)
239
240         SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS)
241         SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS)
242         SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS)
243
244         EXE_SV=$(EXE_WINSV)
245         EXE_SDL=$(EXE_WINSDL)
246         EXE_SVNEXUIZ=$(EXE_WINSVNEXUIZ)
247         EXE_SDLNEXUIZ=$(EXE_WINSDLNEXUIZ)
248
249         DP_LINK_SDL?=shared
250         DP_LINK_ZLIB?=dlopen
251         DP_LINK_JPEG?=shared
252         DP_LINK_ODE?=
253         DP_LINK_CRYPTO?=dlopen
254         DP_LINK_CRYPTO_RIJNDAEL?=dlopen
255         DP_LINK_XMP?=dlopen
256 endif
257
258
259 ##### Library linking #####
260 # SDL2
261 ifeq ($(DP_LINK_SDL), shared)
262         SDL_LIBS=$(SDLCONFIG_LIBS)
263 else ifeq ($(DP_LINK_SDL), static)
264         SDL_LIBS=$(SDLCONFIG_STATICLIBS)
265 else ifeq ($(DP_LINK_SDL), dlopen)
266   $(error libSDL2 can only be used with shared or static linking)
267 endif
268
269 # zlib
270 ifeq ($(DP_LINK_ZLIB), shared)
271         CFLAGS_LIBZ=-DLINK_TO_ZLIB
272         LIB_Z=-lz
273 else ifeq ($(DP_LINK_ZLIB), static)
274         CFLAGS_LIBZ=-DLINK_TO_ZLIB
275         LIB_Z=-l:libz.a
276 else ifeq ($(DP_LINK_ZLIB), dlopen)
277         CFLAGS_LIBZ=
278         LIB_Z=
279 endif
280
281 # jpeg
282 ifeq ($(DP_LINK_JPEG), shared)
283         CFLAGS_LIBJPEG=-DLINK_TO_LIBJPEG
284         LIB_JPEG=-ljpeg
285 else ifeq ($(DP_LINK_JPEG), static)
286         CFLAGS_LIBJPEG=-DLINK_TO_LIBJPEG
287         LIB_JPEG=-l:libjpeg.a
288 else ifeq ($(DP_LINK_JPEG), dlopen)
289         CFLAGS_LIBJPEG=
290         LIB_JPEG=
291 endif
292
293 # ode
294 ifeq ($(DP_LINK_ODE), shared)
295         ODE_CONFIG?=ode-config
296         LIB_ODE=`$(ODE_CONFIG) --libs`
297         CFLAGS_ODE=`$(ODE_CONFIG) --cflags` -DUSEODE -DLINK_TO_LIBODE
298 else ifeq ($(DP_LINK_ODE), static)
299         # This is the configuration from Xonotic
300         ODE_CONFIG?=ode-config
301         LIB_ODE=-l:libode.a -lstdc++ -pthread
302         CFLAGS_ODE=-DUSEODE -DLINK_TO_LIBODE -DdDOUBLE
303 else ifeq ($(DP_LINK_ODE), dlopen)
304         LIB_ODE=
305         CFLAGS_ODE=-DUSEODE
306 endif
307
308 # d0_blind_id
309 ifeq ($(DP_LINK_CRYPTO), shared)
310         LIB_CRYPTO=-ld0_blind_id
311         CFLAGS_CRYPTO=-DLINK_TO_CRYPTO
312 else ifeq ($(DP_LINK_CRYPTO), static)
313         LIB_CRYPTO=-l:libd0_blind_id.a -lgmp
314         CFLAGS_CRYPTO=-DLINK_TO_CRYPTO
315 else ifeq ($(DP_LINK_CRYPTO), static_inc_gmp)
316         LIB_CRYPTO=-l:libd0_blind_id.a -l:libgmp.a
317         CFLAGS_CRYPTO=-DLINK_TO_CRYPTO
318 else ifeq ($(DP_LINK_CRYPTO), dlopen)
319         LIB_CRYPTO=
320         CFLAGS_CRYPTO=
321 endif
322
323 # d0_rijndael
324 ifeq ($(DP_LINK_CRYPTO_RIJNDAEL), shared)
325         LIB_CRYPTO_RIJNDAEL=-ld0_rijndael
326         CFLAGS_CRYPTO_RIJNDAEL=-DLINK_TO_CRYPTO_RIJNDAEL
327 else ifeq ($(DP_LINK_CRYPTO_RIJNDAEL), static)
328         LIB_CRYPTO_RIJNDAEL=-l:libd0_rijndael.a
329         CFLAGS_CRYPTO_RIJNDAEL=-DLINK_TO_CRYPTO_RIJNDAEL
330 else ifeq ($(DP_LINK_CRYPTO_RIJNDAEL), dlopen)
331         LIB_CRYPTO_RIJNDAEL=
332         CFLAGS_CRYPTO_RIJNDAEL=
333 endif
334
335 # xmp
336 ifeq ($(DP_LINK_XMP), shared)
337         OBJ_SND_XMP=snd_xmp.o
338         LIB_SND_XMP=-lxmp
339         CFLAGS_SND_XMP=-DUSEXMP -DLINK_TO_LIBXMP
340 else ifeq ($(DP_LINK_XMP), static)
341         OBJ_SND_XMP=snd_xmp.o
342         LIB_SND_XMP=-l:libxmp.a
343         CFLAGS_SND_XMP=-DUSEXMP -DLINK_TO_LIBXMP
344 else ifeq ($(DP_LINK_XMP), dlopen)
345         OBJ_SND_XMP=snd_xmp.o
346         LIB_SND_XMP=
347         CFLAGS_SND_XMP=-DUSEXMP
348 endif
349
350
351 ##### Extra CFLAGS #####
352 ifneq ($(CC), tcc)
353         CFLAGS_MAKEDEP?=-MMD
354 endif
355
356 ifdef DP_FS_BASEDIR
357         CFLAGS_FS=-DDP_FS_BASEDIR=\"$(DP_FS_BASEDIR)\"
358 else
359         CFLAGS_FS=
360 endif
361
362 CFLAGS_PRELOAD=
363 ifneq ($(DP_MAKE_TARGET), mingw)
364 ifdef DP_PRELOAD_DEPENDENCIES
365 # DP_PRELOAD_DEPENDENCIES: when set, link against the libraries needed using -l
366 # dynamically so they won't get loaded at runtime using dlopen
367         LDFLAGS_CL+=$(LDFLAGS_UNIXCL_PRELOAD)
368         LDFLAGS_SV+=$(LDFLAGS_UNIXSV_PRELOAD)
369         LDFLAGS_SDL+=$(LDFLAGS_UNIXSDL_PRELOAD)
370         CFLAGS_PRELOAD=$(CFLAGS_UNIX_PRELOAD)
371 endif
372 endif
373
374 CFLAGS_NET=
375 # Systems without IPv6 support should uncomment this:
376 #CFLAGS_NET+=-DNOSUPPORTIPV6
377
378 ##### GNU Make specific definitions #####
379
380 DO_LD=$(CC) -o ../../../$@ $^ $(LDFLAGS)
381
382
383 ##### Definitions shared by all makefiles #####
384 include makefile.inc
385
386
387 ##### Dependency files #####
388
389 -include *.d
390
391 # hack to deal with no-longer-needed .h files
392 %.h:
393         @echo
394         @echo "NOTE: file $@ mentioned in dependencies missing, continuing..."
395         @echo "HINT: consider 'make clean'"
396         @echo