Installing/cross compiling programs

Holds topics that document the NAS box's features and any related procedures. Stuff in here should eventually make it into a specification or the user guide.
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Installing/cross compiling programs

Post by hamishmb »

General instructions can be found at http://crosstool-ng.github.io/docs/toolchain-usage/.

The tarballs are available at https://wmtprojectsforum.altervista.org ... x/Packages, in case download locations change.

Specifically, this is the way I've set up my VM:

I have gone for the "Assembling a root filesystem" method in the link above, and picked Option 2. This means when you compile something, you need to do the following steps:

NOTE: In order to get the screen resolution you want, you may need to open a terminal and run eg:

Code: Select all

xrandr -s 1280x768
For a resolution of 1280x768 pixels. For a full list of supported resolutions, run:

Code: Select all

xrandr
Running ./configure

There are some special options to pass. These are the --host, --build, CC, CXX, and LD options. There may be more depending on the requirements of the program you're compiling.

General arguments to ./configure scripts:

Code: Select all

./configure --host=arm-unknown-linux-gnueabi --target=arm-unknown-linux-gnueabi --build=x86_64-linux-gnu CC="arm-unknown-linux-gnueabi-gcc --sysroot=/home/wmt/nas-sysroot" CXX="arm-unknown-linux-gnueabi-g++ --sysroot=/home/wmt/nas-sysroot" LD="arm-unknown-linux-gnueabi-ld --sysroot=/home/wmt/nas-sysroot"
Running make

You can just do this the usual way:

Code: Select all

make
Running tests (if available)

Install the prerequisites:

Code: Select all

sudo apt-get install dejagnu qemu-user-static
This can usually be done by running:

Code: Select all

make test
Or:

Code: Select all

make check
NOTE: The tests often don't pass fully, or at all, but the programs work, so I think these are mostly QEMU-related issues.

Running make install

Here you need to be careful - you don't want to install the cross-compiled libraries and/or programs to your operating system's system folders. Instead, you want to install to our custom rootfs:

Code: Select all

sudo make DESTDIR=/home/wmt/nas-sysroot install
Running these programs on the NAS box

You'll need to copy the entire rootfs to the hard drives, and extract it. Then set LD_LIBRARY_PATH to the correct folders (probably /usr/local/lib and /usr/lib in the new rootfs):

Code: Select all

export LD_LIBRARY_PATH="/mnt/HD/HD_a2/nas-sysroot/usr/local/lib"
There may also be custom files that need to be symbolically linked to for each program - for example "file" has a magic file that it expects to be in /usr/local/share/misc/. Then the programs should run. You also may need to update your PATH variable to run them without the full path.

Code: Select all

export PATH="/mnt/HD/HD_a2/nas-sysroot/usr/local/bin:$PATH"
I will write a script that does all of this setup for us, but it's useful to have a memoir here anyway.

Using pip

Pip can generally be used in the normal way. However, if there are C extensions or anything else to compile, the module will need to be cross-compiled in the VM. After installing pure-python modules on the NAS box with pip, make sure to compress and copy the nas-sysroot folder and extract in the VM! Otherwise, future builds in the VM may remove modules!

Compressing the sysroot

Run the following command to compress the sysroot for transfer between the VM and the NAS box:

Code: Select all

tar -cva -f nas-sysroot.tar.gz nas-sysroot/
Last edited by hamishmb on 22/05/2020, 14:40, edited 14 times in total.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Compiling "file"

Download the file 5.14 source code, and then configure, make, and make install with the standard commands given above.

Run "make check" to test.
Last edited by hamishmb on 19/07/2019, 12:45, edited 3 times in total.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Compiling OpenSSL

Grab a copy of the openssl-1.1.1c source.

This has a different build system. To configure, run:

Code: Select all

./Configure linux-armv4 no-ssl2 no-ssl3 no-weak-ssl-ciphers CC="arm-unknown-linux-gnueabi-gcc --sysroot=/home/wmt/nas-sysroot" CXX="arm-unknown-linux-gnueabi-g++ --sysroot=/home/wmt/nas-sysroot" LD="arm-unknown-linux-gnueabi-ld --sysroot=/home/wmt/nas-sysroot"
To make, run:

Code: Select all

make -j <num_of_cpu_cores>
I recommend the -j option here - OpenSSL took a little while to compile.

Run "make check" to test. These don't all seem to pass, but OpenSSL seems to work fine.

To install, run the usual installation command.
Last edited by hamishmb on 19/07/2019, 12:45, edited 4 times in total.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Compiling Zlib (dependency for OpenSSH)

Download zlib 1.2.11 from zlib.net.

The configure script here is a bit basic. To configure:

Code: Select all

CC="arm-unknown-linux-gnueabi-gcc --sysroot=/home/wmt/nas-sysroot" CXX="arm-unknown-linux-gnueabi-g++ --sysroot=/home/wmt/nas-sysroot" LD="arm-unknown-linux-gnueabi-ld --sysroot=/home/wmt/nas-sysroot" ./configure
To make, run the usual command.

To make install run the usual command.
Last edited by hamishmb on 19/07/2019, 12:45, edited 2 times in total.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Compiling OpenSSH

We need an extra option so the configure script knows where zlib.h is, so run:

Code: Select all

./configure --host=arm-unknown-linux=gnueabi --build=arm-unknown-linux-gnueabi CC="arm-unknown-linux-gnueabi-gcc --sysroot=/home/wmt/nas-sysroot" CXX="arm-unknown-linux-gnueabi-g++ --sysroot=/home/wmt/nas-sysroot" LD="arm-unknown-linux-gnueabi-ld --sysroot=/home/wmt/nas-sysroot" CPPFLAGS="-I/home/wmt/nas-sysroot/usr/local/include" --disable-strip"
To make, run:

Code: Select all

make -j <num_of_cpu_cores>
This takes a while, so I recommend using the -j option.

To install, run the usual command.
Last edited by hamishmb on 19/07/2019, 12:46, edited 2 times in total.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Compiling libncurses (dependency for nano)

Download ncurses 5.9 from ftp://ftp.invisible-island.net/ncurses/

Take care with this one; I had to re-compile and re-install because you have to tell it explicitly to create the shared library.

Configuring ncurses:

We have to manually specify the prefix here as /usr/local, otherwise ncurses will install in the wrong place:

Code: Select all

./configure --host=arm-unknown-linux=gnueabi --build=arm-unknown-linux-gnueabi CC="arm-unknown-linux-gnueabi-gcc --sysroot=/home/wmt/nas-sysroot" CXX="arm-unknown-linux-gnueabi-g++ --sysroot=/home/wmt/nas-sysroot" LD="arm-unknown-linux-gnueabi-ld --sysroot=/home/wmt/nas-sysroot" --prefix=/usr/local --with-shared
To make, run:

Code: Select all

make -j <num_of_cpu cores>
This takes a little while, so I would recommend using the -j option.

To install, run:

Code: Select all

sudo PATH="/home/wmt/x-tools/arm-unknown-linux-gnueabi/bin:$PATH" make DESTDIR=/home/wmt/nas-sysroot install
NOTE: In order to compile MariaDB, make a symlink from libncurses.so to libcurses.so:

Code: Select all

cd /home/wmt/nas-sysroot/usr/local/lib
ln -s libncurses.so libcurses.so
Last edited by hamishmb on 19/07/2019, 12:46, edited 5 times in total.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Compiling GNU nano

Download nano 4.3 from https://www.nano-editor.org.

To configure nano, we need to tell the configure script where to find our ncurses installation:

Code: Select all

./configure --host=arm-unknown-linux=gnueabi --build=arm-unknown-linux-gnueabi CC="arm-unknown-linux-gnueabi-gcc --sysroot=/home/wmt/nas-sysroot" CXX="arm-unknown-linux-gnueabi-g++ --sysroot=/home/wmt/nas-sysroot" LD="arm-unknown-linux-gnueabi-ld --sysroot=/home/wmt/nas-sysroot" CPPFLAGS="-I/home/wmt/nas-sysroot/usr/local/include/ncurses -I/home/wmt/nas-sysroot/usr/local/include/"
To make, run the usual command.

Run "make check" to test.

To install, run the usual command.
Last edited by hamishmb on 19/07/2019, 12:46, edited 3 times in total.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Compiling less

Download less 530 from https://www.gnu.org/software/less/.

To configure, run the usual command.

To make, run the usual command.

Run "make check" to test.

To install, run the usual command.
Last edited by hamishmb on 19/07/2019, 12:46, edited 3 times in total.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Building libffi (dependency for Python 3)

Download libffi from https://sourceware.org/libffi/.

Configure with the usual command.

Make with the usual command.

The tests for this library all seem to fail, but this doesn't seem to matter. Because all of them fail, it's probably a QEMU-or-cross-compilation-related issue.

Install with a custom command to make sure PATH is set correctly:

Code: Select all

sudo PATH="/home/wmt/x-tools/arm-unknown-linux-gnueabi/bin:$PATH" make DESTDIR=/home/wmt/nas-sysroot install
Last edited by hamishmb on 19/07/2019, 12:47, edited 4 times in total.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Compiling Python 3.7

Download Python 3.7.3 from python.org.

Building for the host system

This is more complicated, because a working Python 3.7.3 interpreter is required to cross-compile. First, we will build for the host:

Code: Select all

./configure --prefix=/usr/local
Run make:

Code: Select all

make -j <num_of_cpu_cores>
Using the -j option is recommended: this build takes a significant amount of time.

NOTE: This moans about the SSL module being unavailable. This probably doesn't matter, as we're only using this interpreter to cross compile anyway.

Install:

Code: Select all

sudo make install
NOTE: This fails at the end because the required version of zlib is not available. Again, this probably isn't important.

Building for the target system

Install dependency: readelf on the target:

Code: Select all

sudo apt install elfutils
Some extra options are required here. Some are needed for the build to work, and others tell python where OpenSSL, zlib, ncurses and libffi are installed. To configure python:

Code: Select all

./configure --host=arm-unknown-linux-gnueabi --target=arm-unknown-linux-gnueabi --build=x86_64-linux-gnu CC="arm-unknown-linux-gnueabi-gcc --sysroot=/home/wmt/nas-sysroot" CXX="arm-unknown-linux-gnueabi-g++ --sysroot=/home/wmt/nas-sysroot" LD="arm-unknown-linux-gnueabi-ld --sysroot=/home/wmt/nas-sysroot" --disable-ipv6 ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no ac_cv_have_long_long_format=yes --with-openssl=/home/wmt/nas-sysroot/usr/local/ CFLAGS="-I/home/wmt/nas-sysroot/usr/local/include -I/home/wmt/nas-sysroot/usr/local/include/openssl -I/home/wmt/nas-sysroot/usr/local/include/ncurses" CPPFLAGS="-I/home/wmt/nas-sysroot/usr/local/include -I/home/wmt/nas-sysroot/usr/local/include/openssl -I/home/wmt/nas-sysroot/usr/local/include/ncurses -I/home/wmt/nas-sysroot/usr/local/lib/libffi-3.2.1/include/" LDFLAGS="-L/home/wmt/nas-sysroot/usr/local/lib"
To make:

Code: Select all

make -j <num_of_cpu_cores>
Using the -j option is recommended: this build takes a significant amount of time.

To install, run the usual command.

NOTE: This fails at the end because zlib is not available on the build host. However, everything is installed fine.

To install pip, install the files on the NAS, and then run the get_pip.py script from https://bootstrap.pypa.io/get-pip.py.
Last edited by hamishmb on 19/07/2019, 12:47, edited 2 times in total.
Hamish
Post Reply