Skip to content

Cross compile for arm (raspberry)

Cecil edited this page Sep 16, 2018 · 1 revision

Like all Shoes building, cross compiling is mostly about getting the dependencies correct and that can be a lot of effort - several days work if you are documenting as you go. You can download all the dependencies here and skip down to building Shoes or you can do it the hard way and gain some knowledge. Before you skip, see the requirements.

Requirements for cross building

  1. Linux host (I'm using Mint 18.1, based on ubuntu and debian). You can do it with homebrew on OSX OR or use a virtual machine on OSX or Windows and install a nice linux in the VM.
  2. Ruby installed on host (I use rvm)
  3. A place to put everything. I use ~/Projects/shoesdeps/rpi
  4. a Pi2 or Pi3, networked. Ssh is nice to have. My pi mounts ~/Projects with NFS. A Linux VM on top of Windows might be able to export NFS. Let me know if it does.

Ruby Dependencies

zlib

arm-zlib.sh

#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CROSS=arm-linux-gnueabihf
export CC=${CROSS}-gcc
export LD=${CROSS}-ld
export AS=${CROSS}-as
export TARGETMACH=arm-linux-gnueabihf
export BUILDMACH=x86_64-linux-gnu
export CPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
export INCLUDE_PATH=${dest}/include
export LIBRARY_PATH=${dest}/lib
export BINARY_PATH=${dest}/bin
./configure --prefix=${dest}

gdbm

arm-gdbm.sh

#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CC=arm-linux-gnueabihf-gcc
export CPPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
./configure \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --enable-shared \
  --enable-libgdbm-compat \
  --prefix=${dest}

yaml

arm-yaml.sh

#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CC=arm-linux-gnueabihf-gcc
export CPPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
./configure \
  --enable-shared \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --prefix="$dest"

ffi

arm-fff.sh

#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CC=arm-linux-gnueabihf-gcc
export CPPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
./configure \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --prefix=${dest}

openssl

arm-openssl.sh

#! /bin/bash
# execute it instead of ./Configure
# NOTE: THIS DOESN'T BUILD SHARED
export dest=/home/ccoupe/Projects/shoesdeps/rpi
export CPPFLAGS="-I${dest}/include"
export LDFLAGS=-L${dest}/lib
export CC=arm-linux-gnueabihf-gcc
export AR=arm-linux-gnueabihf-ar 
export RANLIB=arm-linux-gnueabihf-ranlib
./Configure \
  shared os/compiler:arm-linux-gnueabihf \
  -I${dest}/include \
  --prefix="${dest}"

This one is problematic. It doesn't build the shared libraries. I copied libcrypto.so and libssl.so and the links from the Pi's /usr/lib/arm-linux-gnueabihf and/or /lib/arm-linux-gnueabihf.

readline

arm-readline.sh

#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CC=arm-linux-gnueabihf-gcc
export CPPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
./configure \
  --enable-shared \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --prefix="$dest"

Ruby failed to find this lib when configuring. Shoes doesn't need it so move on without it.

Ruby 2.3.7

arm-ruby.sh

#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CC=arm-linux-gnueabihf-gcc
export CFLAGS="-I${dest}/include -I${dest}/lib/libffi-3.2.1/include"
export LDFLAGS="-L${dest}/lib"
./configure \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --enable-shared \
  --enable-load-relative \
  --disable-install-doc \
  --without-tk --without-tcllib --without-tcltk \
  --prefix=${dest}/ruby237

make and make install

Note that the destination is a little different because I like to keep Ruby separate from the other deps. After make install you should try your new arm ruby. If it works then you'll have some confidence. On the pi, cd into that nfs mounted directory (/home/ccoupe/Projects/shoesdeps/rpi/ruby237/ in this example)

$ ssh pi@pi3
$ cd Projects/shoesdeps/rpi/ruby237/
$ bin/ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [arm-linux-eabihf]
$ bin/ruby -e 'puts RUBY_PLATFORM'
arm-linux-eabihf

Rubygems 2.7.7

download and extract into the src directory. Lets really test that new arm ruby! We'll use it to update it's gems. For that we need to be logged into the pi and to cd into the untarred archive. Like

pi@pi3:~/Projects/shoesdeps/rpi/src/rubygems-2.7.7 $ ../../ruby237/bin/ruby setup.rb --no-document
Bundler 1.16.2 installed
RubyGems 2.7.7 installed
Regenerating binstubs
...... skip lots of output
RubyGems installed the following executables:
	/home/pi/Projects/shoesdeps/rpi/ruby237/bin/gem
	/home/pi/Projects/shoesdeps/rpi/ruby237/bin/bundle
pi@pi3:~/Projects/shoesdeps/rpi/src/rubygems-2.7.7 $ ../../ruby237/bin/gem -v
2.7.7

Success is sweet. Take a break.

Shoes Dependencies

Most of these need to be built on the raspberry pi. Which is slow. The configuration of these is obscure and you will make mistakes. Which is slow.

arm-png.sh

#! /bin/bash
# execute it instead of ./configure
export dest=/home/ccoupe/Projects/shoesdeps/rpi
export CC=arm-linux-gnueabihf-gcc
export CPPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
export PKG_CONFIG_PATH=${dest}/lib/pkgconfig
./configure \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --prefix=${dest}

arm-jpeg.sh

#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CC=arm-linux-gnueabihf-gcc
export CPPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
./configure \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --prefix=${dest}

arm-iconv.sh

#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CC=arm-linux-gnueabihf-gcc
export CPPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
./configure \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --prefix=${dest}

arm-xml.sh

#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CC=arm-linux-gnueabihf-gcc
export CPPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
./configure \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --with-zlib=${dest} \
  --without-python \
  --prefix=${dest}

This has to be done on the pi. The rest of them should be done there two. arm-glib.sh

#! /bin/bash
# execute this instead of ./configure
export dest=/home/ccoupe/Projects/shoesdeps/rpi
export CFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
export PKG_CONFIG_PATH="${dest}/lib/pkgconfig"
export LIBFFI_CFLAGS="-I${dest}/lib/libffi-3.2.1/include"
./configure \
  --disable-libmount --with-pcre=internal
  --prefix="${dest}"

That doesn't work. Login to the pi, cd to the directory and ```$ ./configure --prefix=/home/pi/Projects/shoesdeps/rpi --disable-libmount --with-pcre=internal``` Yes it will take time to run on the raspberry. `make` and `make install` -- more time. Look for .cache file. 

### [libcroco-0.6.12](http://ftp.gnome.org/pub/GNOME/sources/libcroco)
arm-croco.sh 
```sh
#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CC=arm-linux-gnueabihf-gcc
export CPPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
export PKG_CONFIG_PATH=/home/ccoupe/Projects/shoesdeps/rpi/lib/pkgconfig
./configure \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --prefix=${dest}

The configure runs but the make fails. Might as well switch to building on the PI.

export PKG_CONFIG_PATH=/home/pi/Projects/shoesdeps/rpi/lib/pkgconfig
./configure --prefix=/home/pi/Projects/shoesdeps/rpi

This one will cross compile - good because it's really slow on the pi.

arm-gettext.sh

#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CC=arm-linux-gnueabihf-gcc
export CPPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
./configure \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --prefix=${dest}

arm-gif.sh

#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CC=arm-linux-gnueabihf-gcc
export CPPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
./configure \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --prefix=${dest}

bzip-1.0.6

do this on the pi. make install PREFIX=/home/pi/Projects/shoesdeps/rpi

We build without harfbuzz. Then we'll comeback and build it again.

arm-freetype.sh

#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CC=arm-linux-gnueabihf-gcc
export CPPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
export LIBPNG_CFLAGS="-I ${dest}/include/libpng16"
export LIBPNG_LIBS="-L${dest}/lib -lpng16"
./configure \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --enable-shared \
  --with-harfbuzz=no \
  --prefix=${dest}

arm-fontconfig.sh

#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CC=arm-linux-gnueabihf-gcc
export CPPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
#export PKG_CONFIG_PATH="${dest}/lib/pkgconfig"
export FREETYPE_CFLAGS="-I${dest}/include/freetype2"
export LIBXML2_CFLAGS="-I${dest}/include/libxml2"
export LIBXML2_LIBS="-L/${dest}/lib -lxml2"
./configure \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --enable-libxml2 \
  --prefix=${dest}

fatal error glib.h -- seen this with ??

On Pi with PKG_CONFIG_PATH= ./configure --prefix=/home/pi/Projects/shoesdeps/rpi/

freetype - pass two

ran on pi, ./configure --prefix=/home/pi/Projects/shoesdeps/rpi --with-harfbuzz=yes --enable-shared

arm-pixman.sh

#! /bin/bash
# execute it instead of ./configure
export dest="/home/ccoupe/Projects/shoesdeps/rpi"
export CC=arm-linux-gnueabihf-gcc
export CPPFLAGS="-I${dest}/include"
export LDFLAGS="-L${dest}/lib"
export PNG_CFLAGS="-I${dest}/include/libpng16"
export PNG_LIBS="-L${dest}/lib -lpng16"
./configure \
  --build=x86_64-linux-gnu \
  --host=arm-linux-gnueabihf \
  --prefix=${dest}

do on pi with PKG_CONFIG_PATH set ./configure --prefix=/home/pi/Projects/shoesdeps/rpi It takes time.

do on pi with PKG_CONFIG_PATH set ./configure --prefix=/home/pi/Projects/shoesdeps/rpi --disable-gtk-doc --disable-installed-tests

do on pi with PKG_CONFIG_PATH set ./configure --prefix=/home/pi/Projects/shoesdeps/rpi

do on pi with PKG_CONFIG_PATH set

./configure --prefix=/home/pi/Projects/shoesdeps/rpi --disable-man --disable-gtk-doc --disable-always-build-tests --without-libtiff

Do you want tiff support? I don't think Shoes supports it. Newer versions like gdk-pixbuf-2.36.11 require it.

Here we go. This is what we've been working to do. 3.22.11 is what Raspbian Stretch uses. 3.22.27 has some build problems on the pi.

./configure --prefix=/home/pi/Projects/shoesdeps/rpi/ --disable-installed-tests --disable-gtk-doc --disable-man

Optional: On the pi desktop (or ssh -X into the pi) cd into the rpi/bin and

pi@pi3:~/Projects/shoesdeps/rpi/bin $ ./gtk3-demo
Fontconfig error: Cannot load default config file

Clearly, we can run gtk3 apps.

Turns out we need this for librsvg. And we need flex sudo apt-get install flex fl-dev configure is ./configure --prefix=/home/pi/Projects/shoesdeps/rpi/

./configure --prefix=/home/pi/Projects/shoesdeps/rpi --disable-introspection --disable-tools

Clone this wiki locally