From 1e8905176d20867fcd370c723ad6d6f15d17658b Mon Sep 17 00:00:00 2001
From: Rosen Penev <rosenp@gmail.com>
Date: Sun, 28 Jan 2018 12:22:42 -0800
Subject: [PATCH] transmission: Use external libminiupnpc instead of internal.

The original patch that forced internal usage hid an actual issue in the build system. Replace patch with upstream one.

Also reorganized the Makefile a bit and removed some cruft.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 net/transmission/Makefile                     | 21 +++--------
 ...ls.patch => 010-add-mbedtls-support.patch} |  0
 .../patches/020-fix-external-miniupnpc.patch  | 35 +++++++++++++++++++
 .../patches/020-use-internal-miniupnp.patch   | 13 -------
 4 files changed, 39 insertions(+), 30 deletions(-)
 rename net/transmission/patches/{040-fix-for-mbedtls.patch => 010-add-mbedtls-support.patch} (100%)
 create mode 100644 net/transmission/patches/020-fix-external-miniupnpc.patch
 delete mode 100644 net/transmission/patches/020-use-internal-miniupnp.patch

diff --git a/net/transmission/Makefile b/net/transmission/Makefile
index cc462776e..7bf83d53d 100644
--- a/net/transmission/Makefile
+++ b/net/transmission/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=transmission
 PKG_VERSION:=2.93
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
 PKG_SOURCE_URL:=https://github.com/transmission/transmission-releases/raw/master
@@ -37,7 +37,7 @@ endef
 
 define Package/transmission-daemon/Default
   $(call Package/transmission/template)
-  DEPENDS:=+libcurl +libpthread +libevent2 +librt +zlib
+  DEPENDS:=+libcurl +libevent2 +libminiupnpc +libpthread +librt +zlib
   USERID:=transmission=224:transmission=224
 endef
 
@@ -57,7 +57,7 @@ endef
 
 define Package/transmission-cli/Default
   $(call Package/transmission/template)
-  DEPENDS:=+libcurl +libpthread +libevent2 +librt +zlib
+  DEPENDS:=+libcurl +libevent2 +libminiupnpc +libpthread +librt +zlib
 endef
 
 define Package/transmission-cli-openssl
@@ -76,7 +76,7 @@ endef
 
 define Package/transmission-remote/Default
   $(call Package/transmission/template)
-  DEPENDS:=+libcurl +libpthread +libevent2 +librt +zlib
+  DEPENDS:=+libcurl +libevent2 +libminiupnpc +libpthread +librt +zlib
 endef
 
 define Package/transmission-remote-openssl
@@ -131,9 +131,6 @@ endef
 Package/transmission-daemon-mbedtls/conffiles = $(Package/transmission-daemon-openssl/conffiles)
 
 
-CONFIGURE_VARS += \
-	LIBEVENT_LIBS="$(STAGING_DIR)/usr/lib/libevent-2.0.so.5"
-
 CONFIGURE_ARGS += \
 	--enable-daemon \
 	--enable-cli \
@@ -154,16 +151,6 @@ ifeq ($(BUILD_VARIANT),mbedtls)
 	MBEDTLS_LIBS="-lmbedtls -lmbedcrypto"
 endif
 
-MAKE_FLAGS += \
-	CFLAGS="$(TARGET_CFLAGS) -D_GNU_SOURCE"
-
-TARGET_CFLAGS += -std=gnu99
-
-define Build/Configure
-	( cd $(PKG_BUILD_DIR); ./autogen.sh $(CONFIGURE_ARGS))
-	$(call Build/Configure/Default,$CONFIGURE_ARGS)
-endef
-
 define Package/transmission-daemon-openssl/install
 	$(INSTALL_DIR) $(1)/usr/bin
 	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/transmission-daemon $(1)/usr/bin/
diff --git a/net/transmission/patches/040-fix-for-mbedtls.patch b/net/transmission/patches/010-add-mbedtls-support.patch
similarity index 100%
rename from net/transmission/patches/040-fix-for-mbedtls.patch
rename to net/transmission/patches/010-add-mbedtls-support.patch
diff --git a/net/transmission/patches/020-fix-external-miniupnpc.patch b/net/transmission/patches/020-fix-external-miniupnpc.patch
new file mode 100644
index 000000000..64a2fca34
--- /dev/null
+++ b/net/transmission/patches/020-fix-external-miniupnpc.patch
@@ -0,0 +1,35 @@
+From 94fa0bba88740b9ab58c5805ddb24b05b2635f34 Mon Sep 17 00:00:00 2001
+From: Mike Gelfand <mikedld@mikedld.com>
+Date: Fri, 26 Jan 2018 08:31:16 +0300
+Subject: [PATCH] Fix FTCBFS due to AC_RUN_IFELSE (patch by Helmut Grohne)
+
+Fixes: #475
+---
+ configure.ac | 8 +++-----
+ 1 file changed, 3 insertions(+), 5 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index cb026df..335f4a7 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -390,14 +390,12 @@ dnl Let's hope it's 1.7 or higher, since it provides
+ dnl MINIUPNPC_API_VERSION and we won't have to figure
+ dnl it out on our own
+ if test "x$upnp_version" = "xunknown" ; then
+-  AC_RUN_IFELSE(
++  AC_COMPILE_IFELSE(
+     [AC_LANG_PROGRAM(
+       [#include <stdlib.h>
+        #include <miniupnpc/miniupnpc.h>],
+-      [#ifdef MINIUPNPC_API_VERSION
+-       return EXIT_SUCCESS;
+-       #else
+-       return EXIT_FAILURE;
++      [#ifndef MINIUPNPC_API_VERSION
++       #error MINIUPNPC_API_VERSION undefined
+        #endif]
+     )],
+     [upnp_version=">= 1.7"]
+-- 
+2.7.4
+
diff --git a/net/transmission/patches/020-use-internal-miniupnp.patch b/net/transmission/patches/020-use-internal-miniupnp.patch
deleted file mode 100644
index 745bfac34..000000000
--- a/net/transmission/patches/020-use-internal-miniupnp.patch
+++ /dev/null
@@ -1,13 +0,0 @@
-diff --git a/configure.ac b/configure.ac
-index aff673b..7e109af 100644
---- a/configure.ac
-+++ b/configure.ac
-@@ -378,7 +378,7 @@ dnl See if ANY version of miniupnpc is installed
- AC_LINK_IFELSE(
-   [AC_LANG_PROGRAM([#include <miniupnpc/miniupnpc.h>],
-                    [struct UPNPDev dev;])],
--  [upnp_version="unknown"],
-+  [upnp_version="none"],
-   [upnp_version="none"]
- )
-