
Stanislav Brabec wrote:
I just tried to analyze the cost of the cross-compilation support in OpenSUSE BS.
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 - chroot/sysroot. 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 /work/CDs/all/full-ppc/suse/ppc/{glibc,filesystem,glibc-devel,coreutils,pam,libacl,libattr,libxcrypt,libdb-4_5,cracklib,cracklib-dict-small,bash,libreadline5,ncurses,audit-libs,info,zlib,libbz2-1,libzio,perl,gzip,perl-base,fillup,grep,sed,gdbm,diffutils}.rpm /work/CDs/all/full-ppc/suse/noarch/linux-kernel-headers.rpm rpm -Uhv /work/CDs/all/full-x86_64/suse/x86_64/{gcc42,gcc42-ada,libada42,cpp42,libgcc42,libmudflap42,libgomp42,gcc-ada,gcc}.rpm 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: --build=%{_target_platform} Packages with ./configure: Now I hacked the spec and added needed args: --host=x86_64-suse-linux --build=powerpc-suse-linux-gnu --target=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 to 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: http://idea.opensuse.org/content/ideas/design-and-implement-sysroot-support-... 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 packages. -- Best Regards / S pozdravem, Stanislav Brabec software developer --------------------------------------------------------------------- SUSE LINUX, s. r. o. e-mail: sbrabec@suse.cz Lihovarská 1060/12 tel: +420 284 028 966 190 00 Praha 9 fax: +420 284 028 951 Czech Republic http://www.suse.cz/ --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-buildservice+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-buildservice+help@opensuse.org