From 3edc093b87869f797f24b187973fb00fd9dd6eab Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Thu, 9 Jan 2025 11:54:18 -0700
Subject: [PATCH] Add love

---
 recipes/wip/games/other/love/recipe.toml | 79 ++++++++++++++++++++++++
 recipes/wip/games/other/love/redox.patch | 38 ++++++++++++
 2 files changed, 117 insertions(+)
 create mode 100644 recipes/wip/games/other/love/recipe.toml
 create mode 100644 recipes/wip/games/other/love/redox.patch

diff --git a/recipes/wip/games/other/love/recipe.toml b/recipes/wip/games/other/love/recipe.toml
new file mode 100644
index 000000000..56144bc67
--- /dev/null
+++ b/recipes/wip/games/other/love/recipe.toml
@@ -0,0 +1,79 @@
+[source]
+tar = "https://github.com/love2d/love/archive/refs/tags/11.5.tar.gz"
+blake3 = "1fe441b04af1c0aa12b5d12f274fd892e6f307bcc882888c3a1ec048294a25c7"
+patches = [
+    "redox.patch"
+]
+
+[build]
+template = "custom"
+dependencies = [
+    "freetype2",
+    "libmodplug1",
+    "libogg",
+    "liborbital",
+    "libpng",
+    "libtheora",
+    "libvorbis",
+    "llvm18",
+    "luajit",
+    "openal",
+    "mesa",
+    "mpg123",
+    "sdl2",
+    "zlib",
+]
+script = """
+export CFLAGS="${CFLAGS} -I${COOKBOOK_SYSROOT}/include -I${COOKBOOK_SYSROOT}/include/SDL2"
+export CXXFLAGS="${CXXFLAGS} -I${COOKBOOK_SYSROOT}/include -I${COOKBOOK_SYSROOT}/include/SDL2"
+
+cat > redox.cmake <<EOF
+# the name of the target operating system
+set(CMAKE_SYSTEM_NAME Generic)
+set(CMAKE_SYSTEM_PROCESSOR "${TARGET%%-*}")
+
+# which compilers to use for C and C++
+set(CMAKE_C_COMPILER "${TARGET}-gcc")
+set(CMAKE_CXX_COMPILER "${TARGET}-g++")
+
+# where is the target environment located
+set(CMAKE_FIND_ROOT_PATH "${COOKBOOK_SYSROOT}")
+
+# adjust the default behavior of the FIND_XXX() commands:
+# search programs in the host environment
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+
+# search headers, libraries, and packages in the target environment
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+EOF
+
+LIBS=(
+    $("${TARGET}-pkg-config" --libs libpng16)
+    $("${TARGET}-pkg-config" --libs vorbis)
+    -lSDL2
+    -lorbital
+    $("${TARGET}-pkg-config" --libs osmesa)
+    -lstdc++
+)
+
+COOKBOOK_CONFIGURE="cmake"
+COOKBOOK_CONFIGURE_FLAGS=(
+    -DCMAKE_BUILD_TYPE=Release
+    -DCMAKE_INSTALL_PREFIX="/usr"
+    -DCMAKE_PREFIX_PATH="${COOKBOOK_SYSROOT}"
+    -DCMAKE_TOOLCHAIN_FILE=redox.cmake
+    -DCMAKE_VERBOSE_MAKEFILE=ON
+    -DOPENGL_opengl_LIBRARY="/dev/null"
+    -DOPENGL_glx_LIBRARY="/dev/null"
+    #TODO: This is a hack to add more libraries
+    -DCMAKE_CXX_STANDARD_LIBRARIES="${LIBS[*]}"
+    "${COOKBOOK_SOURCE}"
+)
+"${COOKBOOK_CONFIGURE}" "${COOKBOOK_CONFIGURE_FLAGS[@]}"
+"${COOKBOOK_MAKE}" -j "${COOKBOOK_MAKE_JOBS}"
+# make install not possible, just copy love
+mkdir -pv "${COOKBOOK_STAGE}/usr/bin"
+cp -v love "${COOKBOOK_STAGE}/usr/bin/love"
+"""
diff --git a/recipes/wip/games/other/love/redox.patch b/recipes/wip/games/other/love/redox.patch
new file mode 100644
index 000000000..08c6e49d4
--- /dev/null
+++ b/recipes/wip/games/other/love/redox.patch
@@ -0,0 +1,38 @@
+diff --git a/src/common/config.h b/src/common/config.h
+index 5679849c..2188d8e5 100644
+--- a/src/common/config.h
++++ b/src/common/config.h
+@@ -48,7 +48,7 @@
+ #		define LOVE_MACOSX 1
+ #	endif
+ #endif
+-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
++#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined (__redox__)
+ // I know it's not linux, but it seems most "linux-only" code is bsd-compatible
+ #	define LOVE_LINUX 1
+ #endif
+diff --git a/src/libraries/luasocket/libluasocket/compat.c b/src/libraries/luasocket/libluasocket/compat.c
+index c2d99cb2..d887d5e1 100644
+--- a/src/libraries/luasocket/libluasocket/compat.c
++++ b/src/libraries/luasocket/libluasocket/compat.c
+@@ -1,6 +1,6 @@
+ #include "compat.h"
+ 
+-#if LUA_VERSION_NUM==501
++#if LUA_VERSION_NUM==501 && !defined(__redox__)
+ /*
+ ** Adapted from Lua 5.2
+ */
+diff --git a/src/libraries/luasocket/libluasocket/compat.h b/src/libraries/luasocket/libluasocket/compat.h
+index 7bf8010e..5ae2853f 100644
+--- a/src/libraries/luasocket/libluasocket/compat.h
++++ b/src/libraries/luasocket/libluasocket/compat.h
+@@ -4,7 +4,7 @@
+ #include "lua.h"
+ #include "lauxlib.h"
+ 
+-#if LUA_VERSION_NUM==501
++#if LUA_VERSION_NUM==501 && !defined(__redox__)
+ void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);
+ #endif
+ 
-- 
GitLab