Ignore:
Timestamp:
May 25, 2007, 12:39:22 AM (18 years ago)
Author:
bird
Message:

PATH_KBUILD and PATH_KBUILD_BIN improvements. Avoid LOCALEDIR, ALIASDIR, LIBDIR and INCLUDEDIR.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmakenew/kbuild.c

    r862 r917  
    2727/* No GNU coding style here! */
    2828
    29 #ifdef KMK_HELPERS
    30 
     29
     30/*******************************************************************************
     31*   Header Files                                                               *
     32*******************************************************************************/
    3133#include "make.h"
    3234#include "filedef.h"
     
    4345#endif
    4446
     47
     48/*******************************************************************************
     49*   Internal Functions                                                         *
     50*******************************************************************************/
    4551/* function.c */
    4652char * abspath(const char *name, char *apath);
     53
     54/*******************************************************************************
     55*   Global Variables                                                           *
     56*******************************************************************************/
     57/** The argv[0] passed to main. */
     58static const char *g_argv0 = "";
     59
     60
     61/**
     62 * Initialize kBuild stuff.
     63 *
     64 * @param   argc    Number of arguments to main().
     65 * @param   argv    The main() argument vector.
     66 */
     67void init_kbuild(int argc, char **argv)
     68{
     69    g_argv0 = argv[0];
     70}
     71
     72
     73/**
     74 * Determin the PATH_KBUILD value.
     75 *
     76 * @returns Pointer to static buffer to be treated as read only!
     77 */
     78const char *get_path_kbuild(void)
     79{
     80    static const char *s_pszPath = NULL;
     81    if (!s_pszPath)
     82    {
     83        PATH_VAR(szTmpPath);
     84        const char *pszEnvVar = getenv("PATH_KBUILD");
     85        if (    !pszEnvVar
     86            ||  !abspath(pszEnvVar, szTmpPath))
     87        {
     88#ifdef PATH_KBUILD
     89            return s_pszPath = PATH_KBUILD;
     90#else
     91            /* $(abspath $(PATH_KBUILD_BIN)/../..)*/
     92            size_t cch = strlen(get_path_kbuild_bin());
     93            char *pszTmp2 = alloca(cch + sizeof("/../.."));
     94            strcat(strcpy(pszTmp2, get_path_kbuild_bin()), "/../..");
     95            if (!abspath(pszTmp2, szTmpPath))
     96                fatal(NILF, _("failed to determin PATH_KBUILD"));
     97#endif
     98        }
     99        s_pszPath = xstrdup(szTmpPath);
     100    }
     101    return s_pszPath;
     102}
     103
     104
     105/**
     106 * Determin the PATH_KBUILD_BIN value.
     107 *
     108 * @returns Pointer to static buffer to be treated as read only!
     109 */
     110const char *get_path_kbuild_bin(void)
     111{
     112    static const char *s_pszPath = NULL;
     113    if (!s_pszPath)
     114    {
     115        PATH_VAR(szTmpPath);
     116        const char *pszEnvVar = getenv("PATH_KBUILD_BIN");
     117        if (    !pszEnvVar
     118            ||  !abspath(pszEnvVar, szTmpPath))
     119        {
     120#ifdef PATH_KBUILD
     121            return s_pszPath = PATH_KBUILD_BIN;
     122#else
     123            /* $(abspath $(ARGV0)/../../..) - the filename shouldn't cause trouble... */
     124            size_t cch = strlen(g_argv0);
     125            char *pszTmp2 = alloca(cch + sizeof("/../../.."));
     126            strcat(strcpy(pszTmp2, g_argv0), "/../../..");
     127            if (!abspath(pszTmp2, szTmpPath))
     128                fatal(NILF, _("failed to determin PATH_KBUILD_BIN"));
     129#endif
     130        }
     131        s_pszPath = xstrdup(szTmpPath);
     132    }
     133    return s_pszPath;
     134}
     135
     136
     137#ifdef KMK_HELPERS
    47138
    48139/**
     
    14751566
    14761567#endif /* KMK_HELPERS */
     1568
Note: See TracChangeset for help on using the changeset viewer.