前面提到过利用 crosstool 快速编译 cross compiler,对于简单的没有太多外部依赖的程序来说,这已经足够了。但是对于基于 GNU autotools 进行配置编译的软件包来说,常常会因为关联到 HOST 上的外部依赖库文件,因此要求我们先要用 cross compiler 编译这些外部依赖库,然后修改或者配置该软件包的外部关联库的查找路径。另外configure通常会利用小程序检测对应的依赖是否存在,如果是不同体系 cpu 间 cross compile,那么这些小程序将无法在 host 运行。还是有不少工作需要去作。
如果利用另外一个工具 scratchbox,那么可以简化上面的流程。
scratchbox [1 ] is a cross-compilation toolkit designed to make embedded Linux application development easier. It provides a full set of tools to integrate and cross-compile an entire Linux distribution. Scratchbox supports cross-compiling for ARM and PowerPC targets. Especially Debian [2 ] is supported, but Scratchbox has also been used to cross-compile e.g. Slackware for ARM.
Scratchbox provides a sandboxed build environment which offers a controlled set of tools and utilities needed for cross-compilation. It is an environment in which it is easy to assure that the intended versions of libraries, headers and other similar files are used during the build. Most of the higher level software built using GNU Autotools do not cross-compile well in their as-is form, Scratchbox solves this problem by allowing the small test programs (used by the configure script to test for availability of features in the environment) to run transparently either using an emulator or through sbrsh protocol between Scratchbox and actual target device. In practice software configuration and building using Scratchbox is quite identical to how it's done for the desktop.
Scratchbox has been designed to allow multiple application developers work simultaneously on a single host machine. Each developer has his private user account, and all configuration is developer-specific.
This document describes Scratchbox install procedure and how Scratchbox can be used to cross-compile applications to ARM target platform.
下面简单介绍 scratchbox 的安装。http://www.scratchbox.org/documentation/user/scratchbox-1.0/html/installdoc.html
这里我们只安装下面三个 package
Base (required):
* scratchbox-core - environment, common tools and host compiler
* scratchbox-libs - libraries required by core, devkits and toolchains
; 解压到 /scratchbox
[root@webhost tmp]# tar zxf scratchbox-core-1.0.17-i386.tar.gz -C /
[root@webhost tmp]# tar zxf scratchbox-libs-1.0.17-i386.tar.gz -C /
[root@webhost tmp]# tar xzf scratchbox-toolchain-host-gcc-1.0.17-i386.tar.gz -C /
[root@webhost tmp]# cd /scratchbox/
[root@webhost scratchbox]# ls -la
total 56
drwxr-xr-x 9 root root 4096 Oct 14 12:16 .
drwxr-xr-x 11 root root 4096 Oct 14 12:14 ..
drwxr-xr-x 4 root root 4096 Oct 14 12:16 compilers
drwxr-xr-x 2 root root 4096 Aug 27 21:09 doc
drwxr-xr-x 5 root root 4096 Aug 27 23:07 etc
drwxr-xr-x 4 root root 4096 Aug 27 21:08 host_shared
-rwxr-xr-x 1 root root 7165 Aug 27 21:07 login
drwxr-xr-x 3 root root 4096 Aug 27 23:07 packages
-rw-r--r-- 1 root root 42 Aug 27 21:07 README
-rwxr-xr-x 1 root root 1414 Aug 27 21:07 run_me_first.sh
drwxr-xr-x 2 root root 4096 Aug 27 21:27 sbin
drwxr-xr-x 11 root root 4096 Oct 14 12:16 tools
; setup Scratchbox
[root@webhost /]# /scratchbox/run_me_first.sh
Do you want to use sudo mode? [yes/no] (no):
Give the name of the scratchbox group (sbox):
The group 'sbox' does not seem to exist!
Would you like me to create the group 'sbox' for you? [yes/no] (yes):
Creating group "sbox"...
Stopping Scratchbox: umount, binfmt_misc.
Starting Scratchbox: binfmt_misc, mount.
Now you should add one or more users with /opt/scratchbox/sbin/sbox_adduser
; 为 scratchbox 增加用户,该用户可以是你的普通 linux 帐号
[root@webhost /]# /scratchbox/sbin/sbox_adduser gang
Add user gang to group 'sbox'? [yes/no] (yes):
Scratchbox user account for user gang added
; 用自己的 linux 帐号登录 scratchbox
[root@webhost /]# su - gang
-bash-3.00$ /scratchbox/login
You dont have active target in scratchbox chroot.
Please create one by running "sb-menu" before continuing
Welcome to Scratchbox, the cross-compilation toolkit!
Use 'sb-menu' to change your compilation target.
See /scratchbox/doc/ for documentation.
sb-conf: No current target
[sbox-: ~] >
; 用 sb-menu 创建一个 target,因为前面我们只安装了 host-gcc toolchain,因此这里也只能选择我们需要创建的 target 对应这个 toolchain。
; 后面我们可以自己编译符合要求的新的 toolchain
; traget 建立后,我们可以测试一下安装
[sbox-MYTARGET: ~] > tar xfz /scratchbox/packages/hello-world.tar.gz
[sbox-MYTARGET: ~] > cd hello-world
[sbox-MYTARGET: ~/hello-world] > ./autogen.sh
[sbox-MYTARGET: ~/hello-world] > make [sbox-MYTARGET: ~/hello-world] > file hello