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