CHECKLEVEL1 = @if [ "$(LEVEL)" != 1 ]; then $(MAKE) help; false; fi
CHECKLEVEL2 = @if [ "$(LEVEL)" != 2 ]; then $(MAKE) help; false; fi
-# Choose the compiler you want to use
-CC?=gcc
-
-# athlon optimizations
-#CPUOPTIMIZATIONS?=-march=athlon
-# athlon xp optimizations
-#CPUOPTIMIZATIONS?=-march=athlon-xp
-# athlon 64 optimizations
-#CPUOPTIMIZATIONS?=-march=athlon64 -m32
-# Pentium 3 optimizations
-#CPUOPTIMIZATIONS?=-march=pentium3
-# Pentium 4 optimizations
-#CPUOPTIMIZATIONS?=-march=pentium4
-# 686 (Pentium Pro/II) optimizations
-#CPUOPTIMIZATIONS?=-march=i686
-# No specific CPU (386 compatible)
-#CPUOPTIMIZATIONS?=
-# Experimental
-#CPUOPTIMIZATIONS?=-fno-math-errno -fno-rounding-math -fno-signaling-nans -fassociative-math -freciprocal-math -fno-signed-zeros -fno-trapping-math
-# Normal
-ifeq ($(CC), clang)
- CPUOPTIMIZATIONS?=-fno-math-errno -fno-rounding-math -fno-trapping-math
-else
- CPUOPTIMIZATIONS?=-fno-math-errno -fno-rounding-math -fno-signaling-nans -fno-trapping-math
-endif
-# NOTE: *never* *ever* use the -ffast-math or -funsafe-math-optimizations flag
-# 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;
-SDL_CONFIG?=sdl2-config
-SDLCONFIG_UNIXCFLAGS?=`$(SDL_CONFIG) --cflags`
-SDLCONFIG_UNIXCFLAGS_X11?=
-SDLCONFIG_UNIXLIBS?=`$(SDL_CONFIG) --libs`
-SDLCONFIG_UNIXLIBS_X11?=-lX11
-SDLCONFIG_UNIXSTATICLIBS?=`$(SDL_CONFIG) --static-libs`
-SDLCONFIG_UNIXSTATICLIBS_X11?=-lX11
-SDLCONFIG_MACOSXCFLAGS=-I/Library/Frameworks/SDL2.framework/Headers -I$(HOME)/Library/Frameworks/SDL2.framework/Headers
-SDLCONFIG_MACOSXLIBS=-F$(HOME)/Library/Frameworks/ -framework SDL2 -framework Cocoa $(SDLCONFIG_MACOSXCFLAGS)
-SDLCONFIG_MACOSXSTATICLIBS=-F$(HOME)/Library/Frameworks/ -framework SDL2 -framework Cocoa $(SDLCONFIG_MACOSXCFLAGS)
STRIP?=strip
OBJ_SND_NULL=snd_null.o
LIB_SND_NULL=
-# Open Sound System (Linux, FreeBSD and Solaris)
-OBJ_SND_OSS=$(OBJ_SND_COMMON) snd_oss.o
-LIB_SND_OSS=
-
-# Advanced Linux Sound Architecture (Linux)
-OBJ_SND_ALSA=$(OBJ_SND_COMMON) snd_alsa.o
-LIB_SND_ALSA=-lasound
-
-# Core Audio (Mac OS X)
-OBJ_SND_COREAUDIO=$(OBJ_SND_COMMON) snd_coreaudio.o
-LIB_SND_COREAUDIO=-framework CoreAudio
-
-# BSD / Sun audio API (NetBSD and OpenBSD)
-OBJ_SND_BSD=$(OBJ_SND_COMMON) snd_bsd.o
-LIB_SND_BSD=
-
-# DirectX and Win32 WAVE output (Win32)
-OBJ_SND_WIN=$(OBJ_SND_COMMON) snd_win.o
-LIB_SND_WIN=
-
-
###### Common objects and flags #####
# Common objects
com_ents.o \
com_ents4.o \
com_game.o \
+ com_infostring.o \
com_msg.o \
common.o \
console.o \
model_sprite.o \
netconn.o \
palette.o \
+ phys.o \
polygon.o \
portals.o \
protocol.o \
# note that builddate.c is very intentionally not compiled to a .o before
# being linked, because it should be recompiled every time an executable is
# built to give the executable a proper date string
-OBJ_SV= builddate.c sys_unix.o vid_null.o thread_null.o $(OBJ_SND_NULL) $(OBJ_COMMON)
+OBJ_SV= builddate.c sys_null.o vid_null.o thread_null.o $(OBJ_SND_NULL) $(OBJ_COMMON)
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)
# Compilation
+# -D_POSIX_C_SOURCE=200809L doesn't enable all of POSIX 2008, wtf?
+# -D_DEFAULT_SOURCE does enables all of POSIX 2008 (without GNU extensions).
ifeq ($(PEDANTIC),1)
- CFLAGS_STANDARD=-std=c11 -pedantic -D_POSIX_C_SOURCE=200809L -DCONFIG_PEDANTIC
+ CFLAGS_STANDARD=-std=c17 -pedantic -D_DEFAULT_SOURCE -DCONFIG_PEDANTIC
else
CFLAGS_STANDARD=
endif
-CFLAGS_TCC=
+CFLAGS_WARNINGS=-Wall -Werror=vla -Werror=c++-compat -Wwrite-strings -Wshadow -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement -Wmissing-prototypes
+CFLAGS_TCC=
ifeq ($(CC), tcc)
CFLAGS_TCC=-DSDL_DISABLE_IMMINTRIN_H
+else
+ CFLAGS_MAKEDEP?=-MMD
endif
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../../../
CFLAGS_SSE2=
endif # ifeq ($(DP_SSE),1)
-OPTIM_DEBUG=$(CPUOPTIMIZATIONS)
+# No specific CPU
+CPUOPTIMIZATIONS?=
+# x86
+ifeq ($(DP_SSE),1)
+ CPUOPTIMIZATIONS+=-mno-avx
+endif
+# 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.
+
+# 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.
+OPTIM_DEBUG=-O1 -fno-omit-frame-pointer $(CPUOPTIMIZATIONS)
#OPTIM_RELEASE=-O2 -fno-strict-aliasing -ffast-math -funroll-loops $(CPUOPTIMIZATIONS)
#OPTIM_RELEASE=-O2 -fno-strict-aliasing -fno-math-errno -fno-trapping-math -fno-signaling-nans -fcx-limited-range -funroll-loops $(CPUOPTIMIZATIONS)
#OPTIM_RELEASE=-O2 -fno-strict-aliasing -funroll-loops $(CPUOPTIMIZATIONS)
#OPTIM_RELEASE=-O2 -fno-strict-aliasing $(CPUOPTIMIZATIONS)
-OPTIM_RELEASE=-O3 -fno-strict-aliasing $(CPUOPTIMIZATIONS)
+#OPTIM_RELEASE=-O3 -fno-strict-aliasing $(CPUOPTIMIZATIONS)
+#OPTIM_RELEASE=-O3 -fno-strict-aliasing -fno-math-errno -fno-trapping-math $(CPUOPTIMIZATIONS)
+# -Winline is here instead of in CFLAGS_WARNINGS because we need inlining disabled for good stack traces in debug builds,
+# also because UBSan and ASan cause this warning to be spammed.
+OPTIM_RELEASE=-O3 -fno-math-errno -fno-trapping-math $(CPUOPTIMIZATIONS) -Winline
# NOTE: *never* *ever* use the -ffast-math or -funsafe-math-optimizations flag
# 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;
# Link
-LDFLAGS_DEBUG=-g -ggdb $(OPTIM_DEBUG) -DSVNREVISION=`{ test -d .svn && svnversion; } || { test -d .git && git describe --always; } || echo -` -DBUILDTYPE=debug
-LDFLAGS_PROFILE=-g -pg -fprofile-arcs $(OPTIM_RELEASE) -DSVNREVISION=`{ test -d .svn && svnversion; } || { test -d .git && git describe --always; } || echo -` -DBUILDTYPE=profile
-LDFLAGS_RELEASE=$(OPTIM_RELEASE) -DSVNREVISION=`{ test -d .svn && svnversion; } || { test -d .git && git describe --always; } || echo -` -DBUILDTYPE=release
+
+# not checking for .git directory before running `git describe` because that would stop it working in a subdirectory
+VCREVISION=$(shell { test -d .svn && svnversion; } || git describe --always --dirty='~' 2>/dev/null || echo -)
+
+LDFLAGS_DEBUG=-g -ggdb $(OPTIM_DEBUG) -DVCREVISION=$(VCREVISION) -DBUILDTYPE=debug
+LDFLAGS_PROFILE=-g -pg -fprofile-arcs $(OPTIM_RELEASE) -DVCREVISION=$(VCREVISION) -DBUILDTYPE=profile
+LDFLAGS_RELEASE=$(OPTIM_RELEASE) -DVCREVISION=$(VCREVISION) -DBUILDTYPE=release
##### UNIX specific variables #####
##### Linux specific variables #####
# Link
-LDFLAGS_LINUXSV=$(LDFLAGS_UNIXCOMMON) -lrt -ldl
-LDFLAGS_LINUXSDL=$(LDFLAGS_UNIXCOMMON) -lrt -ldl $(LDFLAGS_UNIXSDL)
+# -rdynamic allows glibc backtrace_symbols_fd() to convert addresses to function names
+# with a much smaller binary than with full debug symbols
+LDFLAGS_LINUXSV=$(LDFLAGS_UNIXCOMMON) -lrt -ldl -rdynamic
+LDFLAGS_LINUXSDL=$(LDFLAGS_UNIXCOMMON) -lrt -ldl -rdynamic $(LDFLAGS_UNIXSDL)
##### Mac OS X specific variables #####
# Link
LDFLAGS_MACOSXSV=$(LDFLAGS_UNIXCOMMON) -ldl
-LDFLAGS_MACOSXSDL=$(LDFLAGS_UNIXCOMMON) -ldl -framework IOKit $(SDLCONFIG_STATICLIBS) ../../../SDLMain.m
+LDFLAGS_MACOSXSDL=$(LDFLAGS_UNIXCOMMON) -ldl -framework IOKit $(SDLCONFIG_STATICLIBS) #../../../SDLMain.m
##### SunOS specific variables #####
$(CHECKLEVEL2)
$(DO_CC) $(CFLAGS_ODE)
-keysym2ucs.o: keysym2ucs.c
- $(CHECKLEVEL2)
- $(DO_CC) -I/usr/X11R6/include
-
crypto.o: crypto.c
$(CHECKLEVEL2)
$(DO_CC) $(CFLAGS_CRYPTO) $(CFLAGS_CRYPTO_RIJNDAEL)
.c.o:
$(CHECKLEVEL2)
$(DO_CC)
+.c.o: .EXTRA_PREREQS = # According to POSIX, a suffix rule cannot contain prerequisites.
$(EXE_SV): $(OBJ_SV) $(OBJ_ICON)
$(CHECKLEVEL2)
$(CHECKLEVEL2)
$(DO_LD)
+# If requested, these targets must always run first:
+.EXTRA_PREREQS := $(filter clean clean-profile, $(MAKECMDGOALS))
+
clean:
-$(CMD_RM) $(EXE_SV)
-$(CMD_RM) $(EXE_SDL)
-$(CMD_RM) *.d
-$(CMD_RM) *.gch
-$(CMD_RM) build-obj/
+clean: .EXTRA_PREREQS = # prevents circular dependency with clean-profile
clean-profile: clean
-$(CMD_RM) *.gcda