From 126c2ea10b1d354de315a60e47a2da94e69ab850 Mon Sep 17 00:00:00 2001 From: Yamagi Date: Thu, 28 Mar 2024 08:46:53 +0100 Subject: [PATCH] Add SDL 3 support to the Makefile. This is hidden behind WITH_SDL3, which is disabled by default. Additionally rename the SDL sources files in the client to represent the SDL major version they are supporting. They will be forked for SDL 3. That isn't optimal, because it forces us to support two variants of the same code. However the changes between SDL 2 and 3 are too big to work with #ifdef and something like function pointer magic is even more confusing. --- Makefile | 36 +++++++++++++++++--- src/client/input/{sdl.c => sdl2.c} | 0 src/client/sound/{sdl.c => sdl2.c} | 0 src/client/vid/{glimp_sdl.c => glimp_sdl2.c} | 0 4 files changed, 31 insertions(+), 5 deletions(-) rename src/client/input/{sdl.c => sdl2.c} (100%) rename src/client/sound/{sdl.c => sdl2.c} (100%) rename src/client/vid/{glimp_sdl.c => glimp_sdl2.c} (100%) mode change 100755 => 100644 diff --git a/Makefile b/Makefile index b857be6b..1a18a6f6 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,9 @@ WITH_OPENAL:=yes # or libopenal.so. Not supported on Windows. WITH_RPATH:=yes +# Builds with SDL 3 instead of SDL 2. +WITH_SDL3:=no + # Enable systemwide installation of game assets. WITH_SYSTEMWIDE:=no @@ -276,7 +279,12 @@ endif # ---------- # Extra CFLAGS for SDL. +ifeq ($(WITH_SDL3),yes) +SDLCFLAGS := $(shell pkgconf --cflags sdl3) +SDLCFLAGS += -DUSE_SDL3 +else SDLCFLAGS := $(shell sdl2-config --cflags) +endif # ---------- @@ -353,11 +361,19 @@ endif # ---------- # Extra LDFLAGS for SDL +ifeq ($(WITH_SDL3),yes) +ifeq ($(YQ2_OSTYPE), Darwin) +SDLLDFLAGS := -lSDL3 +else +SDLLDFLAGS := $(shell pkgconf --libs sdl3) +endif +else ifeq ($(YQ2_OSTYPE), Darwin) SDLLDFLAGS := -lSDL2 -else # not Darwin +else SDLLDFLAGS := $(shell sdl2-config --libs) -endif # Darwin +endif +endif # The renderer libs don't need libSDL2main, libmingw32 or -mwindows. ifeq ($(YQ2_OSTYPE), Windows) @@ -394,6 +410,7 @@ config: @echo "WITH_CURL = $(WITH_CURL)" @echo "WITH_OPENAL = $(WITH_OPENAL)" @echo "WITH_RPATH = $(WITH_RPATH)" + @echo "WITH_SDL3 = $(WITH_SDL3)" @echo "WITH_SYSTEMWIDE = $(WITH_SYSTEMWIDE)" @echo "WITH_SYSTEMDIR = $(WITH_SYSTEMDIR)" @echo "============================" @@ -852,17 +869,14 @@ CLIENT_OBJS_ := \ src/client/cl_view.o \ src/client/curl/download.o \ src/client/curl/qcurl.o \ - src/client/input/sdl.o \ src/client/menu/menu.o \ src/client/menu/qmenu.o \ src/client/menu/videomenu.o \ - src/client/sound/sdl.o \ src/client/sound/ogg.o \ src/client/sound/openal.o \ src/client/sound/qal.o \ src/client/sound/sound.o \ src/client/sound/wave.o \ - src/client/vid/glimp_sdl.o \ src/client/vid/vid.o \ src/common/argproc.o \ src/common/clientserver.o \ @@ -898,6 +912,18 @@ CLIENT_OBJS_ := \ src/server/sv_user.o \ src/server/sv_world.o +ifeq ($(WITH_SDL3),yes) +CLIENT_OBJS_ += \ + src/client/input/sdl3.o \ + src/client/sound/sdl3.o \ + src/client/vid/glimp_sdl3.o +else +CLIENT_OBJS_ += \ + src/client/input/sdl2.o \ + src/client/sound/sdl2.o \ + src/client/vid/glimp_sdl2.o +endif + ifeq ($(YQ2_OSTYPE), Windows) CLIENT_OBJS_ += \ src/backends/windows/main.o \ diff --git a/src/client/input/sdl.c b/src/client/input/sdl2.c similarity index 100% rename from src/client/input/sdl.c rename to src/client/input/sdl2.c diff --git a/src/client/sound/sdl.c b/src/client/sound/sdl2.c similarity index 100% rename from src/client/sound/sdl.c rename to src/client/sound/sdl2.c diff --git a/src/client/vid/glimp_sdl.c b/src/client/vid/glimp_sdl2.c old mode 100755 new mode 100644 similarity index 100% rename from src/client/vid/glimp_sdl.c rename to src/client/vid/glimp_sdl2.c