From ad45ad57428f180bf889b088ac81e4272b63bebe Mon Sep 17 00:00:00 2001
From: q66 <daniel@octaforge.org>
Date: Tue, 11 Jun 2019 21:32:50 +0200
Subject: [PATCH 1/2] libretro-mupen64plus: update to 20190611

---
 .../patches/gl-typedefs.patch                 | 13 ++++++
 .../libretro-mupen64plus/patches/types.patch  | 29 ++++++++++++
 srcpkgs/libretro-mupen64plus/template         | 46 +++++++++++--------
 srcpkgs/libretro-mupen64plus/update           |  1 -
 4 files changed, 70 insertions(+), 19 deletions(-)
 create mode 100644 srcpkgs/libretro-mupen64plus/patches/gl-typedefs.patch
 create mode 100644 srcpkgs/libretro-mupen64plus/patches/types.patch
 delete mode 100644 srcpkgs/libretro-mupen64plus/update

diff --git a/srcpkgs/libretro-mupen64plus/patches/gl-typedefs.patch b/srcpkgs/libretro-mupen64plus/patches/gl-typedefs.patch
new file mode 100644
index 00000000000..eccef9cca71
--- /dev/null
+++ b/srcpkgs/libretro-mupen64plus/patches/gl-typedefs.patch
@@ -0,0 +1,13 @@
+--- libretro-common/include/glsm/glsm.h
++++ libretro-common/include/glsm/glsm.h
+@@ -32,8 +32,8 @@
+ RETRO_BEGIN_DECLS
+ 
+ #ifdef HAVE_OPENGLES2
+-typedef GLfloat GLdouble;
+-typedef GLclampf GLclampd;
++typedef double GLdouble;
++typedef double GLclampd;
+ #endif
+ 
+ #if defined(HAVE_OPENGLES2)
diff --git a/srcpkgs/libretro-mupen64plus/patches/types.patch b/srcpkgs/libretro-mupen64plus/patches/types.patch
new file mode 100644
index 00000000000..423ed76f406
--- /dev/null
+++ b/srcpkgs/libretro-mupen64plus/patches/types.patch
@@ -0,0 +1,29 @@
+This is needed to build on armv6/7 musl.
+--- mupen64plus-core/src/r4300/new_dynarec/new_dynarec.c
++++ mupen64plus-core/src/r4300/new_dynarec/new_dynarec.c
+@@ -25,12 +25,8 @@
+ #include <stdlib.h>
+ #include <string.h>
+ 
+-#if defined(__APPLE__)
+ #include <sys/types.h> // needed for u_int, u_char, etc
+ 
+-#define MAP_ANONYMOUS MAP_ANON
+-#endif
+-
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+--- mupen64plus-core/src/r4300/new_dynarec/new_dynarec_64.c
++++ mupen64plus-core/src/r4300/new_dynarec/new_dynarec_64.c
+@@ -24,10 +24,7 @@
+ #include <string.h>
+ #include <assert.h>
+ 
+-#if defined(__APPLE__)
+ #include <sys/types.h> // needed for u_int, u_char, etc
+-#define MAP_ANONYMOUS MAP_ANON
+-#endif
+ 
+ #include "new_dynarec.h"
+ #include "main/main.h"
diff --git a/srcpkgs/libretro-mupen64plus/template b/srcpkgs/libretro-mupen64plus/template
index e76143e9d4b..b768a51869b 100644
--- a/srcpkgs/libretro-mupen64plus/template
+++ b/srcpkgs/libretro-mupen64plus/template
@@ -1,40 +1,50 @@
 # Template file for 'libretro-mupen64plus'
 pkgname=libretro-mupen64plus
-version=20150204
+version=20190611
 revision=1
-wrksrc="mupen64plus-libretro-master"
-build_options="opengl rpi"
+_gitrev=e64ef9d9f214e32341fb7cd9633260fbb44b2326
+wrksrc="mupen64plus-libretro-${_gitrev}"
 hostmakedepends="pkg-config unzip"
-makedepends="$(vopt_if opengl MesaLib-devel) $(vopt_if rpi rpi-firmware)"
+makedepends="MesaLib-devel zlib-devel"
 short_desc="Libretro port of Mupen64 Plus"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
-license="GPL-3"
+license="GPL-3.0-or-later"
 homepage="http://www.libretro.com/"
-distfiles="http://ftp.netbsd.org/pub/NetBSD/misc/jmcneill/retroarch/mupen64plus-libretro-${version}.zip"
-checksum=643379eaa840d632cd8fa046fc4858cc8ccd5a57ce5991771ab16f1ef675cee2
+distfiles="https://github.com/libretro/mupen64plus-libretro/archive/${_gitrev}.tar.gz"
+checksum=947abfb1d5ff34d6b22fecfb2df02bd3759fde3f4a0e5d238f65ec7e97d964d4
+conflicts="ĺibretro-mupen64plus-rpi>=0"
 
 case "$XBPS_TARGET_MACHINE" in
-	i686*|x86_64*)  build_options_default="opengl";;
-	armv[67]*) build_options_default="rpi";;
-	ppc*) broken="not supported in this release";;
+	i686*) hostmakedepends+=" nasm";;
+esac
+
+build_options="gles gles3"
+
+case "$XBPS_TARGET_MACHINE" in
+	armv*|aarch64*) build_options_default="gles";;
 esac
 
 do_build() {
 	local _args
 
+	# setting ARCH makes sure proper dynarec is selected
 	case "$XBPS_TARGET_MACHINE" in
-		i686*) _args="DYNAREC=x86";;
-		x86_64*) _args="DYNAREC=x86_64";;
-		arm*) _args="DYNAREC=arm";;
+		i686*) _args="ARCH=i686";;
+		arm*) _args="ARCH=arm";;
+		aarch64*) _args="ARCH=aarch64";;
+		x86_64*) _args="ARCH=x86_64";;
+		*) _args="ARCH=${XBPS_TARGET_MACHINE%-musl}";;
 	esac
-	if [ "$build_option_rpi" ]; then
-		install -d /opt/vc/lib
-		_args+=" platform=rpi"
-		sed -i "s|-L/opt/vc/lib|-L${XBPS_CROSS_BASE}/opt/vc/lib -Wl,-R /opt/vc/lib|g" Makefile
-		sed -i 's|/opt/vc/include|${XBPS_CROSS_BASE}/opt/vc/include|g' Makefile
+
+	if [ "$build_option_gles3" ]; then
+		_args+=" FORCE_GLES3=1"
+	elif [ "$builld_option_gles" ]; then
+		_args+=" FORCE_GLES=1"
 	fi
+
 	make CC=$CC ${_args} ${makejobs}
 }
+
 do_install() {
 	vinstall mupen64plus_libretro.so 755 usr/lib/libretro
 }
diff --git a/srcpkgs/libretro-mupen64plus/update b/srcpkgs/libretro-mupen64plus/update
deleted file mode 100644
index aa6807450d2..00000000000
--- a/srcpkgs/libretro-mupen64plus/update
+++ /dev/null
@@ -1 +0,0 @@
-pkgname=mupen64plus-libretro

From f25fc1956ad49bd028ff2687b34a6bd09f39950f Mon Sep 17 00:00:00 2001
From: q66 <daniel@octaforge.org>
Date: Tue, 11 Jun 2019 21:32:16 +0200
Subject: [PATCH 2/2] New package: libretro-mupen64plus-rpi-20190611

---
 .../patches/rpi.patch                         | 24 ++++++++++++
 .../patches/types.patch                       | 29 +++++++++++++++
 srcpkgs/libretro-mupen64plus-rpi/template     | 37 +++++++++++++++++++
 3 files changed, 90 insertions(+)
 create mode 100644 srcpkgs/libretro-mupen64plus-rpi/patches/rpi.patch
 create mode 100644 srcpkgs/libretro-mupen64plus-rpi/patches/types.patch
 create mode 100644 srcpkgs/libretro-mupen64plus-rpi/template

diff --git a/srcpkgs/libretro-mupen64plus-rpi/patches/rpi.patch b/srcpkgs/libretro-mupen64plus-rpi/patches/rpi.patch
new file mode 100644
index 00000000000..8d16c944337
--- /dev/null
+++ b/srcpkgs/libretro-mupen64plus-rpi/patches/rpi.patch
@@ -0,0 +1,24 @@
+--- Makefile
++++ Makefile
+@@ -99,7 +99,7 @@ else ifneq (,$(findstring rpi,$(platform)))
+       GL_LIB := -lGLESv2
+    else
+       LLE = 0
+-      CPUFLAGS += -DVC
++      CPUFLAGS += -DVC -DGL_GLEXT_PROTOTYPES
+       GL_LIB := -L/opt/vc/lib -lbrcmGLESv2
+       EGL_LIB := -lbrcmEGL
+       INCFLAGS += -I/opt/vc/include -I/opt/vc/include/interface/vcos -I/opt/vc/include/interface/vcos/pthreads
+--- libretro-common/include/glsm/glsm.h
++++ libretro-common/include/glsm/glsm.h
+@@ -32,8 +32,8 @@
+ RETRO_BEGIN_DECLS
+ 
+ #ifdef HAVE_OPENGLES2
+-typedef GLfloat GLdouble;
+-typedef GLclampf GLclampd;
++typedef double GLdouble;
++typedef double GLclampd;
+ #endif
+ 
+ #if defined(HAVE_OPENGLES2)
diff --git a/srcpkgs/libretro-mupen64plus-rpi/patches/types.patch b/srcpkgs/libretro-mupen64plus-rpi/patches/types.patch
new file mode 100644
index 00000000000..423ed76f406
--- /dev/null
+++ b/srcpkgs/libretro-mupen64plus-rpi/patches/types.patch
@@ -0,0 +1,29 @@
+This is needed to build on armv6/7 musl.
+--- mupen64plus-core/src/r4300/new_dynarec/new_dynarec.c
++++ mupen64plus-core/src/r4300/new_dynarec/new_dynarec.c
+@@ -25,12 +25,8 @@
+ #include <stdlib.h>
+ #include <string.h>
+ 
+-#if defined(__APPLE__)
+ #include <sys/types.h> // needed for u_int, u_char, etc
+ 
+-#define MAP_ANONYMOUS MAP_ANON
+-#endif
+-
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+--- mupen64plus-core/src/r4300/new_dynarec/new_dynarec_64.c
++++ mupen64plus-core/src/r4300/new_dynarec/new_dynarec_64.c
+@@ -24,10 +24,7 @@
+ #include <string.h>
+ #include <assert.h>
+ 
+-#if defined(__APPLE__)
+ #include <sys/types.h> // needed for u_int, u_char, etc
+-#define MAP_ANONYMOUS MAP_ANON
+-#endif
+ 
+ #include "new_dynarec.h"
+ #include "main/main.h"
diff --git a/srcpkgs/libretro-mupen64plus-rpi/template b/srcpkgs/libretro-mupen64plus-rpi/template
new file mode 100644
index 00000000000..7365927e058
--- /dev/null
+++ b/srcpkgs/libretro-mupen64plus-rpi/template
@@ -0,0 +1,37 @@
+# Template file for 'libretro-mupen64plus-rpi'
+pkgname=libretro-mupen64plus-rpi
+version=20190611
+revision=1
+archs="armv6l* armv7l*"
+_gitrev=e64ef9d9f214e32341fb7cd9633260fbb44b2326
+wrksrc="mupen64plus-libretro-${_gitrev}"
+hostmakedepends="pkg-config unzip"
+makedepends="rpi-userland-devel zlib-devel"
+short_desc="Libretro port of Mupen64 Plus"
+maintainer="q66 <daniel@octaforge.org>"
+license="GPL-3.0-or-later"
+homepage="http://www.libretro.com/"
+distfiles="https://github.com/libretro/mupen64plus-libretro/archive/${_gitrev}.tar.gz"
+checksum=947abfb1d5ff34d6b22fecfb2df02bd3759fde3f4a0e5d238f65ec7e97d964d4
+conflicts="ĺibretro-mupen64plus>=0"
+
+build_options="mesa"
+
+do_build() {
+	local _args="ARCH=arm"
+
+	if [ "$build_option_mesa" ]; then
+		_args+=" platform=rpi,mesa"
+	else
+		_args+=" platform=rpi"
+	fi
+	install -d /opt/vc/lib
+	sed -i "s|-L/opt/vc/lib|-L${XBPS_CROSS_BASE}/opt/vc/lib -Wl,-R /opt/vc/lib|g" Makefile
+	sed -i 's|/opt/vc/include|${XBPS_CROSS_BASE}/opt/vc/include|g' Makefile
+
+	make CC=$CC ${_args} ${makejobs}
+}
+
+do_install() {
+	vinstall mupen64plus_libretro.so 755 usr/lib/libretro
+}
