]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - makefile.inc
deduplicate Sys_Shutdown()
[xonotic/darkplaces.git] / makefile.inc
index 90e2bf86aaca8a5e9853a262f3a182c0b45a2a69..2534cff705da601a3b61acbd5cb46d0c77557cf8 100644 (file)
@@ -2,42 +2,7 @@
 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?=
-# 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.
-# Also moved -fno-math-errno -fno-trapping-math (etc) to OPTIM_RELEASE as they're not CPU-specific.
-# 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=$(SDLCONFIG_UNIXCFLAGS)
-SDLCONFIG_MACOSXLIBS=$(SDLCONFIG_UNIXLIBS)
-SDLCONFIG_MACOSXSTATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS)
 STRIP?=strip
 
 
@@ -172,10 +137,13 @@ else
        CFLAGS_STANDARD=
 endif
 
-CFLAGS_TCC=
+CFLAGS_WARNINGS=-Wall -Winline -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../../../
@@ -195,13 +163,22 @@ else
        CFLAGS_SSE2=
 endif # ifeq ($(DP_SSE),1)
 
+# 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.
+
 OPTIM_DEBUG=$(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 -fno-math-errno -fno-trapping-math $(CPUOPTIMIZATIONS)
+#OPTIM_RELEASE=-O3 -fno-strict-aliasing -fno-math-errno -fno-trapping-math $(CPUOPTIMIZATIONS)
+OPTIM_RELEASE=-O3 -fno-math-errno -fno-trapping-math $(CPUOPTIMIZATIONS)
 # 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;
 
@@ -209,9 +186,13 @@ DO_CC=$(CC) $(CFLAGS) -c $< -o $@
 
 
 # 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 #####
@@ -485,6 +466,7 @@ nexuiz.o: %.o : %.rc
 .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)
@@ -502,6 +484,9 @@ $(EXE_SDLNEXUIZ): $(OBJ_SDL) $(OBJ_ICON_NEXUIZ)
        $(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)
@@ -511,6 +496,7 @@ clean:
        -$(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