Skip to content

Commit 8eaabf3

Browse files
Stary2001WinterMute
authored andcommitted
switch: add miniupnpc (#109)
1 parent 5b26c83 commit 8eaabf3

2 files changed

Lines changed: 261 additions & 0 deletions

File tree

switch/miniupnpc/PKGBUILD

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Contributor: Ezekiel Bethel <zek@9net.org>
2+
3+
pkgname=switch-miniupnpc
4+
pkgver=2.1.20190824
5+
pkgrel=1
6+
pkgdesc='UPNP support library (for Nintendo Switch homebrew development)'
7+
arch=('any')
8+
url="http://miniupnp.free.fr/"
9+
license=('BSD')
10+
options=(!strip libtool staticlibs)
11+
source=("http://miniupnp.free.fr/files/download.php?file=miniupnpc-${pkgver}.tar.gz" "miniupnpc.patch")
12+
13+
sha256sums=('1fadefea0ecdceb3e35bb5d901f0db880c826740e93148ddfb087b4b4389e165' 'a9e84bdd286f738f6022b5c04160bdf9e4a5a0bd034a9ec55dba0c41ce523852')
14+
makedepends=('switch-pkg-config' 'devkitpro-pkgbuild-helpers')
15+
groups=('switch-portlibs')
16+
build() {
17+
cd miniupnpc-$pkgver
18+
19+
source /opt/devkitpro/switchvars.sh
20+
export CC=aarch64-none-elf-gcc
21+
export CXX=aarch64-none-elf-g++
22+
export LD=aarch64-none-elf-gcc
23+
export LDLIBS=$LIBS
24+
25+
patch -p1 -i $srcdir/miniupnpc.patch
26+
27+
export OVERRIDE_OS_STRING=Horizon/NX
28+
HAVE_IPV6=no make
29+
}
30+
31+
package() {
32+
cd miniupnpc-$pkgver
33+
34+
source /opt/devkitpro/switchvars.sh
35+
36+
make PREFIX=/opt/devkitpro/portlibs/switch DESTDIR="$pkgdir" install
37+
}

switch/miniupnpc/miniupnpc.patch

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
diff -Naur miniupnpc-2.1.20190824/Makefile miniupnpc-2.1.20190824-patched/Makefile
2+
--- miniupnpc-2.1.20190824/Makefile 2018-04-06 11:53:30.000000000 +0100
3+
+++ miniupnpc-2.1.20190824-patched/Makefile 2019-10-09 00:12:41.576580022 +0100
4+
@@ -85,9 +85,11 @@
5+
connecthostport.o portlistingparse.o receivedata.o upnpdev.o
6+
7+
ifeq (, $(findstring amiga, $(OS)))
8+
+ifeq (, $(findstring aarch64-none-elf, $(OS)))
9+
ifeq (, $(findstring mingw, $(OS))$(findstring cygwin, $(OS))$(findstring msys, $(OS)))
10+
CFLAGS := -fPIC $(CFLAGS)
11+
endif
12+
+endif
13+
LIBOBJS := $(LIBOBJS) minissdpc.o
14+
endif
15+
16+
@@ -116,6 +118,7 @@
17+
endif
18+
endif
19+
20+
+ifeq (, $(findstring aarch64-none-elf, $(OS)))
21+
EXECUTABLES = upnpc-static listdevices
22+
EXECUTABLES_ADDTESTS = testminixml minixmlvalid testupnpreplyparse \
23+
testigddescparse testminiwget testportlistingparse
24+
@@ -132,12 +135,15 @@
25+
miniupnpc.o miniwget.o upnpcommands.o upnpreplyparse.o \
26+
minisoap.o connecthostport.o receivedata.o \
27+
portlistingparse.o
28+
+endif
29+
30+
ifeq (, $(findstring amiga, $(OS)))
31+
+ifeq (, $(findstring aarch64-none-elf, $(OS)))
32+
EXECUTABLES := $(EXECUTABLES) upnpc-shared
33+
TESTMINIWGETOBJS := $(TESTMINIWGETOBJS) minissdpc.o
34+
TESTIGDDESCPARSE := $(TESTIGDDESCPARSE) minissdpc.o
35+
endif
36+
+endif
37+
38+
LIBDIR ?= lib
39+
# install directories
40+
@@ -154,8 +160,12 @@
41+
42+
FILESTOINSTALL = $(LIBRARY) $(EXECUTABLES)
43+
ifeq (, $(findstring amiga, $(OS)))
44+
+ifneq (, $(findstring aarch64-none-elf, $(OS)))
45+
+FILESTOINSTALL := $(FILESTOINSTALL) miniupnpc.pc
46+
+else
47+
FILESTOINSTALL := $(FILESTOINSTALL) $(SHAREDLIBRARY) miniupnpc.pc
48+
endif
49+
+endif
50+
51+
52+
.PHONY: install clean depend all check test everything \
53+
@@ -237,11 +247,14 @@
54+
$(INSTALL) -d $(DESTDIR)$(INSTALLDIRLIB)
55+
$(INSTALL) -m 644 $(LIBRARY) $(DESTDIR)$(INSTALLDIRLIB)
56+
ifeq (, $(findstring amiga, $(OS)))
57+
+ifeq (, $(findstring aarch64-none-elf, $(OS)))
58+
$(INSTALL) -m 644 $(SHAREDLIBRARY) $(DESTDIR)$(INSTALLDIRLIB)/$(SONAME)
59+
ln -fs $(SONAME) $(DESTDIR)$(INSTALLDIRLIB)/$(SHAREDLIBRARY)
60+
+endif
61+
$(INSTALL) -d $(DESTDIR)$(PKGCONFIGDIR)
62+
$(INSTALL) -m 644 miniupnpc.pc $(DESTDIR)$(PKGCONFIGDIR)
63+
endif
64+
+ifeq (, $(findstring aarch64-none-elf, $(OS)))
65+
$(INSTALL) -d $(DESTDIR)$(INSTALLDIRBIN)
66+
ifneq (, $(findstring amiga, $(OS)))
67+
$(INSTALL) -m 755 upnpc-static $(DESTDIR)$(INSTALLDIRBIN)/upnpc
68+
@@ -256,6 +269,7 @@
69+
gzip -f $(DESTDIR)$(INSTALLDIRMAN)/man3/miniupnpc.3
70+
endif
71+
endif
72+
+endif
73+
74+
install-static: updateversion $(FILESTOINSTALL)
75+
$(INSTALL) -d $(DESTDIR)$(INSTALLDIRINC)
76+
diff -Naur miniupnpc-2.1.20190824/minissdpc.c miniupnpc-2.1.20190824-patched/minissdpc.c
77+
--- miniupnpc-2.1.20190824/minissdpc.c 2019-06-25 22:30:51.000000000 +0100
78+
+++ miniupnpc-2.1.20190824-patched/minissdpc.c 2019-10-09 00:12:41.576580022 +0100
79+
@@ -52,7 +52,16 @@
80+
#include <sys/socket.h>
81+
#include <sys/param.h>
82+
#include <sys/time.h>
83+
+#ifdef __SWITCH__
84+
+/* Hack */
85+
+#define UNIX_PATH_LEN 108
86+
+struct sockaddr_un {
87+
+ uint16_t sun_family;
88+
+ char sun_path[UNIX_PATH_LEN];
89+
+};
90+
+#else
91+
#include <sys/un.h>
92+
+#endif
93+
#include <netinet/in.h>
94+
#include <arpa/inet.h>
95+
#include <netdb.h>
96+
@@ -62,7 +71,7 @@
97+
98+
#include "miniupnpc_socketdef.h"
99+
100+
-#if !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(__sun) && !defined(__GNU__) && !defined(__FreeBSD_kernel__)
101+
+#if !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(__sun) && !defined(__GNU__) && !defined(__FreeBSD_kernel__) && !defined(__SWITCH__)
102+
#define HAS_IP_MREQN
103+
#endif
104+
105+
@@ -93,7 +102,7 @@
106+
#include "miniupnpc.h"
107+
#include "receivedata.h"
108+
109+
-#if !(defined(_WIN32) || defined(__amigaos__) || defined(__amigaos4__))
110+
+#if !(defined(_WIN32) || defined(__amigaos__) || defined(__amigaos4__) || defined(__SWITCH__))
111+
112+
#include "codelength.h"
113+
114+
@@ -375,7 +384,7 @@
115+
return devlist;
116+
}
117+
118+
-#endif /* !(defined(_WIN32) || defined(__amigaos__) || defined(__amigaos4__)) */
119+
+#endif /* !(defined(_WIN32) || defined(__amigaos__) || defined(__amigaos4__) || defined(__SWITCH__)) */
120+
121+
/* parseMSEARCHReply()
122+
* the last 4 arguments are filled during the parsing :
123+
@@ -667,7 +676,7 @@
124+
if(multicastif)
125+
{
126+
if(ipv6) {
127+
-#if !defined(_WIN32)
128+
+#if !defined(_WIN32) && !defined(__SWITCH__)
129+
/* according to MSDN, if_nametoindex() is supported since
130+
* MS Windows Vista and MS Windows Server 2008.
131+
* http://msdn.microsoft.com/en-us/library/bb408409%28v=vs.85%29.aspx */
132+
@@ -705,7 +714,7 @@
133+
{
134+
PRINT_SOCKET_ERROR("setsockopt IP_MULTICAST_IF");
135+
}
136+
-#elif !defined(_WIN32)
137+
+#elif !defined(_WIN32) && !defined(__SWITCH__)
138+
struct ifreq ifr;
139+
int ifrlen = sizeof(ifr);
140+
strncpy(ifr.ifr_name, multicastif, IFNAMSIZ);
141+
diff -Naur miniupnpc-2.1.20190824/minissdpc.h miniupnpc-2.1.20190824-patched/minissdpc.h
142+
--- miniupnpc-2.1.20190824/minissdpc.h 2019-02-10 12:30:19.000000000 +0000
143+
+++ miniupnpc-2.1.20190824-patched/minissdpc.h 2019-10-09 00:12:41.576580022 +0100
144+
@@ -23,7 +23,7 @@
145+
extern "C" {
146+
#endif
147+
148+
-#if !(defined(_WIN32) || defined(__amigaos__) || defined(__amigaos4__))
149+
+#if !(defined(_WIN32) || defined(__amigaos__) || defined(__amigaos4__) && defined(__SWITCH__))
150+
151+
MINIUPNP_LIBSPEC struct UPNPDev *
152+
getDevicesFromMiniSSDPD(const char * devtype, const char * socketpath, int * error);
153+
diff -Naur miniupnpc-2.1.20190824/miniupnpc.c miniupnpc-2.1.20190824-patched/miniupnpc.c
154+
--- miniupnpc-2.1.20190824/miniupnpc.c 2019-04-30 10:45:52.000000000 +0100
155+
+++ miniupnpc-2.1.20190824-patched/miniupnpc.c 2019-10-09 00:12:41.576580022 +0100
156+
@@ -297,7 +297,7 @@
157+
158+
if(error)
159+
*error = UPNPDISCOVER_UNKNOWN_ERROR;
160+
-#if !defined(_WIN32) && !defined(__amigaos__) && !defined(__amigaos4__)
161+
+#if !defined(_WIN32) && !defined(__amigaos__) && !defined(__amigaos4__) && !defined(__SWITCH__)
162+
/* first try to get infos from minissdpd ! */
163+
if(!minissdpdsock)
164+
minissdpdsock = "/var/run/minissdpd.sock";
165+
@@ -419,7 +419,7 @@
166+
char * s;
167+
const char * base;
168+
char * p;
169+
-#if defined(IF_NAMESIZE) && !defined(_WIN32)
170+
+#if defined(IF_NAMESIZE) && !defined(_WIN32) && !defined(__SWITCH__)
171+
char ifname[IF_NAMESIZE];
172+
#else /* defined(IF_NAMESIZE) && !defined(_WIN32) */
173+
char scope_str[8];
174+
@@ -444,7 +444,7 @@
175+
if(url[0] != '/')
176+
l++;
177+
if(scope_id != 0) {
178+
-#if defined(IF_NAMESIZE) && !defined(_WIN32)
179+
+#if defined(IF_NAMESIZE) && !defined(_WIN32) && !defined(__SWITCH__)
180+
if(if_indextoname(scope_id, ifname)) {
181+
l += 3 + strlen(ifname); /* 3 == strlen(%25) */
182+
}
183+
@@ -463,7 +463,7 @@
184+
p = strchr(s, ']');
185+
if(p) {
186+
/* insert %25<scope> into URL */
187+
-#if defined(IF_NAMESIZE) && !defined(_WIN32)
188+
+#if defined(IF_NAMESIZE) && !defined(_WIN32) && !defined(__SWITCH__)
189+
memmove(p + 3 + strlen(ifname), p, strlen(p) + 1);
190+
memcpy(p, "%25", 3);
191+
memcpy(p + 3, ifname, strlen(ifname));
192+
diff -Naur miniupnpc-2.1.20190824/miniwget.c miniupnpc-2.1.20190824-patched/miniwget.c
193+
--- miniupnpc-2.1.20190824/miniwget.c 2019-02-10 13:25:00.000000000 +0000
194+
+++ miniupnpc-2.1.20190824-patched/miniwget.c 2019-10-09 00:12:41.579913360 +0100
195+
@@ -540,7 +540,7 @@
196+
p2 = strchr(p1, ']');
197+
if(p2 && scope && scope < p2 && scope_id) {
198+
/* parse scope */
199+
-#ifdef IF_NAMESIZE
200+
+#if defined(IF_NAMESIZE) && !defined(__SWITCH__)
201+
char tmp[IF_NAMESIZE];
202+
int l;
203+
scope++;
204+
diff -Naur miniupnpc-2.1.20190824/updateminiupnpcstrings.sh miniupnpc-2.1.20190824-patched/updateminiupnpcstrings.sh
205+
--- miniupnpc-2.1.20190824/updateminiupnpcstrings.sh 2011-01-27 17:50:40.000000000 +0000
206+
+++ miniupnpc-2.1.20190824-patched/updateminiupnpcstrings.sh 2019-10-09 00:15:20.116793159 +0100
207+
@@ -40,10 +40,16 @@
208+
MINIUPNPC_VERSION=`cat VERSION`
209+
echo "MiniUPnPc version [${MINIUPNPC_VERSION}]"
210+
211+
+if [ -z $OVERRIDE_OS_STRING ]; then
212+
EXPR="s|OS_STRING \".*\"|OS_STRING \"${OS_NAME}/${OS_VERSION}\"|"
213+
+echo "setting OS_STRING macro value to ${OS_NAME}/${OS_VERSION} in $FILE."
214+
+else
215+
+EXPR="s|OS_STRING \".*\"|OS_STRING \"${OVERRIDE_OS_STRING}\"|"
216+
+echo "setting OS_STRING macro value to ${OVERRIDE_OS_STRING} in $FILE."
217+
+fi
218+
+
219+
#echo $EXPR
220+
test -f ${FILE}.in
221+
-echo "setting OS_STRING macro value to ${OS_NAME}/${OS_VERSION} in $FILE."
222+
sed -e "$EXPR" < $TEMPLATE_FILE > $TMPFILE
223+
224+
EXPR="s|MINIUPNPC_VERSION_STRING \".*\"|MINIUPNPC_VERSION_STRING \"${MINIUPNPC_VERSION}\"|"

0 commit comments

Comments
 (0)