-CC=gcc
-
-# K6/athlon optimizations
-#CPUOPTIMIZATIONS=-march=k6
-# Note: don't use -march=athlon, every gcc which has it currently (2.96-3.1)
-# have optimizer bugs (like entities disappearing randomly - a bug with
-# compiling BOX_ON_PLANE_SIDE in mathlib.h)
-#CPUOPTIMIZATIONS=-march=athlon
-# 686 optimizations
-#CPUOPTIMIZATIONS=-march=i686
-# No specific CPU
-CPUOPTIMIZATIONS=
-
-
-##### Variables that you shouldn't care about #####
-
-# Sound objects
-OBJ_COMMONSOUND=snd_dma.o snd_mem.o snd_mix.o snd_ogg.o
-OBJ_NOSOUND=snd_null.o
-
-# CD objects
-OBJ_COMMONCD=cd_shared.o
-OBJ_NOCD=cd_null.o
+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
+
+
+###### Sound #####
+
+OBJ_SND_COMMON=snd_main.o snd_mem.o snd_mix.o snd_ogg.o snd_wav.o $(OBJ_SND_XMP)
+
+# No sound
+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 #####