Changeset 2612


Ignore:
Timestamp:
Jul 29, 2012, 8:18:00 PM (13 years ago)
Author:
bird
Message:

kObjCache: Implemented support for generating makefile dependencies using the #line directives inserted by the preprocessor.

Location:
trunk/src/kObjCache
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kObjCache/Makefile.kmk

    r2413 r2612  
    3030kObjCache_TEMPLATE = BIN
    3131kObjCache_SOURCES = kObjCache.c
    32 kObjCache_LIBS = $(LIB_KUTIL)
     32kObjCache_LIBS = \
     33        $(LIB_KDEP) \
     34        $(LIB_KUTIL)
    3335
    3436include $(KBUILD_PATH)/subfooter.kmk
  • trunk/src/kObjCache/kObjCache.c

    r2568 r2612  
    55
    66/*
    7  * Copyright (c) 2007-2011 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
     7 * Copyright (c) 2007-2012 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
    88 *
    99 * This file is part of kBuild.
     
    8080#include "crc32.h"
    8181#include "md5.h"
     82#include "kDep.h"
    8283
    8384
     
    110111#endif
    111112
     113#define MY_IS_BLANK(a_ch)   ((a_ch) == ' ' || (a_ch) == '\t')
     114
    112115
    113116/*******************************************************************************
     
    129132static char *CalcRelativeName(const char *pszPath, const char *pszDir);
    130133static FILE *FOpenFileInDir(const char *pszName, const char *pszDir, const char *pszMode);
    131 static int UnlinkFileInDir(const char *pszName, const char *pszDir);
    132 static int RenameFileInDir(const char *pszOldName, const char *pszNewName, const char *pszDir);
    133 static int DoesFileInDirExist(const char *pszName, const char *pszDir);
     134static int   UnlinkFileInDir(const char *pszName, const char *pszDir);
     135static int   RenameFileInDir(const char *pszOldName, const char *pszNewName, const char *pszDir);
     136static int   DoesFileInDirExist(const char *pszName, const char *pszDir);
    134137static void *ReadFileInDir(const char *pszName, const char *pszDir, size_t *pcbFile);
    135138
     
    757760
    758761
     762/**
     763 * Dependency collector state.
     764 */
     765typedef struct KOCDEP
     766{
     767    /** The statemachine for processing the preprocessed code stream. */
     768    enum KOCDEPSTATE
     769    {
     770        kOCDepState_Invalid = 0,
     771        kOCDepState_NeedNewLine,
     772        kOCDepState_NeedHash,
     773        kOCDepState_NeedLine_l,
     774        kOCDepState_NeedLine_l_HaveSpace,
     775        kOCDepState_NeedLine_i,
     776        kOCDepState_NeedLine_n,
     777        kOCDepState_NeedLine_e,
     778        kOCDepState_NeedSpaceBeforeDigit,
     779        kOCDepState_NeedFirstDigit,
     780        kOCDepState_NeedMoreDigits,
     781        kOCDepState_NeedQuote,
     782        kOCDepState_NeedEndQuote
     783    }   enmState;
     784    /** Current offset into the filename buffer. */
     785    uint32_t offFilename;
     786    /** The amount of space currently allocated for the filename buffer. */
     787    uint32_t cbFilenameAlloced;
     788    /** Pointer to the filename buffer. */
     789    char *pszFilename;
     790    /** The current dependency file. */
     791    PDEP pCurDep;
     792} KOCDEP;
     793/** Pointer to a KOCDEP.  */
     794typedef KOCDEP *PKOCDEP;
     795
     796
     797/**
     798 * Initializes the dependency collector state.
     799 *
     800 * @param   pDepState       The dependency collector state.
     801 */
     802static void kOCDepInit(PKOCDEP pDepState)
     803{
     804    pDepState->enmState = kOCDepState_NeedHash;
     805    pDepState->offFilename = 0;
     806    pDepState->cbFilenameAlloced = 0;
     807    pDepState->pszFilename = NULL;
     808    pDepState->pCurDep = NULL;
     809}
     810
     811
     812/**
     813 * Deletes the dependency collector state, releasing all resources.
     814 *
     815 * @param   pDepState       The dependency collector state.
     816 */
     817static void kOCDepDelete(PKOCDEP pDepState)
     818{
     819    pDepState->enmState = kOCDepState_Invalid;
     820    free(pDepState->pszFilename);
     821    pDepState->pszFilename = NULL;
     822    depCleanup();
     823}
     824
     825
     826/**
     827 * Unescapes a string in place.
     828 *
     829 * @returns The new string length.
     830 * @param   psz             The string to unescape (input and output).
     831 */
     832static size_t kOCDepUnescape(char *psz)
     833{
     834    char *pszSrc = psz;
     835    char *pszDst = psz;
     836    char ch;
     837
     838    while ((ch = *pszSrc++) != '\0')
     839    {
     840        if (ch == '\\')
     841        {
     842            char ch2 = *pszSrc;
     843            if (ch2)
     844            {
     845                pszSrc++;
     846                ch = ch2;
     847            }
     848            /* else: cannot happen / just ignore */
     849        }
     850        *pszDst++ = ch;
     851    }
     852
     853    *pszDst = '\0';
     854    return pszDst - psz;
     855}
     856
     857
     858/**
     859 * Checks if the character at @a offChar is escaped or not.
     860 *
     861 * @returns 1 if escaped, 0 if not.
     862 * @param   pach            The string (not terminated).
     863 * @param   offChar         The offset of the character in question.
     864 */
     865static int kOCDepIsEscaped(char *pach, size_t offChar)
     866{
     867    while (offChar > 0 && pach[offChar - 1] == '\\')
     868    {
     869        if (   offChar == 1
     870            || pach[offChar - 2] != '\\')
     871            return 1;
     872        offChar -= 2;
     873    }
     874    return 0;
     875}
     876
     877
     878/**
     879 * This consumes the preprocessor output and generate dependencies from it.
     880 *
     881 * The trick is to look at the line directives and which files get listed there.
     882 *
     883 * @returns The new state. This is a convenience for saving code space and it
     884 *          isn't really meant to be of any use to the caller.
     885 * @param   pDepState       The dependency collector state.
     886 * @param   pszInput        The input.
     887 * @param   cchInput        The input length.
     888 */
     889static enum KOCDEPSTATE
     890kOCDepConsumer(PKOCDEP pDepState, const char *pszInput, size_t cchInput)
     891{
     892    enum KOCDEPSTATE enmState = pDepState->enmState;
     893    const char *psz;
     894
     895    while (cchInput > 0)
     896    {
     897        switch (enmState)
     898        {
     899            case kOCDepState_NeedNewLine:
     900                psz = (const char *)memchr(pszInput, '\n', cchInput);
     901                if (!psz)
     902                    return enmState;
     903                psz++;
     904                cchInput -= psz - pszInput;
     905                pszInput = psz;
     906
     907            case kOCDepState_NeedHash:
     908                while (cchInput > 0 && MY_IS_BLANK(*pszInput))
     909                    cchInput--, pszInput++;
     910                if (!cchInput)
     911                    return pDepState->enmState = kOCDepState_NeedHash;
     912
     913                if (*pszInput != '#')
     914                    break;
     915                pszInput++;
     916                cchInput--;
     917                enmState = kOCDepState_NeedLine_l;
     918
     919            case kOCDepState_NeedLine_l:
     920            case kOCDepState_NeedLine_l_HaveSpace:
     921                while (cchInput > 0 && MY_IS_BLANK(*pszInput))
     922                {
     923                    enmState = kOCDepState_NeedLine_l_HaveSpace;
     924                    cchInput--, pszInput++;
     925                }
     926                if (!cchInput)
     927                    return pDepState->enmState = enmState;
     928
     929                if (*pszInput != 'l')
     930                {
     931                    /* # <digit> "<file>" */
     932                    if (enmState != kOCDepState_NeedLine_l_HaveSpace || !isdigit(*pszInput))
     933                        break;
     934                    pszInput++;
     935                    cchInput--;
     936                    enmState = kOCDepState_NeedMoreDigits;
     937                    continue;
     938                }
     939                pszInput++;
     940                if (!--cchInput)
     941                    return pDepState->enmState = kOCDepState_NeedLine_i;
     942
     943            case kOCDepState_NeedLine_i:
     944                if (*pszInput != 'i')
     945                    break;
     946                pszInput++;
     947                if (!--cchInput)
     948                    return pDepState->enmState = kOCDepState_NeedLine_n;
     949
     950            case kOCDepState_NeedLine_n:
     951                if (*pszInput != 'n')
     952                    break;
     953                pszInput++;
     954                if (!--cchInput)
     955                    return pDepState->enmState = kOCDepState_NeedLine_e;
     956
     957            case kOCDepState_NeedLine_e:
     958                if (*pszInput != 'e')
     959                    break;
     960                pszInput++;
     961                if (!--cchInput)
     962                    return pDepState->enmState = kOCDepState_NeedSpaceBeforeDigit;
     963
     964            case kOCDepState_NeedSpaceBeforeDigit:
     965                if (!MY_IS_BLANK(*pszInput))
     966                    break;
     967                pszInput++;
     968                cchInput--;
     969
     970            case kOCDepState_NeedFirstDigit:
     971                while (cchInput > 0 && MY_IS_BLANK(*pszInput))
     972                    cchInput--, pszInput++;
     973                if (!cchInput)
     974                    return pDepState->enmState = kOCDepState_NeedFirstDigit;
     975
     976                if (!isdigit(*pszInput))
     977                    break;
     978                pszInput++;
     979                cchInput--;
     980
     981            case kOCDepState_NeedMoreDigits:
     982                while (cchInput > 0 && isdigit(*pszInput))
     983                    cchInput--, pszInput++;
     984                if (!cchInput)
     985                    return pDepState->enmState = kOCDepState_NeedMoreDigits;
     986
     987            case kOCDepState_NeedQuote:
     988                while (cchInput > 0 && MY_IS_BLANK(*pszInput))
     989                    cchInput--, pszInput++;
     990                if (!cchInput)
     991                    return pDepState->enmState = kOCDepState_NeedQuote;
     992
     993                if (*pszInput != '"')
     994                    break;
     995                pszInput++;
     996                cchInput--;
     997
     998            case kOCDepState_NeedEndQuote:
     999            {
     1000                uint32_t off = pDepState->offFilename;
     1001                for (;;)
     1002                {
     1003                    char ch;
     1004
     1005                    if (!cchInput)
     1006                    {
     1007                        pDepState->offFilename = off;
     1008                        return pDepState->enmState = kOCDepState_NeedEndQuote;
     1009                    }
     1010
     1011                    if (off + 1 >= pDepState->cbFilenameAlloced)
     1012                    {
     1013                        if (!pDepState->cbFilenameAlloced)
     1014                            pDepState->cbFilenameAlloced = 32;
     1015                        else
     1016                            pDepState->cbFilenameAlloced *= 2;
     1017                        pDepState->pszFilename = (char *)xrealloc(pDepState->pszFilename, pDepState->cbFilenameAlloced);
     1018                    }
     1019                    pDepState->pszFilename[off] = ch = *pszInput++;
     1020                    cchInput--;
     1021
     1022                    if (   ch == '"'
     1023                        && (   off == 0
     1024                            || pDepState->pszFilename[off - 1] != '\\'
     1025                            || !kOCDepIsEscaped(pDepState->pszFilename, off)))
     1026                    {
     1027                        /* Done, unescape and add the file. */
     1028                        size_t cchFilename;
     1029
     1030                        pDepState->pszFilename[off] = '\0';
     1031                        cchFilename = kOCDepUnescape(pDepState->pszFilename);
     1032
     1033                        if (   !pDepState->pCurDep
     1034                            || cchFilename != pDepState->pCurDep->cchFilename
     1035                            || strcmp(pDepState->pszFilename, pDepState->pCurDep->szFilename))
     1036                            pDepState->pCurDep = depAdd(pDepState->pszFilename, cchFilename);
     1037                        pDepState->offFilename = 0;
     1038                        break;
     1039                    }
     1040
     1041                    off++;
     1042                }
     1043            }
     1044        }
     1045
     1046        /* next newline */
     1047        enmState = kOCDepState_NeedNewLine;
     1048    }
     1049
     1050    return pDepState->enmState = enmState;
     1051}
     1052
     1053
     1054/**
     1055 * Writes the dependencies to the specified file.
     1056 *
     1057 * @param   pDepState       The dependency collector state.
     1058 * @param   pszFilename     The name of the dependency file.
     1059 * @param   pszObjFile      The object file name, relative to @a pszObjDir.
     1060 * @param   pszObjDir       The object file directory.
     1061 * @param   fFixCase        Whether to fix the case of dependency files.
     1062 * @param   fQuiet          Whether to be quiet about the dependencies.
     1063 * @param   fGenStubs       Whether to generate stubs.
     1064 */
     1065static void kOCDepWriteToFile(PKOCDEP pDepState, const char *pszFilename, const char *pszObjFile, const char *pszObjDir,
     1066                              int fFixCase, int fQuiet, int fGenStubs)
     1067{
     1068    char *pszObjFileAbs;
     1069    FILE *pFile = fopen(pszFilename, "w");
     1070    if (!pFile)
     1071        FatalMsg("Failed to open dependency file '%s': %s\n", pszFilename, strerror(errno));
     1072
     1073    depOptimize(fFixCase, fQuiet);
     1074
     1075    pszObjFileAbs = MakePathFromDirAndFile(pszObjFile, pszObjDir);
     1076    fprintf(pFile, "%s:", pszObjFileAbs);
     1077    free(pszObjFileAbs);
     1078    depPrint(pFile);
     1079    if (fGenStubs)
     1080        depPrintStubs(pFile);
     1081
     1082    if (fclose(pFile) != 0)
     1083        FatalMsg("Failed to write dependency file '%s': %s\n", pszFilename, strerror(errno));
     1084}
     1085
    7591086
    7601087
    7611088
    7621089/** A checksum list entry.
    763  * We keep a list checksums (of precompiler output) that matches, The planned
    764  * matching algorithm doesn't require the precompiler output to be indentical,
    765  * only to produce the same object files.
     1090 * We keep a list checksums (of preprocessor output) that matches.
     1091 *
     1092 * The matching algorithm doesn't require the preprocessor output to be
     1093 * indentical, only to produce the same object files.
    7661094 */
    7671095typedef struct KOCSUM
     
    7831111
    7841112/**
    785  * Temporary context record used when calculating
    786  * the checksum of some data.
     1113 * Temporary context record used when calculating the checksum of some data.
    7871114 */
    7881115typedef struct KOCSUMCTX
     
    10801407    /** Set if the object needs to be (re)compiled. */
    10811408    unsigned fNeedCompiling;
    1082     /** Whether the precompiler runs in piped mode. If clear it's file
     1409    /** Whether the preprocessor runs in piped mode. If clear it's file
    10831410     * mode (it could be redirected stdout, but that's essentially the
    10841411     * same from our point of view). */
    10851412    unsigned fPipedPreComp;
    1086     /** Whether the compiler runs in piped mode (precompiler output on stdin). */
     1413    /** Whether the compiler runs in piped mode (preprocessor output on stdin). */
    10871414    unsigned fPipedCompile;
    1088     /** The name of the pipe that we're feeding the precompiled output to the
     1415    /** The name of the pipe that we're feeding the preprocessed output to the
    10891416     *  compiler via.  This is a Windows thing. */
    10901417    char *pszNmPipeCompile;
     1418    /** Name of the dependency file (generated from #line statements in the
     1419     * preprocessor output). */
     1420    char *pszMakeDepFilename;
     1421    /** Whether to fix the case of the make depedencies. */
     1422    int fMakeDepFixCase;
     1423    /** Whether to do the make dependencies quietly. */
     1424    int fMakeDepQuiet;
     1425    /** Whether to generate stubs for headers files. */
     1426    int fMakeDepGenStubs;
     1427    /** The dependency collector state.  */
     1428    KOCDEP DepState;
    10911429    /** Cache entry key that's used for some quick digest validation. */
    10921430    uint32_t uKey;
     
    10951433    struct KOCENTRYDATA
    10961434    {
    1097         /** The name of file containing the precompiler output. */
     1435        /** The name of file containing the preprocessor output. */
    10981436        char *pszCppName;
    1099         /** Pointer to the precompiler output. */
     1437        /** Pointer to the preprocessor output. */
    11001438        char *pszCppMapping;
    1101         /** The size of the precompiler output. 0 if not determined. */
     1439        /** The size of the preprocessor output. 0 if not determined. */
    11021440        size_t cbCpp;
    1103         /** The precompiler output checksums that will produce the cached object. */
     1441        /** The preprocessor output checksums that will produce the cached object. */
    11041442        KOCSUM SumHead;
    11051443        /** The number of milliseconds spent precompiling. */
     
    11171455        uint32_t cMsCompile;
    11181456        /** @todo need a list of additional output files for MSC. */
     1457        /** @todo need compiler output (warnings). */
    11191458
    11201459        /** The target os/arch identifier. */
     
    11481487    pEntry = xmallocz(sizeof(*pEntry));
    11491488
     1489    kOCDepInit(&pEntry->DepState);
     1490
    11501491    kOCSumInit(&pEntry->New.SumHead);
    11511492    kOCSumInit(&pEntry->Old.SumHead);
     
    11811522    free(pEntry->pszAbsPath);
    11821523    free(pEntry->pszNmPipeCompile);
     1524    free(pEntry->pszMakeDepFilename);
     1525
     1526    kOCDepDelete(&pEntry->DepState);
    11831527
    11841528    kOCSumDeleteChain(&pEntry->New.SumHead);
     
    16351979
    16361980/**
    1637  * Sets the precompiler output filename.
    1638  * We don't generally care if this matches the old name or not.
     1981 * Sets the preprocessor output filename. We don't generally care if this
     1982 * matches the old name or not.
    16391983 *
    16401984 * @param   pEntry      The cache entry.
    1641  * @param   pszCppName  The precompiler output filename.
     1985 * @param   pszCppName  The preprocessor output filename.
    16421986 */
    16431987static void kOCEntrySetCppName(PKOCENTRY pEntry, const char *pszCppName)
     
    16491993
    16501994/**
    1651  * Sets the piped mode of the precompiler and compiler.
     1995 * Sets the piped mode of the preprocessor and compiler.
    16521996 *
    16531997 * @param   pEntry                  The cache entry.
    1654  * @param   fRedirPreCompStdOut     Whether the precompiler is in piped mode.
     1998 * @param   fRedirPreCompStdOut     Whether the preprocessor is in piped mode.
    16551999 * @param   fRedirCompileStdIn      Whether the compiler is in piped mode.
    16562000 * @param   pszNmPipeCompile        The name of the named pipe to use to feed
     
    16632007    pEntry->fPipedCompile = fRedirCompileStdIn || pszNmPipeCompile;
    16642008    pEntry->pszNmPipeCompile = xstrdup(pszNmPipeCompile);
     2009}
     2010
     2011
     2012/**
     2013 * Sets the dependency file.
     2014 *
     2015 * @param   pEntry                  The cache entry.
     2016 * @param   pszMakeDepFilename      The dependency filename.
     2017 * @param   fMakeDepFixCase         Whether to fix the case of dependency files.
     2018 * @param   fMakeDepQuiet           Whether to be quiet about the dependencies.
     2019 * @param   fMakeDepGenStubs        Whether to generate stubs.
     2020 */
     2021static void kOCEntrySetDepFilename(PKOCENTRY pEntry, const char *pszMakeDepFilename,
     2022                                   int fMakeDepFixCase, int fMakeDepQuiet, int fMakeDepGenStubs)
     2023{
     2024    pEntry->pszMakeDepFilename = xstrdup(pszMakeDepFilename);
     2025    pEntry->fMakeDepFixCase = fMakeDepFixCase;
     2026    pEntry->fMakeDepQuiet = fMakeDepQuiet;
     2027    pEntry->fMakeDepGenStubs = fMakeDepGenStubs;
    16652028}
    16662029
     
    18252188# endif
    18262189    if (pid == -1)
    1827         FatalDie("precompile - _spawnvp failed: %s\n", strerror(errno));
     2190        FatalDie("preprocess - _spawnvp failed: %s\n", strerror(errno));
    18282191
    18292192#else
     
    18322195    {
    18332196        execvp(papszArgv[0], (char **)papszArgv);
    1834         FatalDie("precompile - execvp failed: %s\n", strerror(errno));
     2197        FatalDie("preprocess - execvp failed: %s\n", strerror(errno));
    18352198    }
    18362199    if (pid == -1)
    1837         FatalDie("precompile - fork() failed: %s\n", strerror(errno));
     2200        FatalDie("preprocess - fork() failed: %s\n", strerror(errno));
    18382201#endif
    18392202
     
    19032266 *
    19042267 * @param   pEntry          The cache entry.
    1905  * @param   pFDs            Where to store the two file descriptors.
     2268 * @param   paFDs           Where to store the two file descriptors.
    19062269 * @param   pszMsg          The operation message for info/error messages.
    19072270 * @param   pszPipeName     The pipe name if it is supposed to be named. (Windows only.)
    19082271 */
    1909 static void kOCEntryCreatePipe(PKOCENTRY pEntry, int *pFDs, const char *pszPipeName, const char *pszMsg)
    1910 {
    1911     pFDs[0] = pFDs[1] = -1;
     2272static void kOCEntryCreatePipe(PKOCENTRY pEntry, int *paFDs, const char *pszPipeName, const char *pszMsg)
     2273{
     2274    paFDs[0] = paFDs[1] = -1;
    19122275#if defined(__WIN__)
    19132276    if (pszPipeName)
     
    19252288            FatalDie("%s - CreateNamedPipe(%s) failed: %d\n", pszMsg, pszPipeName, GetLastError());
    19262289
    1927         pFDs[1 /* write */] = _open_osfhandle((intptr_t)hPipe, _O_WRONLY | _O_TEXT | _O_NOINHERIT);
    1928         if (pFDs[1 /* write */] == -1)
     2290        paFDs[1 /* write */] = _open_osfhandle((intptr_t)hPipe, _O_WRONLY | _O_TEXT | _O_NOINHERIT);
     2291        if (paFDs[1 /* write */] == -1)
    19292292            FatalDie("%s - _open_osfhandle failed: %d\n", pszMsg, strerror(errno));
    19302293    }
    1931     else if (_pipe(pFDs, 0, _O_NOINHERIT | _O_BINARY) < 0)
     2294    else if (   _pipe(paFDs, 256*1024, _O_NOINHERIT | _O_BINARY) < 0
     2295             && _pipe(paFDs,        0, _O_NOINHERIT | _O_BINARY) < 0)
    19322296#else
    1933     if (pipe(pFDs) < 0)
     2297    if (pipe(paFDs) < 0)
    19342298#endif
    19352299        FatalDie("%s - pipe failed: %s\n", pszMsg, strerror(errno));
    19362300#if !defined(__WIN__)
    1937     fcntl(pFDs[0], F_SETFD, FD_CLOEXEC);
    1938     fcntl(pFDs[1], F_SETFD, FD_CLOEXEC);
     2301    fcntl(paFDs[0], F_SETFD, FD_CLOEXEC);
     2302    fcntl(paFDs[1], F_SETFD, FD_CLOEXEC);
    19392303#endif
    19402304
     
    20412405
    20422406/**
    2043  * Reads the output from the precompiler.
     2407 * Reads the output from the preprocessor.
    20442408 *
    20452409 * @param   pEntry      The cache entry. New.cbCpp and New.pszCppMapping will be updated.
     
    20602424    }
    20612425
    2062     InfoMsg(3, "precompiled file is %lu bytes long\n", (unsigned long)pWhich->cbCpp);
     2426    InfoMsg(3, "preprocessed file is %lu bytes long\n", (unsigned long)pWhich->cbCpp);
    20632427    return 0;
    20642428}
     
    20662430
    20672431/**
    2068  * Worker for kOCEntryPreCompile and calculates the checksum of
    2069  * the precompiler output.
     2432 * Worker for kOCEntryPreProcess and calculates the checksum of
     2433 * the preprocessor output.
    20702434 *
    20712435 * @param   pEntry      The cache entry. NewSum will be updated.
     
    20822446
    20832447/**
    2084  * This consumes the precompiler output and checksums it.
     2448 * This consumes the preprocessor output and checksums it.
    20852449 *
    20862450 * @param   pEntry  The cache entry.
    2087  * @param   fdIn    The precompiler output pipe.
     2451 * @param   fdIn    The preprocessor output pipe.
    20882452 * @param   fdOut   The compiler input pipe, -1 if no compiler.
    20892453 */
    2090 static void kOCEntryPreCompileConsumer(PKOCENTRY pEntry, int fdIn)
     2454static void kOCEntryPreProcessConsumer(PKOCENTRY pEntry, int fdIn)
    20912455{
    20922456    KOCSUMCTX Ctx;
     
    21112475            if (errno == EINTR)
    21122476                continue;
    2113             FatalDie("precompile - read(%d,,%ld) failed: %s\n",
     2477            FatalDie("PreProcess - read(%d,,%ld) failed: %s\n",
    21142478                     fdIn, (long)cbLeft, strerror(errno));
    21152479        }
     
    21202484        psz[cbRead] = '\0';
    21212485        kOCSumUpdate(&pEntry->New.SumHead, &Ctx, psz, cbRead);
     2486        if (pEntry->pszMakeDepFilename)
     2487            kOCDepConsumer(&pEntry->DepState, psz, cbRead);
    21222488
    21232489        /*
     
    21462512
    21472513/**
    2148  * Run the precompiler and calculate the checksum of the output.
     2514 * Run the preprocessor and calculate the checksum of the output.
    21492515 *
    21502516 * @param   pEntry              The cache entry.
    2151  * @param   papszArgvPreComp    The argument vector for executing precompiler. The cArgvPreComp'th argument must be NULL.
     2517 * @param   papszArgvPreComp    The argument vector for executing preprocessor.
     2518 *                              The cArgvPreComp'th argument must be NULL.
    21522519 * @param   cArgvPreComp        The number of arguments.
    21532520 */
    2154 static void kOCEntryPreCompile(PKOCENTRY pEntry, const char * const *papszArgvPreComp, unsigned cArgvPreComp)
    2155 {
    2156     /*
    2157      * If we're executing the precompiler in piped mode, it's relatively simple.
     2521static void kOCEntryPreProcess(PKOCENTRY pEntry, const char * const *papszArgvPreComp, unsigned cArgvPreComp)
     2522{
     2523    /*
     2524     * If we're executing the preprocessor in piped mode, it's relatively simple.
    21582525     */
    21592526    if (pEntry->fPipedPreComp)
    2160         kOCEntrySpawnProducer(pEntry, papszArgvPreComp, cArgvPreComp, "precompile",
    2161                               kOCEntryPreCompileConsumer);
     2527        kOCEntrySpawnProducer(pEntry, papszArgvPreComp, cArgvPreComp, "preprocess",
     2528                              kOCEntryPreProcessConsumer);
    21622529    else
    21632530    {
    21642531        /*
    2165          * Rename the old precompiled output to '-old' so the precompiler won't
     2532         * Rename the old preprocessed output to '-old' so the preprocessor won't
    21662533         * overwrite it when we execute it.
    21672534         */
     
    21872554         */
    21882555        InfoMsg(3, "precompiling -> '%s'...\n", pEntry->New.pszCppName);
    2189         kOCEntrySpawn(pEntry, &pEntry->New.cMsCpp, papszArgvPreComp, cArgvPreComp, "precompile", NULL);
     2556        kOCEntrySpawn(pEntry, &pEntry->New.cMsCpp, papszArgvPreComp, cArgvPreComp, "preprocess", NULL);
    21902557        kOCEntryReadCppOutput(pEntry, &pEntry->New, 0 /* fatal */);
    21912558        kOCEntryCalcChecksum(pEntry);
    2192     }
     2559        if (pEntry->pszMakeDepFilename)
     2560            kOCDepConsumer(&pEntry->DepState, pEntry->New.pszCppMapping, pEntry->New.cbCpp);
     2561    }
     2562
     2563    if (pEntry->pszMakeDepFilename)
     2564        kOCDepWriteToFile(&pEntry->DepState, pEntry->pszMakeDepFilename, pEntry->New.pszObjName, pEntry->pszDir,
     2565                          pEntry->fMakeDepFixCase, pEntry->fMakeDepQuiet, pEntry->fMakeDepGenStubs);
    21932566}
    21942567
     
    21962569/**
    21972570 * Worker function for kOCEntryTeeConsumer and kOCEntryCompileIt that
    2198  * writes the precompiler output to disk.
     2571 * writes the preprocessor output to disk.
    21992572 *
    22002573 * @param   pEntry      The cache entry.
     
    22572630
    22582631/**
    2259  * kOCEntrySpawnConsumer callback that passes the precompiler
    2260  * output to the compiler and writes it to the disk (latter only when necesary).
     2632 * kOCEntrySpawnConsumer callback that passes the preprocessor output to the
     2633 * compiler and writes it to the disk (latter only when necesary).
    22612634 *
    22622635 * @param   pEntry      The cache entry.
     
    23462719 * kOCEntrySpawnTee callback that works sort of like 'tee'.
    23472720 *
    2348  * It will calculate the precompiled output checksum and
     2721 * It will calculate the preprocessed output checksum and
    23492722 * write it to disk while the compiler is busy compiling it.
    23502723 *
    23512724 * @param   pEntry  The cache entry.
    2352  * @param   fdIn    The input handle (connected to the precompiler).
     2725 * @param   fdIn    The input handle (connected to the preprocessor).
    23532726 * @param   fdOut   The output handle (connected to the compiler).
    23542727 */
     
    23672740    cbLeft = cbAlloc;
    23682741    pEntry->New.pszCppMapping = psz = xmalloc(cbAlloc);
    2369     InfoMsg(3, "precompiler|compile - starting passhtru...\n");
     2742    InfoMsg(3, "preprocessor|compile - starting passhtru...\n");
    23702743    for (;;)
    23712744    {
     
    23802753            if (errno == EINTR)
    23812754                continue;
    2382             FatalDie("precompile|compile - read(%d,,%ld) failed: %s\n",
     2755            FatalDie("preprocess|compile - read(%d,,%ld) failed: %s\n",
    23832756                     fdIn, (long)cbLeft, strerror(errno));
    23842757        }
    2385         InfoMsg(3, "precompiler|compile - read %d\n", cbRead);
     2758        InfoMsg(3, "preprocessor|compile - read %d\n", cbRead);
    23862759
    23872760        /*
     
    23902763        psz[cbRead] = '\0';
    23912764        kOCSumUpdate(&pEntry->New.SumHead, &Ctx, psz, cbRead);
     2765        if (pEntry->pszMakeDepFilename)
     2766            kOCDepConsumer(&pEntry->DepState, psz, cbRead);
     2767
    23922768#ifdef __WIN__
    23932769        if (   !fConnectedToCompiler
    23942770            && !(fConnectedToCompiler = ConnectNamedPipe((HANDLE)_get_osfhandle(fdOut), NULL)))
    2395             FatalDie("precompile|compile - ConnectNamedPipe failed: %d\n", GetLastError());
     2771            FatalDie("preprocess|compile - ConnectNamedPipe failed: %d\n", GetLastError());
    23962772#endif
    23972773        do
     
    24022778                if (errno == EINTR)
    24032779                    continue;
    2404                 FatalDie("precompile|compile - write(%d,,%ld) failed: %s\n", fdOut, cbRead, strerror(errno));
     2780                FatalDie("preprocess|compile - write(%d,,%ld) failed: %s\n", fdOut, cbRead, strerror(errno));
    24052781            }
    24062782            psz += cbWritten;
     
    24212797        }
    24222798    }
    2423     InfoMsg(3, "precompiler|compile - done passhtru\n");
     2799    InfoMsg(3, "preprocessor|compile - done passhtru\n");
    24242800
    24252801    close(fdIn);
     
    24302806
    24312807    /*
    2432      * Write the precompiler output to disk and free the memory it
     2808     * Write the preprocessor output to disk and free the memory it
    24332809     * occupies while the compiler is busy compiling.
    24342810     */
     
    24412817 *
    24422818 * @param   pEntry              The cache entry.
    2443  * @param   papszArgvPreComp    The argument vector for executing precompiler. The cArgvPreComp'th argument must be NULL.
     2819 * @param   papszArgvPreComp    The argument vector for executing preprocessor.
     2820 *                              The cArgvPreComp'th argument must be NULL.
    24442821 * @param   cArgvPreComp        The number of arguments.
    24452822 */
    2446 static void kOCEntryPreCompileAndCompile(PKOCENTRY pEntry, const char * const *papszArgvPreComp, unsigned cArgvPreComp)
     2823static void kOCEntryPreProcessAndCompile(PKOCENTRY pEntry, const char * const *papszArgvPreComp, unsigned cArgvPreComp)
    24472824{
    24482825    if (    pEntry->fPipedCompile
     
    24622839
    24632840        /*
    2464          * Do the actual compile and write the precompiler output to disk.
     2841         * Do the actual compile and write the preprocessor output to disk.
    24652842         */
    24662843        kOCEntrySpawnTee(pEntry, papszArgvPreComp, cArgvPreComp,
    24672844                         (const char * const *)pEntry->New.papszArgvCompile, pEntry->New.cArgvCompile,
    2468                          "precompile|compile", kOCEntryTeeConsumer);
     2845                         "preprocess|compile", kOCEntryTeeConsumer);
     2846        if (pEntry->pszMakeDepFilename)
     2847            kOCDepWriteToFile(&pEntry->DepState, pEntry->pszMakeDepFilename,  pEntry->New.pszObjName, pEntry->pszDir,
     2848                              pEntry->fMakeDepFixCase, pEntry->fMakeDepQuiet, pEntry->fMakeDepGenStubs);
    24692849    }
    24702850    else
    24712851    {
    2472         kOCEntryPreCompile(pEntry, papszArgvPreComp, cArgvPreComp);
     2852        kOCEntryPreProcess(pEntry, papszArgvPreComp, cArgvPreComp);
    24732853        kOCEntryCompileIt(pEntry);
    24742854    }
     
    25632943/**
    25642944 * Worker for kOCEntryCompareOldAndNewOutput() that compares the
    2565  * precompiled output using a fast but not very good method.
     2945 * preprocessed output using a fast but not very good method.
    25662946 *
    25672947 * @returns 1 if matching, 0 if not matching.
     
    26132993             * possible that we will omit this header from the dependencies
    26142994             * when using VCC. This might not be a problem, since it seems
    2615              * we'll have to use the precompiler output to generate the deps
     2995             * we'll have to use the preprocessor output to generate the deps
    26162996             * anyway.
    26172997             */
     
    27793159/**
    27803160 * Worker for kOCEntryCompileIfNeeded that compares the
    2781  * precompiled output.
     3161 * preprocessed output.
    27823162 *
    27833163 * @returns 1 if matching, 0 if not matching.
     
    28103190
    28113191    /*
    2812      * Check if the precompiler output differ in any significant way?
     3192     * Check if the preprocessor output differ in any significant way?
    28133193     */
    28143194    if (!kOCSumHasEqualInChain(&pEntry->Old.SumHead, &pEntry->New.SumHead))
     
    29573337    /** The checksum of the compile argument vector. */
    29583338    KOCSUM SumCompArgv;
    2959     /** The list of precompiler output checksums that's . */
     3339    /** The list of preprocessor output checksums that's . */
    29603340    KOCSUM SumHead;
    29613341} KOCDIGEST;
     
    38324212            "            <-t|--target <target-name>>\n"
    38334213            "            [-r|--redir-stdout] [-p|--passthru] [--named-pipe-compile <pipename>]\n"
    3834             "            --kObjCache-cpp <filename> <precompiler + args>\n"
     4214            "            --kObjCache-cpp <filename> <preprocessor + args>\n"
    38354215            "            --kObjCache-cc <object> <compiler + args>\n"
    38364216            "            [--kObjCache-both [args]]\n"
     
    38714251    const char *pszNmPipeCompile = NULL;
    38724252
     4253    const char *pszMakeDepFilename = NULL;
     4254    int fMakeDepFixCase = 0;
     4255    int fMakeDepGenStubs = 0;
     4256    int fMakeDepQuiet = 0;
     4257
    38734258    const char *pszTarget = NULL;
    38744259
     
    39114296            {
    39124297                if (++i >= argc)
    3913                     return SyntaxError("--kObjCache-cc requires an precompiler output filename!\n");
     4298                    return SyntaxError("--kObjCache-cc requires an preprocessor output filename!\n");
    39144299                pszObjName = argv[i];
    39154300            }
     
    39754360            fRedirCompileStdIn = 0;
    39764361        }
     4362        else if (!strcmp(argv[i], "-m") || !strcmp(argv[i], "--make-dep-file"))
     4363        {
     4364            if (i + 1 >= argc)
     4365                return SyntaxError("%s requires a filename!\n", argv[i]);
     4366            pszMakeDepFilename = argv[++i];
     4367        }
     4368        else if (!strcmp(argv[i], "--make-dep-fix-case"))
     4369            fMakeDepFixCase = 1;
     4370        else if (!strcmp(argv[i], "--make-dep-gen-stubs"))
     4371            fMakeDepGenStubs = 1;
     4372        else if (!strcmp(argv[i], "--make-dep-quiet"))
     4373            fMakeDepQuiet = 1;
    39774374        else if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "--passthru"))
    39784375            fRedirPreCompStdOut = fRedirCompileStdIn = 1;
     
    39924389        {
    39934390            printf("kObjCache - kBuild version %d.%d.%d ($Revision$)\n"
    3994                    "Copyright (c) 2007-2011 knut st. osmundsen\n",
     4391                   "Copyright (c) 2007-2012 knut st. osmundsen\n",
    39954392                   KBUILD_VERSION_MAJOR, KBUILD_VERSION_MINOR, KBUILD_VERSION_PATCH);
    39964393            return 0;
     
    40064403        return SyntaxError("No compiler arguments (--kObjCache-cc)!\n");
    40074404    if (!cArgvPreComp)
    4008         return SyntaxError("No precompiler arguments (--kObjCache-cc)!\n");
     4405        return SyntaxError("No preprocessor arguments (--kObjCache-cc)!\n");
    40094406
    40104407    /*
     
    40484445    kOCEntrySetCppName(pEntry, pszPreCompName);
    40494446    kOCEntrySetPipedMode(pEntry, fRedirPreCompStdOut, fRedirCompileStdIn, pszNmPipeCompile);
     4447    kOCEntrySetDepFilename(pEntry, pszMakeDepFilename, fMakeDepFixCase, fMakeDepQuiet, fMakeDepGenStubs);
    40504448
    40514449    /*
     
    40624460        kObjCacheUnlock(pCache);
    40634461        InfoMsg(1, "doing full compile\n");
    4064         kOCEntryPreCompileAndCompile(pEntry, papszArgvPreComp, cArgvPreComp);
     4462        kOCEntryPreProcessAndCompile(pEntry, papszArgvPreComp, cArgvPreComp);
    40654463        kObjCacheLock(pCache);
    40664464    }
     
    40684466    {
    40694467        /*
    4070          * Do the precompile (don't need to lock the cache file for this).
     4468         * Do the preprocess (don't need to lock the cache file for this).
    40714469         */
    40724470        kObjCacheUnlock(pCache);
    4073         kOCEntryPreCompile(pEntry, papszArgvPreComp, cArgvPreComp);
     4471        kOCEntryPreProcess(pEntry, papszArgvPreComp, cArgvPreComp);
    40744472
    40754473        /*
Note: See TracChangeset for help on using the changeset viewer.