1ccache(1) ccache(1)
2
3
4
6 ccache - a fast compiler cache
7
9 ccache [OPTION]
10
11 ccache <compiler> [COMPILER OPTIONS]
12
13 <compiler> [COMPILER OPTIONS]
14
16 ccache is a compiler cache. It speeds up re-compilation of C/C++ code
17 by caching previous compiles and detecting when the same compile is
18 being done again.
19
21 Here is a summary of the options to ccache.
22
23 -s show statistics summary
24 -z zero statistics
25 -c run a cache cleanup
26 -C clear the cache completely
27 -F <maxfiles> set maximum files in cache
28 -M <maxsize> set maximum size of cache (use G, M or K)
29 -h this help page
30 -V print version number
31
32
33
34
36 These options only apply when you invoke ccache as "ccache". When
37 invoked as a compiler none of these options apply. In that case your
38 normal compiler options apply and you should refer to your compilers
39 documentation.
40
41 -h Print a options summary page
42
43 -s Print the current statistics summary for the cache. The statis‐
44 tics are stored spread across the subdirectories of the cache.
45 Using "ccache -s" adds up the statistics across all subdirecto‐
46 ries and prints the totals.
47
48 -z Zero the cache statistics.
49
50 -V Print the ccache version number
51
52 -c Clean the cache and re-calculate the cache file count and size
53 totals. Normally the -c option should not be necessary as ccache
54 keeps the cache below the specified limits at runtime and keeps
55 statistics up to date on each compile. This option is mostly
56 useful if you manually modify the cache contents or believe that
57 the cache size statistics may be inaccurate.
58
59 -C Clear the entire cache, removing all cached files.
60
61 -F maxfiles
62 This sets the maximum number of files allowed in the cache. The
63 value is stored inside the cache directory and applies to all
64 future compiles. Due to the way the value is stored the actual
65 value used is always rounded down to the nearest multiple of 16.
66
67 -M maxsize
68 This sets the maximum cache size. You can specify a value in
69 gigabytes, megabytes or kilobytes by appending a G, M or K to
70 the value. The default is gigabytes. The actual value stored is
71 rounded down to the nearest multiple of 16 kilobytes.
72
74 There are two ways to use ccache. You can either prefix your compile
75 commands with "ccache" or you can create a symbolic link between ccache
76 and the names of your compilers. The first method is most convenient if
77 you just want to try out ccache or wish to use it for some specific
78 projects. The second method is most useful for when you wish to use
79 ccache for all your compiles.
80
81 To install for usage by the first method just copy ccache to somewhere
82 in your path.
83
84 To install for the second method do something like this:
85
86
87
88 cp ccache /usr/local/bin/
89 ln -s /usr/local/bin/ccache /usr/local/bin/gcc
90 ln -s /usr/local/bin/ccache /usr/local/bin/g++
91 ln -s /usr/local/bin/ccache /usr/local/bin/cc
92
93
94
95 This will work as long as /usr/local/bin comes before the path to gcc
96 (which is usually in /usr/bin). After installing you may wish to run
97 "which gcc" to make sure that the correct link is being used.
98
99 Note! Do not use a hard link, use a symbolic link. A hardlink will
100 cause "interesting" problems.
101
103 When run as a compiler front end ccache usually just takes the same
104 command line options as the compiler you are using. The only exception
105 to this is the option '--ccache-skip'. That option can be used to tell
106 ccache that the next option is definitely not a input filename, and
107 should be passed along to the compiler as-is.
108
109 The reason this can be important is that ccache does need to parse the
110 command line and determine what is an input filename and what is a com‐
111 piler option, as it needs the input filename to determine the name of
112 the resulting object file (among other things). The heuristic ccache
113 uses in this parse is that any string on the command line that exists
114 as a file is treated as an input file name (usually a C file). By using
115 --ccache-skip you can force an option to not be treated as an input
116 file name and instead be passed along to the compiler as a command line
117 option.
118
120 ccache uses a number of environment variables to control operation. In
121 most cases you won't need any of these as the defaults will be fine.
122
123 CCACHE_DIR
124 the CCACHE_DIR environment variable specifies where ccache will
125 keep its cached compiler output. The default is "$HOME/.ccache".
126
127 CCACHE_TEMPDIR
128 the CCACHE_TEMPDIR environment variable specifies where ccache
129 will put temporary files. The default is the same as CCACHE_DIR.
130 Note that the CCACHE_TEMPDIR path must be on the same filesystem
131 as the CCACHE_DIR path, so that renames of files between the two
132 directories can work.
133
134 CCACHE_LOGFILE
135 If you set the CCACHE_LOGFILE environment variable then ccache
136 will write some log information on cache hits and misses in that
137 file. This is useful for tracking down problems.
138
139 CCACHE_PATH
140 You can optionally set CCACHE_PATH to a colon separated path
141 where ccache will look for the real compilers. If you don't do
142 this then ccache will look for the first executable matching the
143 compiler name in the normal PATH that isn't a symbolic link to
144 ccache itself.
145
146 CCACHE_CC
147 You can optionally set CCACHE_CC to force the name of the com‐
148 piler to use. If you don't do this then ccache works it out from
149 the command line.
150
151 CCACHE_PREFIX
152 This option adds a prefix to the command line that ccache runs
153 when invoking the compiler. Also see the section below on using
154 ccache with distcc.
155
156 CCACHE_DISABLE
157 If you set the environment variable CCACHE_DISABLE then ccache
158 will just call the real compiler, bypassing the cache com‐
159 pletely.
160
161 CCACHE_READONLY
162 the CCACHE_READONLY environment variable tells ccache to attempt
163 to use existing cached object files, but not to try to add any‐
164 thing new to the cache. If you are using this because your
165 CCACHE_DIR is read-only, then you may find that you also need to
166 set CCACHE_TEMPDIR as otherwise ccache will fail to create the
167 temporary files.
168
169 CCACHE_CPP2
170 If you set the environment variable CCACHE_CPP2 then ccache will
171 not use the optimisation of avoiding the 2nd call to the pre-
172 processor by compiling the pre-processed output that was used
173 for finding the hash in the case of a cache miss. This is pri‐
174 marily a debugging option, although it is possible that some
175 unusual compilers will have problems with the intermediate file‐
176 name extensions used in this optimisation, in which case this
177 option could allow ccache to be used.
178
179 CCACHE_NOSTATS
180 If you set the environment variable CCACHE_NOSTATS then ccache
181 will not update the statistics files on each compile.
182
183 CCACHE_NLEVELS
184 The environment variable CCACHE_NLEVELS allows you to choose the
185 number of levels of hash in the cache directory. The default is
186 2. The minimum is 1 and the maximum is 8.
187
188 CCACHE_HARDLINK
189 If you set the environment variable CCACHE_HARDLINK then ccache
190 will attempt to use hard links from the cache directory when
191 creating the compiler output rather than using a file copy.
192 Using hard links is faster, but can confuse programs like 'make'
193 that rely on modification times.
194
195 CCACHE_RECACHE
196 This forces ccache to not use any cached results, even if it
197 finds them. New results are still cached, but existing cache
198 entries are ignored.
199
200 CCACHE_UMASK
201 This sets the umask for ccache and all child processes (such as
202 the compiler). This is mostly useful when you wish to share your
203 cache with other users. Note that this also affects the file
204 permissions set on the object files created from your compila‐
205 tions.
206
207 CCACHE_HASHDIR
208 This tells ccache to hash the current working directory when
209 calculating the hash that is used to distinguish two compiles.
210 This prevents a problem with the storage of the current working
211 directory in the debug info of a object file, which can lead
212 ccache to give a cached object file that has the working direc‐
213 tory in the debug info set incorrectly. This option is off by
214 default as the incorrect setting of this debug info rarely
215 causes problems. If you strike problems with gdb not using the
216 correct directory then enable this option.
217
218 CCACHE_UNIFY
219 If you set the environment variable CCACHE_UNIFY then ccache
220 will use the C/C++ unifier when hashing the pre-processor output
221 if -g is not used in the compile. The unifier is slower than a
222 normal hash, so setting this environment variable loses a little
223 bit of speed, but it means that ccache can take advantage of not
224 recompiling when the changes to the source code consist of
225 reformatting only. Note that using CCACHE_UNIFY changes the
226 hash, so cached compiles with CCACHE_UNIFY set cannot be used
227 when CCACHE_UNIFY is not set and vice versa. The reason the uni‐
228 fier is off by default is that it can give incorrect line number
229 information in compiler warning messages.
230
231 CCACHE_EXTENSION
232 Normally ccache tries to automatically determine the extension
233 to use for intermediate C pre-processor files based on the type
234 of file being compiled. Unfortunately this sometimes doesn't
235 work, for example when using the aCC compiler on HP-UX. On sys‐
236 tems like this you can use the CCACHE_EXTENSION option to over‐
237 ride the default. On HP-UX set this environment variable to "i"
238 if you use the aCC compiler.
239
241 By default ccache has a one gigabyte limit on the cache size and no
242 maximum number of files. You can set a different limit using the
243 "ccache -M" and "ccache -F" options, which set the size and number of
244 files limits.
245
246 When these limits are reached ccache will reduce the cache to 20% below
247 the numbers you specified in order to avoid doing the cache clean oper‐
248 ation too often.
249
251 The basic idea is to detect when you are compiling exactly the same
252 code a 2nd time and use the previously compiled output. You detect that
253 it is the same code by forming a hash of:
254
255 o the pre-processor output from running the compiler with -E
256
257 o the command line options
258
259 o the real compilers size and modification time
260
261 o any stderr output generated by the compiler
262
263 These are hashed using md4 (a strong hash) and a cache file is formed
264 based on that hash result. When the same compilation is done a second
265 time ccache is able to supply the correct compiler output (including
266 all warnings etc) from the cache.
267
268 ccache has been carefully written to always produce exactly the same
269 compiler output that you would get without the cache. If you ever dis‐
270 cover a case where ccache changes the output of your compiler then
271 please let me know.
272
274 distcc is a very useful program for distributing compilation across a
275 range of compiler servers. It is often useful to combine distcc with
276 ccache, so that compiles that are done are sped up by distcc, but that
277 ccache avoids the compile completely where possible.
278
279 To use distcc with ccache I recommend using the CCACHE_PREFIX option.
280 You just need to set the environment variable CCACHE_PREFIX to 'distcc'
281 and ccache will prefix the command line used with the compiler with the
282 command 'distcc'.
283
285 A group of developers can increase the cache hit rate by sharing a
286 cache directory. The hard links however cause unwanted side effects,
287 as all links to a cached file share the file's modification timestamp.
288 This results in false dependencies to be triggered by timestamp-based
289 build systems whenever another user links to an existing file. Typi‐
290 cally, users will see that their libraries and binaries are relinked
291 without reason. To share a cache without side effects, the following
292 conditions need to be met:
293
294 o Use the same CCACHE_DIR environment variable setting
295
296 o Set the CCACHE_NOLINK environment variable
297
298 o Make sure everyone sets the CCACHE_UMASK environment variable to
299 002, this ensures that cached files are accessible to everyone
300 in the group.
301
302 o Make sure that all users have write permission in the entire
303 cache directory (and that you trust all users of the shared
304 cache).
305
306 o Make sure that the setgid bit is set on all directories in the
307 cache. This tells the filesystem to inherit group ownership for
308 new directories. The command "chmod g+s `find $CCACHE_DIR -type
309 d`" might be useful for this.
310
312 ccache was inspired by the compilercache shell script script written by
313 Erik Thiele and I would like to thank him for an excellent piece of
314 work. See http://www.erikyyy.de/compilercache/ for the Erik's scripts.
315
316 I wrote ccache because I wanted to get a bit more speed out of a com‐
317 piler cache and I wanted to remove some of the limitations of the
318 shell-script version.
319
321 The biggest differences between Erik's compilercache script and ccache
322 are:
323
324 o ccache is written in C, which makes it a bit faster (calling out
325 to external programs is mostly what slowed down the scripts).
326
327 o ccache can automatically find the real compiler
328
329 o ccache keeps statistics on hits/misses
330
331 o ccache can do automatic cache management
332
333 o ccache can cache compiler output that includes warnings. In many
334 cases this gives ccache a much higher cache hit rate.
335
336 o ccache can handle a much wider ranger of compiler options
337
338 o ccache avoids a double call to cpp on a cache miss
339
341 When the cache is stored on an NFS filesystem, the filesystem must be
342 exported with the no_subtree_check option to make renames between
343 directories reliable.
344
346 Thanks to the following people for their contributions to ccache
347
348 o Erik Thiele for the original compilercache script
349
350 o Luciano Rocha for the idea of compiling the pre-processor output
351 to avoid a 2nd cpp pass
352
353 o Paul Russell for many suggestions and the debian packaging
354
356 ccache was written by Andrew Tridgell http://samba.org/~tridge/
357
358 If you wish to report a problem or make a suggestion then please email
359 bugs@ccache.samba.org
360
361 ccache is released under the GNU General Public License version 2 or
362 later. Please see the file COPYING for license details.
363
364
365
366 April 2002 ccache(1)