1 # Invalid call detection
2 CHECKLEVEL1 = @if [ "$(LEVEL)" != 1 ]; then $(MAKE) help; false; fi
3 CHECKLEVEL2 = @if [ "$(LEVEL)" != 2 ]; then $(MAKE) help; false; fi
11 OBJ_SND_COMMON=snd_main.o snd_mem.o snd_mix.o snd_ogg.o snd_wav.o $(OBJ_SND_XMP)
14 OBJ_SND_NULL=snd_null.o
17 ###### Common objects and flags #####
76 mod_skeletal_animatevertices_sse.o \
77 mod_skeletal_animatevertices_generic.o \
126 # note that builddate.c is very intentionally not compiled to a .o before
127 # being linked, because it should be recompiled every time an executable is
128 # built to give the executable a proper date string
129 OBJ_SV= builddate.c sys_null.o vid_null.o thread_null.o $(OBJ_SND_NULL) $(OBJ_COMMON)
130 OBJ_SDL= builddate.c sys_sdl.o vid_sdl.o thread_sdl.o $(OBJ_MENU) $(OBJ_SND_COMMON) $(OBJ_SND_XMP) snd_sdl.o $(OBJ_VIDEO_CAPTURE) $(OBJ_COMMON)
135 CFLAGS_STANDARD=-std=c11 -pedantic -D_POSIX_C_SOURCE=200809L -DCONFIG_PEDANTIC
140 CFLAGS_WARNINGS=-Wall -Werror=vla -Werror=c++-compat -Wwrite-strings -Wshadow -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement -Wmissing-prototypes
144 CFLAGS_TCC=-DSDL_DISABLE_IMMINTRIN_H
149 CFLAGS_COMMON=$(CFLAGS_STANDARD) $(CFLAGS_TCC) $(CFLAGS_MAKEDEP) $(CFLAGS_PRELOAD) $(CFLAGS_FS) $(CFLAGS_WARNINGS) $(CFLAGS_LIBZ) $(CFLAGS_LIBJPEG) $(CFLAGS_SND_XMP) $(CFLAGS_NET) $(CFLAGS_SDL) -D_FILE_OFFSET_BITS=64 -D__KERNEL_STRICT_NAMES -I../../../
150 CFLAGS_CLIENT=-DCONFIG_MENU $(CFLAGS_VIDEO_CAPTURE)
153 CFLAGS_PROFILE=-g -pg -ggdb -fprofile-arcs
155 CFLAGS_RELEASE_PROFILE=-fbranch-probabilities
164 endif # ifeq ($(DP_SSE),1)
170 CPUOPTIMIZATIONS+=-mno-avx
172 # bones_was_here: added -mno-avx because when compiling for (at least) haswell or skylake with gcc or clang, with both -O2 and -O3, AVX auto-vectorisation causes subtle bugs in Xonotic QC physics, and changes the hash generated by the CI pipeline. AVX2 seems to be OK.
174 # We can get good stack traces at -O1 with -fno-omit-frame-pointer (as recommended by ASan docs) for a hefty boost compared to unoptimised.
175 OPTIM_DEBUG=-O1 -fno-omit-frame-pointer $(CPUOPTIMIZATIONS)
176 #OPTIM_RELEASE=-O2 -fno-strict-aliasing -ffast-math -funroll-loops $(CPUOPTIMIZATIONS)
177 #OPTIM_RELEASE=-O2 -fno-strict-aliasing -fno-math-errno -fno-trapping-math -fno-signaling-nans -fcx-limited-range -funroll-loops $(CPUOPTIMIZATIONS)
178 #OPTIM_RELEASE=-O2 -fno-strict-aliasing -funroll-loops $(CPUOPTIMIZATIONS)
179 #OPTIM_RELEASE=-O2 -fno-strict-aliasing $(CPUOPTIMIZATIONS)
180 #OPTIM_RELEASE=-O3 -fno-strict-aliasing $(CPUOPTIMIZATIONS)
181 #OPTIM_RELEASE=-O3 -fno-strict-aliasing -fno-math-errno -fno-trapping-math $(CPUOPTIMIZATIONS)
182 # -Winline is here instead of in CFLAGS_WARNINGS because we need inlining disabled for good stack traces in debug builds,
183 # also because UBSan and ASan cause this warning to be spammed.
184 OPTIM_RELEASE=-O3 -fno-math-errno -fno-trapping-math $(CPUOPTIMIZATIONS) -Winline
185 # NOTE: *never* *ever* use the -ffast-math or -funsafe-math-optimizations flag
186 # Also, since gcc 5, -ffinite-math-only makes NaN and zero compare equal inside engine code but not inside QC, which causes error spam for seemingly valid QC code like if (x != 0) return 1 / x;
188 DO_CC=$(CC) $(CFLAGS) -c $< -o $@
193 # not checking for .git directory before running `git describe` because that would stop it working in a subdirectory
194 VCREVISION=$(shell { test -d .svn && svnversion; } || git describe --always --dirty='~' 2>/dev/null || echo -)
196 LDFLAGS_DEBUG=-g -ggdb $(OPTIM_DEBUG) -DVCREVISION=$(VCREVISION) -DBUILDTYPE=debug
197 LDFLAGS_PROFILE=-g -pg -fprofile-arcs $(OPTIM_RELEASE) -DVCREVISION=$(VCREVISION) -DBUILDTYPE=profile
198 LDFLAGS_RELEASE=$(OPTIM_RELEASE) -DVCREVISION=$(VCREVISION) -DBUILDTYPE=release
201 ##### UNIX specific variables #####
203 LDFLAGS_UNIXCOMMON=-lm $(LIB_ODE) $(LIB_Z) $(LIB_JPEG) $(LIB_CRYPTO) $(LIB_CRYPTO_RIJNDAEL) $(LIB_SND_XMP)
204 LDFLAGS_UNIXSV_PRELOAD=-lz -ljpeg -lpng -lcurl
205 LDFLAGS_UNIXSDL_PRELOAD=-lz -ljpeg -lpng -logg -ltheora -lvorbis -lvorbisenc -lvorbisfile -lcurl -lxmp
206 CFLAGS_UNIX_PRELOAD=-DPREFER_PRELOAD
208 LDFLAGS_UNIXSDL=$(SDL_LIBS) #-lGLESv2
209 EXE_UNIXSV=darkplaces-dedicated
210 EXE_UNIXSDL=darkplaces-sdl
211 EXE_UNIXSVNEXUIZ=nexuiz-dedicated
212 EXE_UNIXSDLNEXUIZ=nexuiz-sdl
216 CMD_UNIXMKDIR=mkdir -p
219 ##### Linux specific variables #####
222 # -rdynamic allows glibc backtrace_symbols_fd() to convert addresses to function names
223 # with a much smaller binary than with full debug symbols
224 LDFLAGS_LINUXSV=$(LDFLAGS_UNIXCOMMON) -lrt -ldl -rdynamic
225 LDFLAGS_LINUXSDL=$(LDFLAGS_UNIXCOMMON) -lrt -ldl -rdynamic $(LDFLAGS_UNIXSDL)
228 ##### Mac OS X specific variables #####
231 LDFLAGS_MACOSXSV=$(LDFLAGS_UNIXCOMMON) -ldl
232 LDFLAGS_MACOSXSDL=$(LDFLAGS_UNIXCOMMON) -ldl -framework IOKit $(SDLCONFIG_STATICLIBS) #../../../SDLMain.m
235 ##### SunOS specific variables #####
237 CFLAGS_SUNOS=-I/usr/lib/oss/include -DBSD_COMP -DSUNOS
240 LDFLAGS_SUNOSSV=$(LDFLAGS_UNIXCOMMON) -lrt -ldl -lsocket -lnsl
241 LDFLAGS_SUNOSSDL=$(LDFLAGS_UNIXCOMMON) -lrt -ldl -lsocket -lnsl $(LDFLAGS_UNIXSDL)
244 ##### BSD specific variables #####
247 LDFLAGS_BSDSV=$(LDFLAGS_UNIXCOMMON)
248 LDFLAGS_BSDSDL=$(LDFLAGS_UNIXCOMMON) $(LDFLAGS_UNIXSDL)
251 ##### Win32 specific variables #####
256 # see LDFLAGS_WINCOMMON in makefile
257 LDFLAGS_WINSV=$(LDFLAGS_WINCOMMON) $(LIB_CRYPTO) $(LIB_CRYPTO_RIJNDAEL) -mconsole -lwinmm -lws2_32 $(LIB_Z) $(LIB_JPEG)
258 LDFLAGS_WINSDL=$(LDFLAGS_WINCOMMON) $(LIB_CRYPTO) $(LIB_CRYPTO_RIJNDAEL) $(LDFLAGS_UNIXSDL) -lwinmm -lws2_32 $(LIB_Z) $(LIB_JPEG) $(LIB_SND_XMP)
259 EXE_WINSV=darkplaces-dedicated.exe
260 EXE_WINSDL=darkplaces-sdl.exe
261 EXE_WINSVNEXUIZ=nexuiz-dedicated.exe
262 EXE_WINSDLNEXUIZ=nexuiz-sdl.exe
268 .PHONY : clean clean-profile help \
269 debug profile release \
270 sv-debug sv-profile sv-release \
271 sdl-debug sdl-profile sdl-release
275 @echo "===== Choose one ====="
276 @echo "* $(MAKE) clean : delete all files produced by the build except"
277 @echo " profiling information"
278 @echo "* $(MAKE) clean-profile : delete all files produced by the build, including"
279 @echo " profiling informaiton"
280 @echo "* $(MAKE) help : this help"
281 @echo "* $(MAKE) debug : make client and server binaries (debug versions)"
282 @echo "* $(MAKE) profile : make client and server binaries (profile versions)"
283 @echo "* $(MAKE) release : make client and server binaries (release versions)"
284 @echo "* $(MAKE) release-profile : make client and server binaries (release versions)"
285 @echo " (with profiling optimizations) The profiled"
286 @echo " version of the program must have been"
287 @echo " previously compiled"
288 @echo "* $(MAKE) nexuiz : make client and server binaries with nexuiz icon"
289 @echo " (release versions)"
290 @echo "* $(MAKE) sv-debug : make dedicated server (debug version)"
291 @echo "* $(MAKE) sv-profile : make dedicated server (profile version)"
292 @echo "* $(MAKE) sv-release-profile : make dedicated server (release profile version)"
293 @echo "* $(MAKE) sv-release : make dedicated server (release version)"
294 @echo "* $(MAKE) sv-nexuiz : make dedicated server with nexuiz icon"
295 @echo " (release version)"
296 @echo "* $(MAKE) sdl-debug : make SDL client (debug version)"
297 @echo "* $(MAKE) sdl-profile : make SDL client (profile version)"
298 @echo "* $(MAKE) sdl-release-profile : make SDL client (release version)"
299 @echo "* $(MAKE) sdl-release : make SDL client (release version)"
300 @echo "* $(MAKE) sdl-nexuiz : make SDL client with nexuiz icon (release version)"
304 $(MAKE) $(TARGETS_DEBUG)
307 $(MAKE) $(TARGETS_PROFILE)
310 $(MAKE) $(TARGETS_RELEASE)
313 $(MAKE) $(TARGETS_RELEASE_PROFILE)
316 $(MAKE) $(TARGETS_NEXUIZ)
320 DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
321 EXE='$(EXE_SV)' CFLAGS_FEATURES='$(CFLAGS_SERVER)' LDFLAGS_COMMON='$(LDFLAGS_SV)' LEVEL=1
324 $(MAKE) bin-profile \
325 DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
326 EXE='$(EXE_SV)' CFLAGS_FEATURES='$(CFLAGS_SERVER)' LDFLAGS_COMMON='$(LDFLAGS_SV)' LEVEL=1
329 $(MAKE) bin-release \
330 DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
331 EXE='$(EXE_SV)' CFLAGS_FEATURES='$(CFLAGS_SERVER)' LDFLAGS_COMMON='$(LDFLAGS_SV)' LEVEL=1
334 $(MAKE) bin-release-profile \
335 DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
336 EXE='$(EXE_SV)' CFLAGS_FEATURES='$(CFLAGS_SERVER)' LDFLAGS_COMMON='$(LDFLAGS_SV)' LEVEL=1
339 $(MAKE) bin-release \
340 DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
341 EXE='$(EXE_SVNEXUIZ)' CFLAGS_FEATURES='$(CFLAGS_SERVER)' LDFLAGS_COMMON='$(LDFLAGS_SV)' LEVEL=1
345 DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
346 EXE='$(EXE_SDL)' CFLAGS_FEATURES='$(CFLAGS_CLIENT)' CFLAGS_SDL='$(SDLCONFIG_CFLAGS)' LDFLAGS_COMMON='$(LDFLAGS_SDL)' LEVEL=1
349 $(MAKE) bin-profile \
350 DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
351 EXE='$(EXE_SDL)' CFLAGS_FEATURES='$(CFLAGS_CLIENT)' CFLAGS_SDL='$(SDLCONFIG_CFLAGS)' LDFLAGS_COMMON='$(LDFLAGS_SDL)' LEVEL=1
354 $(MAKE) bin-release \
355 DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
356 EXE='$(EXE_SDL)' CFLAGS_FEATURES='$(CFLAGS_CLIENT)' CFLAGS_SDL='$(SDLCONFIG_CFLAGS)' LDFLAGS_COMMON='$(LDFLAGS_SDL)' LEVEL=1
358 sdl-release-profile :
359 $(MAKE) bin-release-profile \
360 DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
361 EXE='$(EXE_SDL)' CFLAGS_FEATURES='$(CFLAGS_CLIENT)' CFLAGS_SDL='$(SDLCONFIG_CFLAGS)' LDFLAGS_COMMON='$(LDFLAGS_SDL)' LEVEL=1
364 $(MAKE) bin-release \
365 DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
366 EXE='$(EXE_SDLNEXUIZ)' CFLAGS_FEATURES='$(CFLAGS_CLIENT)' CFLAGS_SDL='$(SDLCONFIG_CFLAGS)' LDFLAGS_COMMON='$(LDFLAGS_SDL)' LEVEL=1
371 @echo '========== $(EXE) (debug) =========='
372 $(MAKE) prepare BUILD_DIR=build-obj/debug/$(EXE)
373 $(MAKE) -C build-obj/debug/$(EXE) $(EXE) \
374 DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
375 CFLAGS='$(CFLAGS_COMMON) $(CFLAGS_FEATURES) $(CFLAGS_EXTRA) $(CFLAGS_DEBUG) $(OPTIM_DEBUG)'\
376 LDFLAGS='$(LDFLAGS_DEBUG) $(LDFLAGS_COMMON)' LEVEL=2
381 @echo '========== $(EXE) (profile) =========='
382 $(MAKE) prepare BUILD_DIR=build-obj/profile/$(EXE)
383 $(MAKE) -C build-obj/profile/$(EXE) $(EXE) \
384 DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
385 CFLAGS='$(CFLAGS_COMMON) $(CFLAGS_FEATURES) $(CFLAGS_EXTRA) $(CFLAGS_PROFILE) $(OPTIM_RELEASE)'\
386 LDFLAGS='$(LDFLAGS_PROFILE) $(LDFLAGS_COMMON)' LEVEL=2
391 @echo '========== $(EXE) (release) =========='
392 $(MAKE) prepare BUILD_DIR=build-obj/release/$(EXE)
393 $(MAKE) -C build-obj/release/$(EXE) $(EXE) \
394 DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
395 CFLAGS='$(CFLAGS_COMMON) $(CFLAGS_FEATURES) $(CFLAGS_EXTRA) $(CFLAGS_RELEASE) $(OPTIM_RELEASE)'\
396 LDFLAGS='$(LDFLAGS_RELEASE) $(LDFLAGS_COMMON)' LEVEL=2
399 bin-release-profile :
402 @echo '========== $(EXE) (release) =========='
403 $(MAKE) prepare BUILD_DIR=build-obj/release-profile/$(EXE)
404 $(MAKE) -C build-obj/release-profile/$(EXE) $(EXE) \
405 DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
406 CFLAGS='$(CFLAGS_COMMON) $(CFLAGS_FEATURES) $(CFLAGS_EXTRA) $(CFLAGS_RELEASE_PROFILE) $(OPTIM_RELEASE)'\
407 LDFLAGS='$(LDFLAGS_RELEASE) $(LDFLAGS_COMMON)' LEVEL=2
411 $(CMD_MKDIR) $(BUILD_DIR)
412 $(CMD_CP) makefile.inc $(BUILD_DIR)/
413 $(CMD_CP) $(MAKEFILE) $(BUILD_DIR)/
416 #this checks USEODE when compiling so it needs the ODE flags as well
417 cl_parse.o: cl_parse.c
419 $(DO_CC) $(CFLAGS_ODE)
421 cs_progs.o: cs_progs.c
423 $(DO_CC) $(CFLAGS_ODE)
427 $(DO_CC) $(CFLAGS_ODE)
431 $(DO_CC) $(CFLAGS_ODE)
433 prvm_cmds.o: prvm_cmds.c
435 $(DO_CC) $(CFLAGS_ODE)
439 $(DO_CC) $(CFLAGS_ODE)
443 $(DO_CC) $(CFLAGS_CRYPTO) $(CFLAGS_CRYPTO_RIJNDAEL)
445 mod_skeletal_animatevertices_sse.o: mod_skeletal_animatevertices_sse.c
447 $(DO_CC) $(CFLAGS_SSE)
451 $(DO_CC) $(CFLAGS_SND_XMP)
453 #this checks USEXMP when compiling so it needs the XMP flags as well
454 snd_main.o: snd_main.c
456 $(DO_CC) $(CFLAGS_SND_XMP)
458 #this checks USEXMP when compiling so it needs the XMP flags as well
461 $(DO_CC) $(CFLAGS_SND_XMP)
463 darkplaces.o: %.o : %.rc
474 .c.o: .EXTRA_PREREQS = # According to POSIX, a suffix rule cannot contain prerequisites.
476 $(EXE_SV): $(OBJ_SV) $(OBJ_ICON)
480 $(EXE_SDL): $(OBJ_SDL) $(OBJ_ICON)
484 $(EXE_SVNEXUIZ): $(OBJ_SV) $(OBJ_ICON_NEXUIZ)
488 $(EXE_SDLNEXUIZ): $(OBJ_SDL) $(OBJ_ICON_NEXUIZ)
492 # If requested, these targets must always run first:
493 .EXTRA_PREREQS := $(filter clean clean-profile, $(MAKECMDGOALS))
497 -$(CMD_RM) $(EXE_SDL)
498 -$(CMD_RM) $(EXE_SVNEXUIZ)
499 -$(CMD_RM) $(EXE_SDLNEXUIZ)
503 -$(CMD_RM) build-obj/
504 clean: .EXTRA_PREREQS = # prevents circular dependency with clean-profile