From 04fd57a670584258a38f36eb92aa1f2d5a6ae846 Mon Sep 17 00:00:00 2001
From: mio <miyopan@e.email>
Date: Mon, 30 Sep 2024 04:45:05 +0000
Subject: [PATCH] testing/libretro-daphne: fix build with gcc 14

---
 testing/libretro-daphne/APKBUILD    | 10 +++-
 testing/libretro-daphne/gcc14.patch | 86 +++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+), 3 deletions(-)
 create mode 100644 testing/libretro-daphne/gcc14.patch

diff --git a/testing/libretro-daphne/APKBUILD b/testing/libretro-daphne/APKBUILD
index 1171f9d37652..544cc3b3a783 100644
--- a/testing/libretro-daphne/APKBUILD
+++ b/testing/libretro-daphne/APKBUILD
@@ -2,7 +2,7 @@
 # Maintainer: David Demelier <markand@malikania.fr>
 pkgname=libretro-daphne
 pkgver=0_git20210108
-pkgrel=1
+pkgrel=2
 _commit="0a7e6f0fda1348144369ce0a889876df60263e8f"
 pkgdesc="daphne core for libretro"
 url="https://github.com/libretro/daphne"
@@ -11,6 +11,7 @@ license="GPL-2.0-or-later"
 makedepends="libogg-dev libvorbis-dev zlib-dev"
 source="$pkgname-$_commit.tar.gz::https://github.com/libretro/daphne/archive/$_commit.tar.gz
 	patch-unbundle.patch
+	gcc14.patch
 	"
 builddir="$srcdir/daphne-$_commit"
 options="!check" # No tests
@@ -24,5 +25,8 @@ package() {
 	install -Dm644 daphne_libretro.so "$pkgdir"/usr/lib/libretro/daphne_libretro.so
 }
 
-sha512sums="8af1018ad596887a4a8b64683e89d76010a92677dca5d0d3062f5697b97f5135e25517fae7ed9037c6da947c5162353d31569c629cba154401b76c7ba46d3d6b  libretro-daphne-0a7e6f0fda1348144369ce0a889876df60263e8f.tar.gz
-308588bdafbc470390e53d84c6e5b11a4760e194879add00214960f2625be243ed199205ecbda881ae0616b3d163a216602a776cb3d304da3ec81a8ec1ae298e  patch-unbundle.patch"
+sha512sums="
+8af1018ad596887a4a8b64683e89d76010a92677dca5d0d3062f5697b97f5135e25517fae7ed9037c6da947c5162353d31569c629cba154401b76c7ba46d3d6b  libretro-daphne-0a7e6f0fda1348144369ce0a889876df60263e8f.tar.gz
+308588bdafbc470390e53d84c6e5b11a4760e194879add00214960f2625be243ed199205ecbda881ae0616b3d163a216602a776cb3d304da3ec81a8ec1ae298e  patch-unbundle.patch
+b58529f6a2bc2e90c6dfe46d798bc910a2b1164feec8038017efd3a02685c759bee1afa71b9d5866a3ab23fbfd1a48dce9ef01c4d16a51fdd44e923941b703f3  gcc14.patch
+"
diff --git a/testing/libretro-daphne/gcc14.patch b/testing/libretro-daphne/gcc14.patch
new file mode 100644
index 000000000000..c6b65e7a0588
--- /dev/null
+++ b/testing/libretro-daphne/gcc14.patch
@@ -0,0 +1,86 @@
+Fix -Wimplicit-function-declaration and -Wincompatible-pointer-types errors
+with gcc 14.
+
+Examples of errors:
+
+```
+daphne/daphne-1.0-src/vldp2/vldp/vldp_internal.c: In function 'idle_handler_precache':
+daphne/daphne-1.0-src/vldp2/vldp/vldp_internal.c:852:31: error: implicit declaration of function 'fileno' [-Wimplicit-function-declaration]
+  852 |                         fstat(fileno(F), &filestats);   // get stats for file to get file length
+      |                               ^~~~~~
+```
+
+```
+daphne/src/thread/pthread/SDL_systhread.c:104:24: error: passing argument 1 of 'pthread_create' from incompatible pointer type [-Wincompatible-pointer-types]
+  104 |     if (pthread_create(&thread->handle, &type, RunThread, args) != 0) {
+      |                        ^~~~~~~~~~~~~~~
+      |                        |
+      |                        SYS_ThreadHandle * {aka int *}
+In file included from daphne/src/thread/pthread/SDL_systhread.c:24:
+/usr/include/pthread.h:80:20: note: expected 'struct __pthread ** restrict' but argument is of type 'SYS_ThreadHandle *' {aka 'int *'}
+   80 | int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict);
+      |                    ^
+```
+
+--- a/daphne/daphne-1.0-src/vldp2/vldp/vldp_internal.c
++++ b/daphne/daphne-1.0-src/vldp2/vldp/vldp_internal.c
+@@ -29,6 +29,7 @@
+
+ #include <stdint.h>
+
++#define _DEFAULT_SOURCE
+ #include <stdio.h>
+ #include <stdlib.h>	// for malloc/free
+ #include <string.h>
+--- a/daphne/src/audio/SDL_audiocvt.c
++++ b/daphne/src/audio/SDL_audiocvt.c
+@@ -18,6 +18,7 @@
+      misrepresented as being the original software.
+   3. This notice may not be removed or altered from any source distribution.
+ */
++#include <math.h>
+ #include <stdint.h>
+ #include "../SDL_internal.h"
+
+--- a/daphne/src/thread/pthread/SDL_systhread.c
++++ b/daphne/src/thread/pthread/SDL_systhread.c
+@@ -29,10 +29,12 @@
+
+ #include <signal.h>
+
++#define _BSD_SOURCE
++#include <sys/syscall.h>
++
+ #ifdef __LINUX__
+ #include <sys/time.h>
+ #include <sys/resource.h>
+-#include <sys/syscall.h>
+ #include <unistd.h>
+ #endif /* __LINUX__ */
+
+@@ -98,7 +100,8 @@
+     }
+
+     /* Create the thread and go! */
+-    if (pthread_create(&thread->handle, &type, RunThread, args) != 0) {
++    if (pthread_create((struct __pthread ** restrict) &thread->handle, &type,
++        RunThread, args) != 0) {
+ 		// 2017.02.07 - RJS ADD - Logging.
+         return SDL_SetError("Not enough resources to create thread");
+     }
+@@ -207,13 +210,13 @@
+ void
+ SDL_SYS_WaitThread(SDL_Thread * thread)
+ {
+-    pthread_join(thread->handle, 0);
++    pthread_join((struct __pthread *) thread->handle, 0);
+ }
+
+ void
+ SDL_SYS_DetachThread(SDL_Thread * thread)
+ {
+-    pthread_detach(thread->handle);
++    pthread_detach((struct __pthread *) thread->handle);
+ }
+
+ /* vi: set ts=4 sw=4 expandtab: */
-- 
GitLab