从busybox官网上下载busybox最新版源码:http://www.busybox.net/downloads/
tar -xvf busybox-1.23.2.tar.bz2
解压后的源码里,configs文件压有android版本的配置脚本:
android2_defconfig android_defconfig android_ndk_defconfig
我选用的是android2_defconfig
1) export arm的编译工具:
export PATH=$PATH:/xxx/yyy/android_source/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin
2)修改编译工具
打开android2_defconfig
将
CONFIG_CROSS_COMPILER_PREFIX=" arm-eabi-"
改为
CONFIG_CROSS_COMPILER_PREFIX="arm-linux-androideabi-"
3)修改sysroot路径
由于arm-linux-androideabi-4.6目录下没有sysroot目录,因此需要指定,否则编译时会出现找不到一些头文件的错误,如:
include/platform.h:141:20: fatal error:limits.h: No such file or directory
compilation terminated.
make[1]: *** [applets/applets.o]错误 1
make: *** [applets_dir]错误 2
打开android2_defconfig
在CONFIG_CROSS_COMPILER_PREFIX下再添加一行:
CONFIG_SYSROOT=":/xxx/yyy/android_source/prebuilts/ndk/android-ndk-r7/platforms/android-14/arch-arm"
或者是在make android2_defconfig之后,进入配置选项里改,其位置是在:
Busybox Settings --->
BuildOptions --->
() Path to sysroot (NEW)
4)编译
make android2_defconfig //选项编译脚本
make //开始编译
1) export mips的编译工具:
export PATH=$PATH:/xxx/yyy/android_source/prebuilts/gcc/linux-x86/mips/mipsel-linux-android-4.7/bin
2)修改编译工具
打开android2_defconfig
将
CONFIG_CROSS_COMPILER_PREFIX="arm-eabi-"
改为
CONFIG_CROSS_COMPILER_PREFIX="mipsel-linux-android-"
3)修改sysroot路径
mipsel-linux-android-4.7目录下已包含sysroot目录,不需要修改,默认就行。
4)编译
make android2_defconfig //选项编译脚本
make //开始编译
编译时会出现几次错误,处理原则是将该错误对应的工具选项关闭,实际上很多工具用不上,如果确实需要,才对错误进行修复。
下面是几个错误的处理过程:
Error:
coreutils/touch.c: In function'touch_main':
coreutils/touch.c:171:21: error: 'lutimes'undeclared (first use in this function)
coreutils/touch.c:171:21: note: eachundeclared identifier is reported only once for each function it appears in
make[1]: *** [coreutils/touch.o]错误 1
make: *** [coreutils]错误 2
Solution:
从coreutils/touch.c可看出是core utils里的touch工具出问题,所以进入编译选项coreutiles将touch的选项的勾去掉。如下:
make menuconfig //配置编译选项
Coreutils --->
[*]touch
将touch去掉,然后退出保存,再继续编译。
Error:
networking/udhcp/dhcpc.c: In function'udhcp_recv_raw_packet':
networking/udhcp/dhcpc.c:852:24: error: invalidapplication of 'sizeof' to incomplete type 'struct tpacket_auxdata'
networking/udhcp/dhcpc.c:915:26: error:'PACKET_AUXDATA' undeclared (first use in this function)
networking/udhcp/dhcpc.c:915:26: note: eachundeclared identifier is reported only once for each function it appears in
networking/udhcp/dhcpc.c:922:11: error:dereferencing pointer to incomplete type
networking/udhcp/dhcpc.c:852:16: warning:unused variable 'cmsgbuf' [-Wunused-variable]
networking/udhcp/dhcpc.c: In function'udhcp_raw_socket':
networking/udhcp/dhcpc.c:1050:33: error:'PACKET_AUXDATA' undeclared (first use in this function)
make[1]: *** [networking/udhcp/dhcpc.o]错误 1
make: *** [networking/udhcp]错误 2
Solution:
去掉:
Networking Utilities --->
[*]udhcp client (udhcpc)
Error:
libbb/lib.a(pw_encrypt.o): In function`pw_encrypt':
pw_encrypt.c:(.text.pw_encrypt+0x10):undefined reference to `crypt'
libbb/lib.a(replace.o): In function`xmalloc_substitute_string':
replace.c:(.text.xmalloc_substitute_string+0xa8):undefined reference to `mempcpy'
replace.c:(.text.xmalloc_substitute_string+0xbc):undefined reference to `mempcpy'
collect2: error: ld returned 1 exit status
make: *** [busybox_unstripped]错误 1
Solution:
Crypt错误改起来麻烦,就直接将libbb/ pw_encrypt.c里的crypt(clear, salt);摒蔽掉了。
libbb/replace.c则将mempcpy改为memcpy
然后编译就通过了,并在源码根目录下产生busybox,如果只是要提取busybox里的某个工具,则继续下面的编译。
将Don't use/usr选项勾上,会将工具包编出到源码根目录下。
make menuconfig //配置编译选项
Busybox Settings --->
GeneralConfiguration --->
[*]Don't use /usr
make //开始编译
编译完成后会生成_install文件夹,里面有各种工具文件。