一、android源码编译加速
当你删掉out/target目录或者使用make clean清空输出重新编译源码的时候,编译时间通常都很漫长。
其实这个问题很容易解决,Android官方为我们带来了解决方案–ccache编译器缓存。
官方这么讲:
You can optionally tell the build to use the ccache compilation tool. Ccache acts as a compiler cache that can be used to speed-up rebuilds. This works very well if you do “make clean” often, or if you frequently switch between different build products.
设置方法:
在你home主目录的.bashrc中加入:
export USE_CCACHE=1
如果你需要指定一个特殊的缓存目录,也需要在.bashrc中加入,不指定则为你当前用户目录下的.ccache。
export CCACHE_DIR=/home/mokee/.ccache
export PATH = /usr/lib/ccache:$PATH
在MoKee OpenSource主目录中运行,50G~100G之间手动指定:
prebuilts/misc/linux-x86/ccache/ccache -M 50G
大功告成,开始编译吧!
二、linux内核编译加速
修改内核根目录的Mafile文件,在交叉编译变量“CROSS_COMPILE”前添加ccache即可
$ vi Makefile
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH ?= arm
CROSS_COMPILE ?= ccache /usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-
#CROSS_COMPILE ?= /usr/local/arm/4.5.1/bin/arm-none-linux-gnueabi-
CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
三、ccache的使用
简介
如果你经常编译大型的C/C++工程,不使用ccache你就out了。
英文说明:cache is a compiler cache. It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again. Supported languages are C, C++, Objective-C and Objective-C++.
1. 安装 ccache
sudo apt-get install ccache
2. Usage
ccache -s # 显示状态参数 (s是英语status的缩写,表示《状态》)
ccache -C # 清除缓存(C是大写的,是英语Clear的缩写,表示《清除》)
使用ccache
- 编译指令前增加ccache. $ ccache gcc xxx
- 创建软链接。 $ ln -s ccache /usr/local/bin/gcc
建议使用第一种方式,因为ccache偶尔也犯晕,当由于它出现错误的时候, 很难看出端倪。曾在某次编译某份代码时,ccache对某个编译选项的判断失误导致编译失败,死活查不出来为什么原因。所以当出现某些怪异的现象时,请用正常的方式编译试试。
3. 在交叉编译内核时,编译速度也快了近十倍。
time ./build.sh
real 3m4.146s
user 10m30.640s
sys 0m37.138s
make clean -j4
time ./build.sh
real 0m43.477s
user 1m0.564s
sys 0m14.913s
4.查看ccache的状态用watch ccache -s
Every 2.0s: ccache -s Thu Nov 23 16:35:37 2017
cache directory /home/litin/.ccache
cache hit (direct) 154
cache hit (preprocessed) 15
cache miss 3197
called for link 587
called for preprocessing 23
can't use precompiled header 1
unsupported source language 158
no input file 515
files in cache 8534
cache size 353.8 Mbytes
max cache size 40.0 Gbytes
参考资料:http://blog.csdn.net/jiulousanti/article/details/23343687
http://blog.csdn.net/zgl07/article/details/41819495
http://blog.csdn.net/qq_27062249/article/details/53642444