Saturday, March 24, 2012

Mono 2.11 binary build for Synology 2.11

I have put up a build of Mono 2.11 for Synology DS211, so you can install it without compiling everything yourself. Simply download the archive and then run this:

tar -xvf mono-synology-ds211-2.11.tar.bz2
cp -R opt/mono-2.11 /opt/mono-2.11
Or use the one-line version:

tar -C / -xvf mono-synology-ds211-2.11.tar.bz2

This will install everything in /opt/mono-2.11, you can set up symlinks like this:

ln -s /opt/mono-2.11/bin/mono /opt/bin/mono
ln -s /opt/mono-2.11/bin/mcs /opt/bin/mcs
ln -s /opt/mono-2.11/bin/gmcs /opt/bin/gmcs

I have also put up a build of Mono 2.10.9 for Synology DS211, in case Mono 2.11 turns out to be too alpha. You can have both installed at the same time, just change the symlinks to fit.

Friday, March 23, 2012

Mono on Synology NAS DS 211

Updated 2014-01-21: 
There is a repository with pre-built synology packages (including Mono), which might save you some hassle.

There used to be a Mono package for Synology, using the ipkg system. But it was old (Mono 2.4), and it seems to have disappeared. I have a lot of Mono/.Netstuff that I want to run on my NAS box, especially Duplicati for backups.

If you download the source and build the latest Mono, you get strange errors. Hopefully this guide will help you building Mono on your Synology DS. I have tested with DSM 3.1 and DSM 4.0 and both build fine and appear to run as expected.

First of, you need the Synology ipkg system set up. Once this is installed, you can pull some tools to build it. You will need at least make, automake, autoconf, bison, glib, libc-dev, libstdc++, m4, gcc, gawk, textutils, gettext, zlib. You need gawk and textutils to run the configure script. I use wget to download the Mono sources, and nano to edit the makefiles, so install those too.

Type this to get all the packages:
sudo ipkg install wget nano make automake autoconf bison \
glib libc-dev libstdc++ m4 gcc gawk textutils gettext zlib

Then download Mono sources:

wget "http://download.mono-project.com/sources/mono/mono-2.11.0.tar.bz2"

And extract:

tar -xf mono-2.11.0.tar.bz2

Then configure:

cd mono-2.11
./configure --prefix=/opt/mono-2.11
The --prefix will setup the build to put stuff into /opt/mono-2.11 rather than /usr. If you use just /opt, you will have a hard time uninstalling Mono later should you want to.

Now you should be ready to build it, but there is some weirdness with default includes, so edit the following files:

mono/metadata/Makefile
mono/mini/Makefile
mono/profiler/Makefile

In all files, look for the line:

LDFLAGS =

Add the -lrt flags so the line becomes:

LDFLAGS = -lrt 

If you already have flags on that line, just add the -lrt option to the end, and keep all the other stuff. This fixes problems with "undefined reference to clock_gettime" and also includes the pthreads library.

Now the pthreads library provided by ipkg is a bit broken, so you need to use the normal pthreads library for the build. Simply do this:
mkdir /opt/arm-none-linux-gnueabi/lib_disabled
mv /opt/arm-none-linux-gnueabi/lib/libpthread* /opt/arm-none-linux-gnueabi/lib_disabled
cp /lib/libpthread.so.0 /opt/arm-none-linux-gnueabi/lib/
ln -s /opt/arm-none-linux-gnueabi/lib/libpthread.so.0 /opt/arm-none-linux-gnueabi/lib/libpthread.so
ln -s /opt/arm-none-linux-gnueabi/lib/libpthread.so.0 /opt/arm-none-linux-gnueabi/lib/libpthread-2.5.so

And that is it, now run:

make

This will take a few hours probably, so sit back and wait. I usually run this in a screen so network issues do not stop the build.

After the build has completed, you can install it into /opt/mono-2.11:

make install

To make life a little easier, add some symlinks:

ln -s /opt/mono-2.11/bin/mono /opt/bin/mono
ln -s /opt/mono-2.11/bin/mcs /opt/bin/mcs
ln -s /opt/mono-2.11/bin/gmcs /opt/bin/gmcs

And finally test it:

mono --version


Mono JIT compiler version 2.11 (tarball Fri Mar 23 15:12:18 CET 2012)
Copyright (C) 2002-2011 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS:           __thread
SIGSEGV:       normal
Notifications: epoll
Architecture:  armel,soft-float
Disabled:      none
Misc:          softdebug
LLVM:          supported, not enabled.
GC:            Included Boehm (with typed GC and Parallel Mark)

I have uploaded a complete build, so you can just use it without doing the long and boring build process.