Index: trunk/src/kObjCache/kObjCache.c
===================================================================
--- trunk/src/kObjCache/kObjCache.c	(revision 1044)
+++ trunk/src/kObjCache/kObjCache.c	(revision 1045)
@@ -1091,4 +1091,7 @@
     free(pEntry->Old.pszObjName);
 
+    free(pEntry->New.pszTarget);
+    free(pEntry->Old.pszTarget);
+
     while (pEntry->New.cArgvCompile > 0)
         free(pEntry->New.papszArgvCompile[--pEntry->New.cArgvCompile]);
@@ -1104,4 +1107,33 @@
 
 /**
+ * Calculates the checksum of an compiler argument vector.
+ *
+ * @param   pEntry          The cache entry.
+ * @param   papszArgv       The argument vector.
+ * @param   cArgc           The number of entries in the vector.
+ * @param   pszIgnorePath   Path to ignore when encountered at the end of arguments.
+ *                          (Not quite safe for simple file names, but what the heck.)
+ * @param   pSum            Where to store the check sum.
+ */
+static void kOCEntryCalcArgvSum(PKOCENTRY pEntry, const char * const *papszArgv, unsigned cArgc,
+                                const char *pszIgnorePath, PKOCSUM pSum)
+{
+    size_t cchIgnorePath = strlen(pszIgnorePath);
+    KOCSUMCTX Ctx;
+    unsigned i;
+
+    kOCSumInitWithCtx(pSum, &Ctx);
+    for (i = 0; i < cArgc; i++)
+    {
+        size_t cch = strlen(papszArgv[i]);
+        if (    cch < cchIgnorePath
+            ||  !ArePathsIdentical(papszArgv[i] + cch - cchIgnorePath, pszIgnorePath, cch))
+            kOCSumUpdate(pSum, &Ctx, papszArgv[i], cch + 1);
+    }
+    kOCSumFinalize(pSum, &Ctx);
+}
+
+
+/**
  * Reads and parses the cache file.
  *
@@ -1114,5 +1146,5 @@
     if (pFile)
     {
-        InfoMsg(1, "reading cache file...\n");
+        InfoMsg(4, "reading cache entry...\n");
 
         /*
@@ -1122,5 +1154,5 @@
             ||  strcmp(g_szLine, "magic=kObjCache-1\n"))
         {
-            InfoMsg(1, "bad cache file (magic)\n");
+            InfoMsg(2, "bad cache file (magic)\n");
             pEntry->fNeedCompiling = 1;
         }
@@ -1231,5 +1263,5 @@
             if (!fBad && fBadBeforeMissing)
             {
-                InfoMsg(1, "bad cache file (no end)\n");
+                InfoMsg(2, "bad cache file (no end)\n");
                 fBad = 1;
             }
@@ -1244,24 +1276,19 @@
                     fBad = 1;
                 if (!fBad)
-                {
-                    KOCSUMCTX Ctx;
-                    KOCSUM Sum;
-
-                    kOCSumInitWithCtx(&Sum, &Ctx);
                     for (i = 0; i < pEntry->Old.cArgvCompile; i++)
-                    {
                         if ((fBad = !pEntry->Old.papszArgvCompile[i]))
                             break;
-                        kOCSumUpdate(&Sum, &Ctx, pEntry->Old.papszArgvCompile[i], strlen(pEntry->Old.papszArgvCompile[i]) + 1);
-                    }
-                    kOCSumFinalize(&Sum, &Ctx);
-                    if (!fBad)
-                        fBad = !kOCSumIsEqual(&pEntry->Old.SumCompArgv, &Sum);
+                if (!fBad)
+                {
+                    KOCSUM Sum;
+                    kOCEntryCalcArgvSum(pEntry, (const char * const *)pEntry->Old.papszArgvCompile,
+                                        pEntry->Old.cArgvCompile, pEntry->Old.pszObjName, &Sum);
+                    fBad = !kOCSumIsEqual(&pEntry->Old.SumCompArgv, &Sum);
                 }
                 if (fBad)
-                    InfoMsg(1, "bad cache file (%s)\n", fBadBeforeMissing ? g_szLine : "missing stuff");
+                    InfoMsg(2, "bad cache file (%s)\n", fBadBeforeMissing ? g_szLine : "missing stuff");
                 else if (ferror(pFile))
                 {
-                    InfoMsg(1, "cache file read error\n");
+                    InfoMsg(2, "cache file read error\n");
                     fBad = 1;
                 }
@@ -1276,5 +1303,5 @@
                     if (stat(pszPath, &st) != 0)
                     {
-                        InfoMsg(1, "failed to stat object file: %s\n", strerror(errno));
+                        InfoMsg(2, "failed to stat object file: %s\n", strerror(errno));
                         fBad = 1;
                     }
@@ -1291,5 +1318,5 @@
     else
     {
-        InfoMsg(1, "no cache file\n");
+        InfoMsg(2, "no cache file\n");
         pEntry->fNeedCompiling = 1;
     }
@@ -1308,5 +1335,5 @@
     unsigned i;
 
-    InfoMsg(1, "writing cache entry '%s'...\n", pEntry->pszName);
+    InfoMsg(4, "writing cache entry '%s'...\n", pEntry->pszName);
     pFile = FOpenFileInDir(pEntry->pszName, pEntry->pszDir, "wb");
     if (!pFile)
@@ -1382,5 +1409,33 @@
 static int kOCEntryCheck(PKOCENTRY pEntry)
 {
-    return pEntry->fNeedCompiling;
+    return !pEntry->fNeedCompiling;
+}
+
+
+/**
+ * Sets the object name and compares it with the old name if present.
+ *
+ * @param   pEntry      The cache entry.
+ * @param   pszObjName  The new object name.
+ */
+static void kOCEntrySetCompileObjName(PKOCENTRY pEntry, const char *pszObjName)
+{
+    assert(!pEntry->New.pszObjName);
+    pEntry->New.pszObjName = CalcRelativeName(pszObjName, pEntry->pszDir);
+
+    if (    !pEntry->fNeedCompiling
+        &&  (   !pEntry->Old.pszObjName
+             || strcmp(pEntry->New.pszObjName, pEntry->Old.pszObjName)))
+    {
+        InfoMsg(2, "object file name differs\n");
+        pEntry->fNeedCompiling = 1;
+    }
+
+    if (    !pEntry->fNeedCompiling
+        &&  !DoesFileInDirExist(pEntry->New.pszObjName, pEntry->pszDir))
+    {
+        InfoMsg(2, "object file doesn't exist\n");
+        pEntry->fNeedCompiling = 1;
+    }
 }
 
@@ -1392,27 +1447,27 @@
  * @param   papszArgvCompile    The new argument vector for compilation.
  * @param   cArgvCompile        The number of arguments in the vector.
+ *
+ * @remark  Must call kOCEntrySetCompileObjName before this function!
  */
 static void kOCEntrySetCompileArgv(PKOCENTRY pEntry, const char * const *papszArgvCompile, unsigned cArgvCompile)
 {
-    KOCSUMCTX Ctx;
     unsigned i;
 
     /* call me only once! */
     assert(!pEntry->New.cArgvCompile);
-
-    /*
-     * Copy the argument vector and calculate the checksum while doing so.
+    /* call kOCEntrySetCompilerObjName first! */
+    assert(pEntry->New.pszObjName);
+
+    /*
+     * Copy the argument vector and calculate the checksum.
      */
     pEntry->New.cArgvCompile = cArgvCompile;
     pEntry->New.papszArgvCompile = xmalloc((cArgvCompile + 1) * sizeof(pEntry->New.papszArgvCompile[0]));
-    kOCSumInitWithCtx(&pEntry->New.SumCompArgv, &Ctx);
     for (i = 0; i < cArgvCompile; i++)
-    {
         pEntry->New.papszArgvCompile[i] = xstrdup(papszArgvCompile[i]);
-        kOCSumUpdate(&pEntry->New.SumCompArgv, &Ctx, papszArgvCompile[i], strlen(papszArgvCompile[i]) + 1);
-    }
-    kOCSumFinalize(&pEntry->New.SumCompArgv, &Ctx);
     pEntry->New.papszArgvCompile[i] = NULL; /* for exev/spawnv */
-    kOCSumInfo(&pEntry->New.SumCompArgv, 1, "comp-argv");
+
+    kOCEntryCalcArgvSum(pEntry, papszArgvCompile, cArgvCompile, pEntry->New.pszObjName, &pEntry->New.SumCompArgv);
+    kOCSumInfo(&pEntry->New.SumCompArgv, 4, "comp-argv");
 
     /*
@@ -1422,33 +1477,5 @@
         &&  !kOCSumIsEqual(&pEntry->New.SumCompArgv, &pEntry->Old.SumCompArgv))
     {
-        InfoMsg(1, "compiler args differs\n");
-        pEntry->fNeedCompiling = 1;
-    }
-}
-
-
-/**
- * Sets the object name and compares it with the old name if present.
- *
- * @param   pEntry      The cache entry.
- * @param   pszObjName  The new object name.
- */
-static void kOCEntrySetCompileObjName(PKOCENTRY pEntry, const char *pszObjName)
-{
-    assert(!pEntry->New.pszObjName);
-    pEntry->New.pszObjName = CalcRelativeName(pszObjName, pEntry->pszDir);
-
-    if (    !pEntry->fNeedCompiling
-        &&  (   !pEntry->Old.pszObjName
-             || strcmp(pEntry->New.pszObjName, pEntry->Old.pszObjName)))
-    {
-        InfoMsg(1, "object file name differs\n");
-        pEntry->fNeedCompiling = 1;
-    }
-
-    if (    !pEntry->fNeedCompiling
-        &&  !DoesFileInDirExist(pEntry->New.pszObjName, pEntry->pszDir))
-    {
-        InfoMsg(1, "object file doesn't exist\n");
+        InfoMsg(2, "compiler args differs\n");
         pEntry->fNeedCompiling = 1;
     }
@@ -1471,5 +1498,5 @@
              || strcmp(pEntry->New.pszTarget, pEntry->Old.pszTarget)))
     {
-        InfoMsg(1, "target differs\n");
+        InfoMsg(2, "target differs\n");
         pEntry->fNeedCompiling = 1;
     }
@@ -1687,5 +1714,5 @@
     int iStatus = -1;
     pid_t pidWait;
-    InfoMsg(3, "%s - wait-child(%ld)\n", pszMsg, (long)pid);
+    InfoMsg(3, "%s - wait-child %ld\n", pszMsg, (long)pid);
 
 #ifdef __WIN__
@@ -1841,10 +1868,10 @@
             FatalDie("failed to open/read '%s' in '%s': %s\n",
                      pWhich->pszCppName, pEntry->pszDir, strerror(errno));
-        InfoMsg(1, "failed to open/read '%s' in '%s': %s\n",
+        InfoMsg(2, "failed to open/read '%s' in '%s': %s\n",
                 pWhich->pszCppName, pEntry->pszDir, strerror(errno));
         return -1;
     }
 
-    InfoMsg(1, "precompiled file is %lu bytes long\n", (unsigned long)pWhich->cbCpp);
+    InfoMsg(3, "precompiled file is %lu bytes long\n", (unsigned long)pWhich->cbCpp);
     return 0;
 }
@@ -1863,5 +1890,5 @@
     kOCSumUpdate(&pEntry->New.SumHead, &Ctx, pEntry->New.pszCppMapping, pEntry->New.cbCpp);
     kOCSumFinalize(&pEntry->New.SumHead, &Ctx);
-    kOCSumInfo(&pEntry->New.SumHead, 1, "cpp (file)");
+    kOCSumInfo(&pEntry->New.SumHead, 4, "cpp (file)");
 }
 
@@ -1926,5 +1953,5 @@
     pEntry->New.cbCpp = cbAlloc - cbLeft;
     kOCSumFinalize(&pEntry->New.SumHead, &Ctx);
-    kOCSumInfo(&pEntry->New.SumHead, 1, "cpp (pipe)");
+    kOCSumInfo(&pEntry->New.SumHead, 4, "cpp (pipe)");
 }
 
@@ -1961,5 +1988,5 @@
             memcpy(psz + cch, "-old", sizeof("-old"));
 
-            InfoMsg(1, "renaming '%s' to '%s' in '%s'\n", pEntry->Old.pszCppName, psz, pEntry->pszDir);
+            InfoMsg(3, "renaming '%s' to '%s' in '%s'\n", pEntry->Old.pszCppName, psz, pEntry->pszDir);
             UnlinkFileInDir(psz, pEntry->pszDir);
             if (RenameFileInDir(pEntry->Old.pszCppName, psz, pEntry->pszDir))
@@ -1973,5 +2000,5 @@
          * Precompile it and calculate the checksum on the output.
          */
-        InfoMsg(1, "precompiling -> '%s'...\n", pEntry->New.pszCppName);
+        InfoMsg(3, "precompiling -> '%s'...\n", pEntry->New.pszCppName);
         kOCEntrySpawn(pEntry, papszArgvPreComp, cArgvPreComp, "precompile", NULL);
         kOCEntryReadCppOutput(pEntry, &pEntry->New, 0 /* fatal */);
@@ -2103,5 +2130,5 @@
             &&  !pEntry->New.pszCppMapping)
             kOCEntryReadCppOutput(pEntry, &pEntry->New, 0 /* fatal */);
-        InfoMsg(1, "compiling -> '%s'...\n", pEntry->New.pszObjName);
+        InfoMsg(3, "compiling -> '%s'...\n", pEntry->New.pszObjName);
         kOCEntrySpawnConsumer(pEntry, (const char * const *)pEntry->New.papszArgvCompile, pEntry->New.cArgvCompile,
                               "compile", kOCEntryCompileProducer);
@@ -2111,5 +2138,5 @@
         if (pEntry->fPipedPreComp)
             kOCEntryWriteCppOutput(pEntry, 1 /* free it */);
-        InfoMsg(1, "compiling -> '%s'...\n", pEntry->New.pszObjName);
+        InfoMsg(3, "compiling -> '%s'...\n", pEntry->New.pszObjName);
         kOCEntrySpawn(pEntry, (const char * const *)pEntry->New.papszArgvCompile, pEntry->New.cArgvCompile, "compile", NULL);
     }
@@ -2154,5 +2181,5 @@
                      fdIn, (long)cbLeft, strerror(errno));
         }
-        InfoMsg(2, "precompiler|compile - read %d\n", cbRead);
+        InfoMsg(3, "precompiler|compile - read %d\n", cbRead);
 
         /*
@@ -2188,5 +2215,5 @@
         }
     }
-    InfoMsg(2, "precompiler|compile - done passhtru\n");
+    InfoMsg(3, "precompiler|compile - done passhtru\n");
 
     close(fdIn);
@@ -2194,5 +2221,5 @@
     pEntry->New.cbCpp = cbAlloc - cbLeft;
     kOCSumFinalize(&pEntry->New.SumHead, &Ctx);
-    kOCSumInfo(&pEntry->New.SumHead, 1, "cpp (tee)");
+    kOCSumInfo(&pEntry->New.SumHead, 4, "cpp (tee)");
 
     /*
@@ -2591,5 +2618,5 @@
     if (!kOCSumHasEqualInChain(&pEntry->Old.SumHead, &pEntry->New.SumHead))
     {
-        InfoMsg(1, "no checksum match - comparing output\n");
+        InfoMsg(2, "no checksum match - comparing output\n");
         if (!kOCEntryCompareOldAndNewOutput(pEntry))
             pEntry->fNeedCompiling = 1;
@@ -2986,4 +3013,6 @@
     int fBad = 0;
 
+    InfoMsg(4, "reading cache file...\n");
+
     /*
      * Rewind the file & stream, and associate a temporary buffer
@@ -3002,5 +3031,5 @@
         ||  strcmp(g_szLine, "magic=kObjCache-v0.1.0\n"))
     {
-        InfoMsg(1, "bad cache file (magic)\n");
+        InfoMsg(2, "bad cache file (magic)\n");
         fBad = 1;
     }
@@ -3008,5 +3037,5 @@
              ||  strncmp(g_szLine, "generation=", sizeof("generation=") - 1))
     {
-        InfoMsg(1, "bad cache file (generation)\n");
+        InfoMsg(2, "bad cache file (generation)\n");
         fBad = 1;
     }
@@ -3014,5 +3043,5 @@
              && pCache->uGeneration == atol(&g_szLine[sizeof("generation=") - 1]))
     {
-        InfoMsg(1, "drop re-read unmodified cache file\n");
+        InfoMsg(3, "drop re-read unmodified cache file\n");
         fBad = 0;
     }
@@ -3155,10 +3184,12 @@
                 if ((fBad = pCache->paDigests[i].pszTarget == NULL))
                     break;
+                InfoMsg(4, "digest-%u: %s\n", i, pCache->paDigests[i].pszAbsPath
+                        ? pCache->paDigests[i].pszAbsPath : pCache->paDigests[i].pszRelPath);
             }
         if (fBad)
-            InfoMsg(1, "bad cache file (%s)\n", fBadBeforeMissing ? g_szLine : "missing stuff");
+            InfoMsg(2, "bad cache file (%s)\n", fBadBeforeMissing ? g_szLine : "missing stuff");
         else if (ferror(pCache->pFile))
         {
-            InfoMsg(1, "cache file read error\n");
+            InfoMsg(2, "cache file read error\n");
             fBad = 1;
         }
@@ -3263,5 +3294,5 @@
 #endif
         FatalDie("file truncation failed: %s\n", strerror(errno));
-    InfoMsg(1, "wrote '%s' in '%s', %d bytes\n", pCache->pszName, pCache->pszDir, cb);
+    InfoMsg(4, "wrote '%s' in '%s', %d bytes\n", pCache->pszName, pCache->pszDir, cb);
 }
 
@@ -3368,5 +3399,8 @@
         kObjCacheRead(pCache);
     else
+    {
         pCache->fNewCache = 1;
+        InfoMsg(2, "the cache file is empty\n");
+    }
 }
 
@@ -3438,4 +3472,5 @@
 
             pCache->fDirty = 1;
+            InfoMsg(3, "removing entry '%s'; %d left.\n", kOCEntryAbsPath(pEntry), pCache->cDigests);
         }
     }
@@ -3482,6 +3517,7 @@
      * Create a new digest.
      */
-    i = pCache->cDigests++;
-    kOCDigestInitFromEntry(&pCache->paDigests[i], pEntry);
+    kOCDigestInitFromEntry(&pCache->paDigests[pCache->cDigests], pEntry);
+    pCache->cDigests++;
+    InfoMsg(4, "Inserted digest #%u: %s\n", pCache->cDigests - 1, kOCEntryAbsPath(pEntry));
 
     pCache->fDirty = 1;
@@ -3521,4 +3557,5 @@
 
             /* bad entry, purge it. */
+            InfoMsg(3, "removing bad digest '%s'\n", kOCDigestAbsPath(pDigest, pCache->pszDir));
             kOCDigestPurge(pDigest);
 
@@ -3770,6 +3807,6 @@
     pEntry = kOCEntryCreate(pszEntryFile);
     kOCEntryRead(pEntry);
+    kOCEntrySetCompileObjName(pEntry, pszObjName);
     kOCEntrySetCompileArgv(pEntry, papszArgvCompile, cArgvCompile);
-    kOCEntrySetCompileObjName(pEntry, pszObjName);
     kOCEntrySetTarget(pEntry, pszTarget);
     kOCEntrySetCppName(pEntry, pszPreCompName);
@@ -3788,4 +3825,5 @@
          */
         kObjCacheUnlock(pCache);
+        InfoMsg(1, "doing full compile\n");
         kOCEntryPreCompileAndCompile(pEntry, papszArgvPreComp, cArgvPreComp);
         kObjCacheLock(pCache);
@@ -3811,4 +3849,5 @@
             if (pUseEntry)
             {
+                InfoMsg(1, "using cache entry '%s'\n", kOCEntryAbsPath(pUseEntry));
                 kOCEntryCopy(pEntry, pUseEntry);
                 kOCEntryDestroy(pUseEntry);
@@ -3817,4 +3856,5 @@
             {
                 kObjCacheUnlock(pCache);
+                InfoMsg(1, "recompiling\n");
                 kOCEntryCompileIt(pEntry);
                 kObjCacheLock(pCache);
@@ -3822,5 +3862,8 @@
         }
         else
+        {
+            InfoMsg(1, "no need to recompile\n");
             kObjCacheLock(pCache);
+        }
     }
 
