Changeset 3415 for trunk/src


Ignore:
Timestamp:
Aug 21, 2020, 1:43:33 AM (5 years ago)
Author:
bird
Message:

kmk: Fixed mixup from r2433 where _TARGET_TOOL was extended but the builtin source handling functions wasn't. For instance, using _TOOLS, _TOOLS.amd64 and _TOOLS.x86, we would end up with the first when compiling and one of the latter two when linking. Also replaced a few legacy BUILD_PLATFORM* with KBUILD_HOST* variable names in the footers.

Location:
trunk/src/kmk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/function.c

    r3397 r3415  
    75707570#endif
    75717571#ifdef KMK_HELPERS
    7572   FT_ENTRY ("kb-src-tool",   1,  1,  0,  func_kbuild_source_tool),
    7573   FT_ENTRY ("kb-obj-base",   1,  1,  0,  func_kbuild_object_base),
    7574   FT_ENTRY ("kb-obj-suff",   1,  1,  0,  func_kbuild_object_suffix),
     7572  FT_ENTRY ("kb-src-tool",   1,  2,  0,  func_kbuild_source_tool),
     7573  FT_ENTRY ("kb-obj-base",   1,  2,  0,  func_kbuild_object_base),
     7574  FT_ENTRY ("kb-obj-suff",   1,  2,  0,  func_kbuild_object_suffix),
    75757575  FT_ENTRY ("kb-src-prop",   3,  4,  0,  func_kbuild_source_prop),
    75767576  FT_ENTRY ("kb-src-one",    0,  1,  0,  func_kbuild_source_one),
  • trunk/src/kmk/kbuild.c

    r3322 r3415  
    629629
    630630/**
     631 * Looks up an non-empty variable when simplified and spaces skipped.
     632 *
     633 * This handy when emulating $(firstword )/$(lastword ) behaviour.
     634 *
     635 * @returns Pointer to the variable. NULL if not found.
     636 * @param   pszName     The variable name.
     637 * @param   cchName     The name length.
     638 */
     639MY_INLINE struct variable *
     640kbuild_lookup_not_empty_variable_n(const char *pszName, size_t cchName)
     641{
     642    struct variable *pVar = kbuild_lookup_variable_n(pszName, cchName);
     643    if (pVar && !pVar->recursive)
     644    {
     645        /*
     646         * Skip spaces and make sure it's non-zero.
     647         */
     648        char *psz = pVar->value;
     649        if (!ISSPACE(*psz))
     650        { /* kind of likely */ }
     651        else
     652            do
     653                psz++;
     654            while (ISSPACE(*psz));
     655
     656        if (*psz)
     657        { /*kind of likely */ }
     658        else
     659            pVar = NULL;
     660    }
     661    return pVar;
     662}
     663
     664
     665/**
    631666 * Looks up a variable.
    632667 * The value_length field is valid upon successful return.
     
    693728/**
    694729 * Gets the first defined property variable.
     730 *
     731 * When pBldType is given, additional property variations are consulted.
     732 * See _TARGET_TOOL/r2433 in footer.kmk for the target-level difference.
     733 * Similar extended property lookup is applied to the source part if the
     734 * fExtendedSource parameter is non-zero (not done yet as it'll be expensive).
     735 *
     736 * Since r3415 this function will use $(target)_2_$(type)TOOL to cache the
     737 * result of the target specific part of the lookup (_TARGET_TOOL).
    695738 */
    696739static struct variable *
    697740kbuild_first_prop(struct variable *pTarget, struct variable *pSource,
    698741                  struct variable *pTool, struct variable *pType,
    699                   struct variable *pBldTrg, struct variable *pBldTrgArch,
     742                  struct variable *pBldTrg, struct variable *pBldTrgArch, struct variable *pBldType,
    700743                  const char *pszPropF1, char cchPropF1,
    701744                  const char *pszPropF2, char cchPropF2,
     745                  int fExtendedSource,
    702746                  const char *pszVarName)
    703747{
     
    706750    char *pszBuf;
    707751    char *psz, *psz1, *psz2, *psz3, *psz4, *pszEnd;
     752    int fCacheIt = 1;
     753
     754    fExtendedSource = fExtendedSource && pBldType != NULL;
    708755
    709756    /* calc and allocate a too big name buffer. */
     
    715762           + pType->value_length + 1
    716763           + pBldTrg->value_length + 1
    717            + pBldTrgArch->value_length + 1;
     764           + pBldTrgArch->value_length + 1
     765           + (pBldType ? pBldType->value_length + 1 : 0);
    718766    pszBuf = xmalloc(cchBuf);
    719767
     
    724772
    725773    /*
    726      * $(target)_$(source)_$(type)$(propf2).$(bld_trg).$(bld_trg_arch)
     774     * $(target)_$(source)_$(type)$(propf2).$(bld_trg).$(bld_trg_arch).$(bld_type)
     775     *   ...
     776     * $(target)_$(source)_$(type)$(propf2)
    727777     */
    728778    psz = pszBuf;
     
    731781    ADD_VAR(pSource);
    732782    ADD_CH('_');
    733     psz2 = psz;
     783    psz1 = psz;
    734784    ADD_VAR(pType);
    735785    ADD_STR(pszPropF2, cchPropF2);
    736     psz3 = psz;
    737     ADD_CH('.');
    738     ADD_VAR(pBldTrg);
    739     psz4 = psz;
    740     ADD_CH('.');
    741     ADD_VAR(pBldTrgArch);
    742     pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf);
    743 
    744     /* $(target)_$(source)_$(type)$(propf2).$(bld_trg) */
     786#define DO_VARIATIONS(a_fExtended) do { \
     787    psz2 = psz; \
     788    ADD_CH('.'); \
     789    ADD_VAR(pBldTrg); \
     790    psz3 = psz; \
     791    ADD_CH('.'); \
     792    ADD_VAR(pBldTrgArch); \
     793    psz4 = psz; \
     794    if ((a_fExtended) && pBldType) \
     795    { \
     796        ADD_CH('.'); \
     797        ADD_VAR(pBldType); \
     798        pVar = kbuild_lookup_not_empty_variable_n(pszBuf, psz - pszBuf); \
     799        \
     800        /* <lead>.$(bld_trg).$(bld_trg_arch) */ \
     801        if (!pVar) \
     802            pVar = kbuild_lookup_not_empty_variable_n(pszBuf, psz4 - pszBuf); \
     803        \
     804        /* <lead>.$(bld_trg).$(bld_type) */ \
     805        if (!pVar) \
     806        { \
     807            psz = psz3 + 1; \
     808            ADD_VAR(pBldType); \
     809            pVar = kbuild_lookup_not_empty_variable_n(pszBuf, psz - pszBuf); \
     810        } \
     811        \
     812        /* <lead>.$(bld_trg_arch) */ \
     813        if (!pVar) \
     814        { \
     815            psz = psz2 + 1; \
     816            ADD_VAR(pBldTrgArch); \
     817            pVar = kbuild_lookup_not_empty_variable_n(pszBuf, psz - pszBuf); \
     818        } \
     819        \
     820        /* <lead>.$(bld_trg) */ \
     821        if (!pVar) \
     822        { \
     823            psz = psz2 + 1; \
     824            ADD_VAR(pBldTrg); \
     825            pVar = kbuild_lookup_not_empty_variable_n(pszBuf, psz - pszBuf); \
     826        } \
     827        \
     828        /* <lead>.$(bld_type) */ \
     829        if (!pVar) \
     830        { \
     831            psz = psz2 + 1; \
     832            ADD_VAR(pBldType); \
     833            pVar = kbuild_lookup_not_empty_variable_n(pszBuf, psz - pszBuf); \
     834        } \
     835    } \
     836    else \
     837    { \
     838        /* <lead>.$(bld_trg).$(bld_trg_arch) */ \
     839        pVar = kbuild_lookup_not_empty_variable_n(pszBuf, psz4 - pszBuf); \
     840        \
     841        /* <lead>.$(bld_trg) */ \
     842        if (!pVar) \
     843            pVar = kbuild_lookup_not_empty_variable_n(pszBuf, psz3 - pszBuf); \
     844    } \
     845    \
     846    /* <lead> */ \
     847    if (!pVar) \
     848        pVar = kbuild_lookup_not_empty_variable_n(pszBuf, psz2 - pszBuf); \
     849} while (0)
     850    DO_VARIATIONS(fExtendedSource);
     851
     852    /*
     853     * $(target)_$(source)_$(propf2).$(bld_trg).$(bld_trg_arch).$(bld_type) [omit $(type) prefix to $(propf2)]
     854     *   ...
     855     * $(target)_$(source)_$(propf2)
     856     */
    745857    if (!pVar)
    746         pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf);
    747 
    748     /* $(target)_$(source)_$(type)$(propf2) */
    749     if (!pVar)
    750         pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf);
    751 
    752     /*
    753      * $(target)_$(source)_$(propf2).$(bld_trg).$(bld_trg_arch)
    754      */
    755     if (!pVar)
    756     {
    757         psz = psz2;
     858    {
     859        psz = psz1; /* rewind to '$(target)_$(source)_' */
    758860        ADD_STR(pszPropF2, cchPropF2);
    759         psz3 = psz;
    760         ADD_CH('.');
    761         ADD_VAR(pBldTrg);
    762         psz4 = psz;
    763         ADD_CH('.');
    764         ADD_VAR(pBldTrgArch);
    765         pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf);
    766 
    767         /* $(target)_$(source)_$(propf2).$(bld_trg) */
    768         if (!pVar)
    769             pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf);
    770 
    771         /* $(target)_$(source)_$(propf2) */
    772         if (!pVar)
    773             pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf);
    774     }
    775 
    776 
    777     /*
    778      * $(source)_$(type)$(propf2).$(bld_trg).$(bld_trg_arch)
     861        DO_VARIATIONS(fExtendedSource);
     862    }
     863
     864    /*
     865     * $(source)_$(type)$(propf2).$(bld_trg).$(bld_trg_arch).$(bld_type)
     866     *   ...
     867     * $(source)_$(type)$(propf2)
    779868     */
    780869    if (!pVar)
     
    783872        ADD_VAR(pSource);
    784873        ADD_CH('_');
    785         psz2 = psz;
     874        psz1 = psz;
    786875        ADD_VAR(pType);
    787876        ADD_STR(pszPropF2, cchPropF2);
    788         psz3 = psz;
    789         ADD_CH('.');
    790         ADD_VAR(pBldTrg);
    791         psz4 = psz;
    792         ADD_CH('.');
    793         ADD_VAR(pBldTrgArch);
    794         pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf);
    795 
    796         /* $(source)_$(type)$(propf2).$(bld_trg) */
    797         if (!pVar)
    798             pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf);
    799 
    800         /* $(source)_$(type)$(propf2) */
    801         if (!pVar)
    802             pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf);
     877        DO_VARIATIONS(fExtendedSource);
    803878
    804879        /*
    805          * $(source)_$(propf2).$(bld_trg).$(bld_trg_arch)
     880         * $(source)_$(propf2).$(bld_trg).$(bld_trg_arch).$(bld_type)  [omit $(type) prefix to $(propf2)]
     881         *   ...
     882         * $(source)_$(propf2)
    806883         */
    807884        if (!pVar)
    808885        {
    809             psz = psz2;
     886            psz = psz1; /* rewind to '$(source)_' */
    810887            ADD_STR(pszPropF2, cchPropF2);
    811             psz3 = psz;
    812             ADD_CH('.');
    813             ADD_VAR(pBldTrg);
    814             psz4 = psz;
    815             ADD_CH('.');
    816             ADD_VAR(pBldTrgArch);
    817             pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf);
    818 
    819             /* $(source)_$(propf2).$(bld_trg) */
    820             if (!pVar)
    821                 pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf);
    822 
    823             /* $(source)_$(propf2) */
    824             if (!pVar)
    825                 pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf);
    826         }
    827     }
    828 
    829     /*
    830      * $(target)_$(type)$(propf2).$(bld_trg).$(bld_trg_arch)
     888            DO_VARIATIONS(fExtendedSource);
     889        }
     890    }
     891
     892    /*
     893     * Check the cache: $(target)_2_$(type)$(propf2)
     894     */
     895    if (pVar)
     896        fCacheIt = 0;
     897    else if (fCacheIt)
     898    {
     899        psz = pszBuf;
     900        ADD_VAR(pTarget);
     901        ADD_STR("_2_", 3);
     902        ADD_VAR(pType);
     903        ADD_STR(pszPropF2, cchPropF2);
     904        pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf);
     905
     906        /* If found, this can be duplicated and returned directly. No value stripping
     907           needed as we defined it (or at least should have) ourselves. */
     908        if (pVar)
     909        {
     910            pVar = define_variable_vl(pszVarName, strlen(pszVarName), pVar->value, pVar->value_length,
     911                                      1 /* duplicate */, o_local, 0 /* !recursive */);
     912            free(pszBuf);
     913            return pVar;
     914        }
     915    }
     916
     917    /*
     918     * $(target)_$(type)$(propf2).$(bld_trg).$(bld_trg_arch).$(bld_type)
     919     *   ...
     920     * $(target)_$(type)$(propf2)
    831921     */
    832922    if (!pVar)
     
    835925        ADD_VAR(pTarget);
    836926        ADD_CH('_');
    837         psz2 = psz;
     927        psz1 = psz;
    838928        ADD_VAR(pType);
    839929        ADD_STR(pszPropF2, cchPropF2);
    840         psz3 = psz;
    841         ADD_CH('.');
    842         ADD_VAR(pBldTrg);
    843         psz4 = psz;
    844         ADD_CH('.');
    845         ADD_VAR(pBldTrgArch);
    846         pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf);
    847 
    848         /* $(target)_$(type)$(propf2).$(bld_trg) */
     930        DO_VARIATIONS(1);
     931
     932        /*
     933         * $(target)_$(propf2).$(bld_trg).$(bld_trg_arch).$(bld_type)  [omit $(type) prefix to $(propf2)]
     934         *   ...
     935         * $(target)_$(propf2)
     936         */
    849937        if (!pVar)
    850             pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf);
    851 
    852         /* $(target)_$(type)$(propf2) */
    853         if (!pVar)
    854             pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf);
    855 
    856         /* $(target)_$(propf2).$(bld_trg).$(bld_trg_arch) */
    857         if (!pVar)
    858         {
    859             psz = psz2;
     938        {
     939            psz = psz1; /* rewind to '$(target)_' */
    860940            ADD_STR(pszPropF2, cchPropF2);
    861             psz3 = psz;
    862             ADD_CH('.');
    863             ADD_VAR(pBldTrg);
    864             psz4 = psz;
    865             ADD_CH('.');
    866             ADD_VAR(pBldTrgArch);
    867             pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf);
    868         }
    869 
    870         /* $(target)_$(propf2).$(bld_trg) */
    871         if (!pVar)
    872             pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf);
    873 
    874         /* $(target)_$(propf2) */
    875         if (!pVar)
    876             pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf);
    877     }
    878 
    879     /*
    880      * TOOL_$(tool)_$(type)$(propf2).$(bld_trg).$(bld_trg_arch)
     941            DO_VARIATIONS(1);
     942        }
     943    }
     944
     945    /*
     946     * TOOL_$(tool)_$(type)$(propf2).$(bld_trg).$(bld_trg_arch).$(bld_type)
     947     *   ...
     948     * TOOL_$(tool)_$(type)$(propf2)
    881949     */
    882950    if (!pVar && pTool)
     
    886954        ADD_VAR(pTool);
    887955        ADD_CH('_');
    888         psz2 = psz;
     956        psz1 = psz;
    889957        ADD_VAR(pType);
    890958        ADD_STR(pszPropF2, cchPropF2);
    891         psz3 = psz;
    892         ADD_CH('.');
    893         ADD_VAR(pBldTrg);
    894         psz4 = psz;
    895         ADD_CH('.');
    896         ADD_VAR(pBldTrgArch);
    897         pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf);
    898 
    899         /* TOOL_$(tool)_$(type)$(propf2).$(bld_trg) */
     959        DO_VARIATIONS(1);
     960
     961        /*
     962         * TOOL_$(tool)_$(propf2).$(bld_trg).$(bld_trg_arch).$(bld_type)  [omit $(type) prefix to $(propf2)]
     963         *   ...
     964         * TOOL_$(tool)_$(propf2)
     965         */
    900966        if (!pVar)
    901             pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf);
    902 
    903         /* TOOL_$(tool)_$(type)$(propf2) */
    904         if (!pVar)
    905             pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf);
    906 
    907         /* TOOL_$(tool)_$(propf2).$(bld_trg).$(bld_trg_arch) */
    908         if (!pVar)
    909         {
    910             psz = psz2;
     967        {
     968            psz = psz1; /* rewind to 'TOOL_$(tool)_' */
    911969            ADD_STR(pszPropF2, cchPropF2);
    912             psz3 = psz;
    913             ADD_CH('.');
    914             ADD_VAR(pBldTrg);
    915             psz4 = psz;
    916             ADD_CH('.');
    917             ADD_VAR(pBldTrgArch);
    918             pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf);
    919 
    920             /* TOOL_$(tool)_$(propf2).$(bld_trg) */
    921             if (!pVar)
    922                 pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf);
    923 
    924             /* TOOL_$(tool)_$(propf2) */
    925             if (!pVar)
    926                 pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf);
    927         }
    928     }
    929 
    930     /*
    931      * $(type)$(propf1).$(bld_trg).$(bld_trg_arch)
     970            DO_VARIATIONS(1);
     971        }
     972    }
     973
     974    /*
     975     * $(type)$(propf1).$(bld_trg).$(bld_trg_arch).$(bld_type)
     976     *   ...
     977     * $(type)$(propf1)
    932978     */
    933979    if (!pVar)
     
    936982        ADD_VAR(pType);
    937983        ADD_STR(pszPropF1, cchPropF1);
    938         psz3 = psz;
    939         ADD_CH('.');
    940         ADD_VAR(pBldTrg);
    941         psz4 = psz;
    942         ADD_CH('.');
    943         ADD_VAR(pBldTrgArch);
    944         pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf);
    945 
    946         /* $(type)$(propf1).$(bld_trg) */
    947         if (!pVar)
    948             pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf);
    949 
    950         /* $(type)$(propf1) */
    951         if (!pVar)
    952             pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf);
     984        DO_VARIATIONS(1);
    953985
    954986        /*
    955          * $(propf1).$(bld_trg).$(bld_trg_arch)
     987         * $(propf1).$(bld_trg).$(bld_trg_arch).$(bld_type)
     988         *   ...
     989         * $(propf1)
    956990         */
    957991        if (!pVar)
    958992        {
    959             psz1 = pszBuf + pType->value_length;
    960             pVar = kbuild_lookup_variable_n(psz1, psz - psz1);
    961 
    962             /* $(propf1).$(bld_trg) */
    963             if (!pVar)
    964                 pVar = kbuild_lookup_variable_n(psz1, psz4 - psz1);
    965 
    966             /* $(propf1) */
    967             if (!pVar)
    968                 pVar = kbuild_lookup_variable_n(pszPropF1, cchPropF1);
    969         }
    970     }
    971     free(pszBuf);
    972 #undef ADD_VAR
    973 #undef ADD_STR
    974 #undef ADD_CSTR
    975 #undef ADD_CH
    976 
     993            psz = pszBuf;
     994            ADD_STR(pszPropF1, cchPropF1);
     995            DO_VARIATIONS(1);
     996        }
     997    }
     998
     999    /*
     1000     * Done!
     1001     */
    9771002    if (pVar)
    9781003    {
     
    9911016                                      1 /* duplicate */, o_local, 0 /* !recursive */);
    9921017            *pszEnd = chSaved;
    993             if (pVar)
    994                 return pVar;
    995         }
    996     }
    997     return NULL;
     1018        }
     1019        else
     1020            pVar = NULL;
     1021    }
     1022
     1023    /* Cache the result if needed. */
     1024    if (fCacheIt)
     1025    {
     1026        psz = pszBuf;
     1027        ADD_VAR(pTarget);
     1028        ADD_STR("_2_", 3);
     1029        ADD_VAR(pType);
     1030        ADD_STR(pszPropF2, cchPropF2);
     1031        define_variable_vl_global(pszBuf, psz - pszBuf, pVar ? pVar->value : "", pVar ? pVar->value_length : 0,
     1032                                  1 /* duplicate */, o_file, 0 /* !recursive */, NILF);
     1033    }
     1034
     1035#undef ADD_VAR
     1036#undef ADD_STR
     1037#undef ADD_CSTR
     1038#undef ADD_CH
     1039    free(pszBuf);
     1040    return pVar;
    9981041}
    9991042
    10001043
    10011044/*
     1045 *
    10021046_SOURCE_TOOL = $(strip $(firstword \
    10031047    $($(target)_$(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
     
    10191063    $($(target)_TOOL.$(bld_trg)) \
    10201064    $($(target)_TOOL) \
     1065    \ - the rest depends on pBldType, see _TARGET_TOOL and kbuild_first_prop.
    10211066    $($(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
    10221067    $($(type)TOOL.$(bld_trg)) \
     
    10281073static struct variable *
    10291074kbuild_get_source_tool(struct variable *pTarget, struct variable *pSource, struct variable *pType,
    1030                        struct variable *pBldTrg, struct variable *pBldTrgArch, const char *pszVarName)
    1031 {
    1032     struct variable *pVar = kbuild_first_prop(pTarget, pSource, NULL, pType, pBldTrg, pBldTrgArch,
     1075                       struct variable *pBldTrg, struct variable *pBldTrgArch, struct variable *pBldType,
     1076                       const char *pszVarName)
     1077{
     1078    struct variable *pVar = kbuild_first_prop(pTarget, pSource, NULL, pType, pBldTrg, pBldTrgArch, pBldType,
    10331079                                              "TOOL", sizeof("TOOL") - 1,
    10341080                                              "TOOL", sizeof("TOOL") - 1,
    1035                                               pszVarName);
     1081                                              0 /*fExtendedSource*/, pszVarName);
    10361082    if (!pVar)
    10371083        OSS(fatal, NILF, _("no tool for source `%s' in target `%s'!"), pSource->value, pTarget->value);
     
    10401086
    10411087
    1042 /* Implements _SOURCE_TOOL. */
     1088/**
     1089 * Helper for func_kbuild_source_tool, func_kbuild_source_one, ++.
     1090 */
     1091static int kbuild_version_to_int(const char *pszVersion, int fStrict)
     1092{
     1093    int iVer = 0;
     1094    if (pszVersion && pszVersion[0])
     1095    {
     1096        switch (pszVersion[0] | (pszVersion[1] << 8))
     1097        {
     1098            case '2': iVer = 2; break;
     1099            case '3': iVer = 3; break;
     1100            case '4': iVer = 4; break;
     1101            case '5': iVer = 5; break;
     1102            case '6': iVer = 6; break;
     1103            case '7': iVer = 7; break;
     1104            case '8': iVer = 8; break;
     1105            case '9': iVer = 9; break;
     1106            case '0': iVer = 0; break;
     1107            case '1': iVer = 1; break;
     1108            default:
     1109                while (ISBLANK(*pszVersion))
     1110                    pszVersion++;
     1111                if (*pszVersion)
     1112                {
     1113                    char *pszEnd = NULL;
     1114                    long lVer;
     1115                    errno = 0;
     1116                    lVer = strtol(pszVersion, &pszEnd, 10);
     1117                    iVer = (int)lVer;
     1118                    if (fStrict)
     1119                    {
     1120                        if (lVer == 0 && errno != 0)
     1121                            OSN(fatal, NILF, _("invalid version argument '%s': errno=%d"), pszVersion, errno);
     1122                        else if (iVer != (int)lVer || iVer < 0)
     1123                            OS(fatal, NILF, _("version argument out of range '%s'"), pszVersion);
     1124                        else if (pszEnd)
     1125                        {
     1126                            while (ISBLANK(*pszEnd))
     1127                                pszEnd++;
     1128                            if (*pszEnd)
     1129                                OS(fatal, NILF, _("version is not numerical '%s'"), pszVersion);
     1130                        }
     1131                    }
     1132                }
     1133                break;
     1134        }
     1135    }
     1136    return iVer;
     1137}
     1138
     1139
     1140/**
     1141 * "kb-src-tool <varname> [ver=0]" - implements _SOURCE_TOOL.
     1142 *
     1143 * Since r3415 an extended set of keyword variations is used on the target, tool
     1144 * and global properties.
     1145 */
    10431146char *
    10441147func_kbuild_source_tool(char *o, char **argv, const char *pszFuncName)
    10451148{
     1149    const int        iVer = kbuild_version_to_int(argv[1], 1 /*strict*/);
    10461150    struct variable *pVar = kbuild_get_source_tool(kbuild_get_variable_n(ST("target")),
    10471151                                                   kbuild_get_variable_n(ST("source")),
     
    10491153                                                   kbuild_get_variable_n(ST("bld_trg")),
    10501154                                                   kbuild_get_variable_n(ST("bld_trg_arch")),
     1155                                                   kbuild_get_variable_n(ST("bld_type")),
    10511156                                                   argv[0]);
    10521157    if (pVar)
    10531158         o = variable_buffer_output(o, pVar->value, pVar->value_length);
    1054     (void)pszFuncName;
     1159    (void)pszFuncName; (void)iVer;
    10551160    return o;
    1056 
    1057 }
    1058 
    1059 
    1060 /* This has been extended a bit, it's now identical to _SOURCE_TOOL.
    1061 $(firstword \
    1062         $($(target)_$(source)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
    1063         $($(target)_$(source)_OBJSUFF.$(bld_trg))\
    1064         $($(target)_$(source)_OBJSUFF)\
    1065         $($(source)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
    1066         $($(source)_OBJSUFF.$(bld_trg))\
    1067         $($(source)_OBJSUFF)\
    1068         $($(target)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
    1069         $($(target)_OBJSUFF.$(bld_trg))\
    1070         $($(target)_OBJSUFF)\
    1071         $(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg).$(bld_trg_arch))\
    1072         $(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg))\
    1073         $(TOOL_$(tool)_$(type)OBJSUFF)\
    1074         $(SUFF_OBJ))
    1075 */
     1161}
     1162
     1163
     1164/**
     1165 * Similar to _TARGET_TOOL since r3415.
     1166 */
    10761167static struct variable *
    10771168kbuild_get_object_suffix(struct variable *pTarget, struct variable *pSource,
    10781169                         struct variable *pTool, struct variable *pType,
    1079                          struct variable *pBldTrg, struct variable *pBldTrgArch, const char *pszVarName)
    1080 {
    1081     struct variable *pVar = kbuild_first_prop(pTarget, pSource, pTool, pType, pBldTrg, pBldTrgArch,
     1170                         struct variable *pBldTrg, struct variable *pBldTrgArch, struct variable *pBldType,
     1171                         const char *pszVarName)
     1172{
     1173    struct variable *pVar = kbuild_first_prop(pTarget, pSource, pTool, pType, pBldTrg, pBldTrgArch, pBldType,
    10821174                                              "SUFF_OBJ", sizeof("SUFF_OBJ") - 1,
    10831175                                              "OBJSUFF",  sizeof("OBJSUFF")  - 1,
    1084                                               pszVarName);
     1176                                              0 /*fExtendedSource*/, pszVarName);
    10851177    if (!pVar)
    10861178        OSS(fatal, NILF, _("no OBJSUFF attribute or SUFF_OBJ default for source `%s' in target `%s'!"),
     
    10901182
    10911183
    1092 /*  */
     1184/**
     1185 * "kb-obj-suff <varname> [ver=0]"
     1186 *
     1187 * Since r3415 an extended set of keyword variations is used on the target, tool
     1188 * and global properties.
     1189 */
    10931190char *
    10941191func_kbuild_object_suffix(char *o, char **argv, const char *pszFuncName)
    10951192{
     1193    const int        iVer = kbuild_version_to_int(argv[1], 1 /*strict*/);
    10961194    struct variable *pVar = kbuild_get_object_suffix(kbuild_get_variable_n(ST("target")),
    10971195                                                     kbuild_get_variable_n(ST("source")),
     
    11001198                                                     kbuild_get_variable_n(ST("bld_trg")),
    11011199                                                     kbuild_get_variable_n(ST("bld_trg_arch")),
     1200                                                     kbuild_get_variable_n(ST("bld_type")),
    11021201                                                     argv[0]);
    11031202    if (pVar)
    11041203         o = variable_buffer_output(o, pVar->value, pVar->value_length);
    1105     (void)pszFuncName;
     1204    (void)pszFuncName; (void)iVer;
    11061205    return o;
    11071206
     
    12571356
    12581357
    1259 /* Implements _OBJECT_BASE. */
     1358/**
     1359 * "kb-obj-base <var> [ver]" Implements _OBJECT_BASE.
     1360 */
    12601361char *
    12611362func_kbuild_object_base(char *o, char **argv, const char *pszFuncName)
    12621363{
     1364    const int        iVer = kbuild_version_to_int(argv[1], 1 /*strict*/);
    12631365    struct variable *pVar = kbuild_get_object_base(kbuild_lookup_variable("target"),
    12641366                                                   kbuild_lookup_variable("source"),
     
    12661368    if (pVar)
    12671369         o = variable_buffer_output(o, pVar->value, pVar->value_length);
    1268     (void)pszFuncName;
     1370    (void)pszFuncName; (void)iVer;
    12691371    return o;
    1270 
    12711372}
    12721373
     
    16981799    DO_DOUBLE_PSZ2_VARIATION();
    16991800
    1700 
    17011801    /* the target sdks. */
     1802/** @todo these can be cached in a type specific _2_ variable   */
    17021803    iSdkEnd = iDirection == 1 ? pSdks->iTarget + pSdks->cTarget : pSdks->iTarget - 1;
    17031804    for (iSdk = iDirection == 1 ? pSdks->iTarget : pSdks->iTarget + pSdks->cTarget - 1;
     
    17131814    }
    17141815
     1816
    17151817    /* the target. */
     1818/** @todo these can be cached in a type specific _2_ variable   */
    17161819    psz = pszBuf;
    17171820    ADD_VAR(pTarget);
     
    18201923
    18211924
    1822 /* get a source property. */
     1925/* "kb-src-prop <prop> <var> <dir> [defpath] [ver]"
     1926   get a source property. */
    18231927char *
    18241928func_kbuild_source_prop(char *o, char **argv, const char *pszFuncName)
     
    18351939    struct variable *pVar;
    18361940    struct kbuild_sdks Sdks;
     1941    int iVer = 0;
    18371942    int iDirection;
    18381943    if (!strcmp(argv[2], "left-to-right"))
     
    18491954        if (*psz)
    18501955            pDefPath = kbuild_get_variable_n(ST("defpath"));
     1956        if (argv[4])
     1957            iVer = kbuild_version_to_int(argv[4], 1 /*strict*/);
    18511958    }
    18521959
     
    18631970
    18641971    kbuild_put_sdks(&Sdks);
    1865     (void)pszFuncName;
     1972    (void)pszFuncName; (void)iVer;
    18661973    return o;
    18671974}
     
    19712078
    19722079
    1973 /* setup the base variables for def_target_source_c_cpp_asm_new:
     2080/**
     2081 *
     2082 *
     2083 * Setup the base variables for def_target_source_c_cpp_asm_new:
     2084 * @code
    19742085
    19752086X := $(kb-src-tool tool)
     
    19862097dirdep  := $(call DIRDEP,$(dir $(outbase)))
    19872098dep     := $(obj)$(SUFF_DEP)
    1988 */
     2099 * @endcode
     2100 *
     2101 * argv[0] is the function version. Prior to r1792 (early 0.1.5) this
     2102 * was undefined and footer.kmk always passed an empty string.
     2103 *
     2104 * Version 2, as implemented in r1797, will make use of the async
     2105 * includedep queue feature. This means the files will be read by one or
     2106 * more background threads, leaving the eval'ing to be done later on by
     2107 * the main thread (in snap_deps).
     2108 *
     2109 * Version 3, as implemented in rXXXX, will check
     2110 * TOOL_$(tool)_COMPILE_$(type)_USES_KOBJCACHE and use
     2111 * def_target_source_rule_v3plus_objcache if it's non-empty or
     2112 * def_target_source_rule_v3plus if it's empty (version 2 and older will use
     2113 * def_target_source_rule).  Version 3 will also skip defining several
     2114 * properties that it considers legacy (todo: which).
     2115 *
     2116 * Version 4, as implemented in r3415, will use the extended tool resolution at
     2117 * the target level (not source) as implemented by the _TARGET_TOOL update in
     2118 * r2433.
     2119 *
     2120 * With r3415 the $(target)_2_$(type)TOOL will be used for caching purposes
     2121 * regardless of version.
     2122 */
    19892123char *
    19902124func_kbuild_source_one(char *o, char **argv, const char *pszFuncName)
     
    19992133    struct variable *pBldTrgArch= kbuild_get_variable_n(ST("bld_trg_arch"));
    20002134    struct variable *pBldTrgCpu = kbuild_get_variable_n(ST("bld_trg_cpu"));
    2001     struct variable *pTool      = kbuild_get_source_tool(pTarget, pSource, pType, pBldTrg, pBldTrgArch, "tool");
     2135    const int        iVer       = kbuild_version_to_int(argv[0], 0 /*strict*/);
     2136    struct variable *pTool      = kbuild_get_source_tool(pTarget, pSource, pType, pBldTrg, pBldTrgArch,
     2137                                                         iVer >= 4 ? pBldType : NULL, "tool");
    20022138    struct variable *pOutBase   = kbuild_get_object_base(pTarget, pSource, "outbase");
    2003     struct variable *pObjSuff   = kbuild_get_object_suffix(pTarget, pSource, pTool, pType, pBldTrg, pBldTrgArch, "objsuff");
     2139    struct variable *pObjSuff   = kbuild_get_object_suffix(pTarget, pSource, pTool, pType, pBldTrg, pBldTrgArch,
     2140                                                           iVer >= 4 ? pBldType : NULL, "objsuff");
    20042141    struct variable *pDeps, *pOrderDeps, *pDirDep, *pDep, *pVar, *pOutput, *pOutputMaybe;
    20052142#if 0 /* not used */
     
    20132150    size_t cch;
    20142151    struct kbuild_sdks Sdks;
    2015     int iVer;
    2016 
    2017     /*
    2018      * argv[0] is the function version. Prior to r1792 (early 0.1.5) this
    2019      * was undefined and footer.kmk always passed an empty string.
    2020      *
    2021      * Version 2, as implemented in r1797, will make use of the async
    2022      * includedep queue feature. This means the files will be read by one or
    2023      * more background threads, leaving the eval'ing to be done later on by
    2024      * the main thread (in snap_deps).
    2025      */
    2026     if (!argv[0][0])
    2027         iVer = 0;
    2028     else
    2029         switch (argv[0][0] | (argv[0][1] << 8))
    2030         {
    2031             case '2': iVer = 2; break;
    2032             case '3': iVer = 3; break;
    2033             case '4': iVer = 4; break;
    2034             case '5': iVer = 5; break;
    2035             case '6': iVer = 6; break;
    2036             case '7': iVer = 7; break;
    2037             case '8': iVer = 8; break;
    2038             case '9': iVer = 9; break;
    2039             case '0': iVer = 0; break;
    2040             case '1': iVer = 1; break;
    2041             default:
    2042                 iVer = 0;
    2043                 psz = argv[0];
    2044                 while (ISBLANK(*psz))
    2045                     psz++;
    2046                 if (*psz)
    2047                     iVer = atoi(psz);
    2048                 break;
    2049         }
    20502152
    20512153    /*
     
    20592161
    20602162    /*pDefs  =*/ kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, NULL,
    2061                                             ST("DEFS"),  ST("defs"), 1/* left-to-right */);
     2163                                            ST("DEFS"),      ST("defs"),      1 /* left-to-right */);
    20622164    /*pIncs  =*/ kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, pDefPath,
    2063                                             ST("INCS"),  ST("incs"), -1/* right-to-left */);
     2165                                            ST("INCS"),      ST("incs"),     -1 /* right-to-left */);
    20642166    /*pFlags =*/ kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, NULL,
    2065                                             ST("FLAGS"), ST("flags"), 1/* left-to-right */);
     2167                                            ST("FLAGS"),     ST("flags"),     1 /* left-to-right */);
    20662168    pDeps      = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, pDefPath,
    2067                                             ST("DEPS"),  ST("deps"), 1/* left-to-right */);
     2169                                            ST("DEPS"),      ST("deps"),      1 /* left-to-right */);
    20682170    pOrderDeps = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, pDefPath,
    2069                                             ST("ORDERDEPS"), ST("orderdeps"), 1/* left-to-right */);
     2171                                            ST("ORDERDEPS"), ST("orderdeps"), 1 /* left-to-right */);
    20702172
    20712173    /*
Note: See TracChangeset for help on using the changeset viewer.