changeset 2573:639561060a28

Do a little work towards eventual support for building against SDL3
author Michael Pavone <pavone@retrodev.com>
date Sun, 02 Feb 2025 19:12:50 -0800
parents 941bc319dcd8
children 0da40b1978fd
files Makefile build_release controller_info.c
diffstat 3 files changed, 53 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sun Feb 02 18:06:50 2025 -0800
+++ b/Makefile	Sun Feb 02 19:12:50 2025 -0800
@@ -4,6 +4,10 @@
 ifndef OS
 OS:=$(shell uname -s)
 endif
+ifndef SDL
+SDL:=sdl2
+endif
+SDL_UPPER:=$(shell echo $(SDL) | tr '[a-z]' '[A-Z]')
 FIXUP:=true
 
 BUNDLED_LIBZ:=zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/deflate.o zlib/gzclose.o zlib/gzlib.o zlib/gzread.o\
@@ -35,8 +39,8 @@
 CFLAGS:=-std=gnu99 -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration -Wpointer-arith -Werror=pointer-arith
 LDFLAGS:=-lm -lmingw32 -lws2_32 -lcomdlg32 -mwindows
 ifneq ($(MAKECMDGOALS),libblastem.dll)
-CFLAGS+= -I"$(SDL2_PREFIX)/include/SDL2" -I"$(GLEW_PREFIX)/include" -DGLEW_STATIC
-LDFLAGS+= $(GLEW32S_LIB) -L"$(SDL2_PREFIX)/lib" -lSDL2main -lSDL2 -lopengl32 -lglu32
+CFLAGS+= -I"$(SDL2_PREFIX)/include/$(SDL_UPPER)" -I"$(GLEW_PREFIX)/include" -DGLEW_STATIC
+LDFLAGS+= $(GLEW32S_LIB) -L"$(SDL2_PREFIX)/lib" -l$(SDL_UPPER)main -l$(SDL_UPPER) -lopengl32 -lglu32
 endif
 LIBZOBJS=$(BUNDLED_LIBZ)
 
@@ -51,7 +55,7 @@
 CFLAGS:=-std=gnu99 -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration -Wno-unused-value  -Wpointer-arith -Werror=pointer-arith $(HAS_PROC) -DHAVE_UNISTD_H
 
 ifeq ($(OS),Darwin)
-LIBS=sdl2 glew
+LIBS=$(SDL) glew
 FONT:=nuklear_ui/font_mac.o
 CHOOSER:=nuklear_ui/filechooser_null.o
 SO:=dylib
@@ -66,10 +70,10 @@
 CFLAGS+= -DUSE_GLES -DUSE_FBDEV -pthread
 else
 ifdef USE_GLES
-LIBS=sdl2 glesv2
+LIBS=$(SDL) glesv2
 CFLAGS+= -DUSE_GLES
 else
-LIBS=sdl2 glew gl
+LIBS=$(SDL) glew gl
 endif #USE_GLES
 endif #USE_FBDEV
 FONT:=nuklear_ui/font.o
@@ -114,13 +118,18 @@
 endif #USE_GLES
 
 ifeq ($(OS),Darwin)
-SDL_INCLUDE_PATH:=Frameworks/SDL2.framework/Headers
+SDL_INCLUDE_PATH:=Frameworks/$(SDL_UPPER).framework/Headers
 CFLAGS+=  -mmacosx-version-min=10.10
-LDFLAGS+= -FFrameworks -framework SDL2 -framework OpenGL -framework AppKit -mmacosx-version-min=10.10
-FIXUP:=install_name_tool -change @rpath/SDL2.framework/Versions/A/SDL2 @executable_path/Frameworks/SDL2.framework/Versions/A/SDL2
+LDFLAGS+= -FFrameworks -framework $(SDL_UPPER) -framework OpenGL -framework AppKit -mmacosx-version-min=10.10
+FIXUP:=install_name_tool -change @rpath/$(SDL_UPPER).framework/Versions/A/$(SDL_UPPER) @executable_path/Frameworks/$(SDL_UPPER).framework/Versions/A/$(SDL_UPPER)
 else #Darwin
+ifeq ($(SDL),sdl3)
+SDL_INCLUDE_PATH:=sdl/include/SDL3
+CFLAGS+= -Isdl/include -DSDL_ENABLE_OLD_NAMES
+else
 SDL_INCLUDE_PATH:=sdl/include
-LDFLAGS+= -Wl,-rpath='$$ORIGIN/lib' -Llib -lSDL2
+endif
+LDFLAGS+= -Wl,-rpath='$$ORIGIN/lib' -Llib -l$(SDL_UPPER)
 ifndef USE_GLES
 LDFLAGS+= $(shell pkg-config --libs gl)
 endif
--- a/build_release	Sun Feb 02 18:06:50 2025 -0800
+++ b/build_release	Sun Feb 02 19:12:50 2025 -0800
@@ -5,20 +5,30 @@
 if [ -z "$OS" ]; then
 	OS=`uname -s`
 fi
-
+SDL="sdl2"
 if [ $OS = "Linux" ]; then
-	cd sdl
-	./configure
-	make all
-	cd ..
 	rm -rf lib
 	mkdir lib
-	cp sdl/build/.libs/libSDL2-*.so.*.*.* lib
-	sdl=`ls lib`
-	link=`echo $sdl | sed -E 's/(so\.[0-9]*).*/\1/'`
-	cd lib
-	ln -s "$sdl" "$link"
-	ln -s "$sdl" libSDL2.so
+	cd sdl
+	if [ -f ./configure ]; then
+		./configure
+		make all
+		cp build/.libs/libSDL2-*.so.*.*.* ../lib
+		cd ..
+		sdl=`ls lib`
+		link=`echo $sdl | sed -E 's/(so\.[0-9]*).*/\1/'`
+		cd lib
+		ln -s "$sdl" "$link"
+		ln -s "$sdl" libSDL2.so
+	elif [ -f ./CMakeLists.txt ]; then
+		cmake -S . -B build
+		cmake --build build
+		cp build/libSDL3.so* ../lib
+		SDL="sdl3"
+	else
+		echo "Failed to find SDL build file!";
+		exit 1
+	fi
 	cd ..
 	cd glew
 	make all
@@ -26,10 +36,10 @@
 fi
 echo "Path is: $PATH"
 if [ $OS = "Win64" ]; then
-	make PORTABLE=1 OS=Windows CPU=x86_64 clean all
+	make PORTABLE=1 OS=Windows CPU=x86_64 SDL=$SDL clean all
 	SDLDLLPATH=sdl/x86_64-w64-mingw32/bin
 else
-	make PORTABLE=1 clean all
+	make PORTABLE=1 SDL=$SDL clean all
 	SDLDLLPATH=sdl/i686-w64-mingw32/bin
 fi
 make menu.bin tmss.md
--- a/controller_info.c	Sun Feb 02 18:06:50 2025 -0800
+++ b/controller_info.c	Sun Feb 02 19:12:50 2025 -0800
@@ -93,7 +93,11 @@
 	char guid_string[33];
 	SDL_Joystick *stick = render_get_joystick(joystick);
 	SDL_GameController *control = render_get_controller(joystick);
+#if SDL_VERSION_ATLEAST(3, 2, 0)
+	SDL_GUIDToString(SDL_JoystickGetGUID(stick), guid_string, sizeof(guid_string));
+#else
 	SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(stick), guid_string, sizeof(guid_string));
+#endif
 	tern_node *info = tern_find_node(info_config, guid_string);
 	if (info) {
 		controller_info res;
@@ -223,7 +227,11 @@
 {
 #ifndef USE_FBDEV
 	char guid_string[33];
+#if SDL_VERSION_ATLEAST(3, 2, 0)
+	SDL_GUIDToString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string));
+#else
 	SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string));
+#endif
 	tern_node *existing = tern_find_node(info_config, guid_string);
 	existing = tern_insert_ptr(existing, "subtype", strdup(subtype_names[info->subtype]));
 	existing = tern_insert_ptr(existing, "variant", strdup(variant_names[info->variant]));
@@ -244,7 +252,11 @@
 {
 #ifndef USE_FBDEV
 	char guid_string[33];
+#if SDL_VERSION_ATLEAST(3, 2, 0)
+	SDL_GUIDToString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string));
+#else
 	SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string));
+#endif
 	tern_node *existing = tern_find_node(info_config, guid_string);
 	existing = tern_insert_ptr(existing, "mapping", strdup(mapping_string));
 	info_config = tern_insert_node(info_config, guid_string, existing);