Archive for March, 2009

How to Cross Compile ICU

Tuesday, March 3rd, 2009

Why ICU

ICU (International Components for Unicode) libraries provide robust and full-featured Unicode services (refer to http://www.icu-project.org). Gtk+ port of WebKit requires ICU. Not proper installation of ICU can cause problem in Webkit/Gtk+ (refer to https://bugs.webkit.org/show_bug.cgi?id=17487).

Not compilable in Scratchbox

Due to failure of redirecting path of “gcc” to the corresponding one in cross-compilation toochain (the same problem that compiling Python has) according to the transparency mechanism.

Not really cross-compilable in the Host

After binaries and shared libraries are built from the source, the binary “pkgdata” and its corresponding shared libraries are directly executed in order to package the ICU data. Since it’s cross compiled, the built binary “pkgdata” is not executable on the host, which makes the building process fail.

However, there is work around

It is largely based on the approach by http://cataclysm.cx/git/cgit.cgi?url=aros/icu/tree/BUILD.AROS. However, changes are made to enable shared libraries instead of only static linking.

– First download ICU and extract the source tgz file. Then go to the extracted source directory:

cd source

– Build PC binaries and backup:

./configure --disable-threads
make
cp -r bin bin.linux
cp -r data data.linux
cp -r lib lib.linux
cp -r tools tools.linux

– Build ARM binaries and include the path to cross-compilers. In my case, I re-use the same toolchain from Scratchbox:

make distclean
PATH=/scratchbox/compilers/arm-linux-cs2007q3-51sb1/bin:$PATH ./configure --host=arm-none-linux-gnueabi
PATH=/scratchbox/compilers/arm-linux-cs2007q3-51sb1/bin:$PATH make

– There will be error: “/bin/sh: ../bin/icupkg: cannot execute binary file”. The build system tries to execute “icupkg” to package ICU data files, it will fail since “icupkg” is ARM binary. Anyway, back up ARM binaries first:

cp -r bin bin.arm
cp -r data data.arm

– Restore “bin” and “data” with PC binaries:

cp -r bin.linux/* bin
cp -r data.linux/* data

– “icupkg” needs to resolve links to PC binaries of shared libraries, so LD_LIBRARY_PATH is appended. The original LD_LIBRARY_PATH is kept because then build system still needs ARM binaries of shared libraries in the end in order to finalize building and installing:

PATH=/scratchbox/compilers/arm-linux-cs2007q3-51sb1/bin:$PATH LD_LIBRARY_PATH=[ICU_SRC_ABSOLUTE_PATH]/source/lib.linux:$LD_LIBRARY_PATH make
[PLACE_HOLDER_TO_SOLVE_STUPID_IE_OVERFLOW_VERTICAL_SCROLL_BAR_PROBLEM]

– Get “uconv” built and restore the ARM binaries of “bin”:

rm bin/uconv
PATH=/scratchbox/compilers/arm-linux-cs2007q3-51sb1/bin:$PATH LD_LIBRARY_PATH=[ICU_SRC_ABSOLUTE_PATH]/source/lib.linux:$LD_LIBRARY_PATH make
cp bin/uconv bin.arm
cp bin.arm/* bin

– Use PC binaries of “pkgdata” to install the files in place and restore the ARM binary of “pkgdata” after installing:

cp bin.linux/pkgdata bin
make install PATH=/scratchbox/compilers/arm-linux-cs2007q3-51sb1/bin:$PATH LD_LIBRARY_PATH=/home/esonyua/Projs/Icu/icu/source/lib.linux:$LD_LIBRARY_PATH DESTDIR=[INSTALL_DIR]
cp bin.arm/pkgdata [INSTALL_DIR]/usr/local/bin