From 87fe6331686c8cd028b49d870ef38bb98456b0e8 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Fri, 16 Dec 2022 20:15:45 -0700
Subject: [PATCH] Add mednafen

---
 recipes/mednafen/recipe.toml | 24 ++++++++++++++++++++++++
 recipes/mednafen/redox.patch | 26 ++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
 create mode 100644 recipes/mednafen/recipe.toml
 create mode 100644 recipes/mednafen/redox.patch

diff --git a/recipes/mednafen/recipe.toml b/recipes/mednafen/recipe.toml
new file mode 100644
index 000000000..c4cf7850c
--- /dev/null
+++ b/recipes/mednafen/recipe.toml
@@ -0,0 +1,24 @@
+[source]
+tar = "https://mednafen.github.io/releases/files/mednafen-1.29.0.tar.xz"
+patches = [
+    "redox.patch",
+]
+
+[build]
+template = "custom"
+dependencies = [
+    #TODO: libflac
+    "libiconv",
+    "liborbital",
+    "llvm",
+    "mesa",
+    "sdl2",
+    "zlib",
+]
+script = """
+export SDL_LIBS="-lSDL2 -lorbital $("${TARGET}-pkg-config" --libs osmesa) -lstdc++"
+COOKBOOK_CONFIGURE_FLAGS+=(
+    --without-libflac
+)
+cookbook_configure
+"""
diff --git a/recipes/mednafen/redox.patch b/recipes/mednafen/redox.patch
new file mode 100644
index 000000000..2d323d76e
--- /dev/null
+++ b/recipes/mednafen/redox.patch
@@ -0,0 +1,26 @@
+diff -ruwN source-old/include/mednafen/sound/SwiftResampler.cpp source/include/mednafen/sound/SwiftResampler.cpp
+--- source-old/include/mednafen/sound/SwiftResampler.cpp	2022-01-18 14:16:23.000000000 -0700
++++ source/include/mednafen/sound/SwiftResampler.cpp	2022-12-16 20:01:02.263159230 -0700
+@@ -608,6 +608,9 @@
+ 
+  if(hp_tc > 0)
+  {
++#ifndef M_E
++#define M_E 2.7182818284590452354
++#endif
+   double tdm = (pow(2.0 - pow(M_E, -1.0), 1.0 / (hp_tc * output_rate)) - 1.0);
+ 
+   //printf("%f\n", tdm);
+diff -ruwN source-old/src/sound/SwiftResampler.cpp source/src/sound/SwiftResampler.cpp
+--- source-old/src/sound/SwiftResampler.cpp	2022-01-18 14:16:23.000000000 -0700
++++ source/src/sound/SwiftResampler.cpp	2022-12-16 20:01:02.263159230 -0700
+@@ -608,6 +608,9 @@
+ 
+  if(hp_tc > 0)
+  {
++#ifndef M_E
++#define M_E 2.7182818284590452354
++#endif
+   double tdm = (pow(2.0 - pow(M_E, -1.0), 1.0 / (hp_tc * output_rate)) - 1.0);
+ 
+   //printf("%f\n", tdm);
-- 
GitLab