Cross Compilation

Bigloo is very portable and can be cross-compiled for most Posix-platforms. As long as there exists a C (cross-)compiler for the platform and the garbage collector is supported on the targeted platform there is a good chance that Bigloo or Bigloo-compiled programs will run on the platform.

This chapter describes how to cross-compile Bigloo with a C cross-compiler. Following established conventions we will call the platform where the compiled programs should run the Host platform and we will call the build platform where we actually compile the programs the Build platform.

Introduction

We assume that the host- and build-system are not the same, and that there exists a C cross-compiler CC running on the build system producing executables for the host system.

In order to execute programs on the host, it is however not sufficient to simply compile Bigloo-produced programs with this compiler. Indeed, these programs depend on the Bigloo-library which thus has to exist on the host-platform.

Building a cross-compilation environment is done in two phases: Programs can then be cross-compiled simply by telling Bigloo to use the host-library.

Note: if the cross-compiled executable uses shared libraries, then Bigloo's cross-compiled libraries have to be copied to the host platform. Static executables are self-contained and can be run without modification on the host.

Building the Bigloo library for the host-platform

We assume that we have a C cross-compiler CC and an empty Bigloo source tree. As a first step the configuration script must be executed. However, Bigloo's configure script requires some runtime-information from the host and thus needs access to the host-machine. This is accomplished by passing a hostsh-script to configure.

Hostsh

A hostsh script is passed to Bigloo's configuration script and is invoked whenever a command should be executed on the host-side.

There are already three example scripts inside Bigloo's source tree that are located in the examples/hostsh directory.

Building

Armed with a working cross-compiler CC and a script HOSTSH that invokes commands and executables on the host side the configure invocation is simple:

./configure \
  --prefix=[PREFIX_PATH_ON_TARGET] \
  --cc=[CC] \
  --hostsh=[HOSTSH] \
  --thirdparty-configure-opt=[options]
Other configuration options are of course possible too.

For instance, for configuring Bigloo for a Raspberry model 2.

./configure \
  --cc=/usr/bin/arm-linux-gnueabi-gcc-6 \
  --hostsh=$PWD/ssh-copy.sh \
  --thirdparty-configure-opt=--host=arm-linux-gnueabi
Once the configuration has finished one can build Bigloo (and its library) simply by calling make. This will build the libraries as well as the binaries.

If shared libraries are needed on the host platform one still needs to install them. The easiest way is probably to install them temporary on a build system inside a special directory and then copy them from there to the host system.

make DESTDIR=[temporary-directory] install
Only the lib directory is needed on the host side.

Cross Compiling Bigloo Programs

Once the host-library exists cross compilation is straightforward. Using the -lib-dir compilation flag one simply has to pass the library-directory to Bigloo.

bigloo -lib-dir [path-to-cross-compiled-library] ....
Bigloo will automatically use the same C cross-compiler and compilation flags that have been used to build the library.

Caveats

In general Bigloo's cross-compilation works fine, but developers should be aware of some limitations:

Examples

In this example we will show how to compile for a host-machine that has ssh-access.

We assume With these preconditions satisfied we can first build Bigloo for the host-system:
$ ./configure --hostsh="$PWD/examples/hostsh/ssh/ssh-copy.sh [host]" --cc=[CC]
$ make
$ make DESTDIR=[TMP] install
Now let's compile a simple hello-world for the host.

$ cat > /tmp/hello.scm <<EOF
(module hello (main main))
(define (main args) (print "hello world"))
EOF

$ bigloo -static-all-bigloo -lib-dir [TMP]/lib/3.2c/ -o /tmp/hello /tmp/hello.scm
The generated executable should be able to run on the host.