From c4fd2e16d5f7eca40c38f7916abe5619671408a8 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Fri, 16 Dec 2022 14:38:54 -0700
Subject: [PATCH] Use SNES core by default in retroarch

---
 recipes/libretro-super/recipe.toml | 24 ++++++++++++++++++++++++
 recipes/retroarch/recipe.toml      |  9 +++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 recipes/libretro-super/recipe.toml

diff --git a/recipes/libretro-super/recipe.toml b/recipes/libretro-super/recipe.toml
new file mode 100644
index 000000000..b75ec6271
--- /dev/null
+++ b/recipes/libretro-super/recipe.toml
@@ -0,0 +1,24 @@
+[source]
+git = "https://github.com/jackpot51/libretro-super.git"
+
+[build]
+template = "custom"
+dependencies = [
+    "zlib",
+]
+script = """
+CORES=(
+    snes9x
+)
+
+pushd "${COOKBOOK_SOURCE}"
+./libretro-fetch.sh "${CORES[@]}"
+popd
+
+rsync -av --delete "${COOKBOOK_SOURCE}/" ./
+
+export platform=Redox
+export STATIC_LINKING=1
+./libretro-build.sh "${CORES[@]}"
+./libretro-install.sh "${COOKBOOK_STAGE}/share/libretro"
+"""
diff --git a/recipes/retroarch/recipe.toml b/recipes/retroarch/recipe.toml
index e878cb249..25a383663 100644
--- a/recipes/retroarch/recipe.toml
+++ b/recipes/retroarch/recipe.toml
@@ -5,6 +5,7 @@ git = "https://github.com/jackpot51/retroarch.git"
 template = "custom"
 dependencies = [
     "liborbital",
+    "libretro-super",
     "llvm",
     "mesa",
     "openssl",
@@ -18,17 +19,25 @@ popd
 
 rsync -av --delete "${COOKBOOK_SOURCE}/" ./
 
+# For now, we will statically link with the snes9x libretro
+mkdir -pv "${COOKBOOK_SYSROOT}/lib"
+cp -v "${COOKBOOK_SYSROOT}/share/libretro/snes9x_libretro.a" "${COOKBOOK_SYSROOT}/lib/libretro.a"
+
 COOKBOOK_CONFIGURE_FLAGS=(
     --host="${TARGET}"
     --prefix="/"
     --disable-builtinzlib # conflicts with zlib
     --disable-discord # does not link
+    --disable-dylib
+    --disable-dynamic
     --disable-netplaydiscovery # missing ifaddrs.h
     --disable-thread_storage # crash in pthread_setspecific called by sthread_tls_set
+    --disable-threads # prevents hang
     --enable-opengl
     --enable-sdl2
     --enable-ssl
     --enable-zlib
+    --with-libretro="-lretro -lstdc++ -lz"
 )
 cookbook_configure
 """
-- 
GitLab