Ignore:
Timestamp:
Nov 7, 2005, 8:16:08 PM (20 years ago)
Author:
bird
Message:

Added new option -s for generating stub dependencies just like -Wp,-MP.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kDepPre/kDepPre.c

    r332 r338  
    3737#if !defined(__WIN32__) && !defined(__OS2__)
    3838# include <dirent.h>
    39 #endif 
     39#endif
    4040
    4141#ifdef HAVE_FGETC_UNLOCKED
     
    7474/** List of dependencies. */
    7575static PDEP g_pDeps = NULL;
    76 /** Whether or not to fixup win32 casing. */
    77 static int  g_fFixCase = 0;
     76
     77
     78/*******************************************************************************
     79*   Internal Functions                                                         *
     80*******************************************************************************/
     81static PDEP depAdd(const char *pszFilename, size_t cchFilename);
     82static void depOptimize(int fFixCase);
     83static void depPrint(FILE *pOutput);
     84static void depPrintStubs(FILE *pOutput);
    7885
    7986
     
    198205/**
    199206 * Corrects all slashes to unix slashes.
    200  * 
     207 *
    201208 * @returns pszFilename.
    202209 * @param   pszFilename     The filename to correct.
     
    309316
    310317
    311 
    312318/**
    313  * Prints the dependency chain.
    314  *
    315  * @returns Pointer to the allocated dependency.
    316  * @param   pOutput     Output stream.
     319 * 'Optimizes' and corrects the dependencies.
    317320 */
    318 static void depPrint(FILE *pOutput)
    319 {
     321static void depOptimize(int fFixCase)
     322{
     323    /*
     324     * Walk the list correct the names and re-insert them.
     325     */
     326    PDEP pDepOrg = g_pDeps;
    320327    PDEP pDep = g_pDeps;
    321     for (pDep = g_pDeps; pDep; pDep = pDep->pNext)
    322     {
     328    g_pDeps = NULL;
     329    for (; pDep; pDep = pDep->pNext)
     330    {
     331#ifdef __WIN32__
     332        char        szFilename[_MAX_PATH + 1];
     333#else
     334        char        szFilename[PATH_MAX + 1];
     335#endif
     336        char       *pszFilename;
    323337        struct stat s;
    324 #ifdef __WIN32__
    325         char    szFilename[_MAX_PATH + 1];
    326 #else
    327         char    szFilename[PATH_MAX + 1];
    328 #endif
    329         char   *pszFilename;
    330         char   *psz;
    331338
    332339        /*
     
    344351        if (pszFilename[1] == ':')
    345352            pszFilename += 2;
    346 #endif 
     353#endif
    347354
    348355        /*
    349356         * The microsoft compilers are notoriously screwing up the casing.
    350          * This will screw with kmk (/ GNU Make) on case sensitive systems, it
    351          * may even do so on win32...
     357         * This will screw up kmk (/ GNU Make).
    352358         */
    353         if (g_fFixCase)
     359        if (fFixCase)
    354360        {
    355361#ifdef __WIN32__
     
    372378        }
    373379
    374         fprintf(pOutput, " \\\n\t%s", pszFilename);
    375     } /* foreach dependency */
     380        /*
     381         * Insert the corrected dependency.
     382         */
     383        depAdd(pszFilename, strlen(pszFilename));
     384    }
     385
     386#if 0 /* waste of time */
     387    /*
     388     * Free the old ones.
     389     */
     390    while (pDepOrg)
     391    {
     392        pDep = pDepOrg;
     393        pDepOrg = pDepOrg->pNext;
     394        free(pDep);
     395    }
     396#endif
     397}
     398
     399
     400/**
     401 * Prints the dependency chain.
     402 *
     403 * @returns Pointer to the allocated dependency.
     404 * @param   pOutput     Output stream.
     405 */
     406static void depPrint(FILE *pOutput)
     407{
     408    PDEP pDep;
     409    for (pDep = g_pDeps; pDep; pDep = pDep->pNext)
     410        fprintf(pOutput, " \\\n\t%s", pDep->szFilename);
    376411    fprintf(pOutput, "\n\n");
     412}
     413
     414
     415/**
     416 * Prints empty dependency stubs for all dependencies.
     417 */
     418static void depPrintStubs(FILE *pOutput)
     419{
     420    PDEP pDep;
     421    for (pDep = g_pDeps; pDep; pDep = pDep->pNext)
     422        fprintf(pOutput, "%s:\n\n", pDep->szFilename);
    377423}
    378424
     
    614660static void usage(const char *argv0)
    615661{
    616     printf("syntax: %s [-l=c] -o <output> -t <target> [-f] < - | <filename> | -e <cmdline> >\n", argv0);
     662    printf("syntax: %s [-l=c] -o <output> -t <target> [-f] [-s] < - | <filename> | -e <cmdline> >\n", argv0);
    617663}
    618664
     
    627673    FILE       *pInput = NULL;
    628674    const char *pszTarget = NULL;
     675    int         fStubs = 0;
     676    int         fFixCase = 0;
    629677    /* Argument parsing. */
    630678    int         fInput = 0;             /* set when we've found input argument. */
     
    747795                case 'f':
    748796                {
    749                     g_fFixCase = 1;
     797                    fFixCase = 1;
     798                    break;
     799                }
     800
     801                /*
     802                 * Generate stubs.
     803                 */
     804                case 's':
     805                {
     806                    fStubs = 1;
    750807                    break;
    751808                }
     
    831888    if (!i)
    832889    {
     890        depOptimize(fFixCase);
    833891        fprintf(pOutput, "%s:", pszTarget);
    834892        depPrint(pOutput);
     893        if (fStubs)
     894            depPrintStubs(pOutput);
    835895    }
    836896
Note: See TracChangeset for help on using the changeset viewer.