Index: trunk/src/kDepPre/kDepPre.c
===================================================================
--- trunk/src/kDepPre/kDepPre.c	(revision 3165)
+++ trunk/src/kDepPre/kDepPre.c	(revision 3167)
@@ -56,7 +56,8 @@
  * @returns 0 on success.
  * @returns 1 or other approriate exit code on failure.
+ * @param   pThis       Pointer to the 'dep' instance.
  * @param   pInput      Input stream. (probably not seekable)
  */
-static int ParseCPrecompiler(FILE *pInput)
+static int ParseCPrecompiler(PDEPGLOBALS pThis, FILE *pInput)
 {
     enum
@@ -186,5 +187,5 @@
                             ||  pDep->cchFilename != cchFilename
                             ||  memcmp(pDep->szFilename, szBuf, cchFilename))
-                            pDep = depAdd(szBuf, cchFilename);
+                            pDep = depAdd(pThis, szBuf, cchFilename);
                         break;
                     }
@@ -225,4 +226,5 @@
 {
     int         i;
+    DEPGLOBALS  This;
 
     /* Arguments. */
@@ -450,5 +452,6 @@
      * Do the parsing.
      */
-    i = ParseCPrecompiler(pInput);
+    depInit(&This);
+    i = ParseCPrecompiler(&This, pInput);
 
     /*
@@ -465,9 +468,9 @@
     if (!i)
     {
-        depOptimize(fFixCase, 0 /* fQuiet */, NULL /*pszIgnoredExt*/);
+        depOptimize(&This, fFixCase, 0 /* fQuiet */, NULL /*pszIgnoredExt*/);
         fprintf(pOutput, "%s:", pszTarget);
-        depPrint(pOutput);
+        depPrint(&This, pOutput);
         if (fStubs)
-            depPrintStubs(pOutput);
+            depPrintStubs(&This, pOutput);
     }
 
@@ -487,4 +490,6 @@
     }
 
+    depCleanup(&This);
+
     return i;
 }
Index: trunk/src/kObjCache/kObjCache.c
===================================================================
--- trunk/src/kObjCache/kObjCache.c	(revision 3165)
+++ trunk/src/kObjCache/kObjCache.c	(revision 3167)
@@ -807,4 +807,6 @@
     /** The current dependency file. */
     PDEP pCurDep;
+    /** The core dependency collector state. */
+    DEPGLOBALS Core;
 } KOCDEP;
 /** Pointer to a KOCDEP.  */
@@ -824,4 +826,5 @@
     pDepState->pszFilename = NULL;
     pDepState->pCurDep = NULL;
+    depInit(&pDepState->Core);
 }
 
@@ -837,5 +840,5 @@
     free(pDepState->pszFilename);
     pDepState->pszFilename = NULL;
-    depCleanup();
+    depCleanup(&pDepState->Core);
 }
 
@@ -908,5 +911,5 @@
         || cchFilename != pDepState->pCurDep->cchFilename
         || strcmp(pDepState->pszFilename, pDepState->pCurDep->szFilename))
-        pDepState->pCurDep = depAdd(pDepState->pszFilename, cchFilename);
+        pDepState->pCurDep = depAdd(&pDepState->Core, pDepState->pszFilename, cchFilename);
 }
 
@@ -1070,5 +1073,5 @@
                             || cchFilename != pDepState->pCurDep->cchFilename
                             || strcmp(pDepState->pszFilename, pDepState->pCurDep->szFilename))
-                            pDepState->pCurDep = depAdd(pDepState->pszFilename, cchFilename);
+                            pDepState->pCurDep = depAdd(&pDepState->Core, pDepState->pszFilename, cchFilename);
                         pDepState->offFilename = 0;
                         break;
@@ -1112,5 +1115,5 @@
         FatalMsg("Failed to open dependency file '%s': %s\n", pszFilename, strerror(errno));
 
-    depOptimize(fFixCase, fQuiet, NULL /*pszIgnoredExt*/);
+    depOptimize(&pDepState->Core, fFixCase, fQuiet, NULL /*pszIgnoredExt*/);
 
     /* Make object file name with unix slashes. */
@@ -1122,7 +1125,7 @@
     fprintf(pFile, "%s:", pszObjFileAbs);
     free(pszObjFileAbs);
-    depPrint(pFile);
+    depPrint(&pDepState->Core, pFile);
     if (fGenStubs)
-        depPrintStubs(pFile);
+        depPrintStubs(&pDepState->Core, pFile);
 
     if (fclose(pFile) != 0)
Index: trunk/src/kmk/dir-nt-bird.c
===================================================================
--- trunk/src/kmk/dir-nt-bird.c	(revision 3165)
+++ trunk/src/kmk/dir-nt-bird.c	(revision 3167)
@@ -38,5 +38,5 @@
 # include <glob.h>
 #endif
-
+#include <assert.h>
 
 #include "nt_fullpath.h" /* for the time being - will be implemented here later on. */
@@ -80,8 +80,11 @@
  * from the sources.  */
 static KBOOL g_fFsCacheIsUsingCustomRevision = K_FALSE;
+/** The ID of the main thread.  We currently only let it access the cache. */
+static DWORD g_idMainThread = 0;
 
 
 void hash_init_directories(void)
 {
+    g_idMainThread = GetCurrentThreadId();
     g_pFsCache = kFsCacheCreate(0);
     if (g_pFsCache)
@@ -110,6 +113,8 @@
     KFSLOOKUPERROR  enmError;
     PKFSOBJ         pDirObj = kFsCacheLookupA(g_pFsCache, pszDir, &enmError);
+    assert(GetCurrentThreadId() == g_idMainThread);
     if (pDirObj)
     {
+
         if (pDirObj->bObjType == KFSOBJ_TYPE_DIR)
         {
@@ -145,10 +150,65 @@
 int file_exists_p(const char *pszPath)
 {
+    int fRc;
+    if (GetCurrentThreadId() == g_idMainThread)
+    {
+        KFSLOOKUPERROR  enmError;
+        PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
+        if (pPathObj)
+        {
+            fRc = pPathObj->bObjType != KFSOBJ_TYPE_MISSING;
+            kFsCacheObjRelease(g_pFsCache, pPathObj);
+        }
+        else
+            fRc = 0;
+    }
+    else
+        fRc = GetFileAttributesA(pszPath) != INVALID_FILE_ATTRIBUTES;
+    return fRc;
+}
+
+
+/**
+ * Just a way for vpath.c to get a correctly cased path, I think.
+ *
+ * @returns Directory path in string cache.
+ * @param   pszDir      The directory.
+ */
+const char *dir_name(const char *pszDir)
+{
+    char szTmp[MAX_PATH];
+    assert(GetCurrentThreadId() == g_idMainThread);
+    nt_fullpath(pszDir, szTmp, sizeof(szTmp));
+    return strcache_add(szTmp);
+}
+
+
+/**
+ * Makes future file_impossible_p calls return 1 for pszPath.
+ */
+void file_impossible(const char *pszPath)
+{
+    KFSLOOKUPERROR  enmError;
+    PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
+    assert(GetCurrentThreadId() == g_idMainThread);
+    if (pPathObj)
+    {
+        kFsCacheObjAddUserData(g_pFsCache, pPathObj, KMK_DIR_NT_IMPOSSIBLE_KEY, sizeof(KFSUSERDATA));
+        kFsCacheObjRelease(g_pFsCache, pPathObj);
+    }
+}
+
+/**
+ * Makes future file_impossible_p calls return 1 for pszPath.
+ */
+int file_impossible_p(const char *pszPath)
+{
     int             fRc;
     KFSLOOKUPERROR  enmError;
     PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
+    assert(GetCurrentThreadId() == g_idMainThread);
     if (pPathObj)
     {
-        fRc = pPathObj->bObjType != KFSOBJ_TYPE_MISSING;
+        fRc = kFsCacheObjGetUserData(g_pFsCache, pPathObj, KMK_DIR_NT_IMPOSSIBLE_KEY) != NULL;
         kFsCacheObjRelease(g_pFsCache, pPathObj);
     }
@@ -160,51 +220,4 @@
 
 /**
- * Just a way for vpath.c to get a correctly cased path, I think.
- *
- * @returns Directory path in string cache.
- * @param   pszDir      The directory.
- */
-const char *dir_name(const char *pszDir)
-{
-    char szTmp[MAX_PATH];
-    nt_fullpath(pszDir, szTmp, sizeof(szTmp));
-    return strcache_add(szTmp);
-}
-
-
-/**
- * Makes future file_impossible_p calls return 1 for pszPath.
- */
-void file_impossible(const char *pszPath)
-{
-    KFSLOOKUPERROR  enmError;
-    PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
-    if (pPathObj)
-    {
-        kFsCacheObjAddUserData(g_pFsCache, pPathObj, KMK_DIR_NT_IMPOSSIBLE_KEY, sizeof(KFSUSERDATA));
-        kFsCacheObjRelease(g_pFsCache, pPathObj);
-    }
-}
-
-/**
- * Makes future file_impossible_p calls return 1 for pszPath.
- */
-int file_impossible_p(const char *pszPath)
-{
-    int             fRc;
-    KFSLOOKUPERROR  enmError;
-    PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
-    if (pPathObj)
-    {
-        fRc = kFsCacheObjGetUserData(g_pFsCache, pPathObj, KMK_DIR_NT_IMPOSSIBLE_KEY) != NULL;
-        kFsCacheObjRelease(g_pFsCache, pPathObj);
-    }
-    else
-        fRc = 0;
-    return fRc;
-}
-
-
-/**
  * opendir for glob.
  *
@@ -216,4 +229,5 @@
     KFSLOOKUPERROR  enmError;
     PKFSOBJ         pDirObj = kFsCacheLookupA(g_pFsCache, pszDir, &enmError);
+    assert(GetCurrentThreadId() == g_idMainThread);
     if (pDirObj)
     {
@@ -244,4 +258,5 @@
     KMKNTOPENDIR *pDir = (KMKNTOPENDIR *)pvDir;
     KU32 const    cChildren = pDir->pDir->cChildren;
+    assert(GetCurrentThreadId() == g_idMainThread);
     while (pDir->idxNext < cChildren)
     {
@@ -307,4 +322,5 @@
 {
     KMKNTOPENDIR *pDir = (KMKNTOPENDIR *)pvDir;
+    assert(GetCurrentThreadId() == g_idMainThread);
     kFsCacheObjRelease(g_pFsCache, &pDir->pDir->Obj);
     pDir->pDir = NULL;
@@ -324,4 +340,5 @@
     KFSLOOKUPERROR  enmError;
     PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
+    assert(GetCurrentThreadId() == g_idMainThread);
 /** @todo follow symlinks vs. on symlink!   */
     if (pPathObj)
@@ -352,4 +369,5 @@
     KFSLOOKUPERROR  enmError;
     PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
+    assert(GetCurrentThreadId() == g_idMainThread);
     if (pPathObj)
     {
@@ -384,4 +402,5 @@
     KFSLOOKUPERROR  enmError;
     PKFSOBJ         pDirObj = kFsCacheLookupA(g_pFsCache, pszDir, &enmError);
+    assert(GetCurrentThreadId() == g_idMainThread);
     if (pDirObj)
     {
@@ -403,4 +422,5 @@
 void dir_setup_glob(glob_t *pGlob)
 {
+    assert(GetCurrentThreadId() == g_idMainThread);
     pGlob->gl_opendir   = dir_glob_opendir;
     pGlob->gl_readdir   = dir_glob_readdir;
@@ -465,4 +485,5 @@
     KFSLOOKUPERROR  enmError;
     PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
+    assert(GetCurrentThreadId() == g_idMainThread);
     if (pPathObj)
     {
@@ -558,4 +579,5 @@
     /* Currently a little expensive, so just hit the file system once the
        jobs starts comming in. */
+    assert(GetCurrentThreadId() == g_idMainThread);
     if (g_cInvalidates == 0)
     {
@@ -589,4 +611,5 @@
 void dir_cache_invalid_after_job(void)
 {
+    assert(GetCurrentThreadId() == g_idMainThread);
     g_cInvalidates++;
     if (g_fFsCacheIsUsingCustomRevision)
@@ -603,4 +626,5 @@
 void dir_cache_invalid_all(void)
 {
+    assert(GetCurrentThreadId() == g_idMainThread);
     g_cInvalidates++;
     kFsCacheInvalidateAll(g_pFsCache);
@@ -614,4 +638,5 @@
 void dir_cache_invalid_missing(void)
 {
+    assert(GetCurrentThreadId() == g_idMainThread);
     g_cInvalidates++;
     kFsCacheInvalidateAll(g_pFsCache);
@@ -625,4 +650,5 @@
 void dir_cache_invalid_volatile(void)
 {
+    assert(GetCurrentThreadId() == g_idMainThread);
     g_cInvalidates++;
     if (g_fFsCacheIsUsingCustomRevision)
@@ -644,4 +670,5 @@
     KFSLOOKUPERROR enmError;
     PKFSOBJ pObj = kFsCacheLookupA(g_pFsCache, pszDir, &enmError);
+    assert(GetCurrentThreadId() == g_idMainThread);
     if (pObj)
     {
@@ -670,4 +697,5 @@
 int dir_cache_deleted_directory(const char *pszDir)
 {
+    assert(GetCurrentThreadId() == g_idMainThread);
     if (kFsCacheInvalidateDeletedDirectoryA(g_pFsCache, pszDir))
         return 0;
@@ -678,4 +706,5 @@
 int kmk_builtin_dircache(int argc, char **argv, char **envp)
 {
+    assert(GetCurrentThreadId() == g_idMainThread);
     if (argc >= 2)
     {
Index: trunk/src/kmk/kmkbuiltin/kDepIDB.c
===================================================================
--- trunk/src/kmk/kmkbuiltin/kDepIDB.c	(revision 3165)
+++ trunk/src/kmk/kmkbuiltin/kDepIDB.c	(revision 3167)
@@ -24,7 +24,8 @@
  */
 
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
 #include "config.h"
 #include <stdio.h>
@@ -48,7 +49,7 @@
 
 
-/*******************************************************************************
-*   Defined Constants And Macros                                               *
-*******************************************************************************/
+/*********************************************************************************************************************************
+*   Defined Constants And Macros                                                                                                 *
+*********************************************************************************************************************************/
 /*#define DEBUG*/
 #ifdef DEBUG
@@ -60,10 +61,13 @@
 #endif
 
-
-/*******************************************************************************
-*   Global Variables                                                           *
-*******************************************************************************/
-/** the executable name. */
-static const char *argv0 = "";
+/*********************************************************************************************************************************
+*   Structures and Typedefs                                                                                                      *
+*********************************************************************************************************************************/
+typedef struct KDEPIDBGLOBALS
+{
+    DEPGLOBALS  Core;
+    const char *argv0;
+} KDEPIDBGLOBALS;
+typedef KDEPIDBGLOBALS *PKDEPIDBGLOBALS;
 
 
@@ -73,4 +77,5 @@
  * @returns 0 on success.
  * @returns !0 on failure.
+ * @param   pThis           The kDepIDB instance.
  * @param   pbStream        The stream bits.
  * @param   cbStream        The size of the stream.
@@ -78,5 +83,5 @@
  * @param   cchPrefix       The size of the prefix.
  */
-static int ScanStream(KU8 *pbStream, size_t cbStream, const char *pszPrefix, size_t cchPrefix)
+static int ScanStream(PKDEPIDBGLOBALS pThis, KU8 *pbStream, size_t cbStream, const char *pszPrefix, size_t cchPrefix)
 {
     const KU8      *pbCur = pbStream;
@@ -96,5 +101,5 @@
             pbCur += cchPrefix;
             cchDep = strlen((const char *)pbCur);
-            depAdd((const char *)pbCur, cchDep);
+            depAdd(&pThis->Core, (const char *) pbCur, cchDep);
             dprintf(("%05x: '%s'\n", pbCur - pbStream, pbCur));
 
@@ -189,14 +194,14 @@
 
 
-static int Pdb70ValidateHeader(PPDB70HDR pHdr, size_t cbFile)
+static int Pdb70ValidateHeader(PKDEPIDBGLOBALS pThis, PPDB70HDR pHdr, size_t cbFile)
 {
     if (pHdr->cbPage * pHdr->cPages != cbFile)
     {
-        fprintf(stderr, "%s: error: Bad PDB 2.0 header - cbPage * cPages != cbFile.\n", argv0);
+        fprintf(stderr, "%s: error: Bad PDB 2.0 header - cbPage * cPages != cbFile.\n", pThis->argv0);
         return 1;
     }
     if (pHdr->iStartPage >= pHdr->cPages && pHdr->iStartPage <= 0)
     {
-        fprintf(stderr, "%s: error: Bad PDB 2.0 header - iStartPage=%u cPages=%u.\n", argv0,
+        fprintf(stderr, "%s: error: Bad PDB 2.0 header - iStartPage=%u cPages=%u.\n", pThis->argv0,
                 pHdr->iStartPage, pHdr->cPages);
         return 1;
@@ -204,5 +209,5 @@
     if (pHdr->iRootPages >= pHdr->cPages && pHdr->iRootPages <= 0)
     {
-        fprintf(stderr, "%s: error: Bad PDB 2.0 header - iRootPages=%u cPage=%u.\n", argv0,
+        fprintf(stderr, "%s: error: Bad PDB 2.0 header - iRootPages=%u cPage=%u.\n", pThis->argv0,
                 pHdr->iStartPage, pHdr->cPages);
         return 1;
@@ -227,5 +232,5 @@
 }
 
-static void *Pdb70AllocAndRead(PPDB70HDR pHdr, size_t cb, PPDB70PAGE paiPageMap)
+static void *Pdb70AllocAndRead(PKDEPIDBGLOBALS pThis, PPDB70HDR pHdr, size_t cb, PPDB70PAGE paiPageMap)
 {
     const size_t    cbPage = pHdr->cbPage;
@@ -246,5 +251,5 @@
             else
             {
-                fprintf(stderr, "%s: warning: Invalid page index %u (max %u)!\n", argv0,
+                fprintf(stderr, "%s: warning: Invalid page index %u (max %u)!\n", pThis->argv0,
                         (unsigned)off, pHdr->cPages);
                 memset(pbBuf + iPage * cbPage, 0, cbPage);
@@ -256,9 +261,9 @@
     }
     else
-        fprintf(stderr, "%s: error: failed to allocate %lu bytes\n", argv0, (unsigned long)(cPages * cbPage + 1));
+        fprintf(stderr, "%s: error: failed to allocate %lu bytes\n", pThis->argv0, (unsigned long)(cPages * cbPage + 1));
     return pbBuf;
 }
 
-static PPDB70ROOT Pdb70AllocAndReadRoot(PPDB70HDR pHdr)
+static PPDB70ROOT Pdb70AllocAndReadRoot(PKDEPIDBGLOBALS pThis, PPDB70HDR pHdr)
 {
     /*
@@ -267,5 +272,5 @@
      */
     PPDB70PAGE piPageMap = (KU32 *)((KU8 *)pHdr + pHdr->iRootPages * pHdr->cbPage);
-    PPDB70ROOT pRoot = Pdb70AllocAndRead(pHdr, pHdr->cbRoot, piPageMap);
+    PPDB70ROOT pRoot = Pdb70AllocAndRead(pThis, pHdr, pHdr->cbRoot, piPageMap);
     if (pRoot)
     {
@@ -275,5 +280,5 @@
         size_t cb = K_OFFSETOF(PDB70ROOT, aStreams[pRoot->cStreams]);
         free(pRoot);
-        pRoot = Pdb70AllocAndRead(pHdr, cb, piPageMap);
+        pRoot = Pdb70AllocAndRead(pThis, pHdr, cb, piPageMap);
         if (pRoot)
         {
@@ -284,5 +289,5 @@
                     cb += Pdb70Pages(pHdr, pRoot->aStreams[iStream].cbStream) * sizeof(PDB70PAGE);
             free(pRoot);
-            pRoot = Pdb70AllocAndRead(pHdr, cb, piPageMap);
+            pRoot = Pdb70AllocAndRead(pThis, pHdr, cb, piPageMap);
             if (pRoot)
             {
@@ -299,5 +304,5 @@
 }
 
-static void *Pdb70AllocAndReadStream(PPDB70HDR pHdr, PPDB70ROOT pRoot, unsigned iStream, size_t *pcbStream)
+static void *Pdb70AllocAndReadStream(PKDEPIDBGLOBALS pThis, PPDB70HDR pHdr, PPDB70ROOT pRoot, unsigned iStream, size_t *pcbStream)
 {
     const size_t    cbStream = pRoot->aStreams[iStream].cbStream;
@@ -306,5 +311,5 @@
         ||  cbStream == ~(KU32)0)
     {
-        fprintf(stderr, "%s: error: Invalid stream %d\n", argv0, iStream);
+        fprintf(stderr, "%s: error: Invalid stream %d\n", pThis->argv0, iStream);
         return NULL;
     }
@@ -317,8 +322,8 @@
     if (pcbStream)
         *pcbStream = cbStream;
-    return Pdb70AllocAndRead(pHdr, cbStream, paiPageMap);
-}
-
-static int Pdb70Process(KU8 *pbFile, size_t cbFile)
+    return Pdb70AllocAndRead(pThis, pHdr, cbStream, paiPageMap);
+}
+
+static int Pdb70Process(PKDEPIDBGLOBALS pThis, KU8 *pbFile, size_t cbFile)
 {
     PPDB70HDR   pHdr = (PPDB70HDR)pbFile;
@@ -334,7 +339,7 @@
      * Validate the header and read the root stream.
      */
-    if (Pdb70ValidateHeader(pHdr, cbFile))
-        return 1;
-    pRoot = Pdb70AllocAndReadRoot(pHdr);
+    if (Pdb70ValidateHeader(pThis, pHdr, cbFile))
+        return 1;
+    pRoot = Pdb70AllocAndReadRoot(pThis, pHdr);
     if (!pRoot)
         return 1;
@@ -344,5 +349,5 @@
      */
     dprintf(("Reading the names stream....\n"));
-    pNames = Pdb70AllocAndReadStream(pHdr, pRoot, 1, &cbStream);
+    pNames = Pdb70AllocAndReadStream(pThis, pHdr, pRoot, 1, &cbStream);
     if (pNames)
     {
@@ -366,5 +371,5 @@
                     && !memcmp(psz, "/mr/inversedeps/", sizeof("/mr/inversedeps/") - 1))
                 {
-                    depAdd(psz + sizeof("/mr/inversedeps/") - 1, cch - (sizeof("/mr/inversedeps/") - 1));
+                    depAdd(&pThis->Core, psz + sizeof("/mr/inversedeps/") - 1, cch - (sizeof("/mr/inversedeps/") - 1));
                     fAdded = 1;
                 }
@@ -408,8 +413,8 @@
             dprintf(("Stream #%d: %#x bytes (%#x aligned)\n", iStream, pRoot->aStreams[iStream].cbStream,
                      Pdb70Align(pHdr, pRoot->aStreams[iStream].cbStream)));
-            pbStream = (KU8 *)Pdb70AllocAndReadStream(pHdr, pRoot, iStream, &cbStream);
+            pbStream = (KU8 *)Pdb70AllocAndReadStream(pThis, pHdr, pRoot, iStream, &cbStream);
             if (pbStream)
             {
-                rc = ScanStream(pbStream, cbStream, "/mr/inversedeps/", sizeof("/mr/inversedeps/") - 1);
+                rc = ScanStream(pThis, pbStream, cbStream, "/mr/inversedeps/", sizeof("/mr/inversedeps/") - 1);
                 free(pbStream);
             }
@@ -485,14 +490,14 @@
 
 
-static int Pdb20ValidateHeader(PPDB20HDR pHdr, size_t cbFile)
+static int Pdb20ValidateHeader(PKDEPIDBGLOBALS pThis, PPDB20HDR pHdr, size_t cbFile)
 {
     if (pHdr->cbPage * pHdr->cPages != cbFile)
     {
-        fprintf(stderr, "%s: error: Bad PDB 2.0 header - cbPage * cPages != cbFile.\n", argv0);
+        fprintf(stderr, "%s: error: Bad PDB 2.0 header - cbPage * cPages != cbFile.\n", pThis->argv0);
         return 1;
     }
     if (pHdr->iStartPage >= pHdr->cPages && pHdr->iStartPage <= 0)
     {
-        fprintf(stderr, "%s: error: Bad PDB 2.0 header - cbPage * cPages != cbFile.\n", argv0);
+        fprintf(stderr, "%s: error: Bad PDB 2.0 header - cbPage * cPages != cbFile.\n", pThis->argv0);
         return 1;
     }
@@ -507,5 +512,5 @@
 }
 
-static void *Pdb20AllocAndRead(PPDB20HDR pHdr, size_t cb, PPDB20PAGE paiPageMap)
+static void *Pdb20AllocAndRead(PKDEPIDBGLOBALS pThis, PPDB20HDR pHdr, size_t cb, PPDB20PAGE paiPageMap)
 {
     size_t cPages = Pdb20Pages(pHdr, cb);
@@ -524,9 +529,9 @@
     }
     else
-        fprintf(stderr, "%s: error: failed to allocate %lu bytes\n", argv0, (unsigned long)(cPages * pHdr->cbPage + 1));
+        fprintf(stderr, "%s: error: failed to allocate %lu bytes\n", pThis->argv0, (unsigned long)(cPages * pHdr->cbPage + 1));
     return pbBuf;
 }
 
-static PPDB20ROOT Pdb20AllocAndReadRoot(PPDB20HDR pHdr)
+static PPDB20ROOT Pdb20AllocAndReadRoot(PKDEPIDBGLOBALS pThis, PPDB20HDR pHdr)
 {
     /*
@@ -534,5 +539,5 @@
      * (Todo: Check if we can just use the stream size..)
      */
-    PPDB20ROOT pRoot = Pdb20AllocAndRead(pHdr, sizeof(*pRoot), &pHdr->aiRootPageMap[0]);
+    PPDB20ROOT pRoot = Pdb20AllocAndRead(pThis, pHdr, sizeof(*pRoot), &pHdr->aiRootPageMap[0]);
     if (pRoot)
     {
@@ -540,5 +545,5 @@
         size_t cb = K_OFFSETOF(PDB20ROOT, aStreams[pRoot->cStreams]);
         free(pRoot);
-        pRoot = Pdb20AllocAndRead(pHdr, cb, &pHdr->aiRootPageMap[0]);
+        pRoot = Pdb20AllocAndRead(pThis, pHdr, cb, &pHdr->aiRootPageMap[0]);
         if (pRoot)
         {
@@ -549,5 +554,5 @@
                     cb += Pdb20Pages(pHdr, pRoot->aStreams[iStream].cbStream) * sizeof(PDB20PAGE);
             free(pRoot);
-            pRoot = Pdb20AllocAndRead(pHdr, cb, &pHdr->aiRootPageMap[0]);
+            pRoot = Pdb20AllocAndRead(pThis, pHdr, cb, &pHdr->aiRootPageMap[0]);
             if (pRoot)
             {
@@ -561,5 +566,5 @@
 }
 
-static void *Pdb20AllocAndReadStream(PPDB20HDR pHdr, PPDB20ROOT pRoot, unsigned iStream, size_t *pcbStream)
+static void *Pdb20AllocAndReadStream(PKDEPIDBGLOBALS pThis, PPDB20HDR pHdr, PPDB20ROOT pRoot, unsigned iStream, size_t *pcbStream)
 {
     size_t      cbStream = pRoot->aStreams[iStream].cbStream;
@@ -568,5 +573,5 @@
         ||  cbStream == ~(KU32)0)
     {
-        fprintf(stderr, "%s: error: Invalid stream %d\n", argv0, iStream);
+        fprintf(stderr, "%s: error: Invalid stream %d\n", pThis->argv0, iStream);
         return NULL;
     }
@@ -579,8 +584,8 @@
     if (pcbStream)
         *pcbStream = cbStream;
-    return Pdb20AllocAndRead(pHdr, cbStream, paiPageMap);
-}
-
-static int Pdb20Process(KU8 *pbFile, size_t cbFile)
+    return Pdb20AllocAndRead(pThis, pHdr, cbStream, paiPageMap);
+}
+
+static int Pdb20Process(PKDEPIDBGLOBALS pThis, KU8 *pbFile, size_t cbFile)
 {
     PPDB20HDR   pHdr = (PPDB20HDR)pbFile;
@@ -592,7 +597,7 @@
      * Validate the header and read the root stream.
      */
-    if (Pdb20ValidateHeader(pHdr, cbFile))
-        return 1;
-    pRoot = Pdb20AllocAndReadRoot(pHdr);
+    if (Pdb20ValidateHeader(pThis, pHdr, cbFile))
+        return 1;
+    pRoot = Pdb20AllocAndReadRoot(pThis, pHdr);
     if (!pRoot)
         return 1;
@@ -608,8 +613,8 @@
         if (pRoot->aStreams[iStream].cbStream == ~(KU32)0)
             continue;
-        pbStream = (KU8 *)Pdb20AllocAndReadStream(pHdr, pRoot, iStream, NULL);
+        pbStream = (KU8 *)Pdb20AllocAndReadStream(pThis, pHdr, pRoot, iStream, NULL);
         if (pbStream)
         {
-            rc = ScanStream(pbStream, pRoot->aStreams[iStream].cbStream, "/ipm/header/", sizeof("/ipm/header/") - 1);
+            rc = ScanStream(pThis, pbStream, pRoot->aStreams[iStream].cbStream, "/ipm/header/", sizeof("/ipm/header/") - 1);
             free(pbStream);
         }
@@ -626,5 +631,5 @@
  * Make an attempt at parsing a Visual C++ IDB file.
  */
-static int ProcessIDB(FILE *pInput)
+static int ProcessIDB(PKDEPIDBGLOBALS pThis, FILE *pInput)
 {
     size_t      cbFile;
@@ -644,10 +649,10 @@
      */
     if (!memcmp(pbFile, PDB_SIGNATURE_700, sizeof(PDB_SIGNATURE_700)))
-        rc = Pdb70Process(pbFile, cbFile);
+        rc = Pdb70Process(pThis, pbFile, cbFile);
     else if (!memcmp(pbFile, PDB_SIGNATURE_200, sizeof(PDB_SIGNATURE_200)))
-        rc = Pdb20Process(pbFile, cbFile);
+        rc = Pdb20Process(pThis, pbFile, cbFile);
     else
     {
-        fprintf(stderr, "%s: error: Doesn't recognize the header of the Visual C++ IDB file.\n", argv0);
+        fprintf(stderr, "%s: error: Doesn't recognize the header of the Visual C++ IDB file.\n", pThis->argv0);
         rc = 1;
     }
@@ -658,5 +663,5 @@
 
 
-static void usage(const char *a_argv0)
+static void kDepIDBUsage(const char *a_argv0)
 {
     printf("usage: %s -o <output> -t <target> [-fqs] <vc idb-file>\n"
@@ -669,5 +674,6 @@
 int kmk_builtin_kDepIDB(int argc, char *argv[], char **envp)
 {
-    int         i;
+    int             i;
+    KDEPIDBGLOBALS  This;
 
     /* Arguments. */
@@ -682,5 +688,6 @@
     int         fQuiet = 0;
 
-    argv0 = argv[0];
+    /* Init the instance data. */
+    This.argv0 = argv[0];
 
     /*
@@ -689,5 +696,5 @@
     if (argc <= 1)
     {
-        usage(argv[0]);
+        kDepIDBUsage(This.argv0);
         return 1;
     }
@@ -717,5 +724,5 @@
                     if (pOutput)
                     {
-                        fprintf(stderr, "%s: syntax error: only one output file!\n", argv[0]);
+                        fprintf(stderr, "%s: syntax error: only one output file!\n", This.argv0);
                         return 1;
                     }
@@ -724,5 +731,5 @@
                         if (++i >= argc)
                         {
-                            fprintf(stderr, "%s: syntax error: The '-o' argument is missing the filename.\n", argv[0]);
+                            fprintf(stderr, "%s: syntax error: The '-o' argument is missing the filename.\n", This.argv0);
                             return 1;
                         }
@@ -735,5 +742,5 @@
                     if (!pOutput)
                     {
-                        fprintf(stderr, "%s: error: Failed to create output file '%s'.\n", argv[0], pszOutput);
+                        fprintf(stderr, "%s: error: Failed to create output file '%s'.\n", This.argv0, pszOutput);
                         return 1;
                     }
@@ -748,5 +755,5 @@
                     if (pszTarget)
                     {
-                        fprintf(stderr, "%s: syntax error: only one target!\n", argv[0]);
+                        fprintf(stderr, "%s: syntax error: only one target!\n", This.argv0);
                         return 1;
                     }
@@ -756,5 +763,5 @@
                         if (++i >= argc)
                         {
-                            fprintf(stderr, "%s: syntax error: The '-t' argument is missing the target name.\n", argv[0]);
+                            fprintf(stderr, "%s: syntax error: The '-t' argument is missing the target name.\n", This.argv0);
                             return 1;
                         }
@@ -795,9 +802,9 @@
                  */
                 case '?':
-                    usage(argv[0]);
+                    kDepIDBUsage(This.argv0);
                     return 0;
                 case 'V':
                 case 'v':
-                    return kbuild_version(argv[0]);
+                    return kbuild_version(This.argv0);
 
                 /*
@@ -805,6 +812,6 @@
                  */
                 default:
-                    fprintf(stderr, "%s: syntax error: Invalid argument '%s'.\n", argv[0], argv[i]);
-                    usage(argv[0]);
+                    fprintf(stderr, "%s: syntax error: Invalid argument '%s'.\n", This.argv0, argv[i]);
+                    kDepIDBUsage(This.argv0);
                     return 1;
             }
@@ -815,5 +822,5 @@
             if (!pInput)
             {
-                fprintf(stderr, "%s: error: Failed to open input file '%s'.\n", argv[0], argv[i]);
+                fprintf(stderr, "%s: error: Failed to open input file '%s'.\n", This.argv0, argv[i]);
                 return 1;
             }
@@ -828,5 +835,5 @@
             if (++i < argc)
             {
-                fprintf(stderr, "%s: syntax error: No arguments shall follow the input spec.\n", argv[0]);
+                fprintf(stderr, "%s: syntax error: No arguments shall follow the input spec.\n", This.argv0);
                 return 1;
             }
@@ -840,15 +847,15 @@
     if (!pInput)
     {
-        fprintf(stderr, "%s: syntax error: No input!\n", argv[0]);
+        fprintf(stderr, "%s: syntax error: No input!\n", This.argv0);
         return 1;
     }
     if (!pOutput)
     {
-        fprintf(stderr, "%s: syntax error: No output!\n", argv[0]);
+        fprintf(stderr, "%s: syntax error: No output!\n", This.argv0);
         return 1;
     }
     if (!pszTarget)
     {
-        fprintf(stderr, "%s: syntax error: No target!\n", argv[0]);
+        fprintf(stderr, "%s: syntax error: No target!\n", This.argv0);
         return 1;
     }
@@ -857,5 +864,6 @@
      * Do the parsing.
      */
-    i = ProcessIDB(pInput);
+    depInit(&This.Core);
+    i = ProcessIDB(&This, pInput);
     fclose(pInput);
 
@@ -865,9 +873,9 @@
     if (!i)
     {
-        depOptimize(fFixCase, fQuiet, NULL /*pszIgnoredExt*/);
+        depOptimize(&This.Core, fFixCase, fQuiet, NULL /*pszIgnoredExt*/);
         fprintf(pOutput, "%s:", pszTarget);
-        depPrint(pOutput);
+        depPrint(&This.Core, pOutput);
         if (fStubs)
-            depPrintStubs(pOutput);
+            depPrintStubs(&This.Core, pOutput);
     }
 
@@ -878,5 +886,5 @@
     {
         i = 1;
-        fprintf(stderr, "%s: error: Error writing to '%s'.\n", argv[0], pszOutput);
+        fprintf(stderr, "%s: error: Error writing to '%s'.\n", This.argv0, pszOutput);
     }
     fclose(pOutput);
@@ -884,8 +892,8 @@
     {
         if (unlink(pszOutput))
-            fprintf(stderr, "%s: warning: failed to remove output file '%s' on failure.\n", argv[0], pszOutput);
-    }
-
-    depCleanup();
+            fprintf(stderr, "%s: warning: failed to remove output file '%s' on failure.\n", This.argv0, pszOutput);
+    }
+
+    depCleanup(&This.Core);
     return i;
 }
Index: trunk/src/kmk/kmkbuiltin/kDepObj.c
===================================================================
--- trunk/src/kmk/kmkbuiltin/kDepObj.c	(revision 3165)
+++ trunk/src/kmk/kmkbuiltin/kDepObj.c	(revision 3167)
@@ -165,11 +165,19 @@
 /** @} */
 
-
-/*******************************************************************************
-*   Global Variables                                                           *
-*******************************************************************************/
-/** the executable name. */
-static const char *argv0 = "";
-static const char *g_pszFile = NULL;
+/**
+ * Globals.
+ */
+typedef struct KDEPOBJGLOBALS
+{
+    /** Core instance. */
+    DEPGLOBALS Core;
+    /** the executable name. */
+    const char *argv0;
+    /** The file.    */
+    const char *pszFile;
+} KDEPOBJGLOBALS;
+/** Pointer to kDepObj globals. */
+typedef KDEPOBJGLOBALS *PKDEPOBJGLOBALS;
+
 
 
@@ -178,4 +186,5 @@
  *
  * @returns rc.
+ * @param   pThis       kObjDep instance data.
  * @param   rc          The return code, for making one line return statements.
  * @param   pszFormat   The message format string.
@@ -183,9 +192,9 @@
  * @todo    Promote this to kDep.c.
  */
-static int kDepErr(int rc, const char *pszFormat, ...)
+static int kDepErr(PKDEPOBJGLOBALS pThis, int rc, const char *pszFormat, ...)
 {
     va_list va;
     const char *psz;
-    const char *pszName = argv0;
+    const char *pszName = pThis->argv0;
 
     fflush(stdout);
@@ -195,6 +204,6 @@
         pszName = psz + 1;
 
-    if (g_pszFile)
-        fprintf(stderr, "%s: %s: error: ", pszName, g_pszFile);
+    if (pThis->pszFile)
+        fprintf(stderr, "%s: %s: error: ", pszName, pThis->pszFile);
     else
         fprintf(stderr, "%s: error: ", pszName);
@@ -245,8 +254,9 @@
  *
  * @returns 0 on success, 1 on failure, 2 if no dependencies was found.
+ * @param   pThis       The kDepObj instance data.
  * @param   pbFile      The start of the file.
  * @param   cbFile      The file size.
  */
-int kDepObjOMFParse(const KU8 *pbFile, KSIZE cbFile)
+int kDepObjOMFParse(PKDEPOBJGLOBALS pThis, const KU8 *pbFile, KSIZE cbFile)
 {
     PCKDEPOMFHDR    pHdr        = (PCKDEPOMFHDR)pbFile;
@@ -284,5 +294,5 @@
                 PCKDEPOMFTHEADR pTHeadr = (PCKDEPOMFTHEADR)pHdr;
                 if (1 + pTHeadr->Name.cch + 1 != pHdr->cbRec)
-                    return kDepErr(1, "%#07x - Bad %cHEADR record, length mismatch.\n",
+                    return kDepErr(pThis, 1, "%#07x - Bad %cHEADR record, length mismatch.\n",
                                    (const KU8*)pHdr - pbFile, pHdr->bType == KDEPOMF_THEADR ? 'T' : 'L');
                 if (    (   pTHeadr->Name.cch > 2
@@ -303,5 +313,5 @@
                 {
                     dprintf(("%cHEADR: %.*s\n", pHdr->bType == KDEPOMF_THEADR ? 'T' : 'L', pTHeadr->Name.cch, pTHeadr->Name.ach));
-                    depAdd(pTHeadr->Name.ach, pTHeadr->Name.cch);
+                    depAdd(&pThis->Core, pTHeadr->Name.ach, pTHeadr->Name.cch);
                     iMaybeSrc++;
                 }
@@ -315,7 +325,7 @@
 
                 if (pHdr->cbRec < 2 + 1)
-                    return kDepErr(1, "%#07x - Bad COMMENT record, too small.\n", (const KU8*)pHdr - pbFile);
+                    return kDepErr(pThis, 1, "%#07x - Bad COMMENT record, too small.\n", (const KU8*)pHdr - pbFile);
                 if (uData.pb[0] & 0x3f)
-                    return kDepErr(1, "%#07x - Bad COMMENT record, reserved flags set.\n", (const KU8*)pHdr - pbFile);
+                    return kDepErr(pThis, 1, "%#07x - Bad COMMENT record, reserved flags set.\n", (const KU8*)pHdr - pbFile);
                 uClass = uData.pb[1];
                 uData.pb += 2;
@@ -334,10 +344,10 @@
                             if (pHdr->cbRec == 2 + 1)
                                 return 0;
-                            return kDepErr(1, "%#07lx - Bad DEPENDENCY FILE record, length mismatch. (%u/%u)\n",
+                            return kDepErr(pThis, 1, "%#07lx - Bad DEPENDENCY FILE record, length mismatch. (%u/%u)\n",
                                            (long)((const KU8 *)pHdr - pbFile),
                                            K_OFFSETOF(KDEPOMFDEPFILE, Name.ach[pDep->Name.cch]) + 1,
                                            (unsigned)(pHdr->cbRec + sizeof(*pHdr)));
                         }
-                        depAdd(pDep->Name.ach, pDep->Name.cch);
+                        depAdd(&pThis->Core, pDep->Name.ach, pDep->Name.cch);
                         iSrc++;
                         break;
@@ -388,5 +398,5 @@
                     KU16 uSeg = kDepObjOMFGetIndex(&uData, &cbRecLeft);
                     if (uSeg == KU16_MAX)
-                        return kDepErr(1, "%#07lx - Bad LINNUM32 record\n", (long)((const KU8 *)pHdr - pbFile));
+                        return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record\n", (long)((const KU8 *)pHdr - pbFile));
                     K_NOREF(uGrp);
 
@@ -405,5 +415,5 @@
 
                         if (cbRecLeft < 2+1+1+2+2+4)
-                            return kDepErr(1, "%#07lx - Bad LINNUM32 record, too short\n", (long)((const KU8 *)pHdr - pbFile));
+                            return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record, too short\n", (long)((const KU8 *)pHdr - pbFile));
                         cbRecLeft  -= 2+1+1+2+2+4;
                         uLine       = *uData.pu16++;
@@ -421,5 +431,5 @@
 
                         if (uLine != 0)
-                            return kDepErr(1, "%#07lx - Bad LINNUM32 record, line %#x (MBZ)\n", (long)((const KU8 *)pHdr - pbFile), uLine);
+                            return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record, line %#x (MBZ)\n", (long)((const KU8 *)pHdr - pbFile), uLine);
                         cLinFiles = iLinFile = KU32_MAX;
                         if (   uLinNumType == 3 /* file names table */
@@ -427,5 +437,5 @@
                             cLinNums = 0; /* no line numbers */
                         else if (uLinNumType > 4)
-                            return kDepErr(1, "%#07lx - Bad LINNUM32 record, type %#x unknown\n", (long)((const KU8 *)pHdr - pbFile), uLinNumType);
+                            return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record, type %#x unknown\n", (long)((const KU8 *)pHdr - pbFile), uLinNumType);
                     }
                     else
@@ -442,5 +452,5 @@
                         {
                             if (cbRecLeft < cbEntry)
-                                return kDepErr(1, "%#07lx - Bad LINNUM32 record, incomplete line entry\n", (long)((const KU8 *)pHdr - pbFile));
+                                return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record, incomplete line entry\n", (long)((const KU8 *)pHdr - pbFile));
 
                             switch (uLinNumType)
@@ -482,5 +492,5 @@
 
                             if (cbRecLeft < 4+4+4)
-                                return kDepErr(1, "%#07lx - Bad LINNUM32 record, incomplete file/path table header\n", (long)((const KU8 *)pHdr - pbFile));
+                                return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record, incomplete file/path table header\n", (long)((const KU8 *)pHdr - pbFile));
                             cbRecLeft -= 4+4+4;
 
@@ -491,5 +501,5 @@
                                      uLinNumType == 3 ? "file names" : "path", cLinFiles, cLinFiles, iFirstCol, cCols));
                             if (cLinFiles == KU32_MAX)
-                                return kDepErr(1, "%#07lx - Bad LINNUM32 record, too many file/path table entries.\n", (long)((const KU8 *)pHdr - pbFile));
+                                return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record, too many file/path table entries.\n", (long)((const KU8 *)pHdr - pbFile));
                             iLinFile = 0;
                         }
@@ -500,10 +510,10 @@
                             int cbName = *uData.pb++;
                             if (cbRecLeft < 1 + cbName)
-                                return kDepErr(1, "%#07lx - Bad LINNUM32 record, file/path table entry too long.\n", (long)((const KU8 *)pHdr - pbFile));
+                                return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record, file/path table entry too long.\n", (long)((const KU8 *)pHdr - pbFile));
                             iLinFile++;
                             dprintf(("#%" KU32_PRI": %.*s\n", iLinFile, cbName, uData.pch));
                             if (uLinNumType == 3)
                             {
-                                depAdd(uData.pch, cbName);
+                                depAdd(&pThis->Core, uData.pch, cbName);
                                 iSrc++;
                             }
@@ -532,5 +542,5 @@
 
     if (cbLeft)
-        return kDepErr(1, "%#07x - Unexpected EOF. cbLeft=%#x\n", (const KU8*)pHdr - pbFile, cbLeft);
+        return kDepErr(pThis, 1, "%#07x - Unexpected EOF. cbLeft=%#x\n", (const KU8*)pHdr - pbFile, cbLeft);
 
     if (iSrc == 0 && iMaybeSrc <= 1)
@@ -574,8 +584,9 @@
  *
  * @returns 0 on success, 1 on failure, 2 if no dependencies was found.
+ * @param   pThis       The kDepObj instance data.
  * @param   pbSyms      Pointer to the start of the symbol section.
  * @param   cbSyms      Size of the symbol section.
  */
-int kDepObjCOFFParseCV8SymbolSection(const KU8 *pbSyms, KU32 cbSyms)
+int kDepObjCOFFParseCV8SymbolSection(PKDEPOBJGLOBALS pThis, const KU8 *pbSyms, KU32 cbSyms)
 {
     char const *    pchStrTab  = NULL;
@@ -602,5 +613,5 @@
         {
             fprintf(stderr, "%s: CV symbol table entry at %08" KX32_PRI " is too long; cbSyms=%#" KX32_PRI "\n",
-                    argv0, off, cbSyms);
+                    pThis->argv0, off, cbSyms);
             return 1; /* FIXME */
         }
@@ -610,5 +621,5 @@
         {
             fprintf(stderr, "%s: CV symbol table entry at %08" KX32_PRI " is too long; cbData=%#" KX32_PRI " cbSyms=%#" KX32_PRI "\n",
-                    argv0, off, cbData, cbSyms);
+                    pThis->argv0, off, cbData, cbSyms);
             return 1; /* FIXME */
         }
@@ -634,5 +645,5 @@
                 dprintf(("%06" KX32_PRI " %06" KX32_PRI ": String table\n", off, cbData));
                 if (pchStrTab)
-                    fprintf(stderr, "%s: warning: Found yet another string table!\n", argv0);
+                    fprintf(stderr, "%s: warning: Found yet another string table!\n", pThis->argv0);
                 pchStrTab = uData.pch;
                 cbStrTab = cbData;
@@ -643,5 +654,5 @@
                 dprintf(("%06" KX32_PRI " %06" KX32_PRI ": Source files\n", off, cbData));
                 if (uSrcFiles.pb)
-                    fprintf(stderr, "%s: warning: Found yet another source files table!\n", argv0);
+                    fprintf(stderr, "%s: warning: Found yet another source files table!\n", pThis->argv0);
                 uSrcFiles = uData;
                 cbSrcFiles = cbData;
@@ -694,5 +705,5 @@
         {
             fprintf(stderr, "%s: CV source file entry at %08" KX32_PRI " is too long; cbSrcFiles=%#" KX32_PRI "\n",
-                    argv0, off, cbSrcFiles);
+                    pThis->argv0, off, cbSrcFiles);
             return 1;
         }
@@ -703,5 +714,5 @@
         {
             fprintf(stderr, "%s: CV source file entry at %08" KX32_PRI " is too long; cbSrc=%#" KX32_PRI " cbSrcFiles=%#" KX32_PRI "\n",
-                    argv0, off, cbSrc, cbSrcFiles);
+                    pThis->argv0, off, cbSrc, cbSrcFiles);
             return 1;
         }
@@ -711,5 +722,5 @@
         {
             fprintf(stderr, "%s: CV source file entry at %08" KX32_PRI " is out side the string table; offFile=%#" KX32_PRI " cbStrTab=%#" KX32_PRI "\n",
-                    argv0, off, offFile, cbStrTab);
+                    pThis->argv0, off, offFile, cbStrTab);
             return 1;
         }
@@ -719,5 +730,5 @@
         {
             fprintf(stderr, "%s: CV source file entry at %08" KX32_PRI " has an empty file name; offFile=%#x" KX32_PRI "\n",
-                    argv0, off, offFile);
+                    pThis->argv0, off, offFile);
             return 1;
         }
@@ -726,5 +737,5 @@
          * Display the result and add it to the dependency database.
          */
-        depAdd(pszFile, cchFile);
+        depAdd(&pThis->Core, pszFile, cchFile);
         if (u16Type == 0x0110)
             dprintf(("#%03" KU32_PRI ": {todo-md5-todo} '%s'\n",
@@ -753,8 +764,9 @@
  *
  * @returns 0 on success, 1 on failure, 2 if no dependencies was found.
+ * @param   pThis       The kDepObj instance data.
  * @param   pbFile      The start of the file.
  * @param   cbFile      The file size.
  */
-int kDepObjCOFFParse(const KU8 *pbFile, KSIZE cbFile)
+int kDepObjCOFFParse(PKDEPOBJGLOBALS pThis, const KU8 *pbFile, KSIZE cbFile)
 {
     IMAGE_FILE_HEADER const            *pFileHdr   = (IMAGE_FILE_HEADER const *)pbFile;
@@ -790,5 +802,5 @@
             dprintf(("CV symbol table: version=%x\n", *u.pu32));
             if (*u.pu32 == 0x000000004)
-                rc = kDepObjCOFFParseCV8SymbolSection(u.pb, paSHdrs[iSHdr].SizeOfRawData);
+                rc = kDepObjCOFFParseCV8SymbolSection(pThis, u.pb, paSHdrs[iSHdr].SizeOfRawData);
             else
                 rc = 2;
@@ -946,5 +958,5 @@
  * Read the file into memory and parse it.
  */
-static int kDepObjProcessFile(FILE *pInput)
+static int kDepObjProcessFile(PKDEPOBJGLOBALS pThis, FILE *pInput)
 {
     size_t      cbFile;
@@ -964,10 +976,10 @@
      */
     if (kDepObjOMFTest(pbFile, cbFile))
-        rc = kDepObjOMFParse(pbFile, cbFile);
+        rc = kDepObjOMFParse(pThis, pbFile, cbFile);
     else if (kDepObjCOFFTest(pbFile, cbFile))
-        rc = kDepObjCOFFParse(pbFile, cbFile);
+        rc = kDepObjCOFFParse(pThis, pbFile, cbFile);
     else
     {
-        fprintf(stderr, "%s: error: Doesn't recognize the header of the OMF/COFF file.\n", argv0);
+        fprintf(stderr, "%s: error: Doesn't recognize the header of the OMF/COFF file.\n", pThis->argv0);
         rc = 1;
     }
@@ -978,5 +990,5 @@
 
 
-static void usage(const char *a_argv0)
+static void kDebObjUsage(const char *a_argv0)
 {
     printf("usage: %s -o <output> -t <target> [-fqs] [-e <ignore-ext>] <OMF or COFF file>\n"
@@ -989,5 +1001,6 @@
 int kmk_builtin_kDepObj(int argc, char *argv[], char **envp)
 {
-    int         i;
+    int             i;
+    KDEPOBJGLOBALS  This;
 
     /* Arguments. */
@@ -1003,5 +1016,7 @@
     int         fQuiet = 0;
 
-    argv0 = argv[0];
+    /* Init instance data.   */
+    This.argv0  = argv[0];
+    This.pszFile = NULL;
 
     /*
@@ -1010,5 +1025,5 @@
     if (argc <= 1)
     {
-        usage(argv[0]);
+        kDebObjUsage(argv[0]);
         return 1;
     }
@@ -1033,5 +1048,5 @@
                 {
                     fprintf(stderr, "%s: syntax error: Invalid argument '%s'.\n", argv[0], argv[i]);
-                    usage(argv[0]);
+                    kDebObjUsage(argv[0]);
                     return 2;
                 }
@@ -1148,5 +1163,5 @@
                  */
                 case '?':
-                    usage(argv[0]);
+                    kDebObjUsage(argv[0]);
                     return 0;
                 case 'V':
@@ -1159,5 +1174,5 @@
                 default:
                     fprintf(stderr, "%s: syntax error: Invalid argument '%s'.\n", argv[0], argv[i]);
-                    usage(argv[0]);
+                    kDebObjUsage(argv[0]);
                     return 2;
             }
@@ -1210,5 +1225,6 @@
      * Do the parsing.
      */
-    i = kDepObjProcessFile(pInput);
+    depInit(&This.Core);
+    i = kDepObjProcessFile(&This, pInput);
     fclose(pInput);
 
@@ -1218,9 +1234,9 @@
     if (!i)
     {
-        depOptimize(fFixCase, fQuiet, pszIgnoreExt);
+        depOptimize(&This.Core, fFixCase, fQuiet, pszIgnoreExt);
         fprintf(pOutput, "%s:", pszTarget);
-        depPrint(pOutput);
+        depPrint(&This.Core, pOutput);
         if (fStubs)
-            depPrintStubs(pOutput);
+            depPrintStubs(&This.Core, pOutput);
     }
 
@@ -1240,5 +1256,5 @@
     }
 
-    depCleanup();
+    depCleanup(&This.Core);
     return i;
 }
Index: trunk/src/lib/kDep.c
===================================================================
--- trunk/src/lib/kDep.c	(revision 3165)
+++ trunk/src/lib/kDep.c	(revision 3167)
@@ -73,9 +73,31 @@
 
 
-/*******************************************************************************
-*   Global Variables                                                           *
-*******************************************************************************/
-/** List of dependencies. */
-static PDEP g_pDeps = NULL;
+/**
+ * Initializes the dep instance.
+ *
+ * @param   pThis       The dep instance to init.
+ */
+void depInit(PDEPGLOBALS pThis)
+{
+    pThis->pDeps = NULL;
+}
+
+
+/**
+ * Cleans up the dep instance (frees resources).
+ *
+ * @param   pThis       The dep instance to cleanup.
+ */
+void depCleanup(PDEPGLOBALS pThis)
+{
+    PDEP pDep = pThis->pDeps;
+    pThis->pDeps = NULL;
+    while (pDep)
+    {
+        PDEP pFree = pDep;
+        pDep = pDep->pNext;
+        free(pFree);
+    }
+}
 
 
@@ -196,5 +218,5 @@
  * 'Optimizes' and corrects the dependencies.
  */
-void depOptimize(int fFixCase, int fQuiet, const char *pszIgnoredExt)
+void depOptimize(PDEPGLOBALS pThis, int fFixCase, int fQuiet, const char *pszIgnoredExt)
 {
     /*
@@ -202,7 +224,7 @@
      */
     size_t  cchIgnoredExt = pszIgnoredExt ? strlen(pszIgnoredExt) : 0;
-    PDEP    pDepOrg = g_pDeps;
-    PDEP    pDep = g_pDeps;
-    g_pDeps = NULL;
+    PDEP    pDepOrg = pThis->pDeps;
+    PDEP    pDep = pThis->pDeps;
+    pThis->pDeps = NULL;
     for (; pDep; pDep = pDep->pNext)
     {
@@ -287,5 +309,5 @@
          * Insert the corrected dependency.
          */
-        depAdd(pszFilename, strlen(pszFilename));
+        depAdd(pThis, pszFilename, strlen(pszFilename));
     }
 
@@ -305,11 +327,11 @@
  * Prints the dependency chain.
  *
- * @returns Pointer to the allocated dependency.
+ * @param   pThis       The 'dep' instance.
  * @param   pOutput     Output stream.
  */
-void depPrint(FILE *pOutput)
+void depPrint(PDEPGLOBALS pThis, FILE *pOutput)
 {
     PDEP pDep;
-    for (pDep = g_pDeps; pDep; pDep = pDep->pNext)
+    for (pDep = pThis->pDeps; pDep; pDep = pDep->pNext)
         fprintf(pOutput, " \\\n\t%s", pDep->szFilename);
     fprintf(pOutput, "\n\n");
@@ -319,9 +341,12 @@
 /**
  * Prints empty dependency stubs for all dependencies.
- */
-void depPrintStubs(FILE *pOutput)
+ *
+ * @param   pThis       The 'dep' instance.
+ * @param   pOutput     Output stream.
+ */
+void depPrintStubs(PDEPGLOBALS pThis, FILE *pOutput)
 {
     PDEP pDep;
-    for (pDep = g_pDeps; pDep; pDep = pDep->pNext)
+    for (pDep = pThis->pDeps; pDep; pDep = pDep->pNext)
         fprintf(pOutput, "%s:\n\n", pDep->szFilename);
 }
@@ -355,8 +380,9 @@
  *
  * @returns Pointer to the allocated dependency.
+ * @param   pThis       The 'dep' instance.
  * @param   pszFilename     The filename. Does not need to be terminated.
  * @param   cchFilename     The length of the filename.
  */
-PDEP depAdd(const char *pszFilename, size_t cchFilename)
+PDEP depAdd(PDEPGLOBALS pThis, const char *pszFilename, size_t cchFilename)
 {
     unsigned    uHash = sdbm(pszFilename, cchFilename);
@@ -368,5 +394,5 @@
      */
     pDepPrev = NULL;
-    for (pDep = g_pDeps; pDep; pDepPrev = pDep, pDep = pDep->pNext)
+    for (pDep = pThis->pDeps; pDep; pDepPrev = pDep, pDep = pDep->pNext)
         if (    pDep->uHash == uHash
             &&  pDep->cchFilename == cchFilename
@@ -397,24 +423,8 @@
     else
     {
-        pDep->pNext = g_pDeps;
-        g_pDeps = pDep;
+        pDep->pNext = pThis->pDeps;
+        pThis->pDeps = pDep;
     }
     return pDep;
-}
-
-
-/**
- * Frees the current dependency chain.
- */
-void depCleanup(void)
-{
-    PDEP pDep = g_pDeps;
-    g_pDeps = NULL;
-    while (pDep)
-    {
-        PDEP pFree = pDep;
-        pDep = pDep->pNext;
-        free(pFree);
-    }
 }
 
Index: trunk/src/lib/kDep.h
===================================================================
--- trunk/src/lib/kDep.h	(revision 3165)
+++ trunk/src/lib/kDep.h	(revision 3167)
@@ -46,10 +46,19 @@
 } DEP, *PDEP;
 
+typedef struct DEPGLOBALS
+{
+    /** List of dependencies. */
+    PDEP pDeps;
 
-extern PDEP depAdd(const char *pszFilename, size_t cchFilename);
-extern void depOptimize(int fFixCase, int fQuiet, const char *pszIgnoredExt);
-extern void depPrint(FILE *pOutput);
-extern void depPrintStubs(FILE *pOutput);
-extern void depCleanup(void);
+} DEPGLOBALS;
+typedef DEPGLOBALS *PDEPGLOBALS;
+
+extern void depInit(PDEPGLOBALS pThis);
+extern void depCleanup(PDEPGLOBALS pThis);
+extern PDEP depAdd(PDEPGLOBALS pThis, const char *pszFilename, size_t cchFilename);
+extern void depOptimize(PDEPGLOBALS pThis, int fFixCase, int fQuiet, const char *pszIgnoredExt);
+extern void depPrint(PDEPGLOBALS pThis, FILE *pOutput);
+extern void depPrintStubs(PDEPGLOBALS pThis, FILE *pOutput);
+
 extern void *depReadFileIntoMemory(FILE *pInput, size_t *pcbFile, void **ppvOpaque);
 extern void depFreeFileMemory(void *pvFile, void *pvOpaque);
