VirtualBox

Changeset 332 in kBuild for trunk/src


Ignore:
Timestamp:
Oct 30, 2005 7:20:35 PM (19 years ago)
Author:
bird
Message:

Fix case option - need it on unix for cl.exe with wine.

File:
1 edited

Legend:

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

    r330 r332  
    2929#include <stdlib.h>
    3030#include <string.h>
     31#include <errno.h>
    3132#include <ctype.h>
     33#include <sys/stat.h>
    3234#ifdef __WIN32__
    3335#include <windows.h>
    3436#endif
     37#if !defined(__WIN32__) && !defined(__OS2__)
     38# include <dirent.h>
     39#endif
    3540
    3641#ifdef HAVE_FGETC_UNLOCKED
     
    6974/** List of dependencies. */
    7075static PDEP g_pDeps = NULL;
     76/** Whether or not to fixup win32 casing. */
     77static int  g_fFixCase = 0;
    7178
    7279
     
    7986 *                      The buffer must be able to hold one more byte than the string length.
    8087 */
    81 void w32_fixcase(char *pszPath)
     88void fixcase(char *pszPath)
    8289{
    8390#define my_assert(expr) \
     
    189196}
    190197
     198/**
     199 * Corrects all slashes to unix slashes.
     200 *
     201 * @returns pszFilename.
     202 * @param   pszFilename     The filename to correct.
     203 */
     204char *fixslash(char *pszFilename)
     205{
     206    char *psz = pszFilename;
     207    while ((psz = strchr(psz, '\\')) != NULL)
     208        *psz++ = '/';
     209    return pszFilename;
     210}
     211
     212#elif defined(__OS2__)
     213
     214/**
     215 * Corrects the case of a path.
     216 *
     217 * @param   pszPath     Pointer to the path, both input and output.
     218 *                      The buffer must be able to hold one more byte than the string length.
     219 */
     220void fixcase(char *pszFilename)
     221{
     222    return;
     223}
     224
     225#else
     226
     227/**
     228 * Corrects the case of a path.
     229 *
     230 * @param   pszPath     Pointer to the path, both input and output.
     231 */
     232void fixcase(char *pszFilename)
     233{
     234    char *psz;
     235
     236    /*
     237     * Skip the root.
     238     */
     239    psz = pszFilename;
     240    while (*psz == '/')
     241        psz++;
     242
     243    /*
     244     * Iterate all the components.
     245     */
     246    while (*psz)
     247    {
     248        char  chSlash;
     249        struct stat s;
     250        char   *pszStart = psz;
     251
     252        /*
     253         * Find the next slash (or end of string) and terminate the string there.
     254         */
     255        while (*psz != '/' && *psz)
     256            *psz++;
     257        chSlash = *psz;
     258        *psz = '\0';
     259
     260        /*
     261         * Does this part exist?
     262         * If not we'll enumerate the directory and search for an case-insensitive match.
     263         */
     264        if (stat(pszFilename, &s))
     265        {
     266            struct dirent  *pEntry;
     267            DIR            *pDir;
     268            if (pszStart == pszFilename)
     269                pDir = opendir(*pszFilename ? pszFilename : ".");
     270            else
     271            {
     272                pszStart[-1] = '\0';
     273                pDir = opendir(pszFilename);
     274                pszStart[-1] = '/';
     275            }
     276            if (!pDir)
     277            {
     278                *psz = chSlash;
     279                break; /* giving up, if we fail to open the directory. */
     280            }
     281
     282            while ((pEntry = readdir(pDir)) != NULL)
     283            {
     284                if (!strcasecmp(pEntry->d_name, pszStart))
     285                {
     286                    strcpy(pszStart, pEntry->d_name);
     287                    break;
     288                }
     289            }
     290            closedir(pDir);
     291            if (!pEntry)
     292            {
     293                *psz = chSlash;
     294                break;  /* giving up if not found. */
     295            }
     296        }
     297
     298        /* restore the slash and press on. */
     299        *psz = chSlash;
     300        while (*psz == '/')
     301            psz++;
     302    }
     303
     304    return;
     305}
     306
     307
    191308#endif
     309
    192310
    193311
     
    203321    for (pDep = g_pDeps; pDep; pDep = pDep->pNext)
    204322    {
     323        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;
     331
    205332        /*
    206333         * Skip some fictive names like <built-in> and <command line>.
     
    209336            &&  pDep->szFilename[pDep->cchFilename - 1] == '>')
    210337            continue;
    211 
    212 #if defined(__WIN32__)
    213         {
    214             char *psz;
    215             char szFilename[_MAX_PATH + 1];
    216             if (_fullpath(szFilename, pDep->szFilename, sizeof(szFilename)))
    217                 w32_fixcase(szFilename);
    218             psz = szFilename;
    219             while ((psz = strchr(psz, '\\')) != NULL)
    220                 *psz++ = '/';
    221             fprintf(pOutput, " \\\n\t%s", szFilename);
    222         }
    223 
    224 #elif !defined(__OS2__)
    225         {
    226             const char *psz = strchr(pDep->szFilename, ':');
    227             if (psz)
    228                 fprintf(pOutput, " \\\n\t%s", psz + 1);
     338        pszFilename = pDep->szFilename;
     339
     340#if !defined(__OS2__) && !defined(__WIN32__)
     341        /*
     342         * Skip any drive letters from compilers running in wine.
     343         */
     344        if (pszFilename[1] == ':')
     345            pszFilename += 2;
     346#endif
     347
     348        /*
     349         * 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...
     352         */
     353        if (g_fFixCase)
     354        {
     355#ifdef __WIN32__
     356            if (_fullpath(szFilename, pszFilename, sizeof(szFilename)))
     357                fixslash(szFilename);
    229358            else
    230                 fprintf(pOutput, " \\\n\t%s", pDep->szFilename);
    231         }
    232 
    233 #else /* __OS2__ */
    234         fprintf(pOutput, " \\\n\t%s", pDep->szFilename);
    235 
    236 #endif /* __OS2__ */
    237     }
     359#endif
     360                strcpy(szFilename, pszFilename);
     361            fixcase(szFilename);
     362            pszFilename = szFilename;
     363        }
     364
     365        /*
     366         * Check that the file exists before we start depending on it.
     367         */
     368        if (stat(pszFilename, &s))
     369        {
     370            fprintf(stderr, "kDepPre: Skipping '%s' - %s!\n", szFilename, strerror(errno));
     371            continue;
     372        }
     373
     374        fprintf(pOutput, " \\\n\t%s", pszFilename);
     375    } /* foreach dependency */
    238376    fprintf(pOutput, "\n\n");
    239377}
     
    476614static void usage(const char *argv0)
    477615{
    478     printf("syntax: %s [-l=c] -o <output> -t <target> < - | <filename> | -e <cmdline> >\n", argv0);
     616    printf("syntax: %s [-l=c] -o <output> -t <target> [-f] < - | <filename> | -e <cmdline> >\n", argv0);
    479617}
    480618
     
    526664                        pszOutput = argv[i];
    527665                    }
    528                     pOutput = fopen(pszOutput, "w");
     666                    if (pszOutput[0] == '-' && !pszOutput[1])
     667                        pOutput = stdout;
     668                    else
     669                        pOutput = fopen(pszOutput, "w");
    529670                    if (!pOutput)
    530671                    {
     
    591732                }
    592733
    593 
    594734                /*
    595735                 * Pipe input.
     
    599739                    pInput = stdin;
    600740                    fInput = 1;
     741                    break;
     742                }
     743
     744                /*
     745                 * Fix case.
     746                 */
     747                case 'f':
     748                {
     749                    g_fFixCase = 1;
    601750                    break;
    602751                }
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette