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

Re: Using the cross compiler

Post by hamishmb »

Installing python-mysqlclient - Python library for connecting to the database

Turns out this has a C extension, which means it needs to be compiled.

Install prerequisites

Run the command:

Code: Select all

sudo apt install libmysqlclient-dev
Copying mysql headers from Ubuntu 14.04

NOTE: The header files from the GPL code tarball for the NAS box don't work, so this is the next best option.

Copy the header files to the required location:

Code: Select all

sudo cp -R /usr/include/mysql ~/nas-sysroot/usr/local/include/mysql/
NOTE: These are also provided in the archive "mysql-includes.tar.gz" at https://wmtprojectsforum.altervista.org ... /NAS%20Box

Copying libmysqlclient shared libraries into the right place

Download "nasroot.tar.gz" from https://wmtprojectsforum.altervista.org ... /NAS%20Box

Then, extract it and run the following commands:

Code: Select all

sudo cp usr/local/modules/lib/libmysqlclient* /home/wmt/nas-sysroot/lib
cd /home/wmt/nas-sysroot/lib
sudo ln -s libmysqlclient.so.16 libmysqlclient.so
sudo ln -s libmysqlclient_r.so.16 libmysqlclient_r.so
sudo chown wmt:wmt -R /home/wmt/nas-sysroot/lib
We're now ready to build the module.

Downloading python-libmysqlclient

Download the source tarball for version 1.4.4 from https://pypi.org/project/mysqlclient/

Compiling and installing

Download the "mysql_config.txt" file from https://wmtprojectsforum.altervista.org ... x/Packages, and run the commands:

Code: Select all

sudo cp ./mysql_config /usr/bin
sudo chmod o+rx /usr/bin/
Run the command:

Code: Select all

CC="arm-unknown-linux-gnueabi-gcc --sysroot=/home/wmt/nas-sysroot" CFLAGS="-I/home/wmt/nas-sysroot/usr/local/include/mysql" LD_LIBRARY_PATH="/home/wmt/nas-sysroot/lib:/home/wmt/nas-sysroot/usr/local/lib" qemu-arm-static -L /home/wmt/nas-sysroot ~/nas-sysroot/usr/local/bin/python3 setup.py install
Last edited by hamishmb on 22/05/2020, 14:38, edited 1 time in total.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Downloading FreeType (dependency for matplotlib)

Download the source tarball for v2.10.0 from https://download.savannah.gnu.org/releases/freetype/.

Compiling and Installing

We need extra arguments so zlib is found.

To configure, run:

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" CFLAGS="-I/home/wmt/nas-sysroot/usr/local/include" LIBPNG_CFLAGS="-I/home/wmt/nas-sysroot/usr/local/include/libpng16" LDFLAGS="-L/home/wmt/nas-sysroot/usr/local/lib"
To build, run the usual command.

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
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Installing cycler (dependency for matplotlib)

Run:

Code: Select all

pip3 install cycler
On the NAS box. At the time of writing, this installed v0.10.0.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Installing dateutil (dependency for matplotlib)

Run:

Code: Select all

pip3 install python-dateutil
On the NAS box. At the time of writing, this installed v2.8.1.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Installing Tornado (dependency for matplotlib)

Run:

Code: Select all

pip3 install tornado
On the NAS box. At the time of writing, this installed v6.0.3. There was a warning during installation, but it seemed to install okay.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Installing pyparsing (dependency for matplotlib)

Run:

Code: Select all

pip3 install pyparsing
On the NAS box. At the time of writing, this installed v2.4.6.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Installing cython (dependency for matplotlib)

Run:

Code: Select all

pip3 install cython
On the NAS box. At the time of writing, this installed v0.29.15
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Installing Kiwisolver (dependency for matplotlib)

Download the tarball for v1.1.0 from https://pypi.org/project/kiwisolver/#files.

To build, run:

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_LIBRARY_PATH="/home/wmt/nas-sysroot/lib:/home/wmt/nas-sysroot/usr/local/lib" qemu-arm-static -L /home/wmt/nas-sysroot ~/nas-sysroot/usr/local/bin/python3 setup.py build
This takes quite a long time to build, because of having to use QEMU, but also a lot of C files have to be compiled. It also seems to think it's building from armv7l, but it is building for armv5te as needed - don't be concerned by the warning.

To install, run:

Code: Select all

sudo CC="arm-unknown-linux-gnueabi-gcc --sysroot=/home/wmt/nas-sysroot" CXX="arm-unknown-linux-gnueabi-g++ --sysroot=/home/wmt/nas-sysroot" LD_LIBRARY_PATH="/home/wmt/nas-sysroot/lib:/home/wmt/nas-sysroot/usr/local/lib" qemu-arm-static -L /home/wmt/nas-sysroot ~/nas-sysroot/usr/local/bin/python3 setup.py install
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Installing Pillow (dependency for matplotlib)

Download the tarball for v7.0.0 from https://pypi.org/project/pillow/#files.

It attempts to be clever and detect the platform, but this fails in our case. To disable it, open setup.py and change line 320 from:

Code: Select all

self.disable_platform_guessing = None
To:

Code: Select all

self.disable_platform_guessing = True
To build, run:

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_LIBRARY_PATH="/home/wmt/nas-sysroot/lib:/home/wmt/nas-sysroot/usr/local/lib" qemu-arm-static -L /home/wmt/nas-sysroot ~/nas-sysroot/usr/local/bin/python3 setup.py build
This takes quite a long time to build, because of having to use QEMU, but also a lot of C files have to be compiled. It also seems to think it's building from armv7l, but it is building for armv5te as needed - don't be concerned by the warning.

To install, run:

Code: Select all

sudo CC="arm-unknown-linux-gnueabi-gcc --sysroot=/home/wmt/nas-sysroot" CXX="arm-unknown-linux-gnueabi-g++ --sysroot=/home/wmt/nas-sysroot" LD_LIBRARY_PATH="/home/wmt/nas-sysroot/lib:/home/wmt/nas-sysroot/usr/local/lib" qemu-arm-static -L /home/wmt/nas-sysroot ~/nas-sysroot/usr/local/bin/python3 setup.py install
To test, run:

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_LIBRARY_PATH="/home/wmt/nas-sysroot/lib:/home/wmt/nas-sysroot/usr/local/lib" qemu-arm-static -L /home/wmt/nas-sysroot ~/nas-sysroot/usr/local/bin/python3 selftest.py
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Using the cross compiler

Post by hamishmb »

Installing NumPy (dependency for matplotlib)

This requires a Fortran compiler, but isn't smart enough to find the one we have for cross-compiling, or the linker.

Before building, run:

Code: Select all

sudo ln -s /home/wmt/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gfortran /usr/local/bin/gfortran
sudo ln -s /home/wmt/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-ld /usr/local/bin/ld
sudo ln -s /home/wmt/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc /usr/local/bin/gcc
We also need to patch setup.py to make sure it adds the right compiler flags.

Open it and change line 247 from:

Code: Select all

return is_gcc
To:

Code: Select all

return True
For some reason it doesn't detect that we're using GCC to compile, so we're just hard-coding that in here.

To build, run:

Code: Select all

CC="arm-unknown-linux-gnueabi-gcc --sysroot=/home/wmt/nas-sysroot" CXX="arm-unknown-linux-gnueabi-g++ CFLAGS="-std=gnu99" --sysroot=/home/wmt/nas-sysroot" LD_LIBRARY_PATH="/home/wmt/nas-sysroot/lib:/home/wmt/nas-sysroot/usr/local/lib" qemu-arm-static -L /home/wmt/nas-sysroot ~/nas-sysroot/usr/local/bin/python3 setup.py build --fcompiler gnu95 --compiler unix
You will need to run this several times because QEMU tends to segfault randomly, but eventually the build will be completed. It may also freeze and need to be CRTL-C'd and restarted. This takes quite a long time to build, because of having to use QEMU, but also a lot of C and Fortran files have to be compiled. It also seems to think it's building for armv7l, but it is building for armv5te as needed - don't be concerned by the warning.

To install, run:

Code: Select all

sudo chmod a+rwx /home/wmt/nas-sysroot/usr/local/lib/python3.7/site-packages/
sudo chmod a+rwx /home/wmt/nas-sysroot/usr/local/lib/python3.7/site-packages/easy-install.pth
sudo chmod a+rwx /home/wmt/nas-sysroot/usr/local/bin
CC="arm-unknown-linux-gnueabi-gcc --sysroot=/home/wmt/nas-sysroot" CXX="arm-unknown-gnueabi-g++ CFLAGS="-std=gnu99" --sysroot=/home/wmt/nas-sysroot" LD_LIBRARY_PATH="/home/wmt/nas-sysroot/lib:/home/wmt/nas-sysroot/usr/local/lib" qemu-arm-static -L /home/wmt/nas-sysroot ~/nas-sysroot/usr/local/bin/python3 setup.py install
Installing also takes a while, but does work.

Cleanup:

Without this, you will not be able to build anything else.

Code: Select all

sudo rm /usr/local/bin/gfortran
sudo rm /usr/local/bin/ld
sudo rm /usr/local/bin/gcc
Hamish
Post Reply