Mailinglist Archive: opensuse-buildservice (349 mails)

< Previous Next >
[opensuse-buildservice] cross-compilation (in OBS) - success report
  • From: Stanislav Brabec <sbrabec@xxxxxxx>
  • Date: Fri, 30 Nov 2007 16:57:43 +0100
  • Message-id: <1196438263.26338.65.camel@xxxxxxxxxxxxxx>
Stanislav Brabec wrote:

I just tried to analyze the cost of the cross-compilation support in

I just experimentally cross-compiled several packages from the 10.3
sources. It is not so complicated as it seemed before, but I had to
fight with many minor problems.

I decided to build few simple powerpc RPM on x86_64 machine:
package using ./configure: gzip
package using %configure: lha
package using make: jpeg2ps

I did not test shared library package yet. It needs cross libtool
package and I did not yet created it.

1. Prepare build system

OpenSuSE does not provide full cross compiler package and I failed to
compile my own. Hopefully, SuSE provides cross binutils and cross
compilation support for icecream. I abused it, unpacked, added compiler
libraries from the native powerpc build.

Richard Guenther probably knows, how to build full cross compiler
package. It should be trivial.

Because i am not expert in Build Service, I built build environment
manually in my live system, thinking how it is possible to do by the
Build Service.

Thinking about it and OBS, I can imagine two approaches:

1a. Install packages from BuildRequires for both host and target.

Complicated and maybe superfluous. Most checks will not find them or
fail anyway.

1b. Prepare large enough native tool set.

It will include everything we would need for cross compilation:
native compiler and binutils, cross compiler and binutils, language
tools (sed, awk, bison,...), generator tools (docbook, help2man,...)

This is a way used by existing cross compilation toolchains.

This is easy to do: We could simply add it to the XEN OBS image and
modify chroot preparation tools to use another directory -

2. Prepare build environment

This is a trivial task for the Build Service. I did it manually:
mkdir -p /sysroot/var/lib/rpm
rpm -r /sysroot --initdb
rpm --noscripts -r /root/sysroot -Uhv
rpm -Uhv

Compilation failure found only one trivial compile-critical breakage
caused by --noscripts. Easy to fix.

ln -s asm-powerpc /sysroot/usr/include/asm

3. Cross compilation

Basically it works, but need to pay attention to it in the spec files.
It means:
- Run testsuite only for native build.
- Never use gcc and ld directly, but use proper variables.

I used following command line. Depending on toolchain used, it may vary
(and it will be different for sure with a real cross compiler instead of
my hacks):
PATH=/opt/cross/bin:$PATH CC="gcc --sysroot=/sysroot" LD="gcc
--sysroot=/sysroot" AS=powerpc-linux-as RANLIB=powerpc-linux-ranlib
AR=powerpc-linux-ar STRIP=powerpc-linux-strip rpmbuild -ba
--target=ppc-suse-linux *.spec
(LD should probably have a different value)

Problems discovered:

Package with %configure:

rpm provides --target command line argument, which is intended to cross
compile. But it generates by mistake %configure for native compilation
of cross compiler. One liner fix in /usr/lib/rpm/macros:

Packages with ./configure:
Now I hacked the spec and added needed args:
--host=x86_64-suse-linux --build=powerpc-suse-linux-gnu
But I am nearly sure that playing a bit with CONFIG_SITE would prevent
this requirements.

Package with make:
spec file has to provide needed flags explicitly. One line change:
make CC="$CC" LD="$LD"

General problems of configure:

AC_CHECK_FILE have no idea about sysroot and one has to provide cache
values. It should be improvable on auttools level:

Some other checks can not have any idea about sysroot and target system
by principle. One has to provide cache values.
I guess it should be possible to generate such cache both per package
and globally (maybe better, it is platform specific).

And we are complete.

Package build, installs and runs on powerpc.

4. Fix remaining problem

As I wrote above, some spec files has to be changed to do things more
carefully and many packages has to be fixed.

But this example shows, that cross compilation is an usable way to make

Best Regards / S pozdravem,

Stanislav Brabec
software developer
SUSE LINUX, s. r. o. e-mail: sbrabec@xxxxxxx
Lihovarsk√° 1060/12 tel: +420 284 028 966
190 00 Praha 9 fax: +420 284 028 951
Czech Republic

To unsubscribe, e-mail: opensuse-buildservice+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse-buildservice+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups