Imported Upstream version 3.2
[platform/upstream/ccache.git] / ccache.1
1 '\" t
2 .\"     Title: ccache
3 .\"    Author: [see the "Author" section]
4 .\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
5 .\"      Date: 11/17/2014
6 .\"    Manual: ccache Manual
7 .\"    Source: ccache 3.2
8 .\"  Language: English
9 .\"
10 .TH "CCACHE" "1" "11/17/2014" "ccache 3\&.2" "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 BUGS\&. 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\&. \fBNote\fR: \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\&.
274 .sp
275 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\&.
276 .sp
277 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\&.
278 .SH "CONFIGURATION"
279 .sp
280 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):
281 .sp
282 .RS 4
283 .ie n \{\
284 \h'-04' 1.\h'+01'\c
285 .\}
286 .el \{\
287 .sp -1
288 .IP "  1." 4.2
289 .\}
290 Environment variables\&.
291 .RE
292 .sp
293 .RS 4
294 .ie n \{\
295 \h'-04' 2.\h'+01'\c
296 .\}
297 .el \{\
298 .sp -1
299 .IP "  2." 4.2
300 .\}
301 The cache\-specific configuration file
302 \fB<ccachedir>/ccache\&.conf\fR
303 (typically
304 \fB$HOME/\&.ccache/ccache\&.conf\fR)\&.
305 .RE
306 .sp
307 .RS 4
308 .ie n \{\
309 \h'-04' 3.\h'+01'\c
310 .\}
311 .el \{\
312 .sp -1
313 .IP "  3." 4.2
314 .\}
315 The system\-wide configuration file
316 \fB<sysconfdir>/ccache\&.conf\fR
317 (typically
318 \fB/etc/ccache\&.conf\fR
319 or
320 \fB/usr/local/etc/ccache\&.conf\fR)\&.
321 .RE
322 .sp
323 .RS 4
324 .ie n \{\
325 \h'-04' 4.\h'+01'\c
326 .\}
327 .el \{\
328 .sp -1
329 .IP "  4." 4.2
330 .\}
331 Compile\-time defaults\&.
332 .RE
333 .sp
334 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\&.
335 .SS "Configuration file syntax"
336 .sp
337 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:
338 .sp
339 .if n \{\
340 .RS 4
341 .\}
342 .nf
343 # Set maximum cache size to 10 GB:
344 max_size = 10G
345 .fi
346 .if n \{\
347 .RE
348 .\}
349 .SS "Boolean values"
350 .sp
351 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\&.
352 .SS "Configuration settings"
353 .sp
354 Below is a list of available configuration settings\&. The corresponding environment variable name is indicated in parentheses after each configuration setting key\&. Boolean options are indicated with \(lq[boolean]\(rq
355 .PP
356 \fBbase_dir\fR (\fBCCACHE_BASEDIR\fR)
357 .RS 4
358 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
359 COMPILING IN DIFFERENT DIRECTORIES\&.
360 .RE
361 .PP
362 \fBcache_dir\fR (\fBCCACHE_DIR\fR)
363 .RS 4
364 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
365 \fB$HOME/\&.ccache\fR\&.
366 .RE
367 .PP
368 \fBcache_dir_levels\fR (\fBCCACHE_NLEVELS\fR)
369 .RS 4
370 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\&.
371 .RE
372 .PP
373 \fBcompiler\fR (\fBCCACHE_CC\fR)
374 .RS 4
375 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\&.
376 .RE
377 .PP
378 \fBcompiler_check\fR (\fBCCACHE_COMPILERCHECK\fR)
379 .RS 4
380 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:
381 .PP
382 \fBcontent\fR
383 .RS 4
384 Hash the content of the compiler binary\&. This makes ccache very slightly slower compared to the
385 \fBmtime\fR
386 setting, but makes it cope better with compiler upgrades during a build bootstrapping process\&.
387 .RE
388 .PP
389 \fBmtime\fR
390 .RS 4
391 Hash the compiler\(cqs mtime and size, which is fast\&. This is the default\&.
392 .RE
393 .PP
394 \fBnone\fR
395 .RS 4
396 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
397 \fBnone\fR
398 setting if you know what you are doing\&.
399 .RE
400 .PP
401 \fIa command string\fR
402 .RS 4
403 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
404 \fB%compiler%\fR
405 will be replaced with the path to the compiler\&. Several commands can be specified with semicolon as separator\&. Examples:
406 .sp
407 .RS 4
408 .ie n \{\
409 \h'-04'\(bu\h'+03'\c
410 .\}
411 .el \{\
412 .sp -1
413 .IP \(bu 2.3
414 .\}
415 %compiler% \-v
416 .RE
417 .sp
418 .RS 4
419 .ie n \{\
420 \h'-04'\(bu\h'+03'\c
421 .\}
422 .el \{\
423 .sp -1
424 .IP \(bu 2.3
425 .\}
426 %compiler% \-dumpmachine; %compiler% \-dumpversion
427 .RE
428 .sp
429 You should make sure that the specified command is as fast as possible since it will be run once for each ccache invocation\&.
430 .sp
431 Identifying the compiler using a command is useful if you want to avoid cache misses when the compiler has been rebuilt but not changed\&.
432 .sp
433 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
434 \fBmtime\fR
435 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
436 \fBmtime\fR
437 method in combination with the
438 \fBprefix_command\fR
439 setting if possible\&. See
440 USING CCACHE WITH OTHER COMPILER WRAPPERS\&.
441 .RE
442 .RE
443 .PP
444 \fBcompression\fR (\fBCCACHE_COMPRESS\fR) [boolean]
445 .RS 4
446 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\&.
447 .RE
448 .PP
449 \fBcompression_level\fR (\fBCCACHE_COMPRESSLEVEL\fR)
450 .RS 4
451 This setting determines the level at which ccache will compress object files\&. It only has effect if
452 \fBcompression\fR
453 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)\&.
454 .RE
455 .PP
456 \fBcpp_extension\fR (\fBCCACHE_EXTENSION\fR)
457 .RS 4
458 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
459 \fBi\fR\&.
460 .RE
461 .PP
462 \fBdirect_mode\fR (\fBCCACHE_DIRECT\fR) [boolean]
463 .RS 4
464 If true, the direct mode will be used\&. The default is true\&. See
465 THE DIRECT MODE\&.
466 .RE
467 .PP
468 \fBdisable\fR (\fBCCACHE_DISABLE\fR) [boolean]
469 .RS 4
470 When true, ccache will just call the real compiler, bypassing the cache completely\&. The default is false\&.
471 .RE
472 .PP
473 \fBextra_files_to_hash\fR (\fBCCACHE_EXTRAFILES\fR)
474 .RS 4
475 This setting is a list of paths to files that ccache will include in the the hash sum that idetifies the build\&. The list separator is semicolon on Windows systems and colon on other systems\&.
476 .RE
477 .PP
478 \fBhard_link\fR (\fBCCACHE_HARDLINK\fR) [boolean]
479 .RS 4
480 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\&.
481 .RE
482 .PP
483 \fBhash_dir\fR (\fBCCACHE_HASHDIR\fR) [boolean]
484 .RS 4
485 If true, ccache will include the current working directory in the hash that is used to distinguish two compilations\&. This prevents a problem with the storage of the current working directory in the debug info of a object file, which can lead ccache to give a cached object file that has the working directory in the debug info set incorrectly\&. This option is off by default as the incorrect setting of this debug info rarely causes problems\&. If you strike problems with GDB not using the correct directory then enable this option\&.
486 .RE
487 .PP
488 \fBlog_file\fR (\fBCCACHE_LOGFILE\fR)
489 .RS 4
490 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\&.
491 .RE
492 .PP
493 \fBstats\fR (\fBCCACHE_STATS\fR) [boolean]
494 .RS 4
495 If true, ccache will update the statistics counters on each compilation\&. The default is true\&.
496 .RE
497 .PP
498 \fBpath\fR (\fBCCACHE_PATH\fR)
499 .RS 4
500 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
501 \fBPATH\fR
502 that isn\(cqt a symbolic link to ccache itself\&.
503 .RE
504 .PP
505 \fBprefix_command\fR (\fBCCACHE_PREFIX\fR)
506 .RS 4
507 This option adds a list of prefixes (separated by space) to the command line that ccache uses when invoking the compiler\&. See also
508 USING CCACHE WITH OTHER COMPILER WRAPPERS\&.
509 .RE
510 .PP
511 \fBread_only\fR (\fBCCACHE_READONLY\fR) [boolean]
512 .RS 4
513 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
514 \fBtemporary_dir\fR
515 as otherwise ccache will fail to create temporary files\&.
516 .RE
517 .PP
518 \fBread_only_direct\fR (\fBCCACHE_READONLY_DIRECT\fR) [boolean]
519 .RS 4
520 Just like
521 \fBread_only\fR
522 except that ccache will only try to retrieve results from the cache using the direct mode, not the preprocessor mode\&. See documentation for
523 \fBread_only\fR
524 regarding using a read\-only ccache directory\&.
525 .RE
526 .PP
527 \fBreache\fR (\fBCCACHE_RECACHE\fR) [boolean]
528 .RS 4
529 If true, ccache will not use any previously stored result\&. New results will still be cached, possibly overwriting any pre\-existing results\&.
530 .RE
531 .PP
532 \fBrun_second_cpp\fR (\fBCCACHE_CPP2\fR) [boolean]
533 .RS 4
534 If true, ccache will not use the optimisation of avoiding the second call to the preprocessor by compiling the preprocessed output that was used for finding the hash in the case of a cache miss\&. This is primarily a debugging option, although it is possible that some unusual compilers will have problems with compiling the preprocessed output, in which case this option could allow ccache to be used anyway\&.
535 .RE
536 .PP
537 \fBsloppiness\fR (\fBCCACHE_SLOPPINESS\fR)
538 .RS 4
539 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:
540 .PP
541 \fBfile_macro\fR
542 .RS 4
543 Ignore
544 \fB__FILE__\fR
545 being present in the source\&.
546 .RE
547 .PP
548 \fBfile_stat_matches\fR
549 .RS 4
550 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 sizes, mtimes and ctimes match\&.
551 .RE
552 .PP
553 \fBinclude_file_ctime\fR
554 .RS 4
555 By default, ccache also will not cache a file if it includes a header whose ctime is too new\&. This option disables that check\&.
556 .RE
557 .PP
558 \fBinclude_file_mtime\fR
559 .RS 4
560 By default, ccache will not cache a file if it includes a header whose mtime is too new\&. This option disables that check\&.
561 .RE
562 .PP
563 \fBpch_defines\fR
564 .RS 4
565 Be sloppy about #defines when precompiling a header file\&. See
566 PRECOMPILED HEADERS
567 for more information\&.
568 .RE
569 .PP
570 \fBtime_macros\fR
571 .RS 4
572 Ignore
573 \fB__DATE__\fR
574 and
575 \fB__TIME__\fR
576 being present in the source code\&.
577 .RE
578 .sp
579 See the discussion under
580 TROUBLESHOOTING
581 for more information\&.
582 .RE
583 .PP
584 \fBtemporary_dir\fR (\fBCCACHE_TEMPDIR\fR)
585 .RS 4
586 This setting specifies where ccache will put temporary files\&. The default is
587 \fB<cache_dir>/tmp\fR\&.
588 .if n \{\
589 .sp
590 .\}
591 .RS 4
592 .it 1 an-trap
593 .nr an-no-space-flag 1
594 .nr an-break-flag 1
595 .br
596 .ps +1
597 \fBNote\fR
598 .ps -1
599 .br
600 In previous versions of ccache,
601 \fBCCACHE_TEMPDIR\fR
602 had to be on the same filesystem as the
603 \fBCCACHE_DIR\fR
604 path, but this requirement has been relaxed\&.)
605 .sp .5v
606 .RE
607 .RE
608 .PP
609 \fBumask\fR (\fBCCACHE_UMASK\fR)
610 .RS 4
611 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\&.
612 .RE
613 .PP
614 \fBunify\fR (\fBCCACHE_UNIFY\fR) [boolean]
615 .RS 4
616 If true, ccache will use a C/C++ unifier when hashing the preprocessor output if the
617 \fB\-g\fR
618 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
619 \fB__LINE__\fR
620 macro\&. Also note that enabling the unifier implies turning off the direct mode\&.
621 .RE
622 .SH "CACHE SIZE MANAGEMENT"
623 .sp
624 By default, ccache has a five gigabyte limit on the total size of files in the cache and no maximum 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)\&.
625 .SH "CACHE COMPRESSION"
626 .sp
627 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\&.
628 .SH "HOW CCACHE WORKS"
629 .sp
630 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\&.
631 .sp
632 ccache has two ways of doing the detection:
633 .sp
634 .RS 4
635 .ie n \{\
636 \h'-04'\(bu\h'+03'\c
637 .\}
638 .el \{\
639 .sp -1
640 .IP \(bu 2.3
641 .\}
642 the
643 \fBdirect mode\fR, where ccache hashes the source code and include files directly
644 .RE
645 .sp
646 .RS 4
647 .ie n \{\
648 \h'-04'\(bu\h'+03'\c
649 .\}
650 .el \{\
651 .sp -1
652 .IP \(bu 2.3
653 .\}
654 the
655 \fBpreprocessor mode\fR, where ccache runs the preprocessor on the source code and hashes the result
656 .RE
657 .sp
658 The direct mode is generally faster since running the preprocessor has some overhead\&.
659 .SS "Common hashed information"
660 .sp
661 For both modes, the following information is included in the hash:
662 .sp
663 .RS 4
664 .ie n \{\
665 \h'-04'\(bu\h'+03'\c
666 .\}
667 .el \{\
668 .sp -1
669 .IP \(bu 2.3
670 .\}
671 the extension used by the compiler for a file with preprocessor output (normally
672 \fB\&.i\fR
673 for C code and
674 \fB\&.ii\fR
675 for C++ code)
676 .RE
677 .sp
678 .RS 4
679 .ie n \{\
680 \h'-04'\(bu\h'+03'\c
681 .\}
682 .el \{\
683 .sp -1
684 .IP \(bu 2.3
685 .\}
686 the compiler\(cqs size and modification time (or other compiler\-specific information specified by the
687 \fBcompiler_check\fR
688 setting)
689 .RE
690 .sp
691 .RS 4
692 .ie n \{\
693 \h'-04'\(bu\h'+03'\c
694 .\}
695 .el \{\
696 .sp -1
697 .IP \(bu 2.3
698 .\}
699 the name of the compiler
700 .RE
701 .sp
702 .RS 4
703 .ie n \{\
704 \h'-04'\(bu\h'+03'\c
705 .\}
706 .el \{\
707 .sp -1
708 .IP \(bu 2.3
709 .\}
710 the current directory (if the
711 \fBhash_dir\fR
712 setting is enabled)
713 .RE
714 .sp
715 .RS 4
716 .ie n \{\
717 \h'-04'\(bu\h'+03'\c
718 .\}
719 .el \{\
720 .sp -1
721 .IP \(bu 2.3
722 .\}
723 contents of files specified by the
724 \fBextra_files_to_hash\fR
725 setting (if any)
726 .RE
727 .SS "The direct mode"
728 .sp
729 In the direct mode, the hash is formed of the common information and:
730 .sp
731 .RS 4
732 .ie n \{\
733 \h'-04'\(bu\h'+03'\c
734 .\}
735 .el \{\
736 .sp -1
737 .IP \(bu 2.3
738 .\}
739 the input source file
740 .RE
741 .sp
742 .RS 4
743 .ie n \{\
744 \h'-04'\(bu\h'+03'\c
745 .\}
746 .el \{\
747 .sp -1
748 .IP \(bu 2.3
749 .\}
750 the command line options
751 .RE
752 .sp
753 Based on the hash, a data structure called \(lqmanifest\(rq is looked up in the cache\&. The manifest contains:
754 .sp
755 .RS 4
756 .ie n \{\
757 \h'-04'\(bu\h'+03'\c
758 .\}
759 .el \{\
760 .sp -1
761 .IP \(bu 2.3
762 .\}
763 references to cached compilation results (object file, dependency file, etc) that were produced by previous compilations that matched the hash
764 .RE
765 .sp
766 .RS 4
767 .ie n \{\
768 \h'-04'\(bu\h'+03'\c
769 .\}
770 .el \{\
771 .sp -1
772 .IP \(bu 2.3
773 .\}
774 paths to the include files that were read at the time the compilation results were stored in the cache
775 .RE
776 .sp
777 .RS 4
778 .ie n \{\
779 \h'-04'\(bu\h'+03'\c
780 .\}
781 .el \{\
782 .sp -1
783 .IP \(bu 2.3
784 .\}
785 hash sums of the include files at the time the compilation results were stored in the cache
786 .RE
787 .sp
788 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\&.
789 .sp
790 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\&.
791 .sp
792 The direct mode will be disabled if any of the following holds:
793 .sp
794 .RS 4
795 .ie n \{\
796 \h'-04'\(bu\h'+03'\c
797 .\}
798 .el \{\
799 .sp -1
800 .IP \(bu 2.3
801 .\}
802 the configuration setting
803 \fBdirect_mode\fR
804 is false
805 .RE
806 .sp
807 .RS 4
808 .ie n \{\
809 \h'-04'\(bu\h'+03'\c
810 .\}
811 .el \{\
812 .sp -1
813 .IP \(bu 2.3
814 .\}
815 a modification time of one of the include files is too new (needed to avoid a race condition)
816 .RE
817 .sp
818 .RS 4
819 .ie n \{\
820 \h'-04'\(bu\h'+03'\c
821 .\}
822 .el \{\
823 .sp -1
824 .IP \(bu 2.3
825 .\}
826 the unifier is enabled (the configuration setting
827 \fBunify\fR
828 is true)
829 .RE
830 .sp
831 .RS 4
832 .ie n \{\
833 \h'-04'\(bu\h'+03'\c
834 .\}
835 .el \{\
836 .sp -1
837 .IP \(bu 2.3
838 .\}
839 a compiler option not supported by the direct mode is used:
840 .sp
841 .RS 4
842 .ie n \{\
843 \h'-04'\(bu\h'+03'\c
844 .\}
845 .el \{\
846 .sp -1
847 .IP \(bu 2.3
848 .\}
849 a
850 \fB\-Wp,\fR\fB\fIX\fR\fR
851 compiler option other than
852 \fB\-Wp,\-MD,\fR\fB\fIpath\fR\fR
853 and
854 \fB\-Wp,\-MMD,\fR\fB\fIpath\fR\fR
855 .RE
856 .sp
857 .RS 4
858 .ie n \{\
859 \h'-04'\(bu\h'+03'\c
860 .\}
861 .el \{\
862 .sp -1
863 .IP \(bu 2.3
864 .\}
865 \fB\-Xpreprocessor\fR
866 .RE
867 .RE
868 .sp
869 .RS 4
870 .ie n \{\
871 \h'-04'\(bu\h'+03'\c
872 .\}
873 .el \{\
874 .sp -1
875 .IP \(bu 2.3
876 .\}
877 the string \(lq__TIME__\(rq is present in the source code
878 .RE
879 .SS "The preprocessor mode"
880 .sp
881 In the preprocessor mode, the hash is formed of the common information and:
882 .sp
883 .RS 4
884 .ie n \{\
885 \h'-04'\(bu\h'+03'\c
886 .\}
887 .el \{\
888 .sp -1
889 .IP \(bu 2.3
890 .\}
891 the preprocessor output from running the compiler with
892 \fB\-E\fR
893 .RE
894 .sp
895 .RS 4
896 .ie n \{\
897 \h'-04'\(bu\h'+03'\c
898 .\}
899 .el \{\
900 .sp -1
901 .IP \(bu 2.3
902 .\}
903 the command line options except options that affect include files (\fB\-I\fR,
904 \fB\-include\fR,
905 \fB\-D\fR, etc; the theory is that these options will change the preprocessor output if they have any effect at all)
906 .RE
907 .sp
908 .RS 4
909 .ie n \{\
910 \h'-04'\(bu\h'+03'\c
911 .\}
912 .el \{\
913 .sp -1
914 .IP \(bu 2.3
915 .\}
916 any standard error output generated by the preprocessor
917 .RE
918 .sp
919 Based on the hash, the cached compilation result can be looked up directly in the cache\&.
920 .SH "COMPILING IN DIFFERENT DIRECTORIES"
921 .sp
922 Some information included in the hash that identifies a unique compilation may contain absolute paths:
923 .sp
924 .RS 4
925 .ie n \{\
926 \h'-04'\(bu\h'+03'\c
927 .\}
928 .el \{\
929 .sp -1
930 .IP \(bu 2.3
931 .\}
932 The preprocessed source code may contain absolute paths to include files if the compiler option
933 \fB\-g\fR
934 is used or if absolute paths are given to
935 \fB\-I\fR
936 and similar compiler options\&.
937 .RE
938 .sp
939 .RS 4
940 .ie n \{\
941 \h'-04'\(bu\h'+03'\c
942 .\}
943 .el \{\
944 .sp -1
945 .IP \(bu 2.3
946 .\}
947 Paths specified by compiler options (such as
948 \fB\-I\fR,
949 \fB\-MF\fR, etc) may be absolute\&.
950 .RE
951 .sp
952 .RS 4
953 .ie n \{\
954 \h'-04'\(bu\h'+03'\c
955 .\}
956 .el \{\
957 .sp -1
958 .IP \(bu 2.3
959 .\}
960 The source code file path may be absolute, and that path may substituted for
961 \fB__FILE__\fR
962 macros in the source code or included in warnings emitted to standard error by the preprocessor\&.
963 .RE
964 .sp
965 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\&.)
966 .sp
967 The drawbacks of using a base directory are:
968 .sp
969 .RS 4
970 .ie n \{\
971 \h'-04'\(bu\h'+03'\c
972 .\}
973 .el \{\
974 .sp -1
975 .IP \(bu 2.3
976 .\}
977 If you specify an absolute path to the source code file,
978 \fB__FILE__\fR
979 macros will be expanded to a relative path instead\&.
980 .RE
981 .sp
982 .RS 4
983 .ie n \{\
984 \h'-04'\(bu\h'+03'\c
985 .\}
986 .el \{\
987 .sp -1
988 .IP \(bu 2.3
989 .\}
990 If you specify an absolute path to the source code file and compile with
991 \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\&.
992 .RE
993 .SH "PRECOMPILED HEADERS"
994 .sp
995 ccache has support for GCC\(cqs precompiled headers\&. However, you have to do some things to make it work properly:
996 .sp
997 .RS 4
998 .ie n \{\
999 \h'-04'\(bu\h'+03'\c
1000 .\}
1001 .el \{\
1002 .sp -1
1003 .IP \(bu 2.3
1004 .\}
1005 You must set
1006 \fBsloppiness\fR
1007 to
1008 \fBpch_defines,time_macros\fR\&. The reason is that ccache can\(cqt tell whether
1009 \fB__TIME__\fR
1010 or
1011 \fB__DATE__\fR
1012 is used when using a precompiled header\&. Further, it can\(cqt detect changes in #defines in the source code because of how preprocessing works in combination with precompiled headers\&.
1013 .RE
1014 .sp
1015 .RS 4
1016 .ie n \{\
1017 \h'-04'\(bu\h'+03'\c
1018 .\}
1019 .el \{\
1020 .sp -1
1021 .IP \(bu 2.3
1022 .\}
1023 You must either:
1024 .sp
1025 .RS 4
1026 .ie n \{\
1027 \h'-04'\(bu\h'+03'\c
1028 .\}
1029 .el \{\
1030 .sp -1
1031 .IP \(bu 2.3
1032 .\}
1033 use the
1034 \fB\-include\fR
1035 compiler option to include the precompiled header (i\&.e\&., don\(cqt use
1036 \fB#include\fR
1037 in the source code to include the header); or
1038 .RE
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 (for the Clang compiler) use the
1049 \fB\-include\-pch\fR
1050 compiler option to include the PCH file generated from the precompiled header; or
1051 .RE
1052 .sp
1053 .RS 4
1054 .ie n \{\
1055 \h'-04'\(bu\h'+03'\c
1056 .\}
1057 .el \{\
1058 .sp -1
1059 .IP \(bu 2.3
1060 .\}
1061 add the
1062 \fB\-fpch\-preprocess\fR
1063 compiler option when compiling\&.
1064 .RE
1065 .sp
1066 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)\&.
1067 .RE
1068 .SH "SHARING A CACHE"
1069 .sp
1070 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:
1071 .sp
1072 .RS 4
1073 .ie n \{\
1074 \h'-04'\(bu\h'+03'\c
1075 .\}
1076 .el \{\
1077 .sp -1
1078 .IP \(bu 2.3
1079 .\}
1080 Use the same cache directory\&.
1081 .RE
1082 .sp
1083 .RS 4
1084 .ie n \{\
1085 \h'-04'\(bu\h'+03'\c
1086 .\}
1087 .el \{\
1088 .sp -1
1089 .IP \(bu 2.3
1090 .\}
1091 Make sure that the configuration setting
1092 \fBhard_link\fR
1093 is false (which is the default)\&.
1094 .RE
1095 .sp
1096 .RS 4
1097 .ie n \{\
1098 \h'-04'\(bu\h'+03'\c
1099 .\}
1100 .el \{\
1101 .sp -1
1102 .IP \(bu 2.3
1103 .\}
1104 Make sure that all users are in the same group\&.
1105 .RE
1106 .sp
1107 .RS 4
1108 .ie n \{\
1109 \h'-04'\(bu\h'+03'\c
1110 .\}
1111 .el \{\
1112 .sp -1
1113 .IP \(bu 2.3
1114 .\}
1115 Set the configuration setting
1116 \fBumask\fR
1117 to 002\&. This ensures that cached files are accessible to everyone in the group\&.
1118 .RE
1119 .sp
1120 .RS 4
1121 .ie n \{\
1122 \h'-04'\(bu\h'+03'\c
1123 .\}
1124 .el \{\
1125 .sp -1
1126 .IP \(bu 2.3
1127 .\}
1128 Make sure that all users have write permission in the entire cache directory (and that you trust all users of the shared cache)\&.
1129 .RE
1130 .sp
1131 .RS 4
1132 .ie n \{\
1133 \h'-04'\(bu\h'+03'\c
1134 .\}
1135 .el \{\
1136 .sp -1
1137 .IP \(bu 2.3
1138 .\}
1139 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 command \(lqfind $CCACHE_DIR \-type d | xargs chmod g+s\(rq might be useful for this\&.
1140 .RE
1141 .sp
1142 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\&.
1143 .sp
1144 You may also want to make sure that a base directory is set appropriately, as discussed in a previous section\&.
1145 .SH "SHARING A CACHE ON NFS"
1146 .sp
1147 It is possible to put the cache directory on an NFS filesystem (or similar filesystems), but keep in mind that:
1148 .sp
1149 .RS 4
1150 .ie n \{\
1151 \h'-04'\(bu\h'+03'\c
1152 .\}
1153 .el \{\
1154 .sp -1
1155 .IP \(bu 2.3
1156 .\}
1157 Having the cache on NFS may slow down compilation\&. Make sure to do some benchmarking to see if it\(cqs worth it\&.
1158 .RE
1159 .sp
1160 .RS 4
1161 .ie n \{\
1162 \h'-04'\(bu\h'+03'\c
1163 .\}
1164 .el \{\
1165 .sp -1
1166 .IP \(bu 2.3
1167 .\}
1168 ccache hasn\(cqt been tested very thoroughly on NFS\&.
1169 .RE
1170 .sp
1171 A tip is to set \fBtemporary_dir\fR to a directory on the local host to avoid NFS traffic for temporary files\&.
1172 .SH "USING CCACHE WITH OTHER COMPILER WRAPPERS"
1173 .sp
1174 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\&.
1175 .sp
1176 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:
1177 .sp
1178 .RS 4
1179 .ie n \{\
1180 \h'-04'\(bu\h'+03'\c
1181 .\}
1182 .el \{\
1183 .sp -1
1184 .IP \(bu 2.3
1185 .\}
1186 Compiler upgrades will not be detected properly\&.
1187 .RE
1188 .sp
1189 .RS 4
1190 .ie n \{\
1191 \h'-04'\(bu\h'+03'\c
1192 .\}
1193 .el \{\
1194 .sp -1
1195 .IP \(bu 2.3
1196 .\}
1197 The cached results will not be shared between compilations with and without the other wrapper\&.
1198 .RE
1199 .sp
1200 Another minor thing is that if \fBprefix_command\fR is used, ccache will not invoke the other wrapper when running the preprocessor, which increase performance\&.
1201 .SH "BUGS"
1202 .sp
1203 .RS 4
1204 .ie n \{\
1205 \h'-04'\(bu\h'+03'\c
1206 .\}
1207 .el \{\
1208 .sp -1
1209 .IP \(bu 2.3
1210 .\}
1211 ccache doesn\(cqt handle the GNU Assembler\(cqs
1212 \fB\&.incbin\fR
1213 directive correctly\&. This directive can be embedded in the source code inside an
1214 \fB\fIasm\fR\fR
1215 statement in order to include a file verbatim in the object file\&. If the included file is modified, ccache doesn\(cqt pick up the change since the inclusion isn\(cqt done by the preprocessor\&. A workaround of this problem is to set
1216 \fBextra_files_to_hash\fR
1217 to the path of the included file\&.
1218 .RE
1219 .sp
1220 .RS 4
1221 .ie n \{\
1222 \h'-04'\(bu\h'+03'\c
1223 .\}
1224 .el \{\
1225 .sp -1
1226 .IP \(bu 2.3
1227 .\}
1228 The direct mode fails to pick up new header files in some rare scenarios\&. See
1229 THE DIRECT MODE
1230 above\&.
1231 .RE
1232 .SH "TROUBLESHOOTING"
1233 .SS "General"
1234 .sp
1235 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\&.
1236 .SS "Performance"
1237 .sp
1238 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\&.
1239 .sp
1240 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 preferrable\&.
1241 .sp
1242 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:
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 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:
1253 .sp
1254 .RS 4
1255 .ie n \{\
1256 \h'-04'\(bu\h'+03'\c
1257 .\}
1258 .el \{\
1259 .sp -1
1260 .IP \(bu 2.3
1261 .\}
1262 The source code has been modified in such a way that the preprocessor output is not affected\&.
1263 .RE
1264 .sp
1265 .RS 4
1266 .ie n \{\
1267 \h'-04'\(bu\h'+03'\c
1268 .\}
1269 .el \{\
1270 .sp -1
1271 .IP \(bu 2.3
1272 .\}
1273 Compiler arguments that are hashed in the direct mode but not in the preprocessor mode have changed (\fB\-I\fR,
1274 \fB\-include\fR,
1275 \fB\-D\fR, etc) and they didn\(cqt affect the preprocessor output\&.
1276 .RE
1277 .sp
1278 .RS 4
1279 .ie n \{\
1280 \h'-04'\(bu\h'+03'\c
1281 .\}
1282 .el \{\
1283 .sp -1
1284 .IP \(bu 2.3
1285 .\}
1286 The compiler option
1287 \fB\-Xpreprocessor\fR
1288 or
1289 \fB\-Wp,\fR\fB\fIX\fR\fR
1290 (except
1291 \fB\-Wp,\-MD,\fR\fB\fIpath\fR\fR
1292 and
1293 \fBWp,\-MMD,\fR\fB\fIpath\fR\fR) is used\&.
1294 .RE
1295 .sp
1296 .RS 4
1297 .ie n \{\
1298 \h'-04'\(bu\h'+03'\c
1299 .\}
1300 .el \{\
1301 .sp -1
1302 .IP \(bu 2.3
1303 .\}
1304 This was the first compilation with a new value of the base directory setting\&.
1305 .RE
1306 .sp
1307 .RS 4
1308 .ie n \{\
1309 \h'-04'\(bu\h'+03'\c
1310 .\}
1311 .el \{\
1312 .sp -1
1313 .IP \(bu 2.3
1314 .\}
1315 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
1316 \fBsloppiness\fR
1317 to
1318 \fBinclude_file_mtime\fR
1319 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\&.)
1320 .RE
1321 .sp
1322 .RS 4
1323 .ie n \{\
1324 \h'-04'\(bu\h'+03'\c
1325 .\}
1326 .el \{\
1327 .sp -1
1328 .IP \(bu 2.3
1329 .\}
1330 The
1331 \fB__TIME__\fR
1332 preprocessor macro is (potentially) being used\&. ccache turns off direct mode if \(lq__TIME__\(rq is present in the source code outside comments and string literals\&. This is done as a safety measure since the string indicates that a
1333 \fB__TIME__\fR
1334 macro
1335 \fImay\fR
1336 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
1337 \fB__TIME__\fR
1338 isn\(cqt used in practise, or don\(cqt care if ccache produces objects where
1339 \fB__TIME__\fR
1340 is expanded to something in the past, you can set
1341 \fBsloppiness\fR
1342 to
1343 \fBtime_macros\fR\&.
1344 .RE
1345 .sp
1346 .RS 4
1347 .ie n \{\
1348 \h'-04'\(bu\h'+03'\c
1349 .\}
1350 .el \{\
1351 .sp -1
1352 .IP \(bu 2.3
1353 .\}
1354 The
1355 \fB__DATE__\fR
1356 preprocessor macro is (potentially) being used and the date has changed\&. This is similar to how
1357 \fB__TIME__\fR
1358 is handled\&. If \(lq__DATE__\(rq is present in the source code outside comments and string literals, ccache hashes the current date in order to be able to produce the correct object file if the
1359 \fB__DATE__\fR
1360 macro affects the output\&. If you know that
1361 \fB__DATE__\fR
1362 isn\(cqt used in practise, or don\(cqt care if ccache produces objects where
1363 \fB__DATE__\fR
1364 is expanded to something in the past, you can set
1365 \fBsloppiness\fR
1366 to
1367 \fBtime_macros\fR\&.
1368 .RE
1369 .sp
1370 .RS 4
1371 .ie n \{\
1372 \h'-04'\(bu\h'+03'\c
1373 .\}
1374 .el \{\
1375 .sp -1
1376 .IP \(bu 2.3
1377 .\}
1378 The
1379 \fB__FILE__\fR
1380 preprocessor macro is (potentially) being used and the file path has changed\&. If \(lq__FILE__\(rq is present in the source code outside comments and string literals, ccache hashes the current input file path in order to be able to produce the correct object file if the
1381 \fB__FILE__\fR
1382 macro affects the output\&. If you know that
1383 \fB__FILE__\fR
1384 isn\(cqt used in practise, or don\(cqt care if ccache produces objects where
1385 \fB__FILE__\fR
1386 is expanded to the wrong path, you can set
1387 \fBsloppiness\fR
1388 to
1389 \fBfile_macro\fR\&.
1390 .RE
1391 .RE
1392 .sp
1393 .RS 4
1394 .ie n \{\
1395 \h'-04'\(bu\h'+03'\c
1396 .\}
1397 .el \{\
1398 .sp -1
1399 .IP \(bu 2.3
1400 .\}
1401 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
1402 \fB__TIME__\fR
1403 or
1404 \fB__DATE__\fR
1405 macros, or use of automatically generated code that contains a timestamp, build counter or other volatile information\&.
1406 .RE
1407 .sp
1408 .RS 4
1409 .ie n \{\
1410 \h'-04'\(bu\h'+03'\c
1411 .\}
1412 .el \{\
1413 .sp -1
1414 .IP \(bu 2.3
1415 .\}
1416 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\&.
1417 .RE
1418 .sp
1419 .RS 4
1420 .ie n \{\
1421 \h'-04'\(bu\h'+03'\c
1422 .\}
1423 .el \{\
1424 .sp -1
1425 .IP \(bu 2.3
1426 .\}
1427 If \(lqunsupported compiler option\(rq has been incremented, enable debug logging and check which option was rejected\&.
1428 .RE
1429 .sp
1430 .RS 4
1431 .ie n \{\
1432 \h'-04'\(bu\h'+03'\c
1433 .\}
1434 .el \{\
1435 .sp -1
1436 .IP \(bu 2.3
1437 .\}
1438 If \(lqpreprocessor error\(rq has been incremented, one possible reason is that precompiled headers are being used\&. See
1439 PRECOMPILED HEADERS
1440 for how to remedy this\&.
1441 .RE
1442 .sp
1443 .RS 4
1444 .ie n \{\
1445 \h'-04'\(bu\h'+03'\c
1446 .\}
1447 .el \{\
1448 .sp -1
1449 .IP \(bu 2.3
1450 .\}
1451 If \(lqcan\(cqt use precompiled header\(rq has been incremented, see
1452 PRECOMPILED HEADERS\&.
1453 .RE
1454 .SS "Errors when compiling with ccache"
1455 .sp
1456 If compilation doesn\(cqt work with ccache, but it works without it, one possible reason is that the compiler can\(cqt compile preprocessed output correctly\&. A workaround that may work is to enable \fBrun_second_cpp\fR*\&. This will make cache misses slower, though, so it is better to find and fix the root cause\&.
1457 .SS "Corrupt object files"
1458 .sp
1459 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:
1460 .sp
1461 .RS 4
1462 .ie n \{\
1463 \h'-04' 1.\h'+01'\c
1464 .\}
1465 .el \{\
1466 .sp -1
1467 .IP "  1." 4.2
1468 .\}
1469 Build so that the bad object file ends up in the build tree\&.
1470 .RE
1471 .sp
1472 .RS 4
1473 .ie n \{\
1474 \h'-04' 2.\h'+01'\c
1475 .\}
1476 .el \{\
1477 .sp -1
1478 .IP "  2." 4.2
1479 .\}
1480 Remove the bad object file from the build tree\&.
1481 .RE
1482 .sp
1483 .RS 4
1484 .ie n \{\
1485 \h'-04' 3.\h'+01'\c
1486 .\}
1487 .el \{\
1488 .sp -1
1489 .IP "  3." 4.2
1490 .\}
1491 Rebuild with
1492 \fBCCACHE_RECACHE\fR
1493 set\&.
1494 .RE
1495 .sp
1496 An alternative is to clear the whole cache with \fBccache \-C\fR if you don\(cqt mind losing other cached results\&.
1497 .sp
1498 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\&.
1499 .SH "MORE INFORMATION"
1500 .sp
1501 Credits, mailing list information, bug reporting instructions, source code, etc, can be found on ccache\(cqs web site: http://ccache\&.samba\&.org\&.
1502 .SH "AUTHOR"
1503 .sp
1504 ccache was originally written by Andrew Tridgell and is currently developed and maintained by Joel Rosdahl\&. See AUTHORS\&.txt or AUTHORS\&.html and http://ccache\&.samba\&.org/credits\&.html for a list of contributors\&.