include $(TOPDIR)/rules.mk
PKG_NAME:=libtorrent
-PKG_VERSION:=0.13.8
-PKG_RELEASE:=2
+PKG_VERSION:=0.15.3
+PKG_RELEASE:=1
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
-PKG_SOURCE_URL:=https://codeload.github.com/rakshasa/libtorrent/tar.gz/v$(PKG_VERSION)?
-PKG_HASH:=0f6c2e7ffd3a1723ab47fdac785ec40f85c0a5b5a42c1d002272205b988be722
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=https://github.com/rakshasa/libtorrent
+PKG_SOURCE_VERSION:=v$(PKG_VERSION)
+PKG_MIRROR_HASH:=186058e4a965457b67d7190c1d35e1acd26d273632ca768f394be6785b433d32
PKG_LICENSE:=GPL-2.0-or-later
CONFIGURE_ARGS += \
--enable-shared \
--enable-static \
- --enable-aligned \
- --enable-openssl \
+ --disable-aligned \
--disable-debug \
--disable-instrumentation \
--with-epoll \
--with-zlib=$(STAGING_DIR)/usr \
--without-kqueue
-TARGET_CXXFLAGS += -faligned-new
+CONFIGURE_VARS = \
+ ax_cv_cxx_compile_cxx17=yes
define Build/InstallDev
$(INSTALL_DIR) $(1)/usr/include
--- /dev/null
+From 3f8bc12fe33bac4b063a6284af0f0ff7b53ac9b7 Mon Sep 17 00:00:00 2001
+Date: Sun, 4 May 2025 17:08:34 -0700
+Subject: [PATCH] pkgconfig: fix static linking
+
+A link to libcrypto and pthread are missing, which shows up when trying
+to link a static libtorrent with rtorrent. The latter being an issue
+with older platforms that don't have pthread stuff in libc.
+
+---
+ libtorrent.pc.in | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+--- a/libtorrent.pc.in
++++ b/libtorrent.pc.in
+@@ -6,6 +6,6 @@ includedir=@includedir@
+ Name: libtorrent
+ Description: A BitTorrent library
+ Version: @VERSION@
+-Libs: -L${libdir} -ltorrent
+-Libs.Private: -lz
++Requires: zlib, libcrypto
++Libs: -L${libdir} -ltorrent @ATOMIC_LIBS@
+ Cflags: -I${includedir}
--- /dev/null
+From a7da5a3981d8fd2fadc5146da4ab5ad33de5482e Mon Sep 17 00:00:00 2001
+Date: Tue, 6 May 2025 13:53:04 -0700
+Subject: [PATCH] add support for external libatomic
+
+Needed on some 32-bit platforms where 64-bit atomics are provided by
+libatomic.
+
+---
+ configure.ac | 3 ++-
+ scripts/check_atomic.m4 | 46 +++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 49 insertions(+), 1 deletion(-)
+ create mode 100644 scripts/check_atomic.m4
+
+--- a/configure.ac
++++ b/configure.ac
+@@ -79,13 +79,14 @@ AC_ARG_ENABLE(execinfo,
+ ])
+
+ AX_PTHREAD
++CHECK_ATOMIC
+
+ PKG_CHECK_MODULES([CPPUNIT], [cppunit],, [no_cppunit="yes"])
+ PKG_CHECK_MODULES([ZLIB], [zlib])
+
+ CFLAGS="$PTHREAD_CFLAGS $ZLIB_CFLAGS $CFLAGS"
+ CXXFLAGS="$PTHREAD_CFLAGS $ZLIB_CFLAGS $CXXFLAGS"
+-LIBS="$PTHREAD_LIBS $ZLIB_LIBS $LIBS"
++LIBS="$ATOMIC_LIBS $PTHREAD_LIBS $ZLIB_LIBS $LIBS"
+
+ TORRENT_CHECK_OPENSSL
+
+--- /dev/null
++++ b/scripts/check_atomic.m4
+@@ -0,0 +1,38 @@
++# Some versions of gcc/libstdc++ require linking with -latomic if
++# using the C++ atomic library.
++
++
++# Copying and distribution of this file, with or without modification, are
++# permitted in any medium without royalty provided the copyright notice
++# and this notice are preserved. This file is offered as-is, without any
++# warranty.
++
++m4_define([_CHECK_ATOMIC_testbody], [[
++ #include <atomic>
++ #include <cstdint>
++
++ int main() {
++ std::atomic<int64_t> a{};
++
++ int64_t v = 5;
++ int64_t r = a.fetch_add(v);
++ return static_cast<int>(r);
++ }
++]])
++
++AC_DEFUN([CHECK_ATOMIC], [
++
++ AC_LANG_PUSH(C++)
++
++ AC_MSG_CHECKING([whether std::atomic can be used without link library])
++
++ AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_ATOMIC_testbody])],[
++ AC_MSG_RESULT([yes])
++ ],[
++ ATOMIC_LIBS=-latomic
++ ])
++
++ AC_LANG_POP
++ AC_SUBST([ATOMIC_LIBS])
++])
+++ /dev/null
---- a/src/data/hash_queue.cc
-+++ b/src/data/hash_queue.cc
-@@ -38,9 +38,10 @@
-
- #define __STDC_FORMAT_MACROS
-
-+#include <chrono>
-+#include <thread>
- #include <functional>
- #include <rak/functional.h>
--#include <unistd.h>
-
- #include "torrent/exceptions.h"
- #include "torrent/data/download_data.h"
-@@ -137,7 +138,7 @@ HashQueue::remove(HashQueueNode::id_type
-
- while ((done_itr = m_done_chunks.find(hash_chunk)) == m_done_chunks.end()) {
- pthread_mutex_unlock(&m_done_chunks_lock);
-- usleep(100);
-+ std::this_thread::sleep_for(std::chrono::microseconds(100));
- pthread_mutex_lock(&m_done_chunks_lock);
- }
-
---- a/src/torrent/utils/thread_base.cc
-+++ b/src/torrent/utils/thread_base.cc
-@@ -37,8 +37,9 @@
- #include "config.h"
-
- #include <cstring>
-+#include <chrono>
-+#include <thread>
- #include <signal.h>
--#include <unistd.h>
-
- #include "exceptions.h"
- #include "poll.h"
-@@ -97,7 +98,7 @@ thread_base::stop_thread_wait() {
- release_global_lock();
-
- while (!is_inactive()) {
-- usleep(1000);
-+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
- }
-
- acquire_global_lock();
-@@ -161,7 +162,7 @@ thread_base::event_loop(thread_base* thr
- }
-
- // Add the sleep call when testing interrupts, etc.
-- // usleep(50);
-+ // std::this_thread::sleep_for(std::chrono::microseconds(50));
-
- int poll_flags = 0;
-
+++ /dev/null
-From b3d75a642177f21f00d18f0e46bca4a9f363d08e Mon Sep 17 00:00:00 2001
-Date: Fri, 23 Aug 2019 13:35:28 -0700
-Subject: [PATCH] Replace usleep with C++11 sleep_for
-
-usleep was deprecated with POSIX 2008 and optionally unavailable with
-uClibc-ng.
----
- src/thread_base.cc | 4 +++-
- 1 file changed, 3 insertions(+), 1 deletion(-)
-
---- a/src/thread_base.cc
-+++ b/src/thread_base.cc
-@@ -42,6 +42,8 @@
- #include <cstdlib>
- #include <cstring>
- #include <iostream>
-+#include <chrono>
-+#include <thread>
- #include <signal.h>
- #include <unistd.h>
- #include <rak/error_number.h>
-@@ -66,7 +68,7 @@ public:
-
- thread_queue_hack() { std::memset(this, 0, sizeof(thread_queue_hack)); }
-
-- void lock() { while (!__sync_bool_compare_and_swap(&m_lock, 0, 1)) usleep(0); }
-+ void lock() { while (!__sync_bool_compare_and_swap(&m_lock, 0, 1)) std::this_thread::sleep_for(std::chrono::microseconds(0)); }
- void unlock() { __sync_bool_compare_and_swap(&m_lock, 1, 0); }
-
- iterator begin() { return m_queue; }