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