diff -urN ccache-2.4.orig/ccache.c ccache-2.4/ccache.c --- ccache-2.4.orig/ccache.c 2004-09-13 12:38:30.000000000 +0200 +++ ccache-2.4/ccache.c 2009-10-28 13:58:21.000000000 +0100 @@ -22,6 +22,7 @@ */ #include "ccache.h" +#include "version.h" /* the base cache directory */ char *cache_dir = NULL; @@ -149,6 +150,52 @@ return ret; } +/* filter pathnames in preprocessor output +*/ +static void filter_file(char *path_file) { + char *sed_expr, *debug, *path_tmp; + pid_t pid; + int fd, status; + + sed_expr = getenv("CCACHE_SED_EXPR"); + debug = getenv("CCACHE_DEBUG"); + x_asprintf(&path_tmp, "%s_", path_file); + + if (sed_expr) { + pid = fork(); + if (pid == 0){ + /* child */ + fd = open(path_tmp, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC|O_BINARY, 0666); + if (fd != -1) { + if (dup2(fd, 1) == -1 || execlp("sed", "-e", sed_expr, path_file, NULL)) { + cc_log("executing sed: %s\n", strerror(errno)); + } + } else { + cc_log("creating tmp file %s: %s\n", path_tmp, strerror(errno)); + } + } else if (pid < 0) { + /* error */ + cc_log("can't fork: %s\n", strerror(errno)); + } else { + /* parent */ + wait(&status); + if (! WIFSIGNALED(status) && WIFEXITED(status) && WEXITSTATUS(status) == 0) { + if (rename(path_tmp, path_file) == -1) { + cc_log("can't rename file %s to %s: %s\n", path_tmp, path_file, strerror(errno)); + } + } else { + unlink(path_tmp); + cc_log("sed died\n"); + } + } + } + if (debug) { + if (link(path_file, path_tmp) == -1) { + cc_log("can't link file %s to %s: %s\n", path_file, path_tmp, strerror(errno)); + } + } + free(path_tmp); +} /* run the real compiler and put the result in cache */ static void to_cache(ARGS *args) @@ -391,6 +438,9 @@ failed(); } + /* filter preprocessor output before hashing */ + filter_file(path_stdout); + /* if the compilation is with -g then we have to include the whole of the preprocessor output, which means we are sensitive to line number information. Otherwise we can discard line number info, which makes @@ -878,6 +928,8 @@ { printf("ccache, a compiler cache. Version %s\n", CCACHE_VERSION); printf("Copyright Andrew Tridgell, 2002\n\n"); + + printf("%s\n", VERSION); printf("Usage:\n"); printf("\tccache [options]\n"); diff -urN ccache-2.4.orig/Makefile.in ccache-2.4/Makefile.in --- ccache-2.4.orig/Makefile.in 2004-09-13 12:38:30.000000000 +0200 +++ ccache-2.4/Makefile.in 2009-10-28 13:58:21.000000000 +0100 @@ -13,15 +13,22 @@ 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 +HEADERS = ccache.h mdfour.h version.h all: ccache$(EXEEXT) docs: ccache.1 web/ccache-man.html -ccache$(EXEEXT): $(OBJS) $(HEADERS) +ccache$(EXEEXT): $(HEADERS) $(OBJS) $(CC) $(CFLAGS) -o $@ $(OBJS) +version.h: version + +version: + echo -en '#ifndef VERSION_H\n#define VERSION_H 1\n#define VERSION "' > version.h + svn info | grep '^Last' | sed -e 's/$$/\\n/g' | tr -d '\n' >> version.h + echo -e '"\n#endif /* ! VERSION_H */' >> version.h + ccache.1: ccache.yo -yodl2man -o ccache.1 ccache.yo @@ -36,7 +43,7 @@ ${INSTALLCMD} -m 644 ${srcdir}/ccache.1 $(DESTDIR)${mandir}/man1/ clean: - /bin/rm -f $(OBJS) *~ ccache$(EXEEXT) + /bin/rm -f $(OBJS) *~ ccache$(EXEEXT) version.h test: test.sh CC='$(CC)' ./test.sh