Imported Upstream version 3.3.6
[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/28/2018
6 .\"    Manual: ccache Manual
7 .\"    Source: ccache 3.3.6
8 .\"  Language: English
9 .\"
10 .TH "CCACHE" "1" "01/28/2018" "ccache 3\&.3\&.6" "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\&. 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
375 /
376 as the base directory since that will make ccache also rewrite paths to system header files, which doesn\(cqt gain anything\&.
377 .sp
378 See also the discussion under
379 COMPILING IN DIFFERENT DIRECTORIES\&.
380 .RE
381 .PP
382 \fBcache_dir\fR (\fBCCACHE_DIR\fR)
383 .RS 4
384 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
385 \fB$HOME/\&.ccache\fR\&.
386 .RE
387 .PP
388 \fBcache_dir_levels\fR (\fBCCACHE_NLEVELS\fR)
389 .RS 4
390 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\&.
391 .RE
392 .PP
393 \fBcompiler\fR (\fBCCACHE_CC\fR)
394 .RS 4
395 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\&.
396 .RE
397 .PP
398 \fBcompiler_check\fR (\fBCCACHE_COMPILERCHECK\fR)
399 .RS 4
400 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:
401 .PP
402 \fBcontent\fR
403 .RS 4
404 Hash the content of the compiler binary\&. This makes ccache very slightly slower compared to the
405 \fBmtime\fR
406 setting, but makes it cope better with compiler upgrades during a build bootstrapping process\&.
407 .RE
408 .PP
409 \fBmtime\fR
410 .RS 4
411 Hash the compiler\(cqs mtime and size, which is fast\&. This is the default\&.
412 .RE
413 .PP
414 \fBnone\fR
415 .RS 4
416 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
417 \fBnone\fR
418 setting if you know what you are doing\&.
419 .RE
420 .PP
421 \fBstring:value\fR
422 .RS 4
423 Use
424 \fBvalue\fR
425 as the string to calculate hash from\&. This can be the compiler revision number you retrieved earlier and set here via environment variable\&.
426 .RE
427 .PP
428 \fIa command string\fR
429 .RS 4
430 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
431 \fB%compiler%\fR
432 will be replaced with the path to the compiler\&. Several commands can be specified with semicolon as separator\&. Examples:
433 .sp
434 .if n \{\
435 .RS 4
436 .\}
437 .nf
438 %compiler% \-v
439 .fi
440 .if n \{\
441 .RE
442 .\}
443 .sp
444 .if n \{\
445 .RS 4
446 .\}
447 .nf
448 %compiler% \-dumpmachine; %compiler% \-dumpversion
449 .fi
450 .if n \{\
451 .RE
452 .\}
453 .sp
454 You should make sure that the specified command is as fast as possible since it will be run once for each ccache invocation\&.
455 .sp
456 Identifying the compiler using a command is useful if you want to avoid cache misses when the compiler has been rebuilt but not changed\&.
457 .sp
458 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
459 \fBmtime\fR
460 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
461 \fBmtime\fR
462 method in combination with the
463 \fBprefix_command\fR
464 setting if possible\&. See
465 USING CCACHE WITH OTHER COMPILER WRAPPERS\&.
466 .RE
467 .RE
468 .PP
469 \fBcompression\fR (\fBCCACHE_COMPRESS\fR or \fBCCACHE_NOCOMPRESS\fR, see Boolean values above)
470 .RS 4
471 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\&.
472 .RE
473 .PP
474 \fBcompression_level\fR (\fBCCACHE_COMPRESSLEVEL\fR)
475 .RS 4
476 This setting determines the level at which ccache will compress object files\&. It only has effect if
477 \fBcompression\fR
478 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)\&.
479 .RE
480 .PP
481 \fBcpp_extension\fR (\fBCCACHE_EXTENSION\fR)
482 .RS 4
483 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
484 \fBi\fR\&.
485 .RE
486 .PP
487 \fBdirect_mode\fR (\fBCCACHE_DIRECT\fR or \fBCCACHE_NODIRECT\fR, see Boolean values above)
488 .RS 4
489 If true, the direct mode will be used\&. The default is true\&. See
490 THE DIRECT MODE\&.
491 .RE
492 .PP
493 \fBdisable\fR (\fBCCACHE_DISABLE\fR or \fBCCACHE_NODISABLE\fR, see Boolean values above)
494 .RS 4
495 When true, ccache will just call the real compiler, bypassing the cache completely\&. The default is false\&.
496 .RE
497 .PP
498 \fBextra_files_to_hash\fR (\fBCCACHE_EXTRAFILES\fR)
499 .RS 4
500 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\&.
501 .RE
502 .PP
503 \fBhard_link\fR (\fBCCACHE_HARDLINK\fR or \fBCCACHE_NOHARDLINK\fR, see Boolean values above)
504 .RS 4
505 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\&.
506 .RE
507 .PP
508 \fBhash_dir\fR (\fBCCACHE_HASHDIR\fR or \fBCCACHE_NOHASHDIR\fR, see Boolean values above)
509 .RS 4
510 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
511 \fB\-g\fR
512 with variations)\&. Exception: The CWD will not be included in the hash if
513 \fBbase_dir\fR
514 is set (and matches the CWD) and the compiler option
515 \fB\-fdebug\-prefix\-map\fR
516 is used\&. See also the discussion under
517 COMPILING IN DIFFERENT DIRECTORIES\&.
518 .sp
519 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\&.
520 .sp
521 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\&.
522 .RE
523 .PP
524 \fBignore_headers_in_manifest\fR (\fBCCACHE_IGNOREHEADERS\fR)
525 .RS 4
526 This setting is a list of paths to files (or directories with headers) that ccache will
527 \fBnot\fR
528 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\&.
529 .RE
530 .PP
531 \fBkeep_comments_cpp\fR (\fBCCACHE_COMMENTS\fR or \fBCCACHE_NOCOMMENTS\fR, see Boolean values above)
532 .RS 4
533 If true, ccache will not discard the comments before hashing preprocessor output\&. This can be used to check documentation with
534 \fB\-Wdocumentation\fR\&.
535 .RE
536 .PP
537 \fBlimit_multiple\fR (\fBCCACHE_LIMIT_MULTIPLE\fR)
538 .RS 4
539 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
540 AUTOMATIC CLEANUP
541 for more information\&.
542 .RE
543 .PP
544 \fBlog_file\fR (\fBCCACHE_LOGFILE\fR)
545 .RS 4
546 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\&.
547 .RE
548 .PP
549 \fBmax_files\fR (\fBCCACHE_MAXFILES\fR)
550 .RS 4
551 This option specifies the maximum number of files to keep in the cache\&. Use 0 for no limit (which is the default)\&. See also
552 CACHE SIZE MANAGEMENT\&.
553 .RE
554 .PP
555 \fBmax_size\fR (\fBCCACHE_MAXSIZE\fR)
556 .RS 4
557 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
558 CACHE SIZE MANAGEMENT\&.
559 .RE
560 .PP
561 \fBpath\fR (\fBCCACHE_PATH\fR)
562 .RS 4
563 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
564 \fBPATH\fR
565 that isn\(cqt a symbolic link to ccache itself\&.
566 .RE
567 .PP
568 \fBprefix_command\fR (\fBCCACHE_PREFIX\fR)
569 .RS 4
570 This option adds a list of prefixes (separated by space) to the command line that ccache uses when invoking the compiler\&. See also
571 USING CCACHE WITH OTHER COMPILER WRAPPERS\&.
572 .RE
573 .PP
574 \fBprefix_command_cpp\fR (\fBCCACHE_PREFIX_CPP\fR)
575 .RS 4
576 This option adds a list of prefixes (separated by space) to the command line that ccache uses when invoking the preprocessor\&.
577 .RE
578 .PP
579 \fBread_only\fR (\fBCCACHE_READONLY\fR or \fBCCACHE_NOREADONLY\fR, see Boolean values above)
580 .RS 4
581 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
582 \fBtemporary_dir\fR
583 as otherwise ccache will fail to create temporary files\&.
584 .RE
585 .PP
586 \fBread_only_direct\fR (\fBCCACHE_READONLY_DIRECT\fR or \fBCCACHE_NOREADONLY_DIRECT\fR, see Boolean values above)
587 .RS 4
588 Just like
589 \fBread_only\fR
590 except that ccache will only try to retrieve results from the cache using the direct mode, not the preprocessor mode\&. See documentation for
591 \fBread_only\fR
592 regarding using a read\-only ccache directory\&.
593 .RE
594 .PP
595 \fBrecache\fR (\fBCCACHE_RECACHE\fR or \fBCCACHE_NORECACHE\fR, see Boolean values above)
596 .RS 4
597 If true, ccache will not use any previously stored result\&. New results will still be cached, possibly overwriting any pre\-existing results\&.
598 .RE
599 .PP
600 \fBrun_second_cpp\fR (\fBCCACHE_CPP2\fR or \fBCCACHE_NOCPP2\fR, see Boolean values above)
601 .RS 4
602 If true, ccache will first run the preprocessor to preprocess the source code (see
603 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\&.
604 .sp
605 If false, ccache will first run preprocessor to preprocess the source code and then on a cache miss run the compiler on the
606 \fIpreprocessed source code\fR
607 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\&.
608 .RE
609 .PP
610 \fBsloppiness\fR (\fBCCACHE_SLOPPINESS\fR)
611 .RS 4
612 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:
613 .PP
614 \fBfile_macro\fR
615 .RS 4
616 Ignore
617 \fB__FILE__\fR
618 being present in the source\&.
619 .RE
620 .PP
621 \fBfile_stat_matches\fR
622 .RS 4
623 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\&.
624 .RE
625 .PP
626 \fBinclude_file_ctime\fR
627 .RS 4
628 By default, ccache also will not cache a file if it includes a header whose ctime is too new\&. This option disables that check\&.
629 .RE
630 .PP
631 \fBinclude_file_mtime\fR
632 .RS 4
633 By default, ccache will not cache a file if it includes a header whose mtime is too new\&. This option disables that check\&.
634 .RE
635 .PP
636 \fBno_system_headers\fR
637 .RS 4
638 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\&.
639 .RE
640 .PP
641 \fBpch_defines\fR
642 .RS 4
643 Be sloppy about
644 \fB#define\fRs when precompiling a header file\&. See
645 PRECOMPILED HEADERS
646 for more information\&.
647 .RE
648 .PP
649 \fBtime_macros\fR
650 .RS 4
651 Ignore
652 \fB__DATE__\fR
653 and
654 \fB__TIME__\fR
655 being present in the source code\&.
656 .RE
657 .sp
658 See the discussion under
659 TROUBLESHOOTING
660 for more information\&.
661 .RE
662 .PP
663 \fBstats\fR (\fBCCACHE_STATS\fR or \fBCCACHE_NOSTATS\fR, see Boolean values above)
664 .RS 4
665 If true, ccache will update the statistics counters on each compilation\&. The default is true\&.
666 .RE
667 .PP
668 \fBtemporary_dir\fR (\fBCCACHE_TEMPDIR\fR)
669 .RS 4
670 This setting specifies where ccache will put temporary files\&. The default is
671 \fB<cache_dir>/tmp\fR\&.
672 .if n \{\
673 .sp
674 .\}
675 .RS 4
676 .it 1 an-trap
677 .nr an-no-space-flag 1
678 .nr an-break-flag 1
679 .br
680 .ps +1
681 \fBNote\fR
682 .ps -1
683 .br
684 In previous versions of ccache,
685 \fBCCACHE_TEMPDIR\fR
686 had to be on the same filesystem as the
687 \fBCCACHE_DIR\fR
688 path, but this requirement has been relaxed\&.)
689 .sp .5v
690 .RE
691 .RE
692 .PP
693 \fBumask\fR (\fBCCACHE_UMASK\fR)
694 .RS 4
695 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\&.
696 .RE
697 .PP
698 \fBunify\fR (\fBCCACHE_UNIFY\fR or \fBCCACHE_NOUNIFY\fR, see Boolean values above)
699 .RS 4
700 If true, ccache will use a C/C++ unifier when hashing the preprocessor output if the
701 \fB\-g\fR
702 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
703 \fB__LINE__\fR
704 macro\&. Also note that enabling the unifier implies turning off the direct mode\&.
705 .RE
706 .SH "CACHE SIZE MANAGEMENT"
707 .sp
708 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)\&.
709 .sp
710 Cleanup can be triggered in two different ways: automatic and manual\&.
711 .SS "Automatic cleanup"
712 .sp
713 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\&.
714 .sp
715 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\&.
716 .sp
717 When automatic cleanup is triggered for a subdirectory in the cache, ccache will:
718 .sp
719 .RS 4
720 .ie n \{\
721 \h'-04' 1.\h'+01'\c
722 .\}
723 .el \{\
724 .sp -1
725 .IP "  1." 4.2
726 .\}
727 Count all files in the subdirectory and compute their aggregated size\&.
728 .RE
729 .sp
730 .RS 4
731 .ie n \{\
732 \h'-04' 2.\h'+01'\c
733 .\}
734 .el \{\
735 .sp -1
736 .IP "  2." 4.2
737 .\}
738 Remove files in LRU (least recently used) order until the size is at most
739 \fBlimit_multiple * max_size / 16\fR
740 and the number of files is at most
741 \fBlimit_multiple * max_files / 16\fR, where
742 \fBlimit_multiple\fR,
743 \fBmax_size\fR
744 and
745 \fBmax_files\fR
746 are configuration settings\&.
747 .RE
748 .sp
749 .RS 4
750 .ie n \{\
751 \h'-04' 3.\h'+01'\c
752 .\}
753 .el \{\
754 .sp -1
755 .IP "  3." 4.2
756 .\}
757 Set the size and file number counters to match the files that were kept\&.
758 .RE
759 .sp
760 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\&.
761 .SS "Manual cleanup"
762 .sp
763 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\&.
764 .SH "CACHE COMPRESSION"
765 .sp
766 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\&.
767 .SH "CACHE STATISTICS"
768 .sp
769 \fBccache \-s/\-\-show\-stats\fR can show the following statistics:
770 .TS
771 allbox tab(:);
772 ltB ltB.
773 T{
774 Name
775 T}:T{
776 Description
777 T}
778 .T&
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 lt lt
805 lt lt
806 lt lt.
807 T{
808 .sp
809 autoconf compile/link
810 T}:T{
811 .sp
812 Uncachable compilation or linking by an autoconf test\&.
813 T}
814 T{
815 .sp
816 bad compiler arguments
817 T}:T{
818 .sp
819 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\&.
820 T}
821 T{
822 .sp
823 cache file missing
824 T}:T{
825 .sp
826 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\&.
827 T}
828 T{
829 .sp
830 cache hit (direct)
831 T}:T{
832 .sp
833 A result was successfully found using the direct mode\&.
834 T}
835 T{
836 .sp
837 cache hit (preprocessed)
838 T}:T{
839 .sp
840 A result was successfully found using the preprocessor mode\&.
841 T}
842 T{
843 .sp
844 cache miss
845 T}:T{
846 .sp
847 No result was found\&.
848 T}
849 T{
850 .sp
851 cache size
852 T}:T{
853 .sp
854 Current size of the cache\&.
855 T}
856 T{
857 .sp
858 called for link
859 T}:T{
860 .sp
861 The compiler was called for linking, not compiling\&.
862 T}
863 T{
864 .sp
865 called for preprocessing
866 T}:T{
867 .sp
868 The compiler was called for preprocessing, not compiling\&.
869 T}
870 T{
871 .sp
872 can\(cqt use precompiled header
873 T}:T{
874 .sp
875 Preconditions for using precompiled headers were not fulfilled\&.
876 T}
877 T{
878 .sp
879 ccache internal error
880 T}:T{
881 .sp
882 Unexpected failure, e\&.g\&. due to problems reading/writing the cache\&.
883 T}
884 T{
885 .sp
886 cleanups performed
887 T}:T{
888 .sp
889 Number of cleanups performed, either implicitly due to the cache size limit being reached or due to explicit \fBccache \-c/\-\-cleanup\fR calls\&.
890 T}
891 T{
892 .sp
893 compile failed
894 T}:T{
895 .sp
896 The compilation failed\&. No result stored in the cache\&.
897 T}
898 T{
899 .sp
900 compiler check failed
901 T}:T{
902 .sp
903 A compiler check program specified by \fBcompiler_check\fR (\fBCCACHE_COMPILERCHECK\fR) failed\&.
904 T}
905 T{
906 .sp
907 compiler produced empty output
908 T}:T{
909 .sp
910 The compiler\(cqs output file (typically an object file) was empty after compilation\&.
911 T}
912 T{
913 .sp
914 compiler produced no output
915 T}:T{
916 .sp
917 The compiler\(cqs output file (typically an object file) was missing after compilation\&.
918 T}
919 T{
920 .sp
921 compiler produced stdout
922 T}:T{
923 .sp
924 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\&.
925 T}
926 T{
927 .sp
928 couldn\(cqt find the compiler
929 T}:T{
930 .sp
931 The compiler to execute could not be found\&.
932 T}
933 T{
934 .sp
935 error hashing extra file
936 T}:T{
937 .sp
938 Failure reading a file specified by \fBextra_files_to_hash\fR (\fBCCACHE_EXTRAFILES\fR)\&.
939 T}
940 T{
941 .sp
942 files in cache
943 T}:T{
944 .sp
945 Current number of files in the cache\&.
946 T}
947 T{
948 .sp
949 multiple source files
950 T}:T{
951 .sp
952 The compiler was called to compile multiple source files in one go\&. This is not supported by ccache\&.
953 T}
954 T{
955 .sp
956 no input file
957 T}:T{
958 .sp
959 No input file was specified to the compiler\&.
960 T}
961 T{
962 .sp
963 output to a non\-regular file
964 T}:T{
965 .sp
966 The output path specified with \fB\-o\fR is not a file (e\&.g\&. a directory or a device node)\&.
967 T}
968 T{
969 .sp
970 output to stdout
971 T}:T{
972 .sp
973 The compiler was instructed to write its output to standard output using \fB\-o \-\fR\&. This is not supported by ccache\&.
974 T}
975 T{
976 .sp
977 preprocessor error
978 T}:T{
979 .sp
980 Preprocessing the source code using the compiler\(cqs \fB\-E\fR option failed\&.
981 T}
982 T{
983 .sp
984 unsupported code directive
985 T}:T{
986 .sp
987 Code like the assembler \(lq\&.incbin\(rq directive was found\&. This is not supported by ccache\&.
988 T}
989 T{
990 .sp
991 unsupported compiler option
992 T}:T{
993 .sp
994 A compiler option not supported by ccache was found\&.
995 T}
996 T{
997 .sp
998 unsupported source language
999 T}:T{
1000 .sp
1001 A source language e\&.g\&. specified with \fB\-x\fR was unsupported by ccache\&.
1002 T}
1003 .TE
1004 .sp 1
1005 .SH "HOW CCACHE WORKS"
1006 .sp
1007 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\&.
1008 .sp
1009 ccache has two ways of doing the detection:
1010 .sp
1011 .RS 4
1012 .ie n \{\
1013 \h'-04'\(bu\h'+03'\c
1014 .\}
1015 .el \{\
1016 .sp -1
1017 .IP \(bu 2.3
1018 .\}
1019 the
1020 \fBdirect mode\fR, where ccache hashes the source code and include files directly
1021 .RE
1022 .sp
1023 .RS 4
1024 .ie n \{\
1025 \h'-04'\(bu\h'+03'\c
1026 .\}
1027 .el \{\
1028 .sp -1
1029 .IP \(bu 2.3
1030 .\}
1031 the
1032 \fBpreprocessor mode\fR, where ccache runs the preprocessor on the source code and hashes the result
1033 .RE
1034 .sp
1035 The direct mode is generally faster since running the preprocessor has some overhead\&.
1036 .SS "Common hashed information"
1037 .sp
1038 For both modes, the following information is included in the hash:
1039 .sp
1040 .RS 4
1041 .ie n \{\
1042 \h'-04'\(bu\h'+03'\c
1043 .\}
1044 .el \{\
1045 .sp -1
1046 .IP \(bu 2.3
1047 .\}
1048 the extension used by the compiler for a file with preprocessor output (normally
1049 \fB\&.i\fR
1050 for C code and
1051 \fB\&.ii\fR
1052 for C++ code)
1053 .RE
1054 .sp
1055 .RS 4
1056 .ie n \{\
1057 \h'-04'\(bu\h'+03'\c
1058 .\}
1059 .el \{\
1060 .sp -1
1061 .IP \(bu 2.3
1062 .\}
1063 the compiler\(cqs size and modification time (or other compiler\-specific information specified by the
1064 \fBcompiler_check\fR
1065 setting)
1066 .RE
1067 .sp
1068 .RS 4
1069 .ie n \{\
1070 \h'-04'\(bu\h'+03'\c
1071 .\}
1072 .el \{\
1073 .sp -1
1074 .IP \(bu 2.3
1075 .\}
1076 the name of the compiler
1077 .RE
1078 .sp
1079 .RS 4
1080 .ie n \{\
1081 \h'-04'\(bu\h'+03'\c
1082 .\}
1083 .el \{\
1084 .sp -1
1085 .IP \(bu 2.3
1086 .\}
1087 the current directory (if the
1088 \fBhash_dir\fR
1089 setting is enabled)
1090 .RE
1091 .sp
1092 .RS 4
1093 .ie n \{\
1094 \h'-04'\(bu\h'+03'\c
1095 .\}
1096 .el \{\
1097 .sp -1
1098 .IP \(bu 2.3
1099 .\}
1100 contents of files specified by the
1101 \fBextra_files_to_hash\fR
1102 setting (if any)
1103 .RE
1104 .SS "The direct mode"
1105 .sp
1106 In the direct mode, the hash is formed of the common information and:
1107 .sp
1108 .RS 4
1109 .ie n \{\
1110 \h'-04'\(bu\h'+03'\c
1111 .\}
1112 .el \{\
1113 .sp -1
1114 .IP \(bu 2.3
1115 .\}
1116 the input source file
1117 .RE
1118 .sp
1119 .RS 4
1120 .ie n \{\
1121 \h'-04'\(bu\h'+03'\c
1122 .\}
1123 .el \{\
1124 .sp -1
1125 .IP \(bu 2.3
1126 .\}
1127 the command line options
1128 .RE
1129 .sp
1130 Based on the hash, a data structure called \(lqmanifest\(rq is looked up in the cache\&. The manifest contains:
1131 .sp
1132 .RS 4
1133 .ie n \{\
1134 \h'-04'\(bu\h'+03'\c
1135 .\}
1136 .el \{\
1137 .sp -1
1138 .IP \(bu 2.3
1139 .\}
1140 references to cached compilation results (object file, dependency file, etc) that were produced by previous compilations that matched the hash
1141 .RE
1142 .sp
1143 .RS 4
1144 .ie n \{\
1145 \h'-04'\(bu\h'+03'\c
1146 .\}
1147 .el \{\
1148 .sp -1
1149 .IP \(bu 2.3
1150 .\}
1151 paths to the include files that were read at the time the compilation results were stored in the cache
1152 .RE
1153 .sp
1154 .RS 4
1155 .ie n \{\
1156 \h'-04'\(bu\h'+03'\c
1157 .\}
1158 .el \{\
1159 .sp -1
1160 .IP \(bu 2.3
1161 .\}
1162 hash sums of the include files at the time the compilation results were stored in the cache
1163 .RE
1164 .sp
1165 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\&.
1166 .sp
1167 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\&.
1168 .sp
1169 The direct mode will be disabled if any of the following holds:
1170 .sp
1171 .RS 4
1172 .ie n \{\
1173 \h'-04'\(bu\h'+03'\c
1174 .\}
1175 .el \{\
1176 .sp -1
1177 .IP \(bu 2.3
1178 .\}
1179 the configuration setting
1180 \fBdirect_mode\fR
1181 is false
1182 .RE
1183 .sp
1184 .RS 4
1185 .ie n \{\
1186 \h'-04'\(bu\h'+03'\c
1187 .\}
1188 .el \{\
1189 .sp -1
1190 .IP \(bu 2.3
1191 .\}
1192 a modification time of one of the include files is too new (needed to avoid a race condition)
1193 .RE
1194 .sp
1195 .RS 4
1196 .ie n \{\
1197 \h'-04'\(bu\h'+03'\c
1198 .\}
1199 .el \{\
1200 .sp -1
1201 .IP \(bu 2.3
1202 .\}
1203 the unifier is enabled (the configuration setting
1204 \fBunify\fR
1205 is true)
1206 .RE
1207 .sp
1208 .RS 4
1209 .ie n \{\
1210 \h'-04'\(bu\h'+03'\c
1211 .\}
1212 .el \{\
1213 .sp -1
1214 .IP \(bu 2.3
1215 .\}
1216 a compiler option not supported by the direct mode is used:
1217 .sp
1218 .RS 4
1219 .ie n \{\
1220 \h'-04'\(bu\h'+03'\c
1221 .\}
1222 .el \{\
1223 .sp -1
1224 .IP \(bu 2.3
1225 .\}
1226 a
1227 \fB\-Wp,\fR\fB\fIX\fR\fR
1228 compiler option other than
1229 \fB\-Wp,\-MD,\fR\fB\fIpath\fR\fR,
1230 \fB\-Wp,\-MMD,\fR\fB\fIpath\fR\fR
1231 and
1232 \fB\-Wp,\-D_define_\fR
1233 .RE
1234 .sp
1235 .RS 4
1236 .ie n \{\
1237 \h'-04'\(bu\h'+03'\c
1238 .\}
1239 .el \{\
1240 .sp -1
1241 .IP \(bu 2.3
1242 .\}
1243 \fB\-Xpreprocessor\fR
1244 .RE
1245 .RE
1246 .sp
1247 .RS 4
1248 .ie n \{\
1249 \h'-04'\(bu\h'+03'\c
1250 .\}
1251 .el \{\
1252 .sp -1
1253 .IP \(bu 2.3
1254 .\}
1255 the string \(lq__TIME__\(rq is present in the source code
1256 .RE
1257 .SS "The preprocessor mode"
1258 .sp
1259 In the preprocessor mode, the hash is formed of the common information and:
1260 .sp
1261 .RS 4
1262 .ie n \{\
1263 \h'-04'\(bu\h'+03'\c
1264 .\}
1265 .el \{\
1266 .sp -1
1267 .IP \(bu 2.3
1268 .\}
1269 the preprocessor output from running the compiler with
1270 \fB\-E\fR
1271 .RE
1272 .sp
1273 .RS 4
1274 .ie n \{\
1275 \h'-04'\(bu\h'+03'\c
1276 .\}
1277 .el \{\
1278 .sp -1
1279 .IP \(bu 2.3
1280 .\}
1281 the command line options except options that affect include files (\fB\-I\fR,
1282 \fB\-include\fR,
1283 \fB\-D\fR, etc; the theory is that these options will change the preprocessor output if they have any effect at all)
1284 .RE
1285 .sp
1286 .RS 4
1287 .ie n \{\
1288 \h'-04'\(bu\h'+03'\c
1289 .\}
1290 .el \{\
1291 .sp -1
1292 .IP \(bu 2.3
1293 .\}
1294 any standard error output generated by the preprocessor
1295 .RE
1296 .sp
1297 Based on the hash, the cached compilation result can be looked up directly in the cache\&.
1298 .SH "COMPILING IN DIFFERENT DIRECTORIES"
1299 .sp
1300 Some information included in the hash that identifies a unique compilation can contain absolute paths:
1301 .sp
1302 .RS 4
1303 .ie n \{\
1304 \h'-04'\(bu\h'+03'\c
1305 .\}
1306 .el \{\
1307 .sp -1
1308 .IP \(bu 2.3
1309 .\}
1310 The preprocessed source code may contain absolute paths to include files if the compiler option
1311 \fB\-g\fR
1312 is used or if absolute paths are given to
1313 \fB\-I\fR
1314 and similar compiler options\&.
1315 .RE
1316 .sp
1317 .RS 4
1318 .ie n \{\
1319 \h'-04'\(bu\h'+03'\c
1320 .\}
1321 .el \{\
1322 .sp -1
1323 .IP \(bu 2.3
1324 .\}
1325 Paths specified by compiler options (such as
1326 \fB\-I\fR,
1327 \fB\-MF\fR, etc) on the command line may be absolute\&.
1328 .RE
1329 .sp
1330 .RS 4
1331 .ie n \{\
1332 \h'-04'\(bu\h'+03'\c
1333 .\}
1334 .el \{\
1335 .sp -1
1336 .IP \(bu 2.3
1337 .\}
1338 The source code file path may be absolute, and that path may substituted for
1339 \fB__FILE__\fR
1340 macros in the source code or included in warnings emitted to standard error by the preprocessor\&.
1341 .RE
1342 .sp
1343 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\&.
1344 .sp
1345 Here\(cqs what can be done to enable cache hits between different build directories:
1346 .sp
1347 .RS 4
1348 .ie n \{\
1349 \h'-04'\(bu\h'+03'\c
1350 .\}
1351 .el \{\
1352 .sp -1
1353 .IP \(bu 2.3
1354 .\}
1355 If you build with
1356 \fB\-g\fR
1357 (or similar) to add debug information to the object file, you must either:
1358 .sp
1359 .RS 4
1360 .ie n \{\
1361 \h'-04'\(bu\h'+03'\c
1362 .\}
1363 .el \{\
1364 .sp -1
1365 .IP \(bu 2.3
1366 .\}
1367 use the
1368 \fB\-fdebug\-prefix\-map=\fR\fB\fIold\fR\fR\fB=\fR\fB\fInew\fR\fR
1369 option for relocating debug info to a common prefix (e\&.g\&.
1370 \fB\-fdebug\-prefix\-map=$PWD=\&.\fR); or
1371 .RE
1372 .sp
1373 .RS 4
1374 .ie n \{\
1375 \h'-04'\(bu\h'+03'\c
1376 .\}
1377 .el \{\
1378 .sp -1
1379 .IP \(bu 2.3
1380 .\}
1381 set
1382 \fBhash_dir = false\fR\&.
1383 .RE
1384 .RE
1385 .sp
1386 .RS 4
1387 .ie n \{\
1388 \h'-04'\(bu\h'+03'\c
1389 .\}
1390 .el \{\
1391 .sp -1
1392 .IP \(bu 2.3
1393 .\}
1394 If you use absolute paths anywhere on the command line (e\&.g\&. the source code file path or an argument to compiler options like
1395 \fB\-I\fR
1396 and
1397 \fB\-MF\fR), you must to set
1398 \fBbase_dir\fR
1399 to an absolute path to a \(lqbase directory\(rq\&. ccache will then rewrite absolute paths under that directory to relative before computing the hash\&.
1400 .RE
1401 .SH "PRECOMPILED HEADERS"
1402 .sp
1403 ccache has support for GCC\(cqs precompiled headers\&. However, you have to do some things to make it work properly:
1404 .sp
1405 .RS 4
1406 .ie n \{\
1407 \h'-04'\(bu\h'+03'\c
1408 .\}
1409 .el \{\
1410 .sp -1
1411 .IP \(bu 2.3
1412 .\}
1413 You must set
1414 \fBsloppiness\fR
1415 to
1416 \fBpch_defines,time_macros\fR\&. The reason is that ccache can\(cqt tell whether
1417 \fB__TIME__\fR
1418 or
1419 \fB__DATE__\fR
1420 is used when using a precompiled header\&. Further, it can\(cqt detect changes in
1421 \fB#define\fRs in the source code because of how preprocessing works in combination with precompiled headers\&.
1422 .RE
1423 .sp
1424 .RS 4
1425 .ie n \{\
1426 \h'-04'\(bu\h'+03'\c
1427 .\}
1428 .el \{\
1429 .sp -1
1430 .IP \(bu 2.3
1431 .\}
1432 You must either:
1433 .sp
1434 .RS 4
1435 .ie n \{\
1436 \h'-04'\(bu\h'+03'\c
1437 .\}
1438 .el \{\
1439 .sp -1
1440 .IP \(bu 2.3
1441 .\}
1442 use the
1443 \fB\-include\fR
1444 compiler option to include the precompiled header (i\&.e\&., don\(cqt use
1445 \fB#include\fR
1446 in the source code to include the header); or
1447 .RE
1448 .sp
1449 .RS 4
1450 .ie n \{\
1451 \h'-04'\(bu\h'+03'\c
1452 .\}
1453 .el \{\
1454 .sp -1
1455 .IP \(bu 2.3
1456 .\}
1457 (for the Clang compiler) use the
1458 \fB\-include\-pch\fR
1459 compiler option to include the PCH file generated from the precompiled header; or
1460 .RE
1461 .sp
1462 .RS 4
1463 .ie n \{\
1464 \h'-04'\(bu\h'+03'\c
1465 .\}
1466 .el \{\
1467 .sp -1
1468 .IP \(bu 2.3
1469 .\}
1470 add the
1471 \fB\-fpch\-preprocess\fR
1472 compiler option when compiling\&.
1473 .RE
1474 .sp
1475 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)\&.
1476 .RE
1477 .SH "SHARING A CACHE"
1478 .sp
1479 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:
1480 .sp
1481 .RS 4
1482 .ie n \{\
1483 \h'-04'\(bu\h'+03'\c
1484 .\}
1485 .el \{\
1486 .sp -1
1487 .IP \(bu 2.3
1488 .\}
1489 Use the same cache directory\&.
1490 .RE
1491 .sp
1492 .RS 4
1493 .ie n \{\
1494 \h'-04'\(bu\h'+03'\c
1495 .\}
1496 .el \{\
1497 .sp -1
1498 .IP \(bu 2.3
1499 .\}
1500 Make sure that the configuration setting
1501 \fBhard_link\fR
1502 is false (which is the default)\&.
1503 .RE
1504 .sp
1505 .RS 4
1506 .ie n \{\
1507 \h'-04'\(bu\h'+03'\c
1508 .\}
1509 .el \{\
1510 .sp -1
1511 .IP \(bu 2.3
1512 .\}
1513 Make sure that all users are in the same group\&.
1514 .RE
1515 .sp
1516 .RS 4
1517 .ie n \{\
1518 \h'-04'\(bu\h'+03'\c
1519 .\}
1520 .el \{\
1521 .sp -1
1522 .IP \(bu 2.3
1523 .\}
1524 Set the configuration setting
1525 \fBumask\fR
1526 to 002\&. This ensures that cached files are accessible to everyone in the group\&.
1527 .RE
1528 .sp
1529 .RS 4
1530 .ie n \{\
1531 \h'-04'\(bu\h'+03'\c
1532 .\}
1533 .el \{\
1534 .sp -1
1535 .IP \(bu 2.3
1536 .\}
1537 Make sure that all users have write permission in the entire cache directory (and that you trust all users of the shared cache)\&.
1538 .RE
1539 .sp
1540 .RS 4
1541 .ie n \{\
1542 \h'-04'\(bu\h'+03'\c
1543 .\}
1544 .el \{\
1545 .sp -1
1546 .IP \(bu 2.3
1547 .\}
1548 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:
1549 .sp
1550 .if n \{\
1551 .RS 4
1552 .\}
1553 .nf
1554 find $CCACHE_DIR \-type d | xargs chmod g+s
1555 .fi
1556 .if n \{\
1557 .RE
1558 .\}
1559 .RE
1560 .sp
1561 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\&.
1562 .sp
1563 You may also want to make sure that a base directory is set appropriately, as discussed in a previous section\&.
1564 .SH "SHARING A CACHE ON NFS"
1565 .sp
1566 It is possible to put the cache directory on an NFS filesystem (or similar filesystems), but keep in mind that:
1567 .sp
1568 .RS 4
1569 .ie n \{\
1570 \h'-04'\(bu\h'+03'\c
1571 .\}
1572 .el \{\
1573 .sp -1
1574 .IP \(bu 2.3
1575 .\}
1576 Having the cache on NFS may slow down compilation\&. Make sure to do some benchmarking to see if it\(cqs worth it\&.
1577 .RE
1578 .sp
1579 .RS 4
1580 .ie n \{\
1581 \h'-04'\(bu\h'+03'\c
1582 .\}
1583 .el \{\
1584 .sp -1
1585 .IP \(bu 2.3
1586 .\}
1587 ccache hasn\(cqt been tested very thoroughly on NFS\&.
1588 .RE
1589 .sp
1590 A tip is to set \fBtemporary_dir\fR to a directory on the local host to avoid NFS traffic for temporary files\&.
1591 .SH "USING CCACHE WITH OTHER COMPILER WRAPPERS"
1592 .sp
1593 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\&.
1594 .sp
1595 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:
1596 .sp
1597 .RS 4
1598 .ie n \{\
1599 \h'-04'\(bu\h'+03'\c
1600 .\}
1601 .el \{\
1602 .sp -1
1603 .IP \(bu 2.3
1604 .\}
1605 Compiler upgrades will not be detected properly\&.
1606 .RE
1607 .sp
1608 .RS 4
1609 .ie n \{\
1610 \h'-04'\(bu\h'+03'\c
1611 .\}
1612 .el \{\
1613 .sp -1
1614 .IP \(bu 2.3
1615 .\}
1616 The cached results will not be shared between compilations with and without the other wrapper\&.
1617 .RE
1618 .sp
1619 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)\&.
1620 .SH "CAVEATS"
1621 .sp
1622 .RS 4
1623 .ie n \{\
1624 \h'-04'\(bu\h'+03'\c
1625 .\}
1626 .el \{\
1627 .sp -1
1628 .IP \(bu 2.3
1629 .\}
1630 The direct mode fails to pick up new header files in some rare scenarios\&. See
1631 THE DIRECT MODE
1632 above\&.
1633 .RE
1634 .SH "TROUBLESHOOTING"
1635 .SS "General"
1636 .sp
1637 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\&.
1638 .SS "Performance"
1639 .sp
1640 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\&.
1641 .sp
1642 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\&.
1643 .sp
1644 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:
1645 .sp
1646 .RS 4
1647 .ie n \{\
1648 \h'-04'\(bu\h'+03'\c
1649 .\}
1650 .el \{\
1651 .sp -1
1652 .IP \(bu 2.3
1653 .\}
1654 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:
1655 .sp
1656 .RS 4
1657 .ie n \{\
1658 \h'-04'\(bu\h'+03'\c
1659 .\}
1660 .el \{\
1661 .sp -1
1662 .IP \(bu 2.3
1663 .\}
1664 The source code has been modified in such a way that the preprocessor output is not affected\&.
1665 .RE
1666 .sp
1667 .RS 4
1668 .ie n \{\
1669 \h'-04'\(bu\h'+03'\c
1670 .\}
1671 .el \{\
1672 .sp -1
1673 .IP \(bu 2.3
1674 .\}
1675 Compiler arguments that are hashed in the direct mode but not in the preprocessor mode have changed (\fB\-I\fR,
1676 \fB\-include\fR,
1677 \fB\-D\fR, etc) and they didn\(cqt affect the preprocessor output\&.
1678 .RE
1679 .sp
1680 .RS 4
1681 .ie n \{\
1682 \h'-04'\(bu\h'+03'\c
1683 .\}
1684 .el \{\
1685 .sp -1
1686 .IP \(bu 2.3
1687 .\}
1688 The compiler option
1689 \fB\-Xpreprocessor\fR
1690 or
1691 \fB\-Wp,\fR\fB\fIX\fR\fR
1692 (except
1693 \fB\-Wp,\-MD,\fR\fB\fIpath\fR\fR,
1694 \fB\-Wp,\-MMD,\fR\fB\fIpath\fR\fR, and
1695 \fB\-Wp,\-D_define_\fR) is used\&.
1696 .RE
1697 .sp
1698 .RS 4
1699 .ie n \{\
1700 \h'-04'\(bu\h'+03'\c
1701 .\}
1702 .el \{\
1703 .sp -1
1704 .IP \(bu 2.3
1705 .\}
1706 This was the first compilation with a new value of the base directory setting\&.
1707 .RE
1708 .sp
1709 .RS 4
1710 .ie n \{\
1711 \h'-04'\(bu\h'+03'\c
1712 .\}
1713 .el \{\
1714 .sp -1
1715 .IP \(bu 2.3
1716 .\}
1717 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
1718 \fBsloppiness\fR
1719 to
1720 \fBinclude_file_mtime\fR
1721 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\&.)
1722 .RE
1723 .sp
1724 .RS 4
1725 .ie n \{\
1726 \h'-04'\(bu\h'+03'\c
1727 .\}
1728 .el \{\
1729 .sp -1
1730 .IP \(bu 2.3
1731 .\}
1732 The
1733 \fB__TIME__\fR
1734 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
1735 \fB__TIME__\fR
1736 macro
1737 \fImay\fR
1738 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
1739 \fB__TIME__\fR
1740 isn\(cqt used in practise, or don\(cqt care if ccache produces objects where
1741 \fB__TIME__\fR
1742 is expanded to something in the past, you can set
1743 \fBsloppiness\fR
1744 to
1745 \fBtime_macros\fR\&.
1746 .RE
1747 .sp
1748 .RS 4
1749 .ie n \{\
1750 \h'-04'\(bu\h'+03'\c
1751 .\}
1752 .el \{\
1753 .sp -1
1754 .IP \(bu 2.3
1755 .\}
1756 The
1757 \fB__DATE__\fR
1758 preprocessor macro is (potentially) being used and the date has changed\&. This is similar to how
1759 \fB__TIME__\fR
1760 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
1761 \fB__DATE__\fR
1762 macro affects the output\&. If you know that
1763 \fB__DATE__\fR
1764 isn\(cqt used in practise, or don\(cqt care if ccache produces objects where
1765 \fB__DATE__\fR
1766 is expanded to something in the past, you can set
1767 \fBsloppiness\fR
1768 to
1769 \fBtime_macros\fR\&.
1770 .RE
1771 .sp
1772 .RS 4
1773 .ie n \{\
1774 \h'-04'\(bu\h'+03'\c
1775 .\}
1776 .el \{\
1777 .sp -1
1778 .IP \(bu 2.3
1779 .\}
1780 The
1781 \fB__FILE__\fR
1782 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
1783 \fB__FILE__\fR
1784 macro affects the output\&. If you know that
1785 \fB__FILE__\fR
1786 isn\(cqt used in practise, or don\(cqt care if ccache produces objects where
1787 \fB__FILE__\fR
1788 is expanded to the wrong path, you can set
1789 \fBsloppiness\fR
1790 to
1791 \fBfile_macro\fR\&.
1792 .RE
1793 .RE
1794 .sp
1795 .RS 4
1796 .ie n \{\
1797 \h'-04'\(bu\h'+03'\c
1798 .\}
1799 .el \{\
1800 .sp -1
1801 .IP \(bu 2.3
1802 .\}
1803 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
1804 \fB__TIME__\fR
1805 or
1806 \fB__DATE__\fR
1807 macros, or use of automatically generated code that contains a timestamp, build counter or other volatile information\&.
1808 .RE
1809 .sp
1810 .RS 4
1811 .ie n \{\
1812 \h'-04'\(bu\h'+03'\c
1813 .\}
1814 .el \{\
1815 .sp -1
1816 .IP \(bu 2.3
1817 .\}
1818 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\&.
1819 .RE
1820 .sp
1821 .RS 4
1822 .ie n \{\
1823 \h'-04'\(bu\h'+03'\c
1824 .\}
1825 .el \{\
1826 .sp -1
1827 .IP \(bu 2.3
1828 .\}
1829 If \(lqunsupported compiler option\(rq has been incremented, enable debug logging and check which option was rejected\&.
1830 .RE
1831 .sp
1832 .RS 4
1833 .ie n \{\
1834 \h'-04'\(bu\h'+03'\c
1835 .\}
1836 .el \{\
1837 .sp -1
1838 .IP \(bu 2.3
1839 .\}
1840 If \(lqpreprocessor error\(rq has been incremented, one possible reason is that precompiled headers are being used\&. See
1841 PRECOMPILED HEADERS
1842 for how to remedy this\&.
1843 .RE
1844 .sp
1845 .RS 4
1846 .ie n \{\
1847 \h'-04'\(bu\h'+03'\c
1848 .\}
1849 .el \{\
1850 .sp -1
1851 .IP \(bu 2.3
1852 .\}
1853 If \(lqcan\(cqt use precompiled header\(rq has been incremented, see
1854 PRECOMPILED HEADERS\&.
1855 .RE
1856 .SS "Corrupt object files"
1857 .sp
1858 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:
1859 .sp
1860 .RS 4
1861 .ie n \{\
1862 \h'-04' 1.\h'+01'\c
1863 .\}
1864 .el \{\
1865 .sp -1
1866 .IP "  1." 4.2
1867 .\}
1868 Build so that the bad object file ends up in the build tree\&.
1869 .RE
1870 .sp
1871 .RS 4
1872 .ie n \{\
1873 \h'-04' 2.\h'+01'\c
1874 .\}
1875 .el \{\
1876 .sp -1
1877 .IP "  2." 4.2
1878 .\}
1879 Remove the bad object file from the build tree\&.
1880 .RE
1881 .sp
1882 .RS 4
1883 .ie n \{\
1884 \h'-04' 3.\h'+01'\c
1885 .\}
1886 .el \{\
1887 .sp -1
1888 .IP "  3." 4.2
1889 .\}
1890 Rebuild with
1891 \fBCCACHE_RECACHE\fR
1892 set\&.
1893 .RE
1894 .sp
1895 An alternative is to clear the whole cache with \fBccache \-C\fR if you don\(cqt mind losing other cached results\&.
1896 .sp
1897 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\&.
1898 .SH "MORE INFORMATION"
1899 .sp
1900 Credits, mailing list information, bug reporting instructions, source code, etc, can be found on ccache\(cqs web site: https://ccache\&.samba\&.org\&.
1901 .SH "AUTHOR"
1902 .sp
1903 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\&.