compiling ncdu for synology
Ncdu is a command line tool that evaluates disk space. I wanted to run this on my Synology NAS, so I decided to compile it. Note that ncdu is available for Synology, for instance as part of https://synocommunity.com/ which uses spksrc (https://github.com/SynoCommunity/spksrc) but this is about the raw compile. Also, I cheat here and take a short cut that might not otherwise work, except I’m relying on a slow pace of change for both the ncurses package and ncdu.
This is being compiled on ubuntu on a Oracle VirtualBox VM on an intel mac.
The first step is to download a DSM tool chain as described here. https://help.synology.com/developer-guide/compile\_applications/manual.html
As suggested, I untarred it into /usr/local. I have a DS220j which I used to figure out what toolchain was required.
Then, I downloaded ncdu version 1.20. ncdu comes with a configure script and you have to call it pointing to the cross-compile environment, that is with the -host option set to “aarch64-unknown=linux-gnua”. The DSM tool chain adds some compilation tools to /usr/local/aarch64-unknown-linux-gnu/bin/, so configure will need pointers to these tools. CC should be set to the compiler from this directory (aarch64-unknown-linux-gnu-gcc) and LD to the loader (aarch64-unknown-linux-gnu-ld).
The resulting ./configure failed, as the ncurses library was not present in the synology sde. Looking at the NAS itself, we see ncurses libraries present but we don't see the ncurses header files. The ncurses library is present on the NAS and can be used as long as you compile it.
We don't off-hand know the version of the package on the NAS. One option is to write a ncurses application that prints out the version, but instead, I took a short cut to assume that both ncdu and ncurses don't make fundamental changes often, so basically the latest version is fine. I eventually added a –disable-dependency-tracking option to configure due to this shortcut.
On my linux build machine, I installed the libncurses-dev package in the standard locations so I had access to the required header files. However, they need to be in the cross-compilation environment for the compile to work.for, here /usr/local/aarch64-unknown-linux-gnu/sysroot. It's straightforward to copy the header files in the ncurses-dev package from /usr/include to /usr/local/aarch64-unknown-linux-gnu/sysroot/usr/include. For the headers, I just copied them from the nas itself to /usr/local/aarch64-unknown-linux-gnu/sysroot//lib.
Rather than copy one file at a time, I copied everything the package added to the system into the proper directories, headers from the linux system itself and library .so files from the NAS.
At this point, configure and make creates a ncdu executable, which can be transferred to the NAS and used.