Changeset 1922 in kBuild
- Timestamp:
- Oct 24, 2008 2:10:58 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kbuild.c
r1834 r1922 48 48 #include <assert.h> 49 49 #include <stdarg.h> 50 51 52 /******************************************************************************* 53 * Defined Constants And Macros * 54 *******************************************************************************/ 50 55 #ifndef va_copy 51 56 # define va_copy(dst, src) do {(dst) = (src);} while (0) 52 57 #endif 53 58 59 /** Helper for passing a string constant to kbuild_get_variable_n. */ 60 #define ST(strconst) strconst, sizeof(strconst) - 1 61 62 #if 1 63 # define my_memcpy(dst, src, len) \ 64 do { \ 65 if (len > 8) \ 66 memcpy(dst, src, len); \ 67 else \ 68 switch (len) \ 69 { \ 70 case 8: dst[7] = src[7]; \ 71 case 7: dst[6] = src[6]; \ 72 case 6: dst[5] = src[5]; \ 73 case 5: dst[4] = src[4]; \ 74 case 4: dst[3] = src[3]; \ 75 case 3: dst[2] = src[2]; \ 76 case 2: dst[1] = src[1]; \ 77 case 1: dst[0] = src[0]; \ 78 case 0: break; \ 79 } \ 80 } while (0) 81 #elif defined(__GNUC__) 82 # define my_memcpy __builtin_memcpy 83 #elif defined(_MSC_VER) 84 # pragma instrinic(memcpy) 85 # define my_memcpy memcpy 86 #endif 54 87 55 88 … … 638 671 639 672 640 /** Same as kbuild_lookup_variable except that a '%s' in the name string641 * will be substituted with the values of the variables in the va list. */642 struct variable *643 kbuild_lookup_variable_fmt_va(struct variable *pDefPath, size_t cchName, const char *pszNameFmt, va_list va)644 {645 va_list va2;646 const char *pszFmt;647 char *pszName;648 char *psz;649 char ch;650 651 /* first pass, calc value name size and allocate stack buffer. */652 va_copy(va2, va);653 654 pszFmt = pszNameFmt;655 while (*pszFmt != '%')656 pszFmt++;657 for (;;)658 {659 struct variable *pVar = va_arg(va, struct variable *);660 if (pVar)661 cchName += pVar->value_length;662 ch = *++pszFmt;663 if (ch != '%')664 {665 if (!ch)666 break;667 pszFmt++;668 }669 assert(*pszFmt == '%');670 };671 pszName = alloca(cchName + 1);672 673 /* second pass format it. */674 pszFmt = pszNameFmt;675 psz = pszName;676 while (*pszFmt != '%')677 *psz++ = *pszFmt++;678 679 for (;;)680 {681 struct variable *pVar = va_arg(va2, struct variable *);682 if (pVar)683 {684 memcpy(psz, pVar->value, pVar->value_length);685 psz += pVar->value_length;686 }687 ch = *++pszFmt;688 if (ch != '%')689 {690 *psz++ = ch;691 if (!ch)692 break;693 pszFmt++;694 }695 }696 va_end(va2);697 698 if (pDefPath)699 return kbuild_lookup_variable_defpath_n(pDefPath, pszName, psz - pszName - 1);700 return kbuild_lookup_variable_n(pszName, psz - pszName - 1);701 }702 703 704 /** Helper for passing a string constant to kbuild_lookup_variable_fmt or705 * kbuild_lookup_variable_NN. */706 #define ST(strconst) strconst, sizeof(strconst) - 1707 /** Helper for passing a variable to kbuild_lookup_variable_NN. */708 #define VT(var) (var)->value_length, (var)->value709 710 711 /** Same as kbuild_lookup_variable except that a '%s' in the name string712 * will be substituted with the values of the variables in the ellipsis. */713 MY_INLINE struct variable *714 kbuild_lookup_variable_fmt(struct variable *pDefPath, const char *pszNameFmt, size_t cchNameFmt, ...)715 {716 struct variable *pVar;717 va_list va;718 va_start(va, cchNameFmt);719 pVar = kbuild_lookup_variable_fmt_va(pDefPath, cchNameFmt, pszNameFmt, va);720 va_end(va);721 return pVar;722 }723 724 725 673 /** 726 674 * Gets the first defined property variable. … … 750 698 pszBuf = xmalloc(cchBuf); 751 699 752 #if 1753 # define my_memcpy(dst, src, len) \754 do { \755 if (len > 4) \756 memcpy(dst, src, len); \757 else \758 switch (len) \759 { \760 case 8: dst[7] = src[7]; \761 case 7: dst[6] = src[6]; \762 case 6: dst[5] = src[5]; \763 case 5: dst[4] = src[4]; \764 case 4: dst[3] = src[3]; \765 case 3: dst[2] = src[2]; \766 case 2: dst[1] = src[1]; \767 case 1: dst[0] = src[0]; \768 case 0: break; \769 } \770 } while (0)771 #elif defined(__GNUC__)772 # define my_memcpy __builtin_memcpy773 #elif defined(_MSC_VER)774 # pragma instrinic(memcpy)775 # define my_memcpy memcpy776 #endif777 700 #define ADD_VAR(pVar) do { my_memcpy(psz, (pVar)->value, (pVar)->value_length); psz += (pVar)->value_length; } while (0) 778 701 #define ADD_STR(pszStr, cchStr) do { my_memcpy(psz, (pszStr), (cchStr)); psz += (cchStr); } while (0) … … 1342 1265 unsigned iTargetSource; 1343 1266 unsigned cTargetSource; 1267 unsigned int cchMax; 1344 1268 }; 1345 1269 … … 1358 1282 const char *pszIterator; 1359 1283 1284 /** @todo rewrite this to avoid sprintf and allocated_varaible_expand_2. */ 1285 1360 1286 /* basic init. */ 1287 pSdks->cchMax = 0; 1361 1288 pSdks->pa = NULL; 1362 1289 pSdks->c = 0; … … 1451 1378 /* terminate them (find_next_token won't work if we terminate them in the previous loop). */ 1452 1379 while (i-- > 0) 1380 { 1453 1381 pSdks->pa[i].value[pSdks->pa[i].value_length] = '\0'; 1382 1383 /* calc the max variable length too. */ 1384 if (pSdks->cchMax < (unsigned int)pSdks->pa[i].value_length) 1385 pSdks->cchMax = pSdks->pa[i].value_length; 1386 } 1454 1387 } 1455 1388 … … 1603 1536 unsigned iSdk, iSdkEnd; 1604 1537 int cVars, iVar, iVarEnd; 1605 size_t cchTotal ;1606 char *pszResult, *psz ;1538 size_t cchTotal, cchBuf; 1539 char *pszResult, *pszBuf, *psz, *psz2, *psz3; 1607 1540 struct 1608 1541 { … … 1612 1545 } *paVars; 1613 1546 1614 struct variable Prop = {0};1615 Prop.value = (char *)pszProp;1616 Prop.value_length = cchProp;1617 1618 1547 assert(iDirection == 1 || iDirection == -1); 1548 1549 /* 1550 * Calc and allocate a too big name buffer. 1551 */ 1552 cchBuf = cchProp + 1 1553 + pTarget->value_length + 1 1554 + pSource->value_length + 1 1555 + pSdks->cchMax + 1 1556 + (pTool ? pTool->value_length + 1 : 0) 1557 + pType->value_length + 1 1558 + pBldTrg->value_length + 1 1559 + pBldTrgArch->value_length + 1 1560 + pBldTrgCpu->value_length + 1 1561 + pBldType->value_length + 1; 1562 pszBuf = xmalloc(cchBuf); 1619 1563 1620 1564 /* … … 1625 1569 1626 1570 iVar = 0; 1627 /* the tool (lowest priority) */ 1628 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%"), pTool, &Prop); 1629 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%.%"), pTool, &Prop, pBldType); 1630 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%.%"), pTool, &Prop, pBldTrg); 1631 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%.%"), pTool, &Prop, pBldTrgArch); 1632 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%.%.%"), pTool, &Prop, pBldTrg, pBldTrgArch); 1633 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%.%"), pTool, &Prop, pBldTrgCpu); 1634 1635 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%%"), pTool, pType, &Prop); 1636 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%%.%"), pTool, pType, &Prop, pBldType); 1637 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%%.%"), pTool, pType, &Prop, pBldTrg); 1638 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%%.%"), pTool, pType, &Prop, pBldTrgArch); 1639 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%%.%.%"), pTool, pType, &Prop, pBldTrg, pBldTrgArch); 1640 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%%.%"), pTool, pType, &Prop, pBldTrgCpu); 1641 1642 /* the global sdks */ 1571 1572 #define ADD_VAR(pVar) do { my_memcpy(psz, (pVar)->value, (pVar)->value_length); psz += (pVar)->value_length; } while (0) 1573 #define ADD_STR(pszStr, cchStr) do { my_memcpy(psz, (pszStr), (cchStr)); psz += (cchStr); } while (0) 1574 #define ADD_CSTR(pszStr) do { my_memcpy(psz, pszStr, sizeof(pszStr) - 1); psz += sizeof(pszStr) - 1; } while (0) 1575 #define ADD_CH(ch) do { *psz++ = (ch); } while (0) 1576 # define DO_VAR_LOOKUP() \ 1577 do { \ 1578 pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf); \ 1579 /*if (pVar)*/ \ 1580 paVars[iVar++].pVar = pVar; \ 1581 } while (0) 1582 #define DO_SINGLE_PSZ3_VARIATION() \ 1583 do { \ 1584 DO_VAR_LOOKUP(); \ 1585 \ 1586 ADD_CH('.'); \ 1587 psz3 = psz; \ 1588 ADD_VAR(pBldType); \ 1589 DO_VAR_LOOKUP(); \ 1590 \ 1591 psz = psz3; \ 1592 ADD_VAR(pBldTrg); \ 1593 DO_VAR_LOOKUP(); \ 1594 \ 1595 psz = psz3; \ 1596 ADD_VAR(pBldTrgArch); \ 1597 DO_VAR_LOOKUP(); \ 1598 \ 1599 psz = psz3; \ 1600 ADD_VAR(pBldTrg); \ 1601 ADD_CH('.'); \ 1602 ADD_VAR(pBldTrgArch); \ 1603 DO_VAR_LOOKUP(); \ 1604 \ 1605 psz = psz3; \ 1606 ADD_VAR(pBldTrgCpu); \ 1607 DO_VAR_LOOKUP(); \ 1608 } while (0) 1609 1610 #define DO_DOUBLE_PSZ2_VARIATION() \ 1611 do { \ 1612 psz2 = psz; \ 1613 ADD_STR(pszProp, cchProp); \ 1614 DO_SINGLE_PSZ3_VARIATION(); \ 1615 \ 1616 /* add prop before type */ \ 1617 psz = psz2; \ 1618 ADD_VAR(pType); \ 1619 ADD_STR(pszProp, cchProp); \ 1620 DO_SINGLE_PSZ3_VARIATION(); \ 1621 } while (0) 1622 1623 /* the tool (lowest priority). */ 1624 psz = pszBuf; 1625 ADD_CSTR("TOOL_"); 1626 ADD_VAR(pTool); 1627 ADD_CH('_'); 1628 DO_DOUBLE_PSZ2_VARIATION(); 1629 1630 1631 /* the global sdks. */ 1643 1632 iSdkEnd = iDirection == 1 ? pSdks->iGlobal + pSdks->cGlobal : pSdks->iGlobal - 1; 1644 1633 for (iSdk = iDirection == 1 ? pSdks->iGlobal : pSdks->iGlobal + pSdks->cGlobal - 1; … … 1647 1636 { 1648 1637 struct variable *pSdk = &pSdks->pa[iSdk]; 1649 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%"), pSdk, &Prop); 1650 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldType); 1651 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldTrg); 1652 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldTrgArch); 1653 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%.%"), pSdk, &Prop, pBldTrg, pBldTrgArch); 1654 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldTrgCpu); 1655 1656 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%"), pSdk, pType, &Prop); 1657 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldType); 1658 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldTrg); 1659 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldTrgArch); 1660 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%.%"), pSdk, pType, &Prop, pBldTrg, pBldTrgArch); 1661 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldTrgCpu); 1662 } 1663 1664 /* the globals */ 1665 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("%"), &Prop); 1666 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("%.%"), &Prop, pBldType); 1667 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("%.%"), &Prop, pBldTrg); 1668 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("%.%"), &Prop, pBldTrgArch); 1669 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("%.%.%"), &Prop, pBldTrg, pBldTrgArch); 1670 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("%.%"), &Prop, pBldTrgCpu); 1671 1672 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("%%"), pType, &Prop); 1673 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("%%.%"), pType, &Prop, pBldType); 1674 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("%%.%"), pType, &Prop, pBldTrg); 1675 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("%%.%"), pType, &Prop, pBldTrgArch); 1676 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("%%.%.%"), pType, &Prop, pBldTrg, pBldTrgArch); 1677 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("%%.%"), pType, &Prop, pBldTrgCpu); 1678 1679 /* the target sdks */ 1638 psz = pszBuf; 1639 ADD_CSTR("SDK_"); 1640 ADD_VAR(pSdk); 1641 ADD_CH('_'); 1642 DO_DOUBLE_PSZ2_VARIATION(); 1643 } 1644 1645 /* the globals. */ 1646 psz = pszBuf; 1647 DO_DOUBLE_PSZ2_VARIATION(); 1648 1649 1650 /* the target sdks. */ 1680 1651 iSdkEnd = iDirection == 1 ? pSdks->iTarget + pSdks->cTarget : pSdks->iTarget - 1; 1681 1652 for (iSdk = iDirection == 1 ? pSdks->iTarget : pSdks->iTarget + pSdks->cTarget - 1; … … 1684 1655 { 1685 1656 struct variable *pSdk = &pSdks->pa[iSdk]; 1686 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%"), pSdk, &Prop); 1687 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldType); 1688 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldTrg); 1689 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldTrgArch); 1690 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%.%"), pSdk, &Prop, pBldTrg, pBldTrgArch); 1691 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldTrgCpu); 1692 1693 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%"), pSdk, pType, &Prop); 1694 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldType); 1695 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldTrg); 1696 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldTrgArch); 1697 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%.%"), pSdk, pType, &Prop, pBldTrg, pBldTrgArch); 1698 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldTrgCpu); 1699 } 1700 1701 /* the target */ 1702 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%"), pTarget, &Prop); 1703 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%.%"), pTarget, &Prop, pBldType); 1704 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%.%"), pTarget, &Prop, pBldTrg); 1705 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%.%"), pTarget, &Prop, pBldTrgArch); 1706 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%.%.%"), pTarget, &Prop, pBldTrg, pBldTrgArch); 1707 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%.%"), pTarget, &Prop, pBldTrgCpu); 1708 1709 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%%"), pTarget, pType, &Prop); 1710 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%%.%"), pTarget, pType, &Prop, pBldType); 1711 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%%.%"), pTarget, pType, &Prop, pBldTrg); 1712 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%%.%"), pTarget, pType, &Prop, pBldTrgArch); 1713 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%%.%.%"), pTarget, pType, &Prop, pBldTrg, pBldTrgArch); 1714 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%%.%"), pTarget, pType, &Prop, pBldTrgCpu); 1715 1716 /* the source sdks */ 1657 psz = pszBuf; 1658 ADD_CSTR("SDK_"); 1659 ADD_VAR(pSdk); 1660 ADD_CH('_'); 1661 DO_DOUBLE_PSZ2_VARIATION(); 1662 } 1663 1664 /* the target. */ 1665 psz = pszBuf; 1666 ADD_VAR(pTarget); 1667 ADD_CH('_'); 1668 DO_DOUBLE_PSZ2_VARIATION(); 1669 1670 /* the source sdks. */ 1717 1671 iSdkEnd = iDirection == 1 ? pSdks->iSource + pSdks->cSource : pSdks->iSource - 1; 1718 1672 for (iSdk = iDirection == 1 ? pSdks->iSource : pSdks->iSource + pSdks->cSource - 1; … … 1721 1675 { 1722 1676 struct variable *pSdk = &pSdks->pa[iSdk]; 1723 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%"), pSdk, &Prop); 1724 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldType); 1725 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldTrg); 1726 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldTrgArch); 1727 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%.%"), pSdk, &Prop, pBldTrg, pBldTrgArch); 1728 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldTrgCpu); 1729 1730 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%"), pSdk, pType, &Prop); 1731 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldType); 1732 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldTrg); 1733 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldTrgArch); 1734 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%.%"), pSdk, pType, &Prop, pBldTrg, pBldTrgArch); 1735 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldTrgCpu); 1736 } 1737 1738 /* the source */ 1739 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%"), pSource, &Prop); 1740 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%.%"), pSource, &Prop, pBldType); 1741 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%.%"), pSource, &Prop, pBldTrg); 1742 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%.%"), pSource, &Prop, pBldTrgArch); 1743 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%.%.%"), pSource, &Prop, pBldTrg, pBldTrgArch); 1744 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%.%"), pSource, &Prop, pBldTrgCpu); 1745 1746 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%%"), pSource, pType, &Prop); 1747 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%%.%"), pSource, pType, &Prop, pBldType); 1748 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%%.%"), pSource, pType, &Prop, pBldTrg); 1749 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%%.%"), pSource, pType, &Prop, pBldTrgArch); 1750 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%%.%.%"), pSource, pType, &Prop, pBldTrg, pBldTrgArch); 1751 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%%.%"), pSource, pType, &Prop, pBldTrgCpu); 1752 1753 1754 /* the target + source sdks */ 1677 psz = pszBuf; 1678 ADD_CSTR("SDK_"); 1679 ADD_VAR(pSdk); 1680 ADD_CH('_'); 1681 DO_DOUBLE_PSZ2_VARIATION(); 1682 } 1683 1684 /* the source. */ 1685 psz = pszBuf; 1686 ADD_VAR(pSource); 1687 ADD_CH('_'); 1688 DO_DOUBLE_PSZ2_VARIATION(); 1689 1690 /* the target + source sdks. */ 1755 1691 iSdkEnd = iDirection == 1 ? pSdks->iTargetSource + pSdks->cTargetSource : pSdks->iTargetSource - 1; 1756 1692 for (iSdk = iDirection == 1 ? pSdks->iTargetSource : pSdks->iTargetSource + pSdks->cTargetSource - 1; … … 1759 1695 { 1760 1696 struct variable *pSdk = &pSdks->pa[iSdk]; 1761 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%"), pSdk, &Prop); 1762 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldType); 1763 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldTrg); 1764 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldTrgArch); 1765 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%.%"), pSdk, &Prop, pBldTrg, pBldTrgArch); 1766 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%.%"), pSdk, &Prop, pBldTrgCpu); 1767 1768 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%"), pSdk, pType, &Prop); 1769 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldType); 1770 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldTrg); 1771 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldTrgArch); 1772 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%.%"), pSdk, pType, &Prop, pBldTrg, pBldTrgArch); 1773 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(NULL, ST("SDK_%_%%.%"), pSdk, pType, &Prop, pBldTrgCpu); 1774 } 1775 1776 /* the target + source */ 1777 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%_%"), pTarget, pSource, &Prop); 1778 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%_%.%"), pTarget, pSource, &Prop, pBldType); 1779 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%_%.%"), pTarget, pSource, &Prop, pBldTrg); 1780 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%_%.%"), pTarget, pSource, &Prop, pBldTrgArch); 1781 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%_%.%.%"), pTarget, pSource, &Prop, pBldTrg, pBldTrgArch); 1782 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%_%.%"), pTarget, pSource, &Prop, pBldTrgCpu); 1783 1784 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%_%%"), pTarget, pSource, pType, &Prop); 1785 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%_%%.%"), pTarget, pSource, pType, &Prop, pBldType); 1786 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%_%%.%"), pTarget, pSource, pType, &Prop, pBldTrg); 1787 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%_%%.%"), pTarget, pSource, pType, &Prop, pBldTrgArch); 1788 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%_%%.%.%"), pTarget, pSource, pType, &Prop, pBldTrg, pBldTrgArch); 1789 paVars[iVar++].pVar = kbuild_lookup_variable_fmt(pDefPath, ST("%_%_%%.%"), pTarget, pSource, pType, &Prop, pBldTrgCpu); 1790 1791 assert(cVars == iVar); 1792 1793 /* 1794 * Expand the variables and calculate the total length. 1795 */ 1796 cchTotal = 0; 1797 iVarEnd = iDirection == 1 ? cVars : 0; 1798 for (iVar = iDirection == 1 ? 0 : cVars - 1; iVar != iVarEnd; iVar += iDirection) 1799 { 1800 paVars[iVar].cchExp = 0; 1801 if (!paVars[iVar].pVar) 1802 continue; 1803 if ( !paVars[iVar].pVar->recursive 1804 || !memchr(paVars[iVar].pVar->value, '$', paVars[iVar].pVar->value_length)) 1697 psz = pszBuf; 1698 ADD_CSTR("SDK_"); 1699 ADD_VAR(pSdk); 1700 ADD_CH('_'); 1701 DO_DOUBLE_PSZ2_VARIATION(); 1702 } 1703 1704 /* the target + source. */ 1705 psz = pszBuf; 1706 ADD_VAR(pTarget); 1707 ADD_CH('_'); 1708 ADD_VAR(pSource); 1709 ADD_CH('_'); 1710 DO_DOUBLE_PSZ2_VARIATION(); 1711 1712 free(pszBuf); 1713 1714 /*assert(iVar <= cVars); 1715 cVars = iVar;*/ 1716 assert(iVar == cVars); 1717 1718 if (!cVars) 1719 pVar = define_variable_vl(pszVarName, cchVarName, "", 0, 1720 1 /* duplicate value */ , o_local, 0 /* !recursive */); 1721 else 1722 { 1723 /* 1724 * Expand the variables and calculate the total length. 1725 */ 1726 cchTotal = 0; 1727 iVarEnd = iDirection == 1 ? cVars : 0; 1728 for (iVar = iDirection == 1 ? 0 : cVars - 1; iVar != iVarEnd; iVar += iDirection) 1805 1729 { 1806 paVars[iVar].pszExp = paVars[iVar].pVar->value; 1807 paVars[iVar].cchExp = paVars[iVar].pVar->value_length; 1730 if (!paVars[iVar].pVar) 1731 { 1732 paVars[iVar].cchExp = 0; 1733 continue; 1734 } 1735 if ( !paVars[iVar].pVar->recursive 1736 || !memchr(paVars[iVar].pVar->value, '$', paVars[iVar].pVar->value_length)) 1737 { 1738 paVars[iVar].pszExp = paVars[iVar].pVar->value; 1739 paVars[iVar].cchExp = paVars[iVar].pVar->value_length; 1740 } 1741 else 1742 { 1743 unsigned int cchExp; 1744 paVars[iVar].pszExp = allocated_variable_expand_2(paVars[iVar].pVar->value, paVars[iVar].pVar->value_length, &cchExp); 1745 paVars[iVar].cchExp = cchExp; 1746 } 1747 if (pDefPath) 1748 kbuild_apply_defpath(pDefPath, &paVars[iVar].pszExp, &paVars[iVar].cchExp, NULL, 1749 paVars[iVar].pszExp != paVars[iVar].pVar->value); 1750 cchTotal += paVars[iVar].cchExp + 1; 1808 1751 } 1809 else 1752 1753 /* 1754 * Construct the result value. 1755 */ 1756 psz = pszResult = xmalloc(cchTotal + 1); 1757 iVarEnd = iDirection == 1 ? cVars : 0; 1758 for (iVar = iDirection == 1 ? 0 : cVars - 1; iVar != iVarEnd; iVar += iDirection) 1810 1759 { 1811 unsigned int cchExp; 1812 paVars[iVar].pszExp = allocated_variable_expand_2(paVars[iVar].pVar->value, paVars[iVar].pVar->value_length, &cchExp); 1813 paVars[iVar].cchExp = cchExp; 1760 if (!paVars[iVar].cchExp) 1761 continue; 1762 memcpy(psz, paVars[iVar].pszExp, paVars[iVar].cchExp); 1763 psz += paVars[iVar].cchExp; 1764 *psz++ = ' '; 1765 if (paVars[iVar].pszExp != paVars[iVar].pVar->value) 1766 free(paVars[iVar].pszExp); 1814 1767 } 1815 if (pDefPath) 1816 kbuild_apply_defpath(pDefPath, &paVars[iVar].pszExp, &paVars[iVar].cchExp, NULL, 1817 paVars[iVar].pszExp != paVars[iVar].pVar->value); 1818 cchTotal += paVars[iVar].cchExp + 1; 1819 } 1820 1821 /* 1822 * Construct the result value. 1823 */ 1824 psz = pszResult = xmalloc(cchTotal + 1); 1825 iVarEnd = iDirection == 1 ? cVars : 0; 1826 for (iVar = iDirection == 1 ? 0 : cVars - 1; iVar != iVarEnd; iVar += iDirection) 1827 { 1828 if (!paVars[iVar].cchExp) 1829 continue; 1830 memcpy(psz, paVars[iVar].pszExp, paVars[iVar].cchExp); 1831 psz += paVars[iVar].cchExp; 1832 *psz++ = ' '; 1833 if (paVars[iVar].pszExp != paVars[iVar].pVar->value) 1834 free(paVars[iVar].pszExp); 1835 } 1836 if (psz != pszResult) 1837 psz--; 1838 *psz = '\0'; 1839 cchTotal = psz - pszResult; 1840 1841 pVar = define_variable_vl(pszVarName, cchVarName, pszResult, cchTotal, 1842 0 /* take pszResult */ , o_local, 0 /* !recursive */); 1768 if (psz != pszResult) 1769 psz--; 1770 *psz = '\0'; 1771 cchTotal = psz - pszResult; 1772 pVar = define_variable_vl(pszVarName, cchVarName, pszResult, cchTotal, 1773 0 /* take pszResult */ , o_local, 0 /* !recursive */); 1774 } 1775 1843 1776 return pVar; 1777 1778 #undef ADD_VAR 1779 #undef ADD_STR 1780 #undef ADD_CSTR 1781 #undef ADD_CH 1782 #undef DO_VAR_LOOKUP 1783 #undef DO_DOUBLE_PSZ2_VARIATION 1784 #undef DO_SINGLE_PSZ3_VARIATION 1844 1785 } 1845 1786
Note:
See TracChangeset
for help on using the changeset viewer.