Index: debian/patches/CREDITS
===================================================================
--- debian/patches/CREDITS	(revision 11878)
+++ debian/patches/CREDITS	(working copy)
@@ -53,3 +53,7 @@
 14_hardlink_doc.diff:
   Ville Skytta <ville.skytta@iki.fi>
   http://cvs.fedoraproject.org/viewcvs/rpms/ccache/F-9/ccache-2.4-hardlink-doc.patch?rev=1.1&view=markup
+
+15_hash_compiler_version.diff
+  Alexander Block <ablock@blocksoftware.net>
+  http://lists.samba.org/archive/ccache/2008q4/000359.html
Index: debian/patches/15_hash_compiler_version.diff
===================================================================
--- debian/patches/15_hash_compiler_version.diff	(revision 0)
+++ debian/patches/15_hash_compiler_version.diff	(revision 0)
@@ -0,0 +1,151 @@
+diff -u ccache-2.4/ccache.c ccache-2.4-changed/ccache.c
+--- ccache.c	2004-09-13 12:38:30.000000000 +0200
++++ ccache.c	2008-11-26 15:31:35.000000000 +0100
+@@ -27,7 +27,7 @@
+ char *cache_dir = NULL;
+ 
+ /* the directory for temporary files */
+-static char *temp_dir = NULL;
++char *temp_dir = NULL;
+ 
+ /* the debug logfile name, if set */
+ char *cache_logfile = NULL;
+@@ -132,7 +132,7 @@
+ /* return a string to be used to distinguish temporary files 
+    this also tries to cope with NFS by adding the local hostname 
+ */
+-static const char *tmp_string(void)
++const char *tmp_string(void)
+ {
+ 	static char *ret;
+ 
+@@ -259,6 +259,7 @@
+ 	struct stat st;
+ 	int status;
+ 	int nlevels = 2;
++    int do_hash_size_mtime = 1;
+ 	char *input_base;
+ 	char *tmp;
+ 	
+@@ -331,8 +332,16 @@
+ 		hash_string(str_basename(args->argv[0]));
+ 	}
+ 
+-	hash_int(st.st_size);
+-	hash_int(st.st_mtime);
++	/* hash "gcc -dumpversion" and "gcc -dumpmachine" */
++  	if (getenv("CCACHE_HASH_COMPILER_VERSION")) {
++		if (hash_gcc_version(args->argv) == 0)
++			do_hash_size_mtime = 0;
++  	} 
++ 
++	if (do_hash_size_mtime) {
++  		hash_int(st.st_size);
++		hash_int(st.st_mtime);
++	}   
+ 
+ 	/* possibly hash the current working directory */
+ 	if (getenv("CCACHE_HASHDIR")) {
+diff -u ccache-2.4/ccache.h ccache-2.4-changed/ccache.h
+--- ccache.h	2004-09-13 12:38:30.000000000 +0200
++++ ccache.h	2008-11-26 15:26:46.000000000 +0100
+@@ -73,6 +73,8 @@
+ void hash_file(const char *fname);
+ char *hash_result(void);
+ void hash_buffer(const char *s, int len);
++int hash_execute_output(char **argv);
++int hash_gcc_version(char **argv);
+ 
+ void cc_log(const char *format, ...);
+ void fatal(const char *msg);
+@@ -119,6 +121,8 @@
+ int snprintf(char *,size_t ,const char *, ...);
+ #endif
+ 
++const char *tmp_string(void);
++
+ void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize);
+ void cleanup_all(const char *dir);
+ void wipe_all(const char *dir);
+diff -u ccache-2.4/ccache.yo ccache-2.4-changed/ccache.yo
+--- ccache.yo	2004-09-13 12:38:30.000000000 +0200
++++ ccache.yo	2008-11-26 15:27:50.000000000 +0100
+@@ -203,6 +203,11 @@
+ strike problems with gdb not using the correct directory then enable
+ this option.
+ 
++dit(bf(CCACHE_HASH_COMPILER_VERSION)) This tells ccache to hash the 
++compiler by using the output of "gcc -dumpversion" and 
++gcc -dumpmachine". This method can prevent cache misses when the used 
++compiler was rebuilt but not changed.
++
+ dit(bf(CCACHE_UNIFY)) If you set the environment variable CCACHE_UNIFY
+ then ccache will use the C/C++ unifier when hashing the pre-processor
+ output if -g is not used in the compile. The unifier is slower than a
+diff -u ccache-2.4/hash.c ccache-2.4-changed/hash.c
+--- hash.c	2004-09-13 12:38:30.000000000 +0200
++++ hash.c	2008-11-26 15:26:46.000000000 +0100
+@@ -23,6 +23,9 @@
+ 
+ static struct mdfour md;
+ 
++/* found in ccache.c */
++extern char *temp_dir;
++
+ void hash_buffer(const char *s, int len)
+ {
+ 	mdfour_update(&md, (unsigned char *)s, len);
+@@ -61,6 +64,51 @@
+ 	close(fd);
+ }
+ 
++int hash_execute_output(char **argv)
++{
++	char *tmp_stdout, *tmp_stderr;
++	char *exe_path, *exe_basename;
++	int status;
++
++	exe_path = strdup(argv[0]); // We need a copy because basename() may change the original
++	exe_basename = basename(exe_path);
++
++	// TODO: I'm not sure if the naming of the temporary files is ok this way. Please 
++	// modify it if required (or delete this TODO)
++	x_asprintf(&tmp_stdout, "%s/%s.stdout.%s", temp_dir, exe_basename, tmp_string());
++	x_asprintf(&tmp_stderr, "%s/%s.stderr.%s", temp_dir, exe_basename, tmp_string());
++
++	status = execute(argv, tmp_stdout, tmp_stderr);
++	if (status == 0) {
++		hash_file(tmp_stdout);
++		hash_file(tmp_stderr);
++	}
++	unlink(tmp_stdout);
++	unlink(tmp_stderr);
++ 
++	free(exe_path);
++	free(tmp_stdout);
++	free(tmp_stderr);
++
++	return status;
++}
++
++/* hash gcc version with "gcc -dumpversion" and "gcc -dumpmachine" */
++int hash_gcc_version(char **argv)
++{
++	char* tmp_argv[3];
++	tmp_argv[0] = argv[0];
++	tmp_argv[1] = "-dumpversion";
++	tmp_argv[2] = NULL;
++	if (hash_execute_output(tmp_argv) == 0) {
++		tmp_argv[1] = "-dumpmachine";
++		if (hash_execute_output(tmp_argv) == 0) {
++			return 0;
++		}
++	}
++	return -1;
++}
++
+ /* return the hash result as a static string */
+ char *hash_result(void)
+ {
+Common subdirectories: ccache-2.4/packaging and ccache-2.4-changed/packaging
+Common subdirectories: ccache-2.4/web and ccache-2.4-changed/web
Index: debian/rules
===================================================================
--- debian/rules	(revision 11878)
+++ debian/rules	(working copy)
@@ -29,6 +29,8 @@
         # Apply Debian specific patches
 	cp $(CURDIR)/ccache.c $(CURDIR)/ccache.c.unpatched
 	cp $(CURDIR)/util.c $(CURDIR)/util.c.unpatched
+	cp $(CURDIR)/hash.c $(CURDIR)/hash.c.unpatched
+	cp $(CURDIR)/stats.c $(CURDIR)/stats.c.unpatched
 	cp $(CURDIR)/ccache.1 $(CURDIR)/ccache.1.unpatched
 	cp $(CURDIR)/ccache.h $(CURDIR)/ccache.h.unpatched
 	cp $(CURDIR)/ccache.yo $(CURDIR)/ccache.yo.unpatched
@@ -36,6 +38,8 @@
 	cp $(CURDIR)/configure $(CURDIR)/configure.unpatched
 	cp $(CURDIR)/configure.in $(CURDIR)/configure.in.unpatched
 	cp $(CURDIR)/Makefile.in $(CURDIR)/Makefile.in.unpatched
+	cp $(CURDIR)/web/index.html $(CURDIR)/web/index.html.unpatched
+	cp $(CURDIR)/web/ccache-man.html $(CURDIR)/web/ccache-man.html.unpatched
 	if test ! -f patch-stamp; then \
 		for patch in $(CURDIR)/debian/patches/*.diff ;\
 		do \
@@ -65,6 +69,8 @@
 	# Unapply patches
 	-test -r $(CURDIR)/ccache.c.unpatched && mv $(CURDIR)/ccache.c.unpatched $(CURDIR)/ccache.c
 	-test -r $(CURDIR)/util.c.unpatched && mv $(CURDIR)/util.c.unpatched $(CURDIR)/util.c
+	-test -r $(CURDIR)/hash.c.unpatched && mv $(CURDIR)/hash.c.unpatched $(CURDIR)/hash.c
+	-test -r $(CURDIR)/stats.c.unpatched && mv $(CURDIR)/stats.c.unpatched $(CURDIR)/stats.c
 	-test -r $(CURDIR)/ccache.1.unpatched && mv $(CURDIR)/ccache.1.unpatched $(CURDIR)/ccache.1
 	-test -r $(CURDIR)/ccache.h.unpatched && mv $(CURDIR)/ccache.h.unpatched $(CURDIR)/ccache.h
 	-test -r $(CURDIR)/ccache.yo.unpatched && mv $(CURDIR)/ccache.yo.unpatched $(CURDIR)/ccache.yo
@@ -72,6 +78,8 @@
 	-test -r $(CURDIR)/configure.unpatched && mv $(CURDIR)/configure.unpatched $(CURDIR)/configure
 	-test -r $(CURDIR)/configure.in.unpatched && mv $(CURDIR)/configure.in.unpatched $(CURDIR)/configure.in
 	-test -r $(CURDIR)/Makefile.in.unpatched && mv $(CURDIR)/Makefile.in.unpatched $(CURDIR)/Makefile.in
+	-test -r $(CURDIR)/web/index.html.unpatched && mv $(CURDIR)/web/index.html.unpatched $(CURDIR)/web/index.html
+	-test -r $(CURDIR)/web/ccache-man.html.unpatched && mv $(CURDIR)/web/ccache-man.html.unpatched $(CURDIR)/web/ccache-man.html
 	-rm -f $(CURDIR)/manage-cache.sh
 	-rm -f patch-stamp
 
