File: 02_ccache-compressed.diff

package info (click to toggle)
renderdoc 1.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 79,584 kB
  • sloc: cpp: 491,671; ansic: 285,823; python: 12,617; java: 11,345; cs: 7,181; makefile: 6,703; yacc: 5,682; ruby: 4,648; perl: 3,461; php: 2,119; sh: 2,068; lisp: 1,835; tcl: 1,068; ml: 747; xml: 137
file content (1026 lines) | stat: -rw-r--r-- 30,713 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
Index: ccache.1
===================================================================
RCS file: /home/cvsroot/lars/ccache/ccache.1,v
retrieving revision 1.1.1.1.2.1
retrieving revision 1.6
diff -u -r1.1.1.1.2.1 -r1.6
--- ccache.1	21 Nov 2004 17:55:36 -0000	1.1.1.1.2.1
+++ ccache.1	21 Nov 2004 18:19:28 -0000	1.6
@@ -210,7 +210,8 @@
 CCACHE_HARDLINK then 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 is faster, but can confuse programs like
-\&'make\&' that rely on modification times\&.
+\&'make\&' that rely on modification times\&. Hard links are never made for
+compressed cache files\&.
 .IP 
 .IP "\fBCCACHE_RECACHE\fP" 
 This forces ccache to not use any cached
@@ -257,6 +258,11 @@
 the default\&. On HP-UX set this environment variable to "i" if you use
 the aCC compiler\&.
 .IP 
+.IP "\fBCCACHE_NOCOMPRESS\fP" 
+If you set the environment variable
+CCACHE_NOCOMPRESS then there is no compression used on files that go
+into the cache\&.
+.IP 
 .PP 
 .SH "CACHE SIZE MANAGEMENT" 
 .PP 
@@ -269,6 +275,14 @@
 below the numbers you specified in order to avoid doing the cache
 clean operation too often\&.
 .PP 
+.SH "CACHE COMPRESSION" 
+.PP 
+By default ccache will compress all files it puts into the cache
+using the zlib compression\&. While this involves a negligible
+performance slowdown, it significantly increases the number of files
+that fit in the cache\&. You can turn off compression setting the
+CCACHE_NOCOMPRESS environment variable\&.
+.PP 
 .SH "HOW IT WORKS" 
 .PP 
 The basic idea is to detect when you are compiling exactly the same
Index: ccache.c
===================================================================
RCS file: /home/cvsroot/lars/ccache/ccache.c,v
retrieving revision 1.1.1.1.2.1
retrieving revision 1.9
diff -u -r1.1.1.1.2.1 -r1.9
--- ccache.c	21 Nov 2004 17:55:36 -0000	1.1.1.1.2.1
+++ ccache.c	21 Nov 2004 18:19:28 -0000	1.9
@@ -199,7 +199,7 @@
 		fd = open(tmp_stderr, O_RDONLY | O_BINARY);
 		if (fd != -1) {
 			if (strcmp(output_file, "/dev/null") == 0 ||
-			    rename(tmp_hashname, output_file) == 0 || errno == ENOENT) {
+			    move_file(tmp_hashname, output_file) == 0 || errno == ENOENT) {
 				if (cpp_stderr) {
 					/* we might have some stderr from cpp */
 					int fd2 = open(cpp_stderr, O_RDONLY | O_BINARY);
@@ -231,14 +231,25 @@
 	x_asprintf(&path_stderr, "%s.stderr", hashname);
 
 	if (stat(tmp_stderr, &st1) != 0 ||
-	    stat(tmp_hashname, &st2) != 0 ||
-	    rename(tmp_hashname, hashname) != 0 ||
-	    rename(tmp_stderr, path_stderr) != 0) {
+		stat(tmp_hashname, &st2) != 0 ||
+		move_file(tmp_hashname, hashname) != 0 ||
+		move_file(tmp_stderr, path_stderr) != 0) {
 		cc_log("failed to rename tmp files - %s\n", strerror(errno));
 		stats_update(STATS_ERROR);
 		failed();
 	}
 
+#if ENABLE_ZLIB
+	/* do an extra stat on the cache files for
+	   the size statistics */
+	if (stat(path_stderr, &st1) != 0 ||
+		stat(hashname, &st2) != 0) {
+		cc_log("failed to stat cache files - %s\n", strerror(errno));
+		stats_update(STATS_ERROR);
+		failed();
+    }
+#endif
+
 	cc_log("Placed %s into cache\n", output_file);
 	stats_tocache(file_size(&st1) + file_size(&st2));
 
@@ -474,7 +485,13 @@
 	}
 
 	/* the user might be disabling cache hits */
+#ifndef ENABLE_ZLIB
+	/* if the cache file is compressed we must recache */
+	if ((first && getenv("CCACHE_RECACHE")) ||
+		test_if_compressed(hashname) == 1) {
+#else
 	if (first && getenv("CCACHE_RECACHE")) {
+#endif
 		close(fd_stderr);
 		unlink(stderr_file);
 		free(stderr_file);
@@ -487,7 +504,9 @@
 		ret = 0;
 	} else {
 		unlink(output_file);
-		if (getenv("CCACHE_HARDLINK")) {
+		/* only make a hardlink if the cache file is uncompressed */
+		if (getenv("CCACHE_HARDLINK") &&
+			test_if_compressed(hashname) == 0) {
 			ret = link(hashname, output_file);
 		} else {
 			ret = copy_file(hashname, output_file);
Index: ccache.h
===================================================================
RCS file: /home/cvsroot/lars/ccache/ccache.h,v
retrieving revision 1.1.1.1.2.1
retrieving revision 1.7
diff -u -r1.1.1.1.2.1 -r1.7
--- ccache.h	21 Nov 2004 17:55:36 -0000	1.1.1.1.2.1
+++ ccache.h	21 Nov 2004 18:19:28 -0000	1.7
@@ -23,6 +23,10 @@
 #include <pwd.h>
 #endif
 
+#ifdef ENABLE_ZLIB
+#include <zlib.h>
+#endif
+
 #define STATUS_NOTFOUND 3
 #define STATUS_FATAL 4
 #define STATUS_NOCACHE 5
@@ -36,6 +40,13 @@
 #define DEFAULT_MAXSIZE (1000*1000)
 #endif
 
+/* file copy mode */
+#ifdef ENABLE_ZLIB
+#define COPY_UNCOMPRESSED 0
+#define COPY_FROM_CACHE 1
+#define COPY_TO_CACHE 2
+#endif
+
 enum stats {
 	STATS_NONE=0,
 	STATS_STDOUT,
@@ -79,6 +90,8 @@
 
 void copy_fd(int fd_in, int fd_out);
 int copy_file(const char *src, const char *dest);
+int move_file(const char *src, const char *dest);
+int test_if_compressed(const char *filename);
 
 int create_dir(const char *dir);
 void x_asprintf(char **ptr, const char *format, ...);
Index: ccache.yo
===================================================================
RCS file: /home/cvsroot/lars/ccache/ccache.yo,v
retrieving revision 1.1.1.1.2.1
retrieving revision 1.5
diff -u -r1.1.1.1.2.1 -r1.5
--- ccache.yo	21 Nov 2004 17:55:36 -0000	1.1.1.1.2.1
+++ ccache.yo	21 Nov 2004 18:19:28 -0000	1.5
@@ -169,6 +169,11 @@
 this optimisation, in which case this option could allow ccache to be
 used.
 
+dit(bf(CCACHE_NOCOMPRESS)) If you set the environment variable
+CCACHE_NOCOMPRESS then there is no compression used on files that go
+into the cache. However, this setting has no effect on how files are
+retrieved from the cache, compressed results will still be usable.
+
 dit(bf(CCACHE_NOSTATS)) If you set the environment variable
 CCACHE_NOSTATS then ccache will not update the statistics files on
 each compile.
@@ -181,7 +186,8 @@
 CCACHE_HARDLINK then 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 is faster, but can confuse programs like
-'make' that rely on modification times.
+'make' that rely on modification times. Hard links are never made for
+compressed cache files.
 
 dit(bf(CCACHE_RECACHE)) This forces ccache to not use any cached
 results, even if it finds them. New results are still cached, but
@@ -236,6 +242,14 @@
 below the numbers you specified in order to avoid doing the cache
 clean operation too often.
 
+manpagesection(CACHE COMPRESSION)
+
+By default ccache will compress all files it puts into the cache
+using the zlib compression. While this involves a negligible
+performance slowdown, it significantly increases the number of files
+that fit in the cache. You can turn off compression setting the
+CCACHE_NOCOMPRESS environment variable.
+
 manpagesection(HOW IT WORKS)
 
 The basic idea is to detect when you are compiling exactly the same
@@ -294,6 +308,8 @@
   cache. This tells the filesystem to inherit group ownership for new
   directories. The command "chmod g+s `find $CCACHE_DIR -type d`" might
   be useful for this.
+  it() Set bf(CCACHE_NOCOMPRESS) for all users, if there are users with
+  versions of ccache that do not support compression.
 )
 
 manpagesection(HISTORY)
Index: config.h.in
===================================================================
RCS file: /home/cvsroot/lars/ccache/config.h.in,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- config.h.in	30 Apr 2004 13:13:41 -0000	1.1.1.1
+++ config.h.in	4 May 2004 20:49:26 -0000	1.2
@@ -98,3 +98,6 @@
 
 /* Define _GNU_SOURCE so that we get all necessary prototypes */
 #undef _GNU_SOURCE
+
+/* Define to 1 if you like to have zlib compression for the ccache. */
+#undef ENABLE_ZLIB
Index: configure
===================================================================
RCS file: /home/cvsroot/lars/ccache/configure,v
retrieving revision 1.1.1.1.2.1
diff -u -r1.1.1.1.2.1 configure
--- configure	21 Nov 2004 17:55:36 -0000	1.1.1.1.2.1
+++ configure	21 Nov 2004 18:24:42 -0000
@@ -836,6 +836,11 @@
 
   cat <<\_ACEOF
 
+Optional Features:
+  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
+  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --enable-zlib           enable zlib support for ccache compression
+
 Some influential environment variables:
   CC          C compiler command
   CFLAGS      C compiler flags
@@ -936,7 +941,7 @@
     else
       echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
     fi
-    cd "$ac_popdir"
+    cd $ac_popdir
   done
 fi
 
@@ -1859,7 +1864,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -1917,7 +1923,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -2033,7 +2040,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -2087,7 +2095,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -2132,7 +2141,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -2176,7 +2186,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -2609,7 +2620,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -2681,7 +2693,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -2735,7 +2748,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -2806,7 +2820,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -2860,7 +2875,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -2927,7 +2943,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -2997,7 +3014,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -3078,7 +3096,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -3248,7 +3267,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -3319,7 +3339,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -3509,7 +3530,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -3611,7 +3633,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -3676,7 +3699,8 @@
   cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -3775,6 +3799,229 @@
 
 fi
 
+# Check whether --enable-zlib or --disable-zlib was given.
+if test "${enable_zlib+set}" = set; then
+  enableval="$enable_zlib"
+
+else
+  enable_zlib=yes
+fi;
+
+if test x"$enable_zlib" = x"yes"; then
+    if test "${ac_cv_header_zlib_h+set}" = set; then
+  echo "$as_me:$LINENO: checking for zlib.h" >&5
+echo $ECHO_N "checking for zlib.h... $ECHO_C" >&6
+if test "${ac_cv_header_zlib_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+echo "$as_me:$LINENO: result: $ac_cv_header_zlib_h" >&5
+echo "${ECHO_T}$ac_cv_header_zlib_h" >&6
+else
+  # Is the header compilable?
+echo "$as_me:$LINENO: checking zlib.h usability" >&5
+echo $ECHO_N "checking zlib.h usability... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <zlib.h>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_header_compiler=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6
+
+# Is the header present?
+echo "$as_me:$LINENO: checking zlib.h presence" >&5
+echo $ECHO_N "checking zlib.h presence... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <zlib.h>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: zlib.h: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: zlib.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: zlib.h: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: zlib.h: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: zlib.h: present but cannot be compiled" >&5
+echo "$as_me: WARNING: zlib.h: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: zlib.h:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: zlib.h:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: zlib.h: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: zlib.h: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: zlib.h:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: zlib.h:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: zlib.h: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: zlib.h: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: zlib.h: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: zlib.h: in the future, the compiler will take precedence" >&2;}
+    (
+      cat <<\_ASBOX
+## ------------------------------------------ ##
+## Report this to the AC_PACKAGE_NAME lists.  ##
+## ------------------------------------------ ##
+_ASBOX
+    ) |
+      sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+echo "$as_me:$LINENO: checking for zlib.h" >&5
+echo $ECHO_N "checking for zlib.h... $ECHO_C" >&6
+if test "${ac_cv_header_zlib_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_header_zlib_h=$ac_header_preproc
+fi
+echo "$as_me:$LINENO: result: $ac_cv_header_zlib_h" >&5
+echo "${ECHO_T}$ac_cv_header_zlib_h" >&6
+
+fi
+if test $ac_cv_header_zlib_h = yes; then
+  echo "$as_me:$LINENO: checking for gzdopen in -lz" >&5
+echo $ECHO_N "checking for gzdopen in -lz... $ECHO_C" >&6
+if test "${ac_cv_lib_z_gzdopen+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lz  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char gzdopen ();
+int
+main ()
+{
+gzdopen ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_z_gzdopen=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_z_gzdopen=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_z_gzdopen" >&5
+echo "${ECHO_T}$ac_cv_lib_z_gzdopen" >&6
+if test $ac_cv_lib_z_gzdopen = yes; then
+  LIBS="-lz $LIBS"; cat >>confdefs.h <<\_ACEOF
+#define ENABLE_ZLIB 1
+_ACEOF
+
+fi
+
+fi
+
+
+fi
+
           ac_config_files="$ac_config_files Makefile"
 
 cat >confcache <<\_ACEOF
@@ -4568,6 +4815,11 @@
   *) ac_INSTALL=$ac_top_builddir$INSTALL ;;
   esac
 
+  if test x"$ac_file" != x-; then
+    { echo "$as_me:$LINENO: creating $ac_file" >&5
+echo "$as_me: creating $ac_file" >&6;}
+    rm -f "$ac_file"
+  fi
   # Let's still pretend it is `configure' which instantiates (i.e., don't
   # use $as_me), people would be surprised to read:
   #    /* config.h.  Generated by config.status.  */
@@ -4606,12 +4858,6 @@
 	 fi;;
       esac
     done` || { (exit 1); exit 1; }
-
-  if test x"$ac_file" != x-; then
-    { echo "$as_me:$LINENO: creating $ac_file" >&5
-echo "$as_me: creating $ac_file" >&6;}
-    rm -f "$ac_file"
-  fi
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF
   sed "$ac_vpsub
Index: configure.in
===================================================================
RCS file: /home/cvsroot/lars/ccache/configure.in,v
retrieving revision 1.1.1.1.2.1
retrieving revision 1.4
diff -u -r1.1.1.1.2.1 -r1.4
--- configure.in	21 Nov 2004 17:55:36 -0000	1.1.1.1.2.1
+++ configure.in	21 Nov 2004 18:19:28 -0000	1.4
@@ -68,5 +68,14 @@
     AC_DEFINE(HAVE_C99_VSNPRINTF, 1, [ ])
 fi
 
+dnl Check for zlib.
+AC_ARG_ENABLE([zlib],
+              AS_HELP_STRING([--enable-zlib], [enable zlib support for ccache compression]),,
+              [enable_zlib=yes])
+
+if test x"$enable_zlib" = x"yes"; then
+    AC_CHECK_HEADER(zlib.h, AC_CHECK_LIB(z, gzdopen, LIBS="-lz $LIBS"; AC_DEFINE(ENABLE_ZLIB)))
+fi
+
 AC_CONFIG_FILES([Makefile])
 AC_OUTPUT
Index: util.c
===================================================================
RCS file: /home/cvsroot/lars/ccache/util.c,v
retrieving revision 1.1.1.1.2.1
retrieving revision 1.11
diff -u -r1.1.1.1.2.1 -r1.11
--- util.c	21 Nov 2004 17:55:36 -0000	1.1.1.1.2.1
+++ util.c	21 Nov 2004 18:19:28 -0000	1.11
@@ -44,6 +44,7 @@
 	exit(1);
 }
 
+#ifndef ENABLE_ZLIB
 /* copy all data from one file descriptor to another */
 void copy_fd(int fd_in, int fd_out)
 {
@@ -57,6 +58,11 @@
 	}
 }
 
+/* move a file using rename */
+int move_file(const char *src, const char *dest) {
+	return rename(src, dest);
+}
+
 /* copy a file - used when hard links don't work 
    the copy is done via a temporary file and atomic rename
 */
@@ -120,6 +126,174 @@
 	return 0;
 }
 
+#else /* ENABLE_ZLIB */
+
+/* copy all data from one file descriptor to another
+   possibly decompressing it
+*/
+void copy_fd(int fd_in, int fd_out) {
+	char buf[10240];
+	int n;
+	gzFile gz_in;
+
+	gz_in = gzdopen(dup(fd_in), "rb");
+
+	if (!gz_in) {
+		fatal("Failed to copy fd");
+	}
+
+	while ((n = gzread(gz_in, buf, sizeof(buf))) > 0) {
+		if (write(fd_out, buf, n) != n) {
+			fatal("Failed to copy fd");
+		}
+	}
+}
+
+static int _copy_file(const char *src, const char *dest, int mode) {
+	int fd_in, fd_out;
+	gzFile gz_in, gz_out = NULL;
+	char buf[10240];
+	int n, ret;
+	char *tmp_name;
+	mode_t mask;
+	struct stat st;
+
+	x_asprintf(&tmp_name, "%s.XXXXXX", dest);
+
+	if (getenv("CCACHE_NOCOMPRESS")) {
+		mode = COPY_UNCOMPRESSED;
+	}
+
+	/* open source file */
+	fd_in = open(src, O_RDONLY);
+	if (fd_in == -1) {
+		return -1;
+	}
+
+	gz_in = gzdopen(fd_in, "rb");
+	if (!gz_in) {
+		close(fd_in);
+		return -1;
+	}
+
+	/* open destination file */
+	fd_out = mkstemp(tmp_name);
+	if (fd_out == -1) {
+		gzclose(gz_in);
+		free(tmp_name);
+		return -1;
+	}
+
+	if (mode == COPY_TO_CACHE) {
+		/* The gzip file format occupies at least 20 bytes. So
+		   it will always occupy an entire filesystem block,
+		   even for empty files.
+		   Since most stderr files will be empty, we turn off
+		   compression in this case to save space.
+		*/
+		if (fstat(fd_in, &st) != 0) {
+			gzclose(gz_in);
+			close(fd_out);
+			free(tmp_name);
+			return -1;
+		}
+		if (file_size(&st) == 0) {
+			mode = COPY_UNCOMPRESSED;
+		}
+	}
+
+	if (mode == COPY_TO_CACHE) {
+		gz_out = gzdopen(dup(fd_out), "wb");
+		if (!gz_out) {
+			gzclose(gz_in);
+			close(fd_out);
+			free(tmp_name);
+			return -1;
+		}
+	}
+
+	while ((n = gzread(gz_in, buf, sizeof(buf))) > 0) {
+		if (mode == COPY_TO_CACHE) {
+			ret = gzwrite(gz_out, buf, n);
+		} else {
+			ret = write(fd_out, buf, n);
+		}
+		if (ret != n) {
+			gzclose(gz_in);
+			if (gz_out) {
+				gzclose(gz_out);
+			}
+			close(fd_out);
+			unlink(tmp_name);
+			free(tmp_name);
+			return -1;
+		}
+	}
+
+	gzclose(gz_in);
+	if (gz_out) {
+		gzclose(gz_out);
+	}
+
+	/* get perms right on the tmp file */
+	mask = umask(0);
+	fchmod(fd_out, 0666 & ~mask);
+	umask(mask);
+
+	/* the close can fail on NFS if out of space */
+	if (close(fd_out) == -1) {
+		unlink(tmp_name);
+		free(tmp_name);
+		return -1;
+	}
+
+	unlink(dest);
+
+	if (rename(tmp_name, dest) == -1) {
+		unlink(tmp_name);
+		free(tmp_name);
+		return -1;
+	}
+
+	free(tmp_name);
+
+	return 0;
+}
+
+/* move a file to the cache, compressing it */
+int move_file(const char *src, const char *dest) {
+	int ret;
+
+	ret = _copy_file(src, dest, COPY_TO_CACHE);
+	if (ret != -1) unlink(src);
+	return ret;
+}
+
+/* copy a file from the cache, decompressing it */
+int copy_file(const char *src, const char *dest) {
+	return _copy_file(src, dest, COPY_FROM_CACHE);
+}
+#endif /* ENABLE_ZLIB */
+
+/* test if a file is zlib compressed */
+int test_if_compressed(const char *filename) {
+	FILE *f;
+
+	f = fopen(filename, "rb");
+	if (!f) {
+		return 0;
+	}
+
+	/* test if file starts with 1F8B, which is zlib's
+	 * magic number */
+	if ((fgetc(f) != 0x1f) || (fgetc(f) != 0x8b)) {
+		fclose(f);
+		return 0;
+	}
+	
+	fclose(f);
+	return 1;
+}
 
 /* make sure a directory exists */
 int create_dir(const char *dir)
Index: manage-cache.sh
===================================================================
RCS file: manage-cache.sh
diff -N manage-cache.sh
--- manage-cache.sh	1 Jan 1970 00:00:00 -0000
+++ manage-cache.sh-cache.sh	12 May 2004 19:22:20 -0000	1.1
@@ -0,0 +1,68 @@
+#!/bin/bash
+#
+# 2004-05-12 lars@gustaebel.de
+
+CCACHE_DIR=${CCACHE_DIR:-$HOME/.ccache}
+
+echo "Do you want to compress or decompress the ccache in $CCACHE_DIR?"
+read -p "Type c or d: " mode
+
+if [ "$mode" != "c" ] && [ "$mode" != "d" ]
+then
+    exit 1
+fi
+
+is_compressed() {
+    test "$(head -c 2 $1)" = $'\x1f\x8b'
+    return $?
+}
+
+tmpfile=$(mktemp)
+
+for dir in 0 1 2 3 4 5 6 7 8 9 a b c d e f
+do
+    # process ccache subdir
+    echo -n "$dir "
+
+    # find cache files
+    find $CCACHE_DIR/$dir -type f -name '*-*' |
+    sort > $tmpfile
+
+    oldsize=$(cat $CCACHE_DIR/$dir/stats | cut -d ' ' -f 13)
+    newsize=0
+
+    while read file
+    do
+        # empty files will be ignored since compressing
+        # them makes them bigger
+        test $(stat -c %s $file) -eq 0 && continue
+
+        if [ $mode = c ]
+        then
+            if ! is_compressed $file
+            then
+                gzip $file
+                mv $file.gz $file
+            fi
+        else
+            if is_compressed $file
+            then
+                mv $file $file.gz
+                gzip -d $file.gz
+            fi
+        fi
+
+        # calculate new size statistic for this subdir
+        let newsize=$newsize+$(stat -c "%B*%b" $file)/1024
+    done < $tmpfile
+
+    # update statistic file
+    read -a numbers < $CCACHE_DIR/$dir/stats
+    numbers[12]=$newsize
+    echo "${numbers[*]} " > $CCACHE_DIR/$dir/stats
+done
+echo
+
+# clean up
+rm $tmpfile
+
Index: Makefile.in
===================================================================
RCS file: /home/cvsroot/lars/ccache/Makefile.in,v
retrieving revision 1.1.1.1.2.1
retrieving revision 1.12
diff -u -r1.1.1.1.2.1 -r1.12
--- Makefile.in	21 Nov 2004 17:55:36 -0000	1.1.1.1.2.1
+++ Makefile.in	21 Nov 2004 18:19:28 -0000	1.12
@@ -11,6 +11,7 @@
 CFLAGS=@CFLAGS@ -I.
 EXEEXT=@EXEEXT@
 
+LIBS= @LIBS@
 OBJS= ccache.o mdfour.o hash.o execute.o util.o args.o stats.o \
 	cleanup.o snprintf.o unify.o
 HEADERS = ccache.h mdfour.h
@@ -20,7 +21,7 @@
 docs: ccache.1 web/ccache-man.html
 
 ccache$(EXEEXT): $(OBJS) $(HEADERS)
-	$(CC) $(CFLAGS) -o $@ $(OBJS)
+	$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)
 
 ccache.1: ccache.yo
 	-yodl2man -o ccache.1 ccache.yo