Imported Upstream version 3.3.5
[platform/upstream/ccache.git] / ccache.1
1 '\" t
2 .\"     Title: ccache
3 .\"    Author: [see the "Author" section]
4 .\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
5 .\"      Date: 01/13/2018
6 .\"    Manual: ccache Manual
7 .\"    Source: ccache 3.3.5
8 .\"  Language: English
9 .\"
10 .TH "CCACHE" "1" "01/13/2018" "ccache 3\&.3\&.5" "ccache Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 ccache \- a fast C/C++ compiler cache
32 .SH "SYNOPSIS"
33 .sp
34 .nf
35 \fBccache\fR [\fIoptions\fR]
36 \fBccache\fR \fIcompiler\fR [\fIcompiler options\fR]
37 \fIcompiler\fR [\fIcompiler options\fR]                   (via symbolic link)
38 .fi
39 .SH "DESCRIPTION"
40 .sp
41 ccache is a compiler cache\&. It speeds up recompilation by caching the result of previous compilations and detecting when the same compilation is being done again\&. Supported languages are C, C++, Objective\-C and Objective\-C++\&.
42 .sp
43 ccache has been carefully written to always produce exactly the same compiler output that you would get without the cache\&. The only way you should be able to tell that you are using ccache is the speed\&. Currently known exceptions to this goal are listed under CAVEATS\&. If you ever discover an undocumented case where ccache changes the output of your compiler, please let us know\&.
44 .SS "Features"
45 .sp
46 .RS 4
47 .ie n \{\
48 \h'-04'\(bu\h'+03'\c
49 .\}
50 .el \{\
51 .sp -1
52 .IP \(bu 2.3
53 .\}
54 Keeps statistics on hits/misses\&.
55 .RE
56 .sp
57 .RS 4
58 .ie n \{\
59 \h'-04'\(bu\h'+03'\c
60 .\}
61 .el \{\
62 .sp -1
63 .IP \(bu 2.3
64 .\}
65 Automatic cache size management\&.
66 .RE
67 .sp
68 .RS 4
69 .ie n \{\
70 \h'-04'\(bu\h'+03'\c
71 .\}
72 .el \{\
73 .sp -1
74 .IP \(bu 2.3
75 .\}
76 Can cache compilations that generate warnings\&.
77 .RE
78 .sp
79 .RS 4
80 .ie n \{\
81 \h'-04'\(bu\h'+03'\c
82 .\}
83 .el \{\
84 .sp -1
85 .IP \(bu 2.3
86 .\}
87 Easy installation\&.
88 .RE
89 .sp
90 .RS 4
91 .ie n \{\
92 \h'-04'\(bu\h'+03'\c
93 .\}
94 .el \{\
95 .sp -1
96 .IP \(bu 2.3
97 .\}
98 Low overhead\&.
99 .RE
100 .sp
101 .RS 4
102 .ie n \{\
103 \h'-04'\(bu\h'+03'\c
104 .\}
105 .el \{\
106 .sp -1
107 .IP \(bu 2.3
108 .\}
109 Optionally uses hard links where possible to avoid copies\&.
110 .RE
111 .sp
112 .RS 4
113 .ie n \{\
114 \h'-04'\(bu\h'+03'\c
115 .\}
116 .el \{\
117 .sp -1
118 .IP \(bu 2.3
119 .\}
120 Optionally compresses files in the cache to reduce disk space\&.
121 .RE
122 .SS "Limitations"
123 .sp
124 .RS 4
125 .ie n \{\
126 \h'-04'\(bu\h'+03'\c
127 .\}
128 .el \{\
129 .sp -1
130 .IP \(bu 2.3
131 .\}
132 Only knows how to cache the compilation of a single C/C++/Objective\-C/Objective\-C++ file\&. Other types of compilations (multi\-file compilation, linking, etc) will silently fall back to running the real compiler\&.
133 .RE
134 .sp
135 .RS 4
136 .ie n \{\
137 \h'-04'\(bu\h'+03'\c
138 .\}
139 .el \{\
140 .sp -1
141 .IP \(bu 2.3
142 .\}
143 Only works with GCC and compilers that behave similar enough\&.
144 .RE
145 .sp
146 .RS 4
147 .ie n \{\
148 \h'-04'\(bu\h'+03'\c
149 .\}
150 .el \{\
151 .sp -1
152 .IP \(bu 2.3
153 .\}
154 Some compiler flags are not supported\&. If such a flag is detected, ccache will silently fall back to running the real compiler\&.
155 .RE
156 .SH "RUN MODES"
157 .sp
158 There are two ways to use ccache\&. You can either prefix your compilation commands with \fBccache\fR or you can let ccache masquerade as the compiler by creating a symbolic link (named as the compiler) to ccache\&. The first method is most convenient if you just want to try out ccache or wish to use it for some specific projects\&. The second method is most useful for when you wish to use ccache for all your compilations\&.
159 .sp
160 To use the first method, just make sure that \fBccache\fR is in your \fBPATH\fR\&.
161 .sp
162 To use the symlinks method, do something like this:
163 .sp
164 .if n \{\
165 .RS 4
166 .\}
167 .nf
168 cp ccache /usr/local/bin/
169 ln \-s ccache /usr/local/bin/gcc
170 ln \-s ccache /usr/local/bin/g++
171 ln \-s ccache /usr/local/bin/cc
172 ln \-s ccache /usr/local/bin/c++
173 .fi
174 .if n \{\
175 .RE
176 .\}
177 .sp
178 And so forth\&. This will work as long as the directory with symlinks comes before the path to the compiler (which is usually in /usr/bin)\&. After installing you may wish to run \(lqwhich gcc\(rq to make sure that the correct link is being used\&.
179 .if n \{\
180 .sp
181 .\}
182 .RS 4
183 .it 1 an-trap
184 .nr an-no-space-flag 1
185 .nr an-break-flag 1
186 .br
187 .ps +1
188 \fBWarning\fR
189 .ps -1
190 .br
191 .sp
192 The technique of letting ccache masquerade as the compiler works well, but currently doesn\(cqt interact well with other tools that do the same thing\&. See USING CCACHE WITH OTHER COMPILER WRAPPERS\&.
193 .sp .5v
194 .RE
195 .if n \{\
196 .sp
197 .\}
198 .RS 4
199 .it 1 an-trap
200 .nr an-no-space-flag 1
201 .nr an-break-flag 1
202 .br
203 .ps +1
204 \fBWarning\fR
205 .ps -1
206 .br
207 .sp
208 Do not use a hard link, use a symbolic link\&. A hard link will cause \(lqinteresting\(rq problems\&.
209 .sp .5v
210 .RE
211 .SH "OPTIONS"
212 .sp
213 These options only apply when you invoke ccache as \(lqccache\(rq\&. When invoked as a compiler (via a symlink as described in the previous section), the normal compiler options apply and you should refer to the compiler\(cqs documentation\&.
214 .PP
215 \fB\-c, \-\-cleanup\fR
216 .RS 4
217 Clean up the cache by removing old cached files until the specified file number and cache size limits are not exceeded\&. This also recalculates the cache file count and size totals\&. Normally, there is no need to initiate cleanup manually as ccache keeps the cache below the specified limits at runtime and keeps statistics up to date on each compilation\&. Forcing a cleanup is mostly useful if you manually modify the cache contents or believe that the cache size statistics may be inaccurate\&.
218 .RE
219 .PP
220 \fB\-C, \-\-clear\fR
221 .RS 4
222 Clear the entire cache, removing all cached files, but keeping the configuration file\&.
223 .RE
224 .PP
225 \fB\-F, \-\-max\-files\fR=\fIN\fR
226 .RS 4
227 Set the maximum number of files allowed in the cache\&. Use 0 for no limit\&. The value is stored in a configuration file in the cache directory and applies to all future compilations\&.
228 .RE
229 .PP
230 \fB\-h, \-\-help\fR
231 .RS 4
232 Print an options summary page\&.
233 .RE
234 .PP
235 \fB\-M, \-\-max\-size\fR=\fISIZE\fR
236 .RS 4
237 Set the maximum size of the files stored in the cache\&.
238 \fISIZE\fR
239 should be a number followed by an optional suffix: k, M, G, T (decimal), Ki, Mi, Gi or Ti (binary)\&. The default suffix is G\&. Use 0 for no limit\&. The value is stored in a configuration file in the cache directory and applies to all future compilations\&.
240 .RE
241 .PP
242 \fB\-o, \-\-set\-config\fR=\fIKEY=VALUE\fR
243 .RS 4
244 Set configuration
245 \fIKEY\fR
246 to
247 \fIVALUE\fR\&. See
248 CONFIGURATION
249 for more information\&.
250 .RE
251 .PP
252 \fB\-p, \-\-print\-config\fR
253 .RS 4
254 Print current configuration options and from where they originate (environment variable, configuration file or compile\-time default)\&.
255 .RE
256 .PP
257 \fB\-s, \-\-show\-stats\fR
258 .RS 4
259 Print the current statistics summary for the cache\&.
260 .RE
261 .PP
262 \fB\-V, \-\-version\fR
263 .RS 4
264 Print version and copyright information\&.
265 .RE
266 .PP
267 \fB\-z, \-\-zero\-stats\fR
268 .RS 4
269 Zero the cache statistics (but not the configuration options)\&.
270 .RE
271 .SH "EXTRA OPTIONS"
272 .sp
273 When run as a compiler, ccache usually just takes the same command line options as the compiler you are using\&. The only exception to this is the option \fB\-\-ccache\-skip\fR\&. That option can be used to tell ccache to avoid interpreting the next option in any way and to pass it along to the compiler as\-is\&.
274 .if n \{\
275 .sp
276 .\}
277 .RS 4
278 .it 1 an-trap
279 .nr an-no-space-flag 1
280 .nr an-break-flag 1
281 .br
282 .ps +1
283 \fBNote\fR
284 .ps -1
285 .br
286 .sp
287 \fB\-\-ccache\-skip\fR currently only tells ccache not to interpret the next option as a special compiler option \(em the option will still be included in the direct mode hash\&.
288 .sp .5v
289 .RE
290 .sp
291 The reason this can be important is that ccache does need to parse the command line and determine what is an input filename and what is a compiler option, as it needs the input filename to determine the name of the resulting object file (among other things)\&. The heuristic ccache uses when parsing the command line is that any argument that exists as a file is treated as an input file name\&. By using \fB\-\-ccache\-skip\fR you can force an option to not be treated as an input file name and instead be passed along to the compiler as a command line option\&.
292 .sp
293 Another case where \fB\-\-ccache\-skip\fR can be useful is if ccache interprets an option specially but shouldn\(cqt, since the option has another meaning for your compiler than what ccache thinks\&.
294 .SH "CONFIGURATION"
295 .sp
296 ccache\(cqs default behavior can be overridden by configuration file settings, which in turn can be overridden by environment variables with names starting with \fBCCACHE_\fR\&. ccache normally reads configuration from two files: first a system\-level configuration file and secondly a cache\-specific configuration file\&. The priority of configuration settings is as follows (where 1 is highest):
297 .sp
298 .RS 4
299 .ie n \{\
300 \h'-04' 1.\h'+01'\c
301 .\}
302 .el \{\
303 .sp -1
304 .IP "  1." 4.2
305 .\}
306 Environment variables\&.
307 .RE
308 .sp
309 .RS 4
310 .ie n \{\
311 \h'-04' 2.\h'+01'\c
312 .\}
313 .el \{\
314 .sp -1
315 .IP "  2." 4.2
316 .\}
317 The cache\-specific configuration file
318 \fB<ccachedir>/ccache\&.conf\fR
319 (typically
320 \fB$HOME/\&.ccache/ccache\&.conf\fR)\&.
321 .RE
322 .sp
323 .RS 4
324 .ie n \{\
325 \h'-04' 3.\h'+01'\c
326 .\}
327 .el \{\
328 .sp -1
329 .IP "  3." 4.2
330 .\}
331 The system\-wide configuration file
332 \fB<sysconfdir>/ccache\&.conf\fR
333 (typically
334 \fB/etc/ccache\&.conf\fR
335 or
336 \fB/usr/local/etc/ccache\&.conf\fR)\&.
337 .RE
338 .sp
339 .RS 4
340 .ie n \{\
341 \h'-04' 4.\h'+01'\c
342 .\}
343 .el \{\
344 .sp -1
345 .IP "  4." 4.2
346 .\}
347 Compile\-time defaults\&.
348 .RE
349 .sp
350 As a special case, if the environment variable \fBCCACHE_CONFIGPATH\fR is set, ccache reads configuration from the specified path instead of the default paths\&.
351 .SS "Configuration file syntax"
352 .sp
353 Configuration files are in a simple \(lqkey = value\(rq format, one setting per line\&. Lines starting with a hash sign are comments\&. Blank lines are ignored, as is whitespace surrounding keys and values\&. Example:
354 .sp
355 .if n \{\
356 .RS 4
357 .\}
358 .nf
359 # Set maximum cache size to 10 GB:
360 max_size = 10G
361 .fi
362 .if n \{\
363 .RE
364 .\}
365 .SS "Boolean values"
366 .sp
367 Some settings are boolean values (i\&.e\&. truth values)\&. In a configuration file, such values must be set to the string \fBtrue\fR or \fBfalse\fR\&. For the corresponding environment variables, the semantics are a bit different: a set environment variable means \(lqtrue\(rq regardless of the value (even if set to the empty string), and an unset environment variable means \(lqfalse\(rq\&. Each boolean environment variable also has a negated form starting with \fBCCACHE_NO\fR\&. For example, \fBCCACHE_COMPRESS\fR can be set to force compression and \fBCCACHE_NOCOMPRESS\fR can be set to force no compression\&.
368 .SS "Configuration settings"
369 .sp
370 Below is a list of available configuration settings\&. The corresponding environment variable name is indicated in parentheses after each configuration setting key\&.
371 .PP
372 \fBbase_dir\fR (\fBCCACHE_BASEDIR\fR)
373 .RS 4
374 This setting should be an absolute path to a directory\&. ccache then rewrites absolute paths into relative paths before computing the hash that identifies the compilation, but only for paths under the specified directory\&. If set to the empty string (which is the default), no rewriting is done\&. See also the discussion under
375 COMPILING IN DIFFERENT DIRECTORIES\&. If using GCC or newer versions of Clang, you might want to look into the
376 \fB\-fdebug\-prefix\-map=old=new\fR
377 option for relocating debug info to a common prefix (mapping prefix with old=new)\&.
378 .RE
379 .PP
380 \fBcache_dir\fR (\fBCCACHE_DIR\fR)
381 .RS 4
382 This setting specifies where ccache will keep its cached compiler outputs\&. It will only take effect if set in the system\-wide configuration file or as an environment variable\&. The default is
383 \fB$HOME/\&.ccache\fR\&.
384 .RE
385 .PP
386 \fBcache_dir_levels\fR (\fBCCACHE_NLEVELS\fR)
387 .RS 4
388 This setting allows you to choose the number of directory levels in the cache directory\&. The default is 2\&. The minimum is 1 and the maximum is 8\&.
389 .RE
390 .PP
391 \fBcompiler\fR (\fBCCACHE_CC\fR)
392 .RS 4
393 This setting can be used to force the name of the compiler to use\&. If set to the empty string (which is the default), ccache works it out from the command line\&.
394 .RE
395 .PP
396 \fBcompiler_check\fR (\fBCCACHE_COMPILERCHECK\fR)
397 .RS 4
398 By default, ccache includes the modification time (\(lqmtime\(rq) and size of the compiler in the hash to ensure that results retrieved from the cache are accurate\&. This setting can be used to select another strategy\&. Possible values are:
399 .PP
400 \fBcontent\fR
401 .RS 4
402 Hash the content of the compiler binary\&. This makes ccache very slightly slower compared to the
403 \fBmtime\fR
404 setting, but makes it cope better with compiler upgrades during a build bootstrapping process\&.
405 .RE
406 .PP
407 \fBmtime\fR
408 .RS 4
409 Hash the compiler\(cqs mtime and size, which is fast\&. This is the default\&.
410 .RE
411 .PP
412 \fBnone\fR
413 .RS 4
414 Don\(cqt hash anything\&. This may be good for situations where you can safely use the cached results even though the compiler\(cqs mtime or size has changed (e\&.g\&. if the compiler is built as part of your build system and the compiler\(cqs source has not changed, or if the compiler only has changes that don\(cqt affect code generation)\&. You should only use the
415 \fBnone\fR
416 setting if you know what you are doing\&.
417 .RE
418 .PP
419 \fBstring:value\fR
420 .RS 4
421 Use
422 \fBvalue\fR
423 as the string to calculate hash from\&. This can be the compiler revision number you retrieved earlier and set here via environment variable\&.
424 .RE
425 .PP
426 \fIa command string\fR
427 .RS 4
428 Hash the standard output and standard error output of the specified command\&. The string will be split on whitespace to find out the command and arguments to run\&. No other interpretation of the command string will be done, except that the special word
429 \fB%compiler%\fR
430 will be replaced with the path to the compiler\&. Several commands can be specified with semicolon as separator\&. Examples:
431 .sp
432 .if n \{\
433 .RS 4
434 .\}
435 .nf
436 %compiler% \-v
437 .fi
438 .if n \{\
439 .RE
440 .\}
441 .sp
442 .if n \{\
443 .RS 4
444 .\}
445 .nf
446 %compiler% \-dumpmachine; %compiler% \-dumpversion
447 .fi
448 .if n \{\
449 .RE
450 .\}
451 .sp
452 You should make sure that the specified command is as fast as possible since it will be run once for each ccache invocation\&.
453 .sp
454 Identifying the compiler using a command is useful if you want to avoid cache misses when the compiler has been rebuilt but not changed\&.
455 .sp
456 Another case is when the compiler (as seen by ccache) actually isn\(cqt the real compiler but another compiler wrapper \(em in that case, the default
457 \fBmtime\fR
458 method will hash the mtime and size of the other compiler wrapper, which means that ccache won\(cqt be able to detect a compiler upgrade\&. Using a suitable command to identify the compiler is thus safer, but it\(cqs also slower, so you should consider continue using the
459 \fBmtime\fR
460 method in combination with the
461 \fBprefix_command\fR
462 setting if possible\&. See
463 USING CCACHE WITH OTHER COMPILER WRAPPERS\&.
464 .RE
465 .RE
466 .PP
467 \fBcompression\fR (\fBCCACHE_COMPRESS\fR or \fBCCACHE_NOCOMPRESS\fR, see Boolean values above)
468 .RS 4
469 If true, ccache will compress object files and other compiler output it puts in the cache\&. However, this setting has no effect on how files are retrieved from the cache; compressed and uncompressed results will still be usable regardless of this setting\&. The default is false\&.
470 .RE
471 .PP
472 \fBcompression_level\fR (\fBCCACHE_COMPRESSLEVEL\fR)
473 .RS 4
474 This setting determines the level at which ccache will compress object files\&. It only has effect if
475 \fBcompression\fR
476 is enabled\&. The value defaults to 6, and must be no lower than 1 (fastest, worst compression) and no higher than 9 (slowest, best compression)\&.
477 .RE
478 .PP
479 \fBcpp_extension\fR (\fBCCACHE_EXTENSION\fR)
480 .RS 4
481 This setting can be used to force a certain extension for the intermediate preprocessed file\&. The default is to automatically determine the extension to use for intermediate preprocessor files based on the type of file being compiled, but that sometimes doesn\(cqt work\&. For example, when using the \(lqaCC\(rq compiler on HP\-UX, set the cpp extension to
482 \fBi\fR\&.
483 .RE
484 .PP
485 \fBdirect_mode\fR (\fBCCACHE_DIRECT\fR or \fBCCACHE_NODIRECT\fR, see Boolean values above)
486 .RS 4
487 If true, the direct mode will be used\&. The default is true\&. See
488 THE DIRECT MODE\&.
489 .RE
490 .PP
491 \fBdisable\fR (\fBCCACHE_DISABLE\fR or \fBCCACHE_NODISABLE\fR, see Boolean values above)
492 .RS 4
493 When true, ccache will just call the real compiler, bypassing the cache completely\&. The default is false\&.
494 .RE
495 .PP
496 \fBextra_files_to_hash\fR (\fBCCACHE_EXTRAFILES\fR)
497 .RS 4
498 This setting is a list of paths to files that ccache will include in the the hash sum that identifies the build\&. The list separator is semicolon on Windows systems and colon on other systems\&.
499 .RE
500 .PP
501 \fBhard_link\fR (\fBCCACHE_HARDLINK\fR or \fBCCACHE_NOHARDLINK\fR, see Boolean values above)
502 .RS 4
503 If true, ccache will attempt to use hard links from the cache directory when creating the compiler output rather than using a file copy\&. Using hard links may be slightly faster in some situations, but can confuse programs like \(lqmake\(rq that rely on modification times\&. Another thing to keep in mind is that if the resulting object file is modified in any way, this corrupts the cached object file as well\&. Hard links are never made for compressed cache files\&. This means that you should not enable compression if you want to use hard links\&. The default is false\&.
504 .RE
505 .PP
506 \fBhash_dir\fR (\fBCCACHE_HASHDIR\fR or \fBCCACHE_NOHASHDIR\fR, see Boolean values above)
507 .RS 4
508 If true (which is the default), ccache will include the current working directory (CWD) in the hash that is used to distinguish two compilations when generating debug info (compiler option
509 \fB\-g\fR
510 with variations)\&. Exception: The CWD will not be included in the hash if
511 \fBbase_dir\fR
512 is set (and matches the CWD) and the compiler option
513 \fB\-fdebug\-prefix\-map\fR
514 is used\&.
515 .sp
516 The reason for including the CWD in the hash by default is to prevent a problem with the storage of the current working directory in the debug info of an object file, which can lead ccache to return a cached object file that has the working directory in the debug info set incorrectly\&.
517 .sp
518 You can disable this setting to get cache hits when compiling the same source code in different directories if you don\(cqt mind that CWD in the debug info might be incorrect\&.
519 .RE
520 .PP
521 \fBignore_headers_in_manifest\fR (\fBCCACHE_IGNOREHEADERS\fR)
522 .RS 4
523 This setting is a list of paths to files (or directories with headers) that ccache will
524 \fBnot\fR
525 include in the manifest list that makes up the direct mode\&. Note that this can cause stale cache hits if those headers do indeed change\&. The list separator is semicolon on Windows systems and colon on other systems\&.
526 .RE
527 .PP
528 \fBkeep_comments_cpp\fR (\fBCCACHE_COMMENTS\fR or \fBCCACHE_NOCOMMENTS\fR, see Boolean values above)
529 .RS 4
530 If true, ccache will not discard the comments before hashing preprocessor output\&. This can be used to check documentation with
531 \fB\-Wdocumentation\fR\&.
532 .RE
533 .PP
534 \fBlimit_multiple\fR (\fBCCACHE_LIMIT_MULTIPLE\fR)
535 .RS 4
536 Sets the limit when cleaning up\&. Files are deleted (in LRU order) until the levels are below the limit\&. The default is 0\&.8 (= 80%)\&. See
537 AUTOMATIC CLEANUP
538 for more information\&.
539 .RE
540 .PP
541 \fBlog_file\fR (\fBCCACHE_LOGFILE\fR)
542 .RS 4
543 If set to a file path, ccache will write information on what it is doing to the specified file\&. This is useful for tracking down problems\&.
544 .RE
545 .PP
546 \fBmax_files\fR (\fBCCACHE_MAXFILES\fR)
547 .RS 4
548 This option specifies the maximum number of files to keep in the cache\&. Use 0 for no limit (which is the default)\&. See also
549 CACHE SIZE MANAGEMENT\&.
550 .RE
551 .PP
552 \fBmax_size\fR (\fBCCACHE_MAXSIZE\fR)
553 .RS 4
554 This option specifies the maximum size of the cache\&. Use 0 for no limit\&. The default value is 5G\&. Available suffixes: k, M, G, T (decimal) and Ki, Mi, Gi, Ti (binary)\&. The default suffix is "G"\&. See also
555 CACHE SIZE MANAGEMENT\&.
556 .RE
557 .PP
558 \fBpath\fR (\fBCCACHE_PATH\fR)
559 .RS 4
560 If set, ccache will search directories in this list when looking for the real compiler\&. The list separator is semicolon on Windows systems and colon on other systems\&. If not set, ccache will look for the first executable matching the compiler name in the normal
561 \fBPATH\fR
562 that isn\(cqt a symbolic link to ccache itself\&.
563 .RE
564 .PP
565 \fBprefix_command\fR (\fBCCACHE_PREFIX\fR)
566 .RS 4
567 This option adds a list of prefixes (separated by space) to the command line that ccache uses when invoking the compiler\&. See also
568 USING CCACHE WITH OTHER COMPILER WRAPPERS\&.
569 .RE
570 .PP
571 \fBprefix_command_cpp\fR (\fBCCACHE_PREFIX_CPP\fR)
572 .RS 4
573 This option adds a list of prefixes (separated by space) to the command line that ccache uses when invoking the preprocessor\&.
574 .RE
575 .PP
576 \fBread_only\fR (\fBCCACHE_READONLY\fR or \fBCCACHE_NOREADONLY\fR, see Boolean values above)
577 .RS 4
578 If true, ccache will attempt to use existing cached object files, but it will not to try to add anything new to the cache\&. If you are using this because your ccache directory is read\-only, then you need to set
579 \fBtemporary_dir\fR
580 as otherwise ccache will fail to create temporary files\&.
581 .RE
582 .PP
583 \fBread_only_direct\fR (\fBCCACHE_READONLY_DIRECT\fR or \fBCCACHE_NOREADONLY_DIRECT\fR, see Boolean values above)
584 .RS 4
585 Just like
586 \fBread_only\fR
587 except that ccache will only try to retrieve results from the cache using the direct mode, not the preprocessor mode\&. See documentation for
588 \fBread_only\fR
589 regarding using a read\-only ccache directory\&.
590 .RE
591 .PP
592 \fBrecache\fR (\fBCCACHE_RECACHE\fR or \fBCCACHE_NORECACHE\fR, see Boolean values above)
593 .RS 4
594 If true, ccache will not use any previously stored result\&. New results will still be cached, possibly overwriting any pre\-existing results\&.
595 .RE
596 .PP
597 \fBrun_second_cpp\fR (\fBCCACHE_CPP2\fR or \fBCCACHE_NOCPP2\fR, see Boolean values above)
598 .RS 4
599 If true, ccache will first run the preprocessor to preprocess the source code (see
600 THE PREPROCESSOR MODE) and then on a cache miss run the compiler on the source code to get hold of the object file\&. This is the default\&.
601 .sp
602 If false, ccache will first run preprocessor to preprocess the source code and then on a cache miss run the compiler on the
603 \fIpreprocessed source code\fR
604 instead of the original source code\&. This makes cache misses slightly faster since the source code only has to be preprocessed once\&. The downside is that some compilers won\(cqt produce the same result (for instance diagnostics warnings) when compiling preprocessed source code\&.
605 .RE
606 .PP
607 \fBsloppiness\fR (\fBCCACHE_SLOPPINESS\fR)
608 .RS 4
609 By default, ccache tries to give as few false cache hits as possible\&. However, in certain situations it\(cqs possible that you know things that ccache can\(cqt take for granted\&. This setting makes it possible to tell ccache to relax some checks in order to increase the hit rate\&. The value should be a comma\-separated string with options\&. Available options are:
610 .PP
611 \fBfile_macro\fR
612 .RS 4
613 Ignore
614 \fB__FILE__\fR
615 being present in the source\&.
616 .RE
617 .PP
618 \fBfile_stat_matches\fR
619 .RS 4
620 ccache normally examines a file\(cqs contents to determine whether it matches the cached version\&. With this option set, ccache will consider a file as matching its cached version if the mtimes and ctimes match\&.
621 .RE
622 .PP
623 \fBinclude_file_ctime\fR
624 .RS 4
625 By default, ccache also will not cache a file if it includes a header whose ctime is too new\&. This option disables that check\&.
626 .RE
627 .PP
628 \fBinclude_file_mtime\fR
629 .RS 4
630 By default, ccache will not cache a file if it includes a header whose mtime is too new\&. This option disables that check\&.
631 .RE
632 .PP
633 \fBno_system_headers\fR
634 .RS 4
635 By default, ccache will also include all system headers in the manifest\&. With this option set, ccache will only include system headers in the hash but not add the system header files to the list of include files\&.
636 .RE
637 .PP
638 \fBpch_defines\fR
639 .RS 4
640 Be sloppy about
641 \fB#define\fRs when precompiling a header file\&. See
642 PRECOMPILED HEADERS
643 for more information\&.
644 .RE
645 .PP
646 \fBtime_macros\fR
647 .RS 4
648 Ignore
649 \fB__DATE__\fR
650 and
651 \fB__TIME__\fR
652 being present in the source code\&.
653 .RE
654 .sp
655 See the discussion under
656 TROUBLESHOOTING
657 for more information\&.
658 .RE
659 .PP
660 \fBstats\fR (\fBCCACHE_STATS\fR or \fBCCACHE_NOSTATS\fR, see Boolean values above)
661 .RS 4
662 If true, ccache will update the statistics counters on each compilation\&. The default is true\&.
663 .RE
664 .PP
665 \fBtemporary_dir\fR (\fBCCACHE_TEMPDIR\fR)
666 .RS 4
667 This setting specifies where ccache will put temporary files\&. The default is
668 \fB<cache_dir>/tmp\fR\&.
669 .if n \{\
670 .sp
671 .\}
672 .RS 4
673 .it 1 an-trap
674 .nr an-no-space-flag 1
675 .nr an-break-flag 1
676 .br
677 .ps +1
678 \fBNote\fR
679 .ps -1
680 .br
681 In previous versions of ccache,
682 \fBCCACHE_TEMPDIR\fR
683 had to be on the same filesystem as the
684 \fBCCACHE_DIR\fR
685 path, but this requirement has been relaxed\&.)
686 .sp .5v
687 .RE
688 .RE
689 .PP
690 \fBumask\fR (\fBCCACHE_UMASK\fR)
691 .RS 4
692 This setting specifies the umask for ccache and all child processes (such as the compiler)\&. This is mostly useful when you wish to share your cache with other users\&. Note that this also affects the file permissions set on the object files created from your compilations\&.
693 .RE
694 .PP
695 \fBunify\fR (\fBCCACHE_UNIFY\fR or \fBCCACHE_NOUNIFY\fR, see Boolean values above)
696 .RS 4
697 If true, ccache will use a C/C++ unifier when hashing the preprocessor output if the
698 \fB\-g\fR
699 option is not used\&. The unifier is slower than a normal hash, so setting this environment variable loses a little bit of speed, but it means that ccache can take advantage of not recompiling when the changes to the source code consist of reformatting only\&. Note that enabling the unifier changes the hash, so cached compilations produced when the unifier is enabled cannot be reused when the unifier is disabled, and vice versa\&. Enabling the unifier may result in incorrect line number information in compiler warning messages and expansions of the
700 \fB__LINE__\fR
701 macro\&. Also note that enabling the unifier implies turning off the direct mode\&.
702 .RE
703 .SH "CACHE SIZE MANAGEMENT"
704 .sp
705 By default, ccache has a 5 GB limit on the total size of files in the cache and no limit on the number of files\&. You can set different limits using the \fB\-M\fR/\fB\-\-max\-size\fR and \fB\-F\fR/\fB\-\-max\-files\fR options\&. Use \fBccache \-s/\-\-show\-stats\fR to see the cache size and the currently configured limits (in addition to other various statistics)\&.
706 .sp
707 Cleanup can be triggered in two different ways: automatic and manual\&.
708 .SS "Automatic cleanup"
709 .sp
710 ccache maintains counters for various statistics about the cache, including the size and number of all cached files\&. In order to improve performance and reduce issues with concurrent ccache invocations, there is one statistics file for each of the sixteen subdirectories in the cache\&.
711 .sp
712 After a new compilation result has been written to the cache, ccache will update the size and file number statistics for the subdirectory (one of sixteen) to which the result was written\&. Then, if the size counter for said subdirectory is greater than \fBmax_size / 16\fR or the file number counter is greater than \fBmax_files / 16\fR, automatic cleanup is triggered\&.
713 .sp
714 When automatic cleanup is triggered for a subdirectory in the cache, ccache will:
715 .sp
716 .RS 4
717 .ie n \{\
718 \h'-04' 1.\h'+01'\c
719 .\}
720 .el \{\
721 .sp -1
722 .IP "  1." 4.2
723 .\}
724 Count all files in the subdirectory and compute their aggregated size\&.
725 .RE
726 .sp
727 .RS 4
728 .ie n \{\
729 \h'-04' 2.\h'+01'\c
730 .\}
731 .el \{\
732 .sp -1
733 .IP "  2." 4.2
734 .\}
735 Remove files in LRU (least recently used) order until the size is at most
736 \fBlimit_multiple * max_size / 16\fR
737 and the number of files is at most
738 \fBlimit_multiple * max_files / 16\fR, where
739 \fBlimit_multiple\fR,
740 \fBmax_size\fR
741 and
742 \fBmax_files\fR
743 are configuration settings\&.
744 .RE
745 .sp
746 .RS 4
747 .ie n \{\
748 \h'-04' 3.\h'+01'\c
749 .\}
750 .el \{\
751 .sp -1
752 .IP "  3." 4.2
753 .\}
754 Set the size and file number counters to match the files that were kept\&.
755 .RE
756 .sp
757 The reason for removing more files than just those needed to not exceed the max limits is that a cleanup is a fairly slow operation, so it would not be a good idea to trigger it often, like after each cache miss\&.
758 .SS "Manual cleanup"
759 .sp
760 You can run \fBccache \-c/\-\-cleanup\fR to force cleanup of the whole cache, i\&.e\&. all of the sixteen subdirectories\&. This will recalculate the statistics counters and make sure that the \fBmax_size\fR and \fBmax_files\fR settings are not exceeded\&. Note that \fBlimit_multiple\fR is not taken into account for manual cleanup\&.
761 .SH "CACHE COMPRESSION"
762 .sp
763 ccache can optionally compress all files it puts into the cache using the compression library zlib\&. While this may involve a tiny performance slowdown, it increases the number of files that fit in the cache\&. You can turn on compression with the \fBcompression\fR configuration setting and you can also tweak the compression level with \fBcompression_level\fR\&.
764 .SH "CACHE STATISTICS"
765 .sp
766 \fBccache \-s/\-\-show\-stats\fR can show the following statistics:
767 .TS
768 allbox tab(:);
769 ltB ltB.
770 T{
771 Name
772 T}:T{
773 Description
774 T}
775 .T&
776 lt lt
777 lt lt
778 lt lt
779 lt lt
780 lt lt
781 lt lt
782 lt lt
783 lt lt
784 lt lt
785 lt lt
786 lt lt
787 lt lt
788 lt lt
789 lt lt
790 lt lt
791 lt lt
792 lt lt
793 lt lt
794 lt lt
795 lt lt
796 lt lt
797 lt lt
798 lt lt
799 lt lt
800 lt lt
801 lt lt
802 lt lt
803 lt lt.
804 T{
805 .sp
806 autoconf compile/link
807 T}:T{
808 .sp
809 Uncachable compilation or linking by an autoconf test\&.
810 T}
811 T{
812 .sp
813 bad compiler arguments
814 T}:T{
815 .sp
816 Malformed compiler argument, e\&.g\&. missing a value for an option that requires an argument or failure to read a file specified by an option argument\&.
817 T}
818 T{
819 .sp
820 cache file missing
821 T}:T{
822 .sp
823 A file was unexpectedly missing from the cache\&. This only happens in rare situations, e\&.g\&. if one ccache instance is about to get a file from the cache while another instance removed the file as part of cache cleanup\&.
824 T}
825 T{
826 .sp
827 cache hit (direct)
828 T}:T{
829 .sp
830 A result was successfully found using the direct mode\&.
831 T}
832 T{
833 .sp
834 cache hit (preprocessed)
835 T}:T{
836 .sp
837 A result was successfully found using the preprocessor mode\&.
838 T}
839 T{
840 .sp
841 cache miss
842 T}:T{
843 .sp
844 No result was found\&.
845 T}
846 T{
847 .sp
848 cache size
849 T}:T{
850 .sp
851 Current size of the cache\&.
852 T}
853 T{
854 .sp
855 called for link
856 T}:T{
857 .sp
858 The compiler was called for linking, not compiling\&.
859 T}
860 T{
861 .sp
862 called for preprocessing
863 T}:T{
864 .sp
865 The compiler was called for preprocessing, not compiling\&.
866 T}
867 T{
868 .sp
869 can\(cqt use precompiled header
870 T}:T{
871 .sp
872 Preconditions for using precompiled headers were not fulfilled\&.
873 T}
874 T{
875 .sp
876 ccache internal error
877 T}:T{
878 .sp
879 Unexpected failure, e\&.g\&. due to problems reading/writing the cache\&.
880 T}
881 T{
882 .sp
883 cleanups performed
884 T}:T{
885 .sp
886 Number of cleanups performed, either implicitly due to the cache size limit being reached or due to explicit \fBccache \-c/\-\-cleanup\fR calls\&.
887 T}
888 T{
889 .sp
890 compile failed
891 T}:T{
892 .sp
893 The compilation failed\&. No result stored in the cache\&.
894 T}
895 T{
896 .sp
897 compiler check failed
898 T}:T{
899 .sp
900 A compiler check program specified by \fBcompiler_check\fR (\fBCCACHE_COMPILERCHECK\fR) failed\&.
901 T}
902 T{
903 .sp
904 compiler produced empty output
905 T}:T{
906 .sp
907 The compiler\(cqs output file (typically an object file) was empty after compilation\&.
908 T}
909 T{
910 .sp
911 compiler produced no output
912 T}:T{
913 .sp
914 The compiler\(cqs output file (typically an object file) was missing after compilation\&.
915 T}
916 T{
917 .sp
918 compiler produced stdout
919 T}:T{
920 .sp
921 The compiler wrote data to standard output\&. This is something that compilers normally never do, so ccache is not designed to store such output in the cache\&.
922 T}
923 T{
924 .sp
925 couldn\(cqt find the compiler
926 T}:T{
927 .sp
928 The compiler to execute could not be found\&.
929 T}
930 T{
931 .sp
932 error hashing extra file
933 T}:T{
934 .sp
935 Failure reading a file specified by \fBextra_files_to_hash\fR (\fBCCACHE_EXTRAFILES\fR)\&.
936 T}
937 T{
938 .sp
939 files in cache
940 T}:T{
941 .sp
942 Current number of files in the cache\&.
943 T}
944 T{
945 .sp
946 multiple source files
947 T}:T{
948 .sp
949 The compiler was called to compile multiple source files in one go\&. This is not supported by ccache\&.
950 T}
951 T{
952 .sp
953 no input file
954 T}:T{
955 .sp
956 No input file was specified to the compiler\&.
957 T}
958 T{
959 .sp
960 output to a non\-regular file
961 T}:T{
962 .sp
963 The output path specified with \fB\-o\fR is not a file (e\&.g\&. a directory or a device node)\&.
964 T}
965 T{
966 .sp
967 output to stdout
968 T}:T{
969 .sp
970 The compiler was instructed to write its output to standard output using \fB\-o \-\fR\&. This is not supported by ccache\&.
971 T}
972 T{
973 .sp
974 preprocessor error
975 T}:T{
976 .sp
977 Preprocessing the source code using the compiler\(cqs \fB\-E\fR option failed\&.
978 T}
979 T{
980 .sp
981 unsupported code directive
982 T}:T{
983 .sp
984 Code like the assembler \(lq\&.incbin\(rq directive was found\&. This is not supported by ccache\&.
985 T}
986 T{
987 .sp
988 unsupported compiler option
989 T}:T{
990 .sp
991 A compiler option not supported by ccache was found\&.
992 T}
993 T{
994 .sp
995 unsupported source language
996 T}:T{
997 .sp
998 A source language e\&.g\&. specified with \fB\-x\fR was unsupported by ccache\&.
999 T}
1000 .TE
1001 .sp 1
1002 .SH "HOW CCACHE WORKS"
1003 .sp
1004 The basic idea is to detect when you are compiling exactly the same code a second time and reuse the previously produced output\&. The detection is done by hashing different kinds of information that should be unique for the compilation and then using the hash sum to identify the cached output\&. ccache uses MD4, a very fast cryptographic hash algorithm, for the hashing\&. (MD4 is nowadays too weak to be useful in cryptographic contexts, but it should be safe enough to be used to identify recompilations\&.) On a cache hit, ccache is able to supply all of the correct compiler outputs (including all warnings, dependency file, etc) from the cache\&.
1005 .sp
1006 ccache has two ways of doing the detection:
1007 .sp
1008 .RS 4
1009 .ie n \{\
1010 \h'-04'\(bu\h'+03'\c
1011 .\}
1012 .el \{\
1013 .sp -1
1014 .IP \(bu 2.3
1015 .\}
1016 the
1017 \fBdirect mode\fR, where ccache hashes the source code and include files directly
1018 .RE
1019 .sp
1020 .RS 4
1021 .ie n \{\
1022 \h'-04'\(bu\h'+03'\c
1023 .\}
1024 .el \{\
1025 .sp -1
1026 .IP \(bu 2.3
1027 .\}
1028 the
1029 \fBpreprocessor mode\fR, where ccache runs the preprocessor on the source code and hashes the result
1030 .RE
1031 .sp
1032 The direct mode is generally faster since running the preprocessor has some overhead\&.
1033 .SS "Common hashed information"
1034 .sp
1035 For both modes, the following information is included in the hash:
1036 .sp
1037 .RS 4
1038 .ie n \{\
1039 \h'-04'\(bu\h'+03'\c
1040 .\}
1041 .el \{\
1042 .sp -1
1043 .IP \(bu 2.3
1044 .\}
1045 the extension used by the compiler for a file with preprocessor output (normally
1046 \fB\&.i\fR
1047 for C code and
1048 \fB\&.ii\fR
1049 for C++ code)
1050 .RE
1051 .sp
1052 .RS 4
1053 .ie n \{\
1054 \h'-04'\(bu\h'+03'\c
1055 .\}
1056 .el \{\
1057 .sp -1
1058 .IP \(bu 2.3
1059 .\}
1060 the compiler\(cqs size and modification time (or other compiler\-specific information specified by the
1061 \fBcompiler_check\fR
1062 setting)
1063 .RE
1064 .sp
1065 .RS 4
1066 .ie n \{\
1067 \h'-04'\(bu\h'+03'\c
1068 .\}
1069 .el \{\
1070 .sp -1
1071 .IP \(bu 2.3
1072 .\}
1073 the name of the compiler
1074 .RE
1075 .sp
1076 .RS 4
1077 .ie n \{\
1078 \h'-04'\(bu\h'+03'\c
1079 .\}
1080 .el \{\
1081 .sp -1
1082 .IP \(bu 2.3
1083 .\}
1084 the current directory (if the
1085 \fBhash_dir\fR
1086 setting is enabled)
1087 .RE
1088 .sp
1089 .RS 4
1090 .ie n \{\
1091 \h'-04'\(bu\h'+03'\c
1092 .\}
1093 .el \{\
1094 .sp -1
1095 .IP \(bu 2.3
1096 .\}
1097 contents of files specified by the
1098 \fBextra_files_to_hash\fR
1099 setting (if any)
1100 .RE
1101 .SS "The direct mode"
1102 .sp
1103 In the direct mode, the hash is formed of the common information and:
1104 .sp
1105 .RS 4
1106 .ie n \{\
1107 \h'-04'\(bu\h'+03'\c
1108 .\}
1109 .el \{\
1110 .sp -1
1111 .IP \(bu 2.3
1112 .\}
1113 the input source file
1114 .RE
1115 .sp
1116 .RS 4
1117 .ie n \{\
1118 \h'-04'\(bu\h'+03'\c
1119 .\}
1120 .el \{\
1121 .sp -1
1122 .IP \(bu 2.3
1123 .\}
1124 the command line options
1125 .RE
1126 .sp
1127 Based on the hash, a data structure called \(lqmanifest\(rq is looked up in the cache\&. The manifest contains:
1128 .sp
1129 .RS 4
1130 .ie n \{\
1131 \h'-04'\(bu\h'+03'\c
1132 .\}
1133 .el \{\
1134 .sp -1
1135 .IP \(bu 2.3
1136 .\}
1137 references to cached compilation results (object file, dependency file, etc) that were produced by previous compilations that matched the hash
1138 .RE
1139 .sp
1140 .RS 4
1141 .ie n \{\
1142 \h'-04'\(bu\h'+03'\c
1143 .\}
1144 .el \{\
1145 .sp -1
1146 .IP \(bu 2.3
1147 .\}
1148 paths to the include files that were read at the time the compilation results were stored in the cache
1149 .RE
1150 .sp
1151 .RS 4
1152 .ie n \{\
1153 \h'-04'\(bu\h'+03'\c
1154 .\}
1155 .el \{\
1156 .sp -1
1157 .IP \(bu 2.3
1158 .\}
1159 hash sums of the include files at the time the compilation results were stored in the cache
1160 .RE
1161 .sp
1162 The current contents of the include files are then hashed and compared to the information in the manifest\&. If there is a match, ccache knows the result of the compilation\&. If there is no match, ccache falls back to running the preprocessor\&. The output from the preprocessor is parsed to find the include files that were read\&. The paths and hash sums of those include files are then stored in the manifest along with information about the produced compilation result\&.
1163 .sp
1164 There is a catch with the direct mode: header files that were used by the compiler are recorded, but header files that were \fBnot\fR used, but would have been used if they existed, are not\&. So, when ccache checks if a result can be taken from the cache, it currently can\(cqt check if the existence of a new header file should invalidate the result\&. In practice, the direct mode is safe to use in the absolute majority of cases\&.
1165 .sp
1166 The direct mode will be disabled if any of the following holds:
1167 .sp
1168 .RS 4
1169 .ie n \{\
1170 \h'-04'\(bu\h'+03'\c
1171 .\}
1172 .el \{\
1173 .sp -1
1174 .IP \(bu 2.3
1175 .\}
1176 the configuration setting
1177 \fBdirect_mode\fR
1178 is false
1179 .RE
1180 .sp
1181 .RS 4
1182 .ie n \{\
1183 \h'-04'\(bu\h'+03'\c
1184 .\}
1185 .el \{\
1186 .sp -1
1187 .IP \(bu 2.3
1188 .\}
1189 a modification time of one of the include files is too new (needed to avoid a race condition)
1190 .RE
1191 .sp
1192 .RS 4
1193 .ie n \{\
1194 \h'-04'\(bu\h'+03'\c
1195 .\}
1196 .el \{\
1197 .sp -1
1198 .IP \(bu 2.3
1199 .\}
1200 the unifier is enabled (the configuration setting
1201 \fBunify\fR
1202 is true)
1203 .RE
1204 .sp
1205 .RS 4
1206 .ie n \{\
1207 \h'-04'\(bu\h'+03'\c
1208 .\}
1209 .el \{\
1210 .sp -1
1211 .IP \(bu 2.3
1212 .\}
1213 a compiler option not supported by the direct mode is used:
1214 .sp
1215 .RS 4
1216 .ie n \{\
1217 \h'-04'\(bu\h'+03'\c
1218 .\}
1219 .el \{\
1220 .sp -1
1221 .IP \(bu 2.3
1222 .\}
1223 a
1224 \fB\-Wp,\fR\fB\fIX\fR\fR
1225 compiler option other than
1226 \fB\-Wp,\-MD,\fR\fB\fIpath\fR\fR,
1227 \fB\-Wp,\-MMD,\fR\fB\fIpath\fR\fR
1228 and
1229 \fB\-Wp,\-D_define_\fR
1230 .RE
1231 .sp
1232 .RS 4
1233 .ie n \{\
1234 \h'-04'\(bu\h'+03'\c
1235 .\}
1236 .el \{\
1237 .sp -1
1238 .IP \(bu 2.3
1239 .\}
1240 \fB\-Xpreprocessor\fR
1241 .RE
1242 .RE
1243 .sp
1244 .RS 4
1245 .ie n \{\
1246 \h'-04'\(bu\h'+03'\c
1247 .\}
1248 .el \{\
1249 .sp -1
1250 .IP \(bu 2.3
1251 .\}
1252 the string \(lq__TIME__\(rq is present in the source code
1253 .RE
1254 .SS "The preprocessor mode"
1255 .sp
1256 In the preprocessor mode, the hash is formed of the common information and:
1257 .sp
1258 .RS 4
1259 .ie n \{\
1260 \h'-04'\(bu\h'+03'\c
1261 .\}
1262 .el \{\
1263 .sp -1
1264 .IP \(bu 2.3
1265 .\}
1266 the preprocessor output from running the compiler with
1267 \fB\-E\fR
1268 .RE
1269 .sp
1270 .RS 4
1271 .ie n \{\
1272 \h'-04'\(bu\h'+03'\c
1273 .\}
1274 .el \{\
1275 .sp -1
1276 .IP \(bu 2.3
1277 .\}
1278 the command line options except options that affect include files (\fB\-I\fR,
1279 \fB\-include\fR,
1280 \fB\-D\fR, etc; the theory is that these options will change the preprocessor output if they have any effect at all)
1281 .RE
1282 .sp
1283 .RS 4
1284 .ie n \{\
1285 \h'-04'\(bu\h'+03'\c
1286 .\}
1287 .el \{\
1288 .sp -1
1289 .IP \(bu 2.3
1290 .\}
1291 any standard error output generated by the preprocessor
1292 .RE
1293 .sp
1294 Based on the hash, the cached compilation result can be looked up directly in the cache\&.
1295 .SH "COMPILING IN DIFFERENT DIRECTORIES"
1296 .sp
1297 Some information included in the hash that identifies a unique compilation may contain absolute paths:
1298 .sp
1299 .RS 4
1300 .ie n \{\
1301 \h'-04'\(bu\h'+03'\c
1302 .\}
1303 .el \{\
1304 .sp -1
1305 .IP \(bu 2.3
1306 .\}
1307 The preprocessed source code may contain absolute paths to include files if the compiler option
1308 \fB\-g\fR
1309 is used or if absolute paths are given to
1310 \fB\-I\fR
1311 and similar compiler options\&.
1312 .RE
1313 .sp
1314 .RS 4
1315 .ie n \{\
1316 \h'-04'\(bu\h'+03'\c
1317 .\}
1318 .el \{\
1319 .sp -1
1320 .IP \(bu 2.3
1321 .\}
1322 Paths specified by compiler options (such as
1323 \fB\-I\fR,
1324 \fB\-MF\fR, etc) may be absolute\&.
1325 .RE
1326 .sp
1327 .RS 4
1328 .ie n \{\
1329 \h'-04'\(bu\h'+03'\c
1330 .\}
1331 .el \{\
1332 .sp -1
1333 .IP \(bu 2.3
1334 .\}
1335 The source code file path may be absolute, and that path may substituted for
1336 \fB__FILE__\fR
1337 macros in the source code or included in warnings emitted to standard error by the preprocessor\&.
1338 .RE
1339 .sp
1340 This means that if you compile the same code in different locations, you can\(cqt share compilation results between the different build directories since you get cache misses because of the absolute build directory paths that are part of the hash\&. To mitigate this problem, you can specify a \(lqbase directory\(rq in the configuration setting \fBbase_dir\fR to an absolute path to the directory\&. ccache will then rewrite absolute paths that are under the base directory (i\&.e\&., paths that have the base directory as a prefix) to relative paths when constructing the hash\&. A typical path to use as the base directory is your home directory or another directory that is a parent of your build directories\&. (Don\(cqt use / as the base directory since that will make ccache also rewrite paths to system header files, which doesn\(cqt gain anything\&.)
1341 .sp
1342 The drawbacks of using a base directory are:
1343 .sp
1344 .RS 4
1345 .ie n \{\
1346 \h'-04'\(bu\h'+03'\c
1347 .\}
1348 .el \{\
1349 .sp -1
1350 .IP \(bu 2.3
1351 .\}
1352 If you specify an absolute path to the source code file,
1353 \fB__FILE__\fR
1354 macros will be expanded to a relative path instead\&.
1355 .RE
1356 .sp
1357 .RS 4
1358 .ie n \{\
1359 \h'-04'\(bu\h'+03'\c
1360 .\}
1361 .el \{\
1362 .sp -1
1363 .IP \(bu 2.3
1364 .\}
1365 If you specify an absolute path to the source code file and compile with
1366 \fB\-g\fR, the source code path stored in the object file may point to the wrong directory, which may prevent debuggers like GDB from finding the source code\&. Sometimes, a work\-around is to change the directory explicitly with the \(lqcd\(rq command in GDB\&.
1367 .RE
1368 .SH "PRECOMPILED HEADERS"
1369 .sp
1370 ccache has support for GCC\(cqs precompiled headers\&. However, you have to do some things to make it work properly:
1371 .sp
1372 .RS 4
1373 .ie n \{\
1374 \h'-04'\(bu\h'+03'\c
1375 .\}
1376 .el \{\
1377 .sp -1
1378 .IP \(bu 2.3
1379 .\}
1380 You must set
1381 \fBsloppiness\fR
1382 to
1383 \fBpch_defines,time_macros\fR\&. The reason is that ccache can\(cqt tell whether
1384 \fB__TIME__\fR
1385 or
1386 \fB__DATE__\fR
1387 is used when using a precompiled header\&. Further, it can\(cqt detect changes in
1388 \fB#define\fRs in the source code because of how preprocessing works in combination with precompiled headers\&.
1389 .RE
1390 .sp
1391 .RS 4
1392 .ie n \{\
1393 \h'-04'\(bu\h'+03'\c
1394 .\}
1395 .el \{\
1396 .sp -1
1397 .IP \(bu 2.3
1398 .\}
1399 You must either:
1400 .sp
1401 .RS 4
1402 .ie n \{\
1403 \h'-04'\(bu\h'+03'\c
1404 .\}
1405 .el \{\
1406 .sp -1
1407 .IP \(bu 2.3
1408 .\}
1409 use the
1410 \fB\-include\fR
1411 compiler option to include the precompiled header (i\&.e\&., don\(cqt use
1412 \fB#include\fR
1413 in the source code to include the header); or
1414 .RE
1415 .sp
1416 .RS 4
1417 .ie n \{\
1418 \h'-04'\(bu\h'+03'\c
1419 .\}
1420 .el \{\
1421 .sp -1
1422 .IP \(bu 2.3
1423 .\}
1424 (for the Clang compiler) use the
1425 \fB\-include\-pch\fR
1426 compiler option to include the PCH file generated from the precompiled header; or
1427 .RE
1428 .sp
1429 .RS 4
1430 .ie n \{\
1431 \h'-04'\(bu\h'+03'\c
1432 .\}
1433 .el \{\
1434 .sp -1
1435 .IP \(bu 2.3
1436 .\}
1437 add the
1438 \fB\-fpch\-preprocess\fR
1439 compiler option when compiling\&.
1440 .RE
1441 .sp
1442 If you don\(cqt do this, either the non\-precompiled version of the header file will be used (if available) or ccache will fall back to running the real compiler and increase the statistics counter \(lqpreprocessor error\(rq (if the non\-precompiled header file is not available)\&.
1443 .RE
1444 .SH "SHARING A CACHE"
1445 .sp
1446 A group of developers can increase the cache hit rate by sharing a cache directory\&. To share a cache without unpleasant side effects, the following conditions should to be met:
1447 .sp
1448 .RS 4
1449 .ie n \{\
1450 \h'-04'\(bu\h'+03'\c
1451 .\}
1452 .el \{\
1453 .sp -1
1454 .IP \(bu 2.3
1455 .\}
1456 Use the same cache directory\&.
1457 .RE
1458 .sp
1459 .RS 4
1460 .ie n \{\
1461 \h'-04'\(bu\h'+03'\c
1462 .\}
1463 .el \{\
1464 .sp -1
1465 .IP \(bu 2.3
1466 .\}
1467 Make sure that the configuration setting
1468 \fBhard_link\fR
1469 is false (which is the default)\&.
1470 .RE
1471 .sp
1472 .RS 4
1473 .ie n \{\
1474 \h'-04'\(bu\h'+03'\c
1475 .\}
1476 .el \{\
1477 .sp -1
1478 .IP \(bu 2.3
1479 .\}
1480 Make sure that all users are in the same group\&.
1481 .RE
1482 .sp
1483 .RS 4
1484 .ie n \{\
1485 \h'-04'\(bu\h'+03'\c
1486 .\}
1487 .el \{\
1488 .sp -1
1489 .IP \(bu 2.3
1490 .\}
1491 Set the configuration setting
1492 \fBumask\fR
1493 to 002\&. This ensures that cached files are accessible to everyone in the group\&.
1494 .RE
1495 .sp
1496 .RS 4
1497 .ie n \{\
1498 \h'-04'\(bu\h'+03'\c
1499 .\}
1500 .el \{\
1501 .sp -1
1502 .IP \(bu 2.3
1503 .\}
1504 Make sure that all users have write permission in the entire cache directory (and that you trust all users of the shared cache)\&.
1505 .RE
1506 .sp
1507 .RS 4
1508 .ie n \{\
1509 \h'-04'\(bu\h'+03'\c
1510 .\}
1511 .el \{\
1512 .sp -1
1513 .IP \(bu 2.3
1514 .\}
1515 Make sure that the setgid bit is set on all directories in the cache\&. This tells the filesystem to inherit group ownership for new directories\&. The following command might be useful for this:
1516 .sp
1517 .if n \{\
1518 .RS 4
1519 .\}
1520 .nf
1521 find $CCACHE_DIR \-type d | xargs chmod g+s
1522 .fi
1523 .if n \{\
1524 .RE
1525 .\}
1526 .RE
1527 .sp
1528 The reason to avoid the hard link mode is that the hard links cause unwanted side effects, as all links to a cached file share the file\(cqs modification timestamp\&. This results in false dependencies to be triggered by timestamp\-based build systems whenever another user links to an existing file\&. Typically, users will see that their libraries and binaries are relinked without reason\&.
1529 .sp
1530 You may also want to make sure that a base directory is set appropriately, as discussed in a previous section\&.
1531 .SH "SHARING A CACHE ON NFS"
1532 .sp
1533 It is possible to put the cache directory on an NFS filesystem (or similar filesystems), but keep in mind that:
1534 .sp
1535 .RS 4
1536 .ie n \{\
1537 \h'-04'\(bu\h'+03'\c
1538 .\}
1539 .el \{\
1540 .sp -1
1541 .IP \(bu 2.3
1542 .\}
1543 Having the cache on NFS may slow down compilation\&. Make sure to do some benchmarking to see if it\(cqs worth it\&.
1544 .RE
1545 .sp
1546 .RS 4
1547 .ie n \{\
1548 \h'-04'\(bu\h'+03'\c
1549 .\}
1550 .el \{\
1551 .sp -1
1552 .IP \(bu 2.3
1553 .\}
1554 ccache hasn\(cqt been tested very thoroughly on NFS\&.
1555 .RE
1556 .sp
1557 A tip is to set \fBtemporary_dir\fR to a directory on the local host to avoid NFS traffic for temporary files\&.
1558 .SH "USING CCACHE WITH OTHER COMPILER WRAPPERS"
1559 .sp
1560 The recommended way of combining ccache with another compiler wrapper (such as \(lqdistcc\(rq) is by letting ccache execute the compiler wrapper\&. This is accomplished by defining the configuration setting \fBprefix_command\fR, for example by setting the environment variable \fBCCACHE_PREFIX\fR to the name of the wrapper (e\&.g\&. \fBdistcc\fR)\&. ccache will then prefix the command line with the specified command when running the compiler\&. To specify several prefix commands, set \fBprefix_command\fR to a colon\-separated list of commands\&.
1561 .sp
1562 Unless you set \fBcompiler_check\fR to a suitable command (see the description of that configuration option), it is not recommended to use the form \fBccache anotherwrapper compiler args\fR as the compilation command\&. It\(cqs also not recommended to use the masquerading technique for the other compiler wrapper\&. The reason is that by default, ccache will in both cases hash the mtime and size of the other wrapper instead of the real compiler, which means that:
1563 .sp
1564 .RS 4
1565 .ie n \{\
1566 \h'-04'\(bu\h'+03'\c
1567 .\}
1568 .el \{\
1569 .sp -1
1570 .IP \(bu 2.3
1571 .\}
1572 Compiler upgrades will not be detected properly\&.
1573 .RE
1574 .sp
1575 .RS 4
1576 .ie n \{\
1577 \h'-04'\(bu\h'+03'\c
1578 .\}
1579 .el \{\
1580 .sp -1
1581 .IP \(bu 2.3
1582 .\}
1583 The cached results will not be shared between compilations with and without the other wrapper\&.
1584 .RE
1585 .sp
1586 Another minor thing is that if \fBprefix_command\fR is used, ccache will not invoke the other wrapper when running the preprocessor, which increases performance\&. You can use the \fBprefix_command_cpp\fR configuration setting if you also want to invoke the other wrapper when doing preprocessing (normally by adding \fB\-E\fR)\&.
1587 .SH "CAVEATS"
1588 .sp
1589 .RS 4
1590 .ie n \{\
1591 \h'-04'\(bu\h'+03'\c
1592 .\}
1593 .el \{\
1594 .sp -1
1595 .IP \(bu 2.3
1596 .\}
1597 The direct mode fails to pick up new header files in some rare scenarios\&. See
1598 THE DIRECT MODE
1599 above\&.
1600 .RE
1601 .SH "TROUBLESHOOTING"
1602 .SS "General"
1603 .sp
1604 A general tip for getting information about what ccache is doing is to enable debug logging by setting \fBlog_file\fR\&. The log contains executed commands, important decisions that ccache makes, read and written files, etc\&. Another way of keeping track of what is happening is to check the output of \fBccache \-s\fR\&.
1605 .SS "Performance"
1606 .sp
1607 ccache has been written to perform well out of the box, but sometimes you may have to do some adjustments of how you use the compiler and ccache in order to improve performance\&.
1608 .sp
1609 Since ccache works best when I/O is fast, put the cache directory on a fast storage device if possible\&. Having lots of free memory so that files in the cache directory stay in the disk cache is also preferable\&.
1610 .sp
1611 A good way of monitoring how well ccache works is to run \fBccache \-s\fR before and after your build and then compare the statistics counters\&. Here are some common problems and what may be done to increase the hit rate:
1612 .sp
1613 .RS 4
1614 .ie n \{\
1615 \h'-04'\(bu\h'+03'\c
1616 .\}
1617 .el \{\
1618 .sp -1
1619 .IP \(bu 2.3
1620 .\}
1621 If \(lqcache hit (preprocessed)\(rq has been incremented instead of \(lqcache hit (direct)\(rq, ccache has fallen back to preprocessor mode, which is generally slower\&. Some possible reasons are:
1622 .sp
1623 .RS 4
1624 .ie n \{\
1625 \h'-04'\(bu\h'+03'\c
1626 .\}
1627 .el \{\
1628 .sp -1
1629 .IP \(bu 2.3
1630 .\}
1631 The source code has been modified in such a way that the preprocessor output is not affected\&.
1632 .RE
1633 .sp
1634 .RS 4
1635 .ie n \{\
1636 \h'-04'\(bu\h'+03'\c
1637 .\}
1638 .el \{\
1639 .sp -1
1640 .IP \(bu 2.3
1641 .\}
1642 Compiler arguments that are hashed in the direct mode but not in the preprocessor mode have changed (\fB\-I\fR,
1643 \fB\-include\fR,
1644 \fB\-D\fR, etc) and they didn\(cqt affect the preprocessor output\&.
1645 .RE
1646 .sp
1647 .RS 4
1648 .ie n \{\
1649 \h'-04'\(bu\h'+03'\c
1650 .\}
1651 .el \{\
1652 .sp -1
1653 .IP \(bu 2.3
1654 .\}
1655 The compiler option
1656 \fB\-Xpreprocessor\fR
1657 or
1658 \fB\-Wp,\fR\fB\fIX\fR\fR
1659 (except
1660 \fB\-Wp,\-MD,\fR\fB\fIpath\fR\fR,
1661 \fB\-Wp,\-MMD,\fR\fB\fIpath\fR\fR, and
1662 \fB\-Wp,\-D_define_\fR) is used\&.
1663 .RE
1664 .sp
1665 .RS 4
1666 .ie n \{\
1667 \h'-04'\(bu\h'+03'\c
1668 .\}
1669 .el \{\
1670 .sp -1
1671 .IP \(bu 2.3
1672 .\}
1673 This was the first compilation with a new value of the base directory setting\&.
1674 .RE
1675 .sp
1676 .RS 4
1677 .ie n \{\
1678 \h'-04'\(bu\h'+03'\c
1679 .\}
1680 .el \{\
1681 .sp -1
1682 .IP \(bu 2.3
1683 .\}
1684 A modification time of one of the include files is too new (created the same second as the compilation is being done)\&. This check is made to avoid a race condition\&. To fix this, create the include file earlier in the build process, if possible, or set
1685 \fBsloppiness\fR
1686 to
1687 \fBinclude_file_mtime\fR
1688 if you are willing to take the risk\&. (The race condition consists of these events: the preprocessor is run; an include file is modified by someone; the new include file is hashed by ccache; the real compiler is run on the preprocessor\(cqs output, which contains data from the old header file; the wrong object file is stored in the cache\&.)
1689 .RE
1690 .sp
1691 .RS 4
1692 .ie n \{\
1693 \h'-04'\(bu\h'+03'\c
1694 .\}
1695 .el \{\
1696 .sp -1
1697 .IP \(bu 2.3
1698 .\}
1699 The
1700 \fB__TIME__\fR
1701 preprocessor macro is (potentially) being used\&. ccache turns off direct mode if \(lq__TIME__\(rq is present in the source code\&. This is done as a safety measure since the string indicates that a
1702 \fB__TIME__\fR
1703 macro
1704 \fImay\fR
1705 affect the output\&. (To be sure, ccache would have to run the preprocessor, but the sole point of the direct mode is to avoid that\&.) If you know that
1706 \fB__TIME__\fR
1707 isn\(cqt used in practise, or don\(cqt care if ccache produces objects where
1708 \fB__TIME__\fR
1709 is expanded to something in the past, you can set
1710 \fBsloppiness\fR
1711 to
1712 \fBtime_macros\fR\&.
1713 .RE
1714 .sp
1715 .RS 4
1716 .ie n \{\
1717 \h'-04'\(bu\h'+03'\c
1718 .\}
1719 .el \{\
1720 .sp -1
1721 .IP \(bu 2.3
1722 .\}
1723 The
1724 \fB__DATE__\fR
1725 preprocessor macro is (potentially) being used and the date has changed\&. This is similar to how
1726 \fB__TIME__\fR
1727 is handled\&. If \(lq__DATE__\(rq is present in the source code, ccache hashes the current date in order to be able to produce the correct object file if the
1728 \fB__DATE__\fR
1729 macro affects the output\&. If you know that
1730 \fB__DATE__\fR
1731 isn\(cqt used in practise, or don\(cqt care if ccache produces objects where
1732 \fB__DATE__\fR
1733 is expanded to something in the past, you can set
1734 \fBsloppiness\fR
1735 to
1736 \fBtime_macros\fR\&.
1737 .RE
1738 .sp
1739 .RS 4
1740 .ie n \{\
1741 \h'-04'\(bu\h'+03'\c
1742 .\}
1743 .el \{\
1744 .sp -1
1745 .IP \(bu 2.3
1746 .\}
1747 The
1748 \fB__FILE__\fR
1749 preprocessor macro is (potentially) being used and the file path has changed\&. If \(lq__FILE__\(rq is present in the source code, ccache hashes the current input file path in order to be able to produce the correct object file if the
1750 \fB__FILE__\fR
1751 macro affects the output\&. If you know that
1752 \fB__FILE__\fR
1753 isn\(cqt used in practise, or don\(cqt care if ccache produces objects where
1754 \fB__FILE__\fR
1755 is expanded to the wrong path, you can set
1756 \fBsloppiness\fR
1757 to
1758 \fBfile_macro\fR\&.
1759 .RE
1760 .RE
1761 .sp
1762 .RS 4
1763 .ie n \{\
1764 \h'-04'\(bu\h'+03'\c
1765 .\}
1766 .el \{\
1767 .sp -1
1768 .IP \(bu 2.3
1769 .\}
1770 If \(lqcache miss\(rq has been incremented even though the same code has been compiled and cached before, ccache has either detected that something has changed anyway or a cleanup has been performed (either explicitly or implicitly when a cache limit has been reached)\&. Some perhaps unobvious things that may result in a cache miss are usage of
1771 \fB__TIME__\fR
1772 or
1773 \fB__DATE__\fR
1774 macros, or use of automatically generated code that contains a timestamp, build counter or other volatile information\&.
1775 .RE
1776 .sp
1777 .RS 4
1778 .ie n \{\
1779 \h'-04'\(bu\h'+03'\c
1780 .\}
1781 .el \{\
1782 .sp -1
1783 .IP \(bu 2.3
1784 .\}
1785 If \(lqmultiple source files\(rq has been incremented, it\(cqs an indication that the compiler has been invoked on several source code files at once\&. ccache doesn\(cqt support that\&. Compile the source code files separately if possible\&.
1786 .RE
1787 .sp
1788 .RS 4
1789 .ie n \{\
1790 \h'-04'\(bu\h'+03'\c
1791 .\}
1792 .el \{\
1793 .sp -1
1794 .IP \(bu 2.3
1795 .\}
1796 If \(lqunsupported compiler option\(rq has been incremented, enable debug logging and check which option was rejected\&.
1797 .RE
1798 .sp
1799 .RS 4
1800 .ie n \{\
1801 \h'-04'\(bu\h'+03'\c
1802 .\}
1803 .el \{\
1804 .sp -1
1805 .IP \(bu 2.3
1806 .\}
1807 If \(lqpreprocessor error\(rq has been incremented, one possible reason is that precompiled headers are being used\&. See
1808 PRECOMPILED HEADERS
1809 for how to remedy this\&.
1810 .RE
1811 .sp
1812 .RS 4
1813 .ie n \{\
1814 \h'-04'\(bu\h'+03'\c
1815 .\}
1816 .el \{\
1817 .sp -1
1818 .IP \(bu 2.3
1819 .\}
1820 If \(lqcan\(cqt use precompiled header\(rq has been incremented, see
1821 PRECOMPILED HEADERS\&.
1822 .RE
1823 .SS "Corrupt object files"
1824 .sp
1825 It should be noted that ccache is susceptible to general storage problems\&. If a bad object file sneaks into the cache for some reason, it will of course stay bad\&. Some possible reasons for erroneous object files are bad hardware (disk drive, disk controller, memory, etc), buggy drivers or file systems, a bad \fBprefix_command\fR or compiler wrapper\&. If this happens, the easiest way of fixing it is this:
1826 .sp
1827 .RS 4
1828 .ie n \{\
1829 \h'-04' 1.\h'+01'\c
1830 .\}
1831 .el \{\
1832 .sp -1
1833 .IP "  1." 4.2
1834 .\}
1835 Build so that the bad object file ends up in the build tree\&.
1836 .RE
1837 .sp
1838 .RS 4
1839 .ie n \{\
1840 \h'-04' 2.\h'+01'\c
1841 .\}
1842 .el \{\
1843 .sp -1
1844 .IP "  2." 4.2
1845 .\}
1846 Remove the bad object file from the build tree\&.
1847 .RE
1848 .sp
1849 .RS 4
1850 .ie n \{\
1851 \h'-04' 3.\h'+01'\c
1852 .\}
1853 .el \{\
1854 .sp -1
1855 .IP "  3." 4.2
1856 .\}
1857 Rebuild with
1858 \fBCCACHE_RECACHE\fR
1859 set\&.
1860 .RE
1861 .sp
1862 An alternative is to clear the whole cache with \fBccache \-C\fR if you don\(cqt mind losing other cached results\&.
1863 .sp
1864 There are no reported issues about ccache producing broken object files reproducibly\&. That doesn\(cqt mean it can\(cqt happen, so if you find a repeatable case, please report it\&.
1865 .SH "MORE INFORMATION"
1866 .sp
1867 Credits, mailing list information, bug reporting instructions, source code, etc, can be found on ccache\(cqs web site: https://ccache\&.samba\&.org\&.
1868 .SH "AUTHOR"
1869 .sp
1870 ccache was originally written by Andrew Tridgell and is currently developed and maintained by Joel Rosdahl\&. See AUTHORS\&.txt or AUTHORS\&.html and https://ccache\&.samba\&.org/credits\&.html for a list of contributors\&.