(ubuntu)在andorid andk工程中使用ccache加速编译速度

环境

系统:Linux luogw-pc 3.5.0-36-generic #57~precise1-Ubuntu SMP Thu Jun 20 18:21:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

ndk:   ndk-r8d

cache: ccache version 3.1.6


第一步:安装ccache

sudo apt-get install ccache


第二步:配置ccache

添加环境变量 export NDK_CCACHE=ccache


第三步:修改 android-ndk-r8e/build/core/default-build-commands.mk

注:红色部份为修改的内容,原内容被注释掉

#
# IMPORTANT: The following definitions must use lazy assignment because
# the value of TOOLCHAIN_PREFIX or TARGET_CFLAGS can be changed later by
# the toolchain's setup.mk script.
#


ifneq ($(findstring ccc-analyzer,$(CC)),)
TARGET_CC       = $(CC)
else
#TARGET_CC       = $(TOOLCHAIN_PREFIX)gcc
TARGET_CC       = ccache $(TOOLCHAIN_PREFIX)gcc
endif
TARGET_CFLAGS   =


ifneq ($(findstring c++-analyzer,$(CXX)),)
TARGET_CXX      = $(CXX)
else
#TARGET_CXX      = $(TOOLCHAIN_PREFIX)g++
TARGET_CXX      = ccache $(TOOLCHAIN_PREFIX)g++
endif
TARGET_CXXFLAGS = $(TARGET_CFLAGS) -fno-exceptions -fno-rtti

实践对比:

使用ccache前后情况对比如下

 

luogw@luogw-pc:~/study/bitmap-plasma$ ccache -s
cache directory                     /home/luogw/.ccache
cache hit (direct)                     0
cache hit (preprocessed)               0
cache miss                             0
files in cache                         0
cache size                             0 Kbytes
max cache size                       1.0 Gbytes
luogw@luogw-pc:~/study/bitmap-plasma$ time ndk-build
Gdbserver      : [arm-linux-androideabi-4.7] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
Gdbserver      : [arm-linux-androideabi-4.7] libs/armeabi-v7a/gdbserver
Gdbsetup       : libs/armeabi-v7a/gdb.setup
Compile thumb  : plasma <= plasma.c
SharedLibrary  : libplasma.so
Install        : libplasma.so => libs/armeabi/libplasma.so
Compile thumb  : plasma <= plasma.c
SharedLibrary  : libplasma.so
Install        : libplasma.so => libs/armeabi-v7a/libplasma.so

real	0m0.226s
user	0m0.128s
sys	0m0.032s
luogw@luogw-pc:~/study/bitmap-plasma$ ccache -s
cache directory                     /home/luogw/.ccache
cache hit (direct)                     0
cache hit (preprocessed)               0
cache miss                             2
called for link                        2
multiple source files                  2
files in cache                         6
cache size                           108 Kbytes
max cache size                       1.0 Gbytes
luogw@luogw-pc:~/study/bitmap-plasma$ rm -r libs/ obj/
luogw@luogw-pc:~/study/bitmap-plasma$ time ndk-build
Gdbserver      : [arm-linux-androideabi-4.7] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
Gdbserver      : [arm-linux-androideabi-4.7] libs/armeabi-v7a/gdbserver
Gdbsetup       : libs/armeabi-v7a/gdb.setup
Compile thumb  : plasma <= plasma.c
SharedLibrary  : libplasma.so
Install        : libplasma.so => libs/armeabi/libplasma.so
Compile thumb  : plasma <= plasma.c
SharedLibrary  : libplasma.so
Install        : libplasma.so => libs/armeabi-v7a/libplasma.so

real	0m0.114s
user	0m0.052s
sys	0m0.008s
luogw@luogw-pc:~/study/bitmap-plasma$ ccache -s
cache directory                     /home/luogw/.ccache
cache hit (direct)                     2
cache hit (preprocessed)               0
cache miss                             2
called for link                        4
multiple source files                  4
files in cache                         6
cache size                           108 Kbytes
max cache size                       1.0 Gbytes


 

参考文章:

1)http://www.41post.com/4509/programming/android-use-ccache-with-android-ndk-in-cygwin

2)http://www.mirwing.com/2011/11/android-android-ndk-revision-7.html

 

posted @ 2013-07-29 19:42  javawebsoa  Views(747)  Comments(0Edit  收藏  举报