The rtorrent v0.8.1 from the Optware on a Buffalo Linkstation Live (LS-CHLFFE) v2 NAS doesn’t support TLSv1.2. We need to upgrade rtorrent to a recent release in order to support HTTPS trackers requiring TLSv1.2. This post is about the process of building rtorrent v0.9.6 from the source code.
Introduction
This post is about building rtorrent 0.9.6 on a Buffalo Linkstation Live (LS-CHLFFE) v2 NAS. It’s assumed that Optware has been set up. This means that necessary compilation tools can be installed by using ipkg command.
We are going to build the following software components:
Optionally, rtorrent supports XML-RPC, which requires xmlrpc-c. To build xmlrpc-c, a recent version of Boost is required. Since I don’t use XML-RPC functionalities, in this post, rtorrent will be configured without XML-RPC.
Building steps
All the tools will be configured with prefix=/opt/local. This means that compiled built binaries and support files will be installed in subdirectories in /opt/local, for instance, executables will be installed in /opt/local/bin, and libraries in /opt/local/lib. We need to add /opt/local/bin and /opt/local/lib to the font of $PATH and $LD_LIBRARY_PATH respectively.
automake
Change to the directory where automake-1.16.tar.gz is saved.
1 2 3 4 5 6 7 8 9 |
tar zxvf automake-1.16.tar.gz cd automake-1.16 mkdir mybuild cd mybuild ../configure --prefix=/opt/local make # as root make install |
libz
Change to the directory where zlib-1.2.11.tar.gz is saved.
1 2 3 4 5 6 7 8 9 |
tar zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 mkdir mybuild cd mybuild ../configure --prefix=/opt/local make # as root make install |
OpenSSL
Change to the directory where openssl-1.1.0g.tar.gz is saved.
1 2 3 4 5 6 7 8 9 |
tar zxvf openssl-1.1.0h.tar.gz cd openssl-1.1.0h mkdir mybuild cd mybuild ../config -Wl,--enable-new-dtags --prefix=/opt/local/ssl --openssldir=/opt/local/ssl enable-egd make # as root make install |
NB: The prefix is set to “/opt/local/ssl”, therefore, the path should be add to $LD_LIBRARY_PATH as well. The configuration needs to include “enable-egd”, otherwise, curl would fail to compile.
curl
Change to the directory where curl-7.59.0.tar.gz is saved.
1 2 3 4 5 6 7 8 9 |
tar zxvf curl-7.59.0.tar.gz cd curl-7.59.0 mkdir mybuild cd mybuild PKG_CONFIG_PATH=/opt/local/ssl/lib/pkgconfig ../configure --prefix=/opt/local --with-ssl=/opt/local/ssl --with-libssl-prefix=/opt/local/ssl make # as root make install |
libtorrent
Change to the directory where libtorrent-0.13.6.tar.gz is saved.
1 2 3 4 5 6 7 8 9 |
tar zxvf libtorrent-0.13.6.tar.gz cd libtorrent-0.13.6 mkdir mybuild cd mybuild PKG_CONFIG_PATH="/opt/local/ssl/lib/pkgconfig:/opt/local/lib/pkgconfig" ../configure --prefix=/opt/local make # as root make install |
Here is where it gets tricky. The previous steps work normally. But the installation of libtorrent v0.13.6 would fail with errors like the following
1 |
undefined reference to '__sync_sub_and_fetch_4' |
It has turned out to that the version of gcc used for the compilation doesn’t have atomic builtin functions for ARM. Basically, the default gcc, gcc 4.2.3, doesn’t have atomic builtins on ARM. More information can be found here and here.
In fact, libtorrent 0.13.6 can be configured not to use those atomic builtins by passing “-disable-instrumentation” to the configure script. That would allow libtorrent to be installed without any patches or tricks with gcc 4.2.3. However, rtorrent also uses atomic builtins and it can be turned off in rtorrent. Rtorrent would fail to link even with the tricks mentioned in above two links.
So the solution would be to apply the tricks, that is, get the source code of those atomic builtins from gcc source tree, compile the code accordingly and link the compiled object code in both libtorrent and rtorrent. Change to a new working directory, for instance, ~/downloads/linux-atomic
1 2 3 |
wget -O linux-atomic.c "http://gcc.gnu.org/git/?p=gcc.git;a=blob_plain;f=libgcc/config/arm/linux-atomic.c;hb=master" libtool --tag=CC --mode=compile gcc -g -O2 -MT linux-atomic.lo -MD -MP -MF linux-atomic.Tpo -c -o linux-atomic.lo linux-atomic.c libtool --tag=CC --mode=link gcc -g -O2 -o liblinux-atomic.la linux-atomic.lo |
Now change to the directory where the source code of libtorrent is. But before we start building libtorrent, as I have tested, we need to apply one more change to the source code of libtorrent, which is also related to the use of atomic builtins in libtorrent. Edit src/utils/instrumentation.h and src/utils/instrumentation.cc, change the all the instances of int64_t to int32_t, and PRIi64 to PRIi32. Then, let’s change to mybuild directory and build libtorrent again. Note, if you have already run configure before in mybuild directory, please run “make distclean” before running the following commands.
1 2 3 4 5 6 |
# Assume linux-atomic.c is in /home/taohe/downloads/linux-atomic PKG_CONFIG_PATH="/opt/local/ssl/lib/pkgconfig:/opt/local/lib/pkgconfig" ../configure --prefix=/opt/local LDFLAGS="-L/home/taohe/downloads/linux-atomic" LIBS="-llinux-atomic" make # as root make install |
rtorrent
Compilation of rtorrent requires ncurses header files. In Optware, we need to install “ncurses-dev” and “ncursesw-dev”.
Change to the directory where rtorrent-0.9.6.tar.gz is saved.
1 2 3 4 5 6 7 8 9 10 |
# Assume linux-atomic.c is in /home/taohe/downloads/linux-atomic tar zxvf rtorrent-0.9.6.tar.gz cd rtorrent-0.9.6 mkdir mybuild cd mybuild PKG_CONFIG_PATH="/opt/local/lib/pkgconfig:/opt/local/ssl/lib/pkgconfig" ../configure --prefix=/opt/local LDFLAGS="-L/home/taohe/downloads/linux-atomic" LIBS="-llinux-atomic" make # as root make install |
Done! For configuration of rtorrent, command list, and more information about rtorrent, please refer to rtorrent wiki page.
Download
The compilation takes a long time on the NAS. I’ve made an archive of /opt/local. The executables (rtorrent and curl) should be able to run on compatible systems. The archive can be downloaded here. See README file included for more information about the archive.