1*4882a593Smuzhiyun// -*- mode:doc; -*- 2*4882a593Smuzhiyun// vim: set syntax=asciidoc: 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun[[ccache]] 5*4882a593Smuzhiyun==== Using +ccache+ in Buildroot 6*4882a593Smuzhiyun 7*4882a593Smuzhiyunhttp://ccache.samba.org[ccache] is a compiler cache. It stores the 8*4882a593Smuzhiyunobject files resulting from each compilation process, and is able to 9*4882a593Smuzhiyunskip future compilation of the same source file (with same compiler 10*4882a593Smuzhiyunand same arguments) by using the pre-existing object files. When doing 11*4882a593Smuzhiyunalmost identical builds from scratch a number of times, it can nicely 12*4882a593Smuzhiyunspeed up the build process. 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun+ccache+ support is integrated in Buildroot. You just have to enable 15*4882a593Smuzhiyun+Enable compiler cache+ in +Build options+. This will automatically 16*4882a593Smuzhiyunbuild +ccache+ and use it for every host and target compilation. 17*4882a593Smuzhiyun 18*4882a593SmuzhiyunThe cache is located in +$HOME/.buildroot-ccache+. It is stored 19*4882a593Smuzhiyunoutside of Buildroot output directory so that it can be shared by 20*4882a593Smuzhiyunseparate Buildroot builds. If you want to get rid of the cache, simply 21*4882a593Smuzhiyunremove this directory. 22*4882a593Smuzhiyun 23*4882a593SmuzhiyunYou can get statistics on the cache (its size, number of hits, 24*4882a593Smuzhiyunmisses, etc.) by running +make ccache-stats+. 25*4882a593Smuzhiyun 26*4882a593SmuzhiyunThe make target +ccache-options+ and the +CCACHE_OPTIONS+ variable 27*4882a593Smuzhiyunprovide more generic access to the ccache. For example 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun----------------- 30*4882a593Smuzhiyun# set cache limit size 31*4882a593Smuzhiyunmake CCACHE_OPTIONS="--max-size=5G" ccache-options 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun# zero statistics counters 34*4882a593Smuzhiyunmake CCACHE_OPTIONS="--zero-stats" ccache-options 35*4882a593Smuzhiyun----------------- 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun+ccache+ makes a hash of the source files and of the compiler options. 38*4882a593SmuzhiyunIf a compiler option is different, the cached object file will not be 39*4882a593Smuzhiyunused. Many compiler options, however, contain an absolute path to the 40*4882a593Smuzhiyunstaging directory. Because of this, building in a different output 41*4882a593Smuzhiyundirectory would lead to many cache misses. 42*4882a593Smuzhiyun 43*4882a593SmuzhiyunTo avoid this issue, buildroot has the +Use relative paths+ option 44*4882a593Smuzhiyun(+BR2_CCACHE_USE_BASEDIR+). This will rewrite all absolute paths that 45*4882a593Smuzhiyunpoint inside the output directory into relative paths. Thus, changing 46*4882a593Smuzhiyunthe output directory no longer leads to cache misses. 47*4882a593Smuzhiyun 48*4882a593SmuzhiyunA disadvantage of the relative paths is that they also end up to be 49*4882a593Smuzhiyunrelative paths in the object file. Therefore, for example, the debugger 50*4882a593Smuzhiyunwill no longer find the file, unless you cd to the output directory 51*4882a593Smuzhiyunfirst. 52*4882a593Smuzhiyun 53*4882a593SmuzhiyunSee https://ccache.samba.org/manual.html#_compiling_in_different_directories[the 54*4882a593Smuzhiyunccache manual's section on "Compiling in different directories"] for 55*4882a593Smuzhiyunmore details about this rewriting of absolute paths. 56