1
diff --git a/Makefile.in b/Makefile.in
2
index 0bf3eb9..e32ebe5 100644
5
@@ -11,6 +11,7 @@ CC=@CC@
10
OBJS= ccache.o mdfour.o hash.o execute.o util.o args.o stats.o \
11
cleanup.o snprintf.o unify.o
12
HEADERS = ccache.h mdfour.h
13
@@ -20,7 +21,7 @@ all: ccache$(EXEEXT)
14
docs: ccache.1 web/ccache-man.html
16
ccache$(EXEEXT): $(OBJS) $(HEADERS)
17
- $(CC) $(CFLAGS) -o $@ $(OBJS)
18
+ $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)
21
-yodl2man -o ccache.1 ccache.yo
22
diff --git a/ccache.1 b/ccache.1
23
index daec8ee..9d1cbcd 100644
26
@@ -210,7 +210,8 @@ If you set the environment variable
27
CCACHE_HARDLINK then ccache will attempt to use hard links from the
28
cache directory when creating the compiler output rather than using a
29
file copy\&. Using hard links is faster, but can confuse programs like
30
-\&'make\&' that rely on modification times\&.
31
+\&'make\&' that rely on modification times\&. Hard links are never made for
32
+compressed cache files\&.
34
.IP "\fBCCACHE_RECACHE\fP"
35
This forces ccache to not use any cached
36
@@ -257,6 +258,11 @@ systems like this you can use the CCACHE_EXTENSION option to override
37
the default\&. On HP-UX set this environment variable to "i" if you use
40
+.IP "\fBCCACHE_NOCOMPRESS\fP"
41
+If you set the environment variable
42
+CCACHE_NOCOMPRESS then there is no compression used on files that go
46
.SH "CACHE SIZE MANAGEMENT"
48
@@ -269,6 +275,14 @@ When these limits are reached ccache will reduce the cache to 20%
49
below the numbers you specified in order to avoid doing the cache
50
clean operation too often\&.
52
+.SH "CACHE COMPRESSION"
54
+By default ccache will compress all files it puts into the cache
55
+using the zlib compression\&. While this involves a negligible
56
+performance slowdown, it significantly increases the number of files
57
+that fit in the cache\&. You can turn off compression setting the
58
+CCACHE_NOCOMPRESS environment variable\&.
62
The basic idea is to detect when you are compiling exactly the same
63
diff --git a/ccache.c b/ccache.c
64
index e7272d5..f6be1bc 100644
67
@@ -199,7 +199,7 @@ static void to_cache(ARGS *args)
68
fd = open(tmp_stderr, O_RDONLY | O_BINARY);
70
if (strcmp(output_file, "/dev/null") == 0 ||
71
- rename(tmp_hashname, output_file) == 0 || errno == ENOENT) {
72
+ move_file(tmp_hashname, output_file) == 0 || errno == ENOENT) {
74
/* we might have some stderr from cpp */
75
int fd2 = open(cpp_stderr, O_RDONLY | O_BINARY);
76
@@ -231,14 +231,25 @@ static void to_cache(ARGS *args)
77
x_asprintf(&path_stderr, "%s.stderr", hashname);
79
if (stat(tmp_stderr, &st1) != 0 ||
80
- stat(tmp_hashname, &st2) != 0 ||
81
- rename(tmp_hashname, hashname) != 0 ||
82
- rename(tmp_stderr, path_stderr) != 0) {
83
+ stat(tmp_hashname, &st2) != 0 ||
84
+ move_file(tmp_hashname, hashname) != 0 ||
85
+ move_file(tmp_stderr, path_stderr) != 0) {
86
cc_log("failed to rename tmp files - %s\n", strerror(errno));
87
stats_update(STATS_ERROR);
92
+ /* do an extra stat on the cache files for
93
+ the size statistics */
94
+ if (stat(path_stderr, &st1) != 0 ||
95
+ stat(hashname, &st2) != 0) {
96
+ cc_log("failed to stat cache files - %s\n", strerror(errno));
97
+ stats_update(STATS_ERROR);
102
cc_log("Placed %s into cache\n", output_file);
103
stats_tocache(file_size(&st1) + file_size(&st2));
105
@@ -474,7 +485,13 @@ static void from_cache(int first)
108
/* the user might be disabling cache hits */
110
+ /* if the cache file is compressed we must recache */
111
+ if ((first && getenv("CCACHE_RECACHE")) ||
112
+ test_if_compressed(hashname) == 1) {
114
if (first && getenv("CCACHE_RECACHE")) {
119
@@ -487,7 +504,9 @@ static void from_cache(int first)
123
- if (getenv("CCACHE_HARDLINK")) {
124
+ /* only make a hardlink if the cache file is uncompressed */
125
+ if (getenv("CCACHE_HARDLINK") &&
126
+ test_if_compressed(hashname) == 0) {
127
ret = link(hashname, output_file);
129
ret = copy_file(hashname, output_file);
130
diff --git a/ccache.h b/ccache.h
131
index faec597..67904cd 100644
142
#define STATUS_NOTFOUND 3
143
#define STATUS_FATAL 4
144
#define STATUS_NOCACHE 5
146
#define DEFAULT_MAXSIZE (1000*1000)
149
+/* file copy mode */
151
+#define COPY_UNCOMPRESSED 0
152
+#define COPY_FROM_CACHE 1
153
+#define COPY_TO_CACHE 2
159
@@ -79,6 +90,8 @@ void fatal(const char *msg);
161
void copy_fd(int fd_in, int fd_out);
162
int copy_file(const char *src, const char *dest);
163
+int move_file(const char *src, const char *dest);
164
+int test_if_compressed(const char *filename);
166
int create_dir(const char *dir);
167
void x_asprintf(char **ptr, const char *format, ...);
168
diff --git a/ccache.yo b/ccache.yo
169
index 12e45a6..311bead 100644
172
@@ -169,6 +169,11 @@ will have problems with the intermediate filename extensions used in
173
this optimisation, in which case this option could allow ccache to be
176
+dit(bf(CCACHE_NOCOMPRESS)) If you set the environment variable
177
+CCACHE_NOCOMPRESS then there is no compression used on files that go
178
+into the cache. However, this setting has no effect on how files are
179
+retrieved from the cache, compressed results will still be usable.
181
dit(bf(CCACHE_NOSTATS)) If you set the environment variable
182
CCACHE_NOSTATS then ccache will not update the statistics files on
184
@@ -181,7 +186,8 @@ dit(bf(CCACHE_HARDLINK)) If you set the environment variable
185
CCACHE_HARDLINK then ccache will attempt to use hard links from the
186
cache directory when creating the compiler output rather than using a
187
file copy. Using hard links is faster, but can confuse programs like
188
-'make' that rely on modification times.
189
+'make' that rely on modification times. Hard links are never made for
190
+compressed cache files.
192
dit(bf(CCACHE_RECACHE)) This forces ccache to not use any cached
193
results, even if it finds them. New results are still cached, but
194
@@ -236,6 +242,14 @@ When these limits are reached ccache will reduce the cache to 20%
195
below the numbers you specified in order to avoid doing the cache
196
clean operation too often.
198
+manpagesection(CACHE COMPRESSION)
200
+By default ccache will compress all files it puts into the cache
201
+using the zlib compression. While this involves a negligible
202
+performance slowdown, it significantly increases the number of files
203
+that fit in the cache. You can turn off compression setting the
204
+CCACHE_NOCOMPRESS environment variable.
206
manpagesection(HOW IT WORKS)
208
The basic idea is to detect when you are compiling exactly the same
209
@@ -294,6 +308,8 @@ itemize(
210
cache. This tells the filesystem to inherit group ownership for new
211
directories. The command "chmod g+s `find $CCACHE_DIR -type d`" might
213
+ it() Set bf(CCACHE_NOCOMPRESS) for all users, if there are users with
214
+ versions of ccache that do not support compression.
217
manpagesection(HISTORY)
218
diff --git a/config.h.in b/config.h.in
219
index 286f038..3068845 100644
224
/* Define _GNU_SOURCE so that we get all necessary prototypes */
227
+/* Define to 1 if you like to have zlib compression for the ccache. */
229
diff --git a/configure b/configure
230
index 2275677..c96e3ee 100755
233
@@ -836,6 +836,11 @@ if test -n "$ac_init_help"; then
238
+ --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
239
+ --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
240
+ --enable-zlib enable zlib support for ccache compression
242
Some influential environment variables:
243
CC C compiler command
244
CFLAGS C compiler flags
245
@@ -936,7 +941,7 @@ esac
247
echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
254
@@ -1859,7 +1864,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
256
echo "$as_me:$LINENO: \$? = $ac_status" >&5
257
(exit $ac_status); } &&
258
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
259
+ { ac_try='test -z "$ac_c_werror_flag"
260
+ || test ! -s conftest.err'
261
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
264
@@ -1917,7 +1923,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
266
echo "$as_me:$LINENO: \$? = $ac_status" >&5
267
(exit $ac_status); } &&
268
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
269
+ { ac_try='test -z "$ac_c_werror_flag"
270
+ || test ! -s conftest.err'
271
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
274
@@ -2033,7 +2040,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
276
echo "$as_me:$LINENO: \$? = $ac_status" >&5
277
(exit $ac_status); } &&
278
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
279
+ { ac_try='test -z "$ac_c_werror_flag"
280
+ || test ! -s conftest.err'
281
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
284
@@ -2087,7 +2095,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
286
echo "$as_me:$LINENO: \$? = $ac_status" >&5
287
(exit $ac_status); } &&
288
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
289
+ { ac_try='test -z "$ac_c_werror_flag"
290
+ || test ! -s conftest.err'
291
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
294
@@ -2132,7 +2141,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
296
echo "$as_me:$LINENO: \$? = $ac_status" >&5
297
(exit $ac_status); } &&
298
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
299
+ { ac_try='test -z "$ac_c_werror_flag"
300
+ || test ! -s conftest.err'
301
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
304
@@ -2176,7 +2186,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
306
echo "$as_me:$LINENO: \$? = $ac_status" >&5
307
(exit $ac_status); } &&
308
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
309
+ { ac_try='test -z "$ac_c_werror_flag"
310
+ || test ! -s conftest.err'
311
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
314
@@ -2609,7 +2620,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
316
echo "$as_me:$LINENO: \$? = $ac_status" >&5
317
(exit $ac_status); } &&
318
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
319
+ { ac_try='test -z "$ac_c_werror_flag"
320
+ || test ! -s conftest.err'
321
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
324
@@ -2681,7 +2693,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
326
echo "$as_me:$LINENO: \$? = $ac_status" >&5
327
(exit $ac_status); } &&
328
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
329
+ { ac_try='test -z "$ac_c_werror_flag"
330
+ || test ! -s conftest.err'
331
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
334
@@ -2735,7 +2748,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
336
echo "$as_me:$LINENO: \$? = $ac_status" >&5
337
(exit $ac_status); } &&
338
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
339
+ { ac_try='test -z "$ac_c_werror_flag"
340
+ || test ! -s conftest.err'
341
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
344
@@ -2806,7 +2820,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
346
echo "$as_me:$LINENO: \$? = $ac_status" >&5
347
(exit $ac_status); } &&
348
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
349
+ { ac_try='test -z "$ac_c_werror_flag"
350
+ || test ! -s conftest.err'
351
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
354
@@ -2860,7 +2875,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
356
echo "$as_me:$LINENO: \$? = $ac_status" >&5
357
(exit $ac_status); } &&
358
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
359
+ { ac_try='test -z "$ac_c_werror_flag"
360
+ || test ! -s conftest.err'
361
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
364
@@ -2927,7 +2943,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
366
echo "$as_me:$LINENO: \$? = $ac_status" >&5
367
(exit $ac_status); } &&
368
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
369
+ { ac_try='test -z "$ac_c_werror_flag"
370
+ || test ! -s conftest.err'
371
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
374
@@ -2997,7 +3014,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
376
echo "$as_me:$LINENO: \$? = $ac_status" >&5
377
(exit $ac_status); } &&
378
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
379
+ { ac_try='test -z "$ac_c_werror_flag"
380
+ || test ! -s conftest.err'
381
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
384
@@ -3078,7 +3096,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
386
echo "$as_me:$LINENO: \$? = $ac_status" >&5
387
(exit $ac_status); } &&
388
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
389
+ { ac_try='test -z "$ac_c_werror_flag"
390
+ || test ! -s conftest.err'
391
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
394
@@ -3248,7 +3267,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
396
echo "$as_me:$LINENO: \$? = $ac_status" >&5
397
(exit $ac_status); } &&
398
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
399
+ { ac_try='test -z "$ac_c_werror_flag"
400
+ || test ! -s conftest.err'
401
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
404
@@ -3319,7 +3339,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
406
echo "$as_me:$LINENO: \$? = $ac_status" >&5
407
(exit $ac_status); } &&
408
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
409
+ { ac_try='test -z "$ac_c_werror_flag"
410
+ || test ! -s conftest.err'
411
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
414
@@ -3509,7 +3530,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
416
echo "$as_me:$LINENO: \$? = $ac_status" >&5
417
(exit $ac_status); } &&
418
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
419
+ { ac_try='test -z "$ac_c_werror_flag"
420
+ || test ! -s conftest.err'
421
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
424
@@ -3611,7 +3633,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
426
echo "$as_me:$LINENO: \$? = $ac_status" >&5
427
(exit $ac_status); } &&
428
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
429
+ { ac_try='test -z "$ac_c_werror_flag"
430
+ || test ! -s conftest.err'
431
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
434
@@ -3676,7 +3699,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
436
echo "$as_me:$LINENO: \$? = $ac_status" >&5
437
(exit $ac_status); } &&
438
- { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
439
+ { ac_try='test -z "$ac_c_werror_flag"
440
+ || test ! -s conftest.err'
441
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
444
@@ -3775,6 +3799,229 @@ _ACEOF
448
+# Check whether --enable-zlib or --disable-zlib was given.
449
+if test "${enable_zlib+set}" = set; then
450
+ enableval="$enable_zlib"
456
+if test x"$enable_zlib" = x"yes"; then
457
+ if test "${ac_cv_header_zlib_h+set}" = set; then
458
+ echo "$as_me:$LINENO: checking for zlib.h" >&5
459
+echo $ECHO_N "checking for zlib.h... $ECHO_C" >&6
460
+if test "${ac_cv_header_zlib_h+set}" = set; then
461
+ echo $ECHO_N "(cached) $ECHO_C" >&6
463
+echo "$as_me:$LINENO: result: $ac_cv_header_zlib_h" >&5
464
+echo "${ECHO_T}$ac_cv_header_zlib_h" >&6
466
+ # Is the header compilable?
467
+echo "$as_me:$LINENO: checking zlib.h usability" >&5
468
+echo $ECHO_N "checking zlib.h usability... $ECHO_C" >&6
469
+cat >conftest.$ac_ext <<_ACEOF
472
+cat confdefs.h >>conftest.$ac_ext
473
+cat >>conftest.$ac_ext <<_ACEOF
474
+/* end confdefs.h. */
475
+$ac_includes_default
478
+rm -f conftest.$ac_objext
479
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
480
+ (eval $ac_compile) 2>conftest.er1
482
+ grep -v '^ *+' conftest.er1 >conftest.err
484
+ cat conftest.err >&5
485
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
486
+ (exit $ac_status); } &&
487
+ { ac_try='test -z "$ac_c_werror_flag"
488
+ || test ! -s conftest.err'
489
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
490
+ (eval $ac_try) 2>&5
492
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
493
+ (exit $ac_status); }; } &&
494
+ { ac_try='test -s conftest.$ac_objext'
495
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
496
+ (eval $ac_try) 2>&5
498
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
499
+ (exit $ac_status); }; }; then
500
+ ac_header_compiler=yes
502
+ echo "$as_me: failed program was:" >&5
503
+sed 's/^/| /' conftest.$ac_ext >&5
505
+ac_header_compiler=no
507
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
508
+echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
509
+echo "${ECHO_T}$ac_header_compiler" >&6
511
+# Is the header present?
512
+echo "$as_me:$LINENO: checking zlib.h presence" >&5
513
+echo $ECHO_N "checking zlib.h presence... $ECHO_C" >&6
514
+cat >conftest.$ac_ext <<_ACEOF
517
+cat confdefs.h >>conftest.$ac_ext
518
+cat >>conftest.$ac_ext <<_ACEOF
519
+/* end confdefs.h. */
522
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
523
+ (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
525
+ grep -v '^ *+' conftest.er1 >conftest.err
527
+ cat conftest.err >&5
528
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
529
+ (exit $ac_status); } >/dev/null; then
530
+ if test -s conftest.err; then
531
+ ac_cpp_err=$ac_c_preproc_warn_flag
532
+ ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
539
+if test -z "$ac_cpp_err"; then
540
+ ac_header_preproc=yes
542
+ echo "$as_me: failed program was:" >&5
543
+sed 's/^/| /' conftest.$ac_ext >&5
545
+ ac_header_preproc=no
547
+rm -f conftest.err conftest.$ac_ext
548
+echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
549
+echo "${ECHO_T}$ac_header_preproc" >&6
551
+# So? What about this header?
552
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
554
+ { echo "$as_me:$LINENO: WARNING: zlib.h: accepted by the compiler, rejected by the preprocessor!" >&5
555
+echo "$as_me: WARNING: zlib.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
556
+ { echo "$as_me:$LINENO: WARNING: zlib.h: proceeding with the compiler's result" >&5
557
+echo "$as_me: WARNING: zlib.h: proceeding with the compiler's result" >&2;}
558
+ ac_header_preproc=yes
561
+ { echo "$as_me:$LINENO: WARNING: zlib.h: present but cannot be compiled" >&5
562
+echo "$as_me: WARNING: zlib.h: present but cannot be compiled" >&2;}
563
+ { echo "$as_me:$LINENO: WARNING: zlib.h: check for missing prerequisite headers?" >&5
564
+echo "$as_me: WARNING: zlib.h: check for missing prerequisite headers?" >&2;}
565
+ { echo "$as_me:$LINENO: WARNING: zlib.h: see the Autoconf documentation" >&5
566
+echo "$as_me: WARNING: zlib.h: see the Autoconf documentation" >&2;}
567
+ { echo "$as_me:$LINENO: WARNING: zlib.h: section \"Present But Cannot Be Compiled\"" >&5
568
+echo "$as_me: WARNING: zlib.h: section \"Present But Cannot Be Compiled\"" >&2;}
569
+ { echo "$as_me:$LINENO: WARNING: zlib.h: proceeding with the preprocessor's result" >&5
570
+echo "$as_me: WARNING: zlib.h: proceeding with the preprocessor's result" >&2;}
571
+ { echo "$as_me:$LINENO: WARNING: zlib.h: in the future, the compiler will take precedence" >&5
572
+echo "$as_me: WARNING: zlib.h: in the future, the compiler will take precedence" >&2;}
575
+## ------------------------------------------ ##
576
+## Report this to the AC_PACKAGE_NAME lists. ##
577
+## ------------------------------------------ ##
580
+ sed "s/^/$as_me: WARNING: /" >&2
583
+echo "$as_me:$LINENO: checking for zlib.h" >&5
584
+echo $ECHO_N "checking for zlib.h... $ECHO_C" >&6
585
+if test "${ac_cv_header_zlib_h+set}" = set; then
586
+ echo $ECHO_N "(cached) $ECHO_C" >&6
588
+ ac_cv_header_zlib_h=$ac_header_preproc
590
+echo "$as_me:$LINENO: result: $ac_cv_header_zlib_h" >&5
591
+echo "${ECHO_T}$ac_cv_header_zlib_h" >&6
594
+if test $ac_cv_header_zlib_h = yes; then
595
+ echo "$as_me:$LINENO: checking for gzdopen in -lz" >&5
596
+echo $ECHO_N "checking for gzdopen in -lz... $ECHO_C" >&6
597
+if test "${ac_cv_lib_z_gzdopen+set}" = set; then
598
+ echo $ECHO_N "(cached) $ECHO_C" >&6
600
+ ac_check_lib_save_LIBS=$LIBS
602
+cat >conftest.$ac_ext <<_ACEOF
605
+cat confdefs.h >>conftest.$ac_ext
606
+cat >>conftest.$ac_ext <<_ACEOF
607
+/* end confdefs.h. */
609
+/* Override any gcc2 internal prototype to avoid an error. */
613
+/* We use char because int might match the return type of a gcc2
614
+ builtin and then its argument prototype would still apply. */
624
+rm -f conftest.$ac_objext conftest$ac_exeext
625
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
626
+ (eval $ac_link) 2>conftest.er1
628
+ grep -v '^ *+' conftest.er1 >conftest.err
630
+ cat conftest.err >&5
631
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
632
+ (exit $ac_status); } &&
633
+ { ac_try='test -z "$ac_c_werror_flag"
634
+ || test ! -s conftest.err'
635
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
636
+ (eval $ac_try) 2>&5
638
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
639
+ (exit $ac_status); }; } &&
640
+ { ac_try='test -s conftest$ac_exeext'
641
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
642
+ (eval $ac_try) 2>&5
644
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
645
+ (exit $ac_status); }; }; then
646
+ ac_cv_lib_z_gzdopen=yes
648
+ echo "$as_me: failed program was:" >&5
649
+sed 's/^/| /' conftest.$ac_ext >&5
651
+ac_cv_lib_z_gzdopen=no
653
+rm -f conftest.err conftest.$ac_objext \
654
+ conftest$ac_exeext conftest.$ac_ext
655
+LIBS=$ac_check_lib_save_LIBS
657
+echo "$as_me:$LINENO: result: $ac_cv_lib_z_gzdopen" >&5
658
+echo "${ECHO_T}$ac_cv_lib_z_gzdopen" >&6
659
+if test $ac_cv_lib_z_gzdopen = yes; then
660
+ LIBS="-lz $LIBS"; cat >>confdefs.h <<\_ACEOF
661
+#define ENABLE_ZLIB 1
671
ac_config_files="$ac_config_files Makefile"
673
cat >confcache <<\_ACEOF
674
@@ -4568,6 +4815,11 @@ esac
675
*) ac_INSTALL=$ac_top_builddir$INSTALL ;;
678
+ if test x"$ac_file" != x-; then
679
+ { echo "$as_me:$LINENO: creating $ac_file" >&5
680
+echo "$as_me: creating $ac_file" >&6;}
683
# Let's still pretend it is `configure' which instantiates (i.e., don't
684
# use $as_me), people would be surprised to read:
685
# /* config.h. Generated by config.status. */
686
@@ -4606,12 +4858,6 @@ echo "$as_me: error: cannot find input file: $f" >&2;}
689
done` || { (exit 1); exit 1; }
691
- if test x"$ac_file" != x-; then
692
- { echo "$as_me:$LINENO: creating $ac_file" >&5
693
-echo "$as_me: creating $ac_file" >&6;}
697
cat >>$CONFIG_STATUS <<_ACEOF
699
diff --git a/configure.in b/configure.in
700
index 3229ef0..be77bbf 100644
703
@@ -68,5 +68,14 @@ if test x"$ccache_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
704
AC_DEFINE(HAVE_C99_VSNPRINTF, 1, [ ])
708
+AC_ARG_ENABLE([zlib],
709
+ AS_HELP_STRING([--enable-zlib], [enable zlib support for ccache compression]),,
712
+if test x"$enable_zlib" = x"yes"; then
713
+ AC_CHECK_HEADER(zlib.h, AC_CHECK_LIB(z, gzdopen, LIBS="-lz $LIBS"; AC_DEFINE(ENABLE_ZLIB)))
716
AC_CONFIG_FILES([Makefile])
718
diff --git a/manage-cache.sh b/manage-cache.sh
720
index 0000000..7ef329d
722
+++ b/manage-cache.sh
726
+# 2004-05-12 lars@gustaebel.de
728
+CCACHE_DIR=${CCACHE_DIR:-$HOME/.ccache}
730
+echo "Do you want to compress or decompress the ccache in $CCACHE_DIR?"
731
+read -p "Type c or d: " mode
733
+if [ "$mode" != "c" ] && [ "$mode" != "d" ]
739
+ test "$(head -c 2 $1)" = $'\x1f\x8b'
745
+for dir in 0 1 2 3 4 5 6 7 8 9 a b c d e f
747
+ # process ccache subdir
751
+ find $CCACHE_DIR/$dir -type f -name '*-*' |
754
+ oldsize=$(cat $CCACHE_DIR/$dir/stats | cut -d ' ' -f 13)
759
+ # empty files will be ignored since compressing
760
+ # them makes them bigger
761
+ test $(stat -c %s $file) -eq 0 && continue
765
+ if ! is_compressed $file
771
+ if is_compressed $file
778
+ # calculate new size statistic for this subdir
779
+ let newsize=$newsize+$(stat -c "%B*%b" $file)/1024
782
+ # update statistic file
783
+ read -a numbers < $CCACHE_DIR/$dir/stats
784
+ numbers[12]=$newsize
785
+ echo "${numbers[*]} " > $CCACHE_DIR/$dir/stats
792
diff --git a/util.c b/util.c
793
index 962dd49..a6b8899 100644
796
@@ -44,6 +44,7 @@ void fatal(const char *msg)
801
/* copy all data from one file descriptor to another */
802
void copy_fd(int fd_in, int fd_out)
804
@@ -57,6 +58,11 @@ void copy_fd(int fd_in, int fd_out)
808
+/* move a file using rename */
809
+int move_file(const char *src, const char *dest) {
810
+ return rename(src, dest);
813
/* copy a file - used when hard links don't work
814
the copy is done via a temporary file and atomic rename
816
@@ -120,6 +126,174 @@ int copy_file(const char *src, const char *dest)
820
+#else /* ENABLE_ZLIB */
822
+/* copy all data from one file descriptor to another
823
+ possibly decompressing it
825
+void copy_fd(int fd_in, int fd_out) {
830
+ gz_in = gzdopen(dup(fd_in), "rb");
833
+ fatal("Failed to copy fd");
836
+ while ((n = gzread(gz_in, buf, sizeof(buf))) > 0) {
837
+ if (write(fd_out, buf, n) != n) {
838
+ fatal("Failed to copy fd");
843
+static int _copy_file(const char *src, const char *dest, int mode) {
845
+ gzFile gz_in, gz_out = NULL;
852
+ x_asprintf(&tmp_name, "%s.XXXXXX", dest);
854
+ if (getenv("CCACHE_NOCOMPRESS")) {
855
+ mode = COPY_UNCOMPRESSED;
858
+ /* open source file */
859
+ fd_in = open(src, O_RDONLY);
864
+ gz_in = gzdopen(fd_in, "rb");
870
+ /* open destination file */
871
+ fd_out = mkstemp(tmp_name);
872
+ if (fd_out == -1) {
878
+ if (mode == COPY_TO_CACHE) {
879
+ /* The gzip file format occupies at least 20 bytes. So
880
+ it will always occupy an entire filesystem block,
881
+ even for empty files.
882
+ Since most stderr files will be empty, we turn off
883
+ compression in this case to save space.
885
+ if (fstat(fd_in, &st) != 0) {
891
+ if (file_size(&st) == 0) {
892
+ mode = COPY_UNCOMPRESSED;
896
+ if (mode == COPY_TO_CACHE) {
897
+ gz_out = gzdopen(dup(fd_out), "wb");
906
+ while ((n = gzread(gz_in, buf, sizeof(buf))) > 0) {
907
+ if (mode == COPY_TO_CACHE) {
908
+ ret = gzwrite(gz_out, buf, n);
910
+ ret = write(fd_out, buf, n);
929
+ /* get perms right on the tmp file */
931
+ fchmod(fd_out, 0666 & ~mask);
934
+ /* the close can fail on NFS if out of space */
935
+ if (close(fd_out) == -1) {
943
+ if (rename(tmp_name, dest) == -1) {
954
+/* move a file to the cache, compressing it */
955
+int move_file(const char *src, const char *dest) {
958
+ ret = _copy_file(src, dest, COPY_TO_CACHE);
959
+ if (ret != -1) unlink(src);
963
+/* copy a file from the cache, decompressing it */
964
+int copy_file(const char *src, const char *dest) {
965
+ return _copy_file(src, dest, COPY_FROM_CACHE);
967
+#endif /* ENABLE_ZLIB */
969
+/* test if a file is zlib compressed */
970
+int test_if_compressed(const char *filename) {
973
+ f = fopen(filename, "rb");
978
+ /* test if file starts with 1F8B, which is zlib's
980
+ if ((fgetc(f) != 0x1f) || (fgetc(f) != 0x8b)) {
989
/* make sure a directory exists */
990
int create_dir(const char *dir)