From 1e98c944eb679a3b8ead7556f7b688de4593cee4 Mon Sep 17 00:00:00 2001
From: Rinnegatamante <rinnegatamante@gmail.com>
Date: Sun, 9 Jun 2024 13:52:20 +0200
Subject: [PATCH] Add enet.

---
 enet/VITABUILD  | 19 +++++++++++++++++++
 enet/enet.patch | 28 ++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
 create mode 100644 enet/VITABUILD
 create mode 100644 enet/enet.patch

diff --git a/enet/VITABUILD b/enet/VITABUILD
new file mode 100644
index 00000000..b177673f
--- /dev/null
+++ b/enet/VITABUILD
@@ -0,0 +1,19 @@
+pkgname=enet
+pkgver=1.3.18
+pkgrel=1
+url="https://github.com/lsalzman/enet"
+source=("https://github.com/lsalzman/${pkgname}/archive/refs/tags/v${pkgver}.tar.gz")
+sha256sums=('28603c895f9ed24a846478180ee72c7376b39b4bb1287b73877e5eae7d96b0dd')
+
+build() {
+  cd $pkgname-$pkgver
+  patch unix.c "${srcdir}/enet.patch"
+  cmake -DCMAKE_TOOLCHAIN_FILE=$VITASDK/share/vita.toolchain.cmake
+  make -j$(nproc)
+}
+
+package () {
+  cd $pkgname-$pkgver
+  cp lib$pkgname.a $pkgdir/$VITASDK/arm-vita-eabi/lib/
+  cp include/$pkgname $pkgdir/$VITASDK/arm-vita-eabi/include/
+}
diff --git a/enet/enet.patch b/enet/enet.patch
new file mode 100644
index 00000000..e9b67055
--- /dev/null
+++ b/enet/enet.patch
@@ -0,0 +1,28 @@
+--- unix.c	2024-04-15 05:06:53.000000000 +0200
++++ unix.c	2024-06-09 13:46:43.009847600 +0200
+@@ -6,7 +6,9 @@
+ 
+ #include <sys/types.h>
+ #include <sys/socket.h>
++#ifndef __vita__
+ #include <sys/ioctl.h>
++#endif
+ #include <sys/time.h>
+ #include <netinet/tcp.h>
+ #include <netdb.h>
+@@ -303,11 +305,15 @@
+     switch (option)
+     {
+         case ENET_SOCKOPT_NONBLOCK:
++#ifdef __vita__
++            result = setsockopt (socket, SOL_SOCKET, SO_NONBLOCK, (char *) & value, sizeof (int));
++#else
+ #ifdef HAS_FCNTL
+             result = fcntl (socket, F_SETFL, (value ? O_NONBLOCK : 0) | (fcntl (socket, F_GETFL) & ~O_NONBLOCK));
+ #else
+             result = ioctl (socket, FIONBIO, & value);
+ #endif
++#endif
+             break;
+ 
+         case ENET_SOCKOPT_BROADCAST: