Changeset 1832 in kBuild for trunk/src/kmk
- Timestamp:
- Oct 11, 2008 3:10:54 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kbuild.c
r1831 r1832 51 51 # define va_copy(dst, src) do {(dst) = (src);} while (0) 52 52 #endif 53 #ifdef _MSC_VER 54 # define MY_INLINE _inline static 55 #elif defined(__GNUC__) 56 # define MY_INLINE static __inline__ 57 #else 58 # define MY_INLINE static 59 #endif 60 53 61 54 62 … … 418 426 } 419 427 420 428 /** 429 * Gets a variable that must exist. 430 * Will cause a fatal failure if the variable doesn't exist. 431 * 432 * @returns Pointer to the variable. 433 * @param pszName The variable name. 434 * @param cchName The name length. 435 */ 436 MY_INLINE struct variable * 437 kbuild_get_variable_n(const char *pszName, size_t cchName) 438 { 439 #ifndef NDEBUG 440 int i; 441 #endif 442 struct variable *pVar = lookup_variable(pszName, cchName); 443 if (!pVar) 444 fatal(NILF, _("variable `%.*s' isn't defined!"), (int)cchName, pszName); 445 if (pVar->recursive) 446 fatal(NILF, _("variable `%.*s' is defined as `recursive' instead of `simple'!"), (int)cchName, pszName); 447 #ifndef NDEBUG 448 i = strlen(pVar->value); 449 if (i != pVar->value_length) 450 { 451 printf("%d != %d %s\n", pVar->value_length, i, pVar->name); 452 # ifdef _MSC_VER 453 __debugbreak(); 454 # endif 455 assert(0); 456 } 457 #endif 458 return pVar; 459 } 460 461 462 #if 0 /* unused */ 421 463 /** 422 464 * Gets a variable that must exist. … … 429 471 kbuild_get_variable(const char *pszName) 430 472 { 431 #ifndef NDEBUG 432 int i; 433 #endif 434 struct variable *pVar = lookup_variable(pszName, strlen(pszName)); 435 if (!pVar) 436 fatal(NILF, _("variable `%s' isn't defined!"), pszName); 437 if (pVar->recursive) 438 fatal(NILF, _("variable `%s' is defined as `recursive' instead of `simple'!"), pszName); 439 #ifndef NDEBUG 440 i = strlen(pVar->value); 441 if (i != pVar->value_length) 442 { 443 printf("%d != %d %s\n", pVar->value_length, i, pVar->name); 444 # ifdef _MSC_VER 445 __debugbreak(); 446 # endif 447 assert(0); 448 } 449 #endif 450 return pVar; 451 } 473 return kbuild_get_variable_n(pszName, strlen(pszName)); 474 } 475 #endif 452 476 453 477 … … 543 567 * @returns Pointer to the variable. NULL if not found. 544 568 * @param pszName The variable name. 569 * @param cchName The name length. 545 570 */ 546 staticstruct variable *547 kbuild_lookup_variable (const char *pszName)548 { 549 struct variable *pVar = lookup_variable(pszName, strlen(pszName));571 MY_INLINE struct variable * 572 kbuild_lookup_variable_n(const char *pszName, size_t cchName) 573 { 574 struct variable *pVar = lookup_variable(pszName, cchName); 550 575 if (pVar) 551 576 { … … 570 595 571 596 /** 597 * Looks up a variable. 598 * The value_length field is valid upon successful return. 599 * 600 * @returns Pointer to the variable. NULL if not found. 601 * @param pszName The variable name. 602 */ 603 MY_INLINE struct variable * 604 kbuild_lookup_variable(const char *pszName) 605 { 606 return kbuild_lookup_variable_n(pszName, strlen(pszName)); 607 } 608 609 610 /** 611 * Looks up a variable and applies default a path to all relative paths. 612 * The value_length field is valid upon successful return. 613 * 614 * @returns Pointer to the variable. NULL if not found. 615 * @param pDefPath The default path. 616 * @param pszName The variable name. 617 * @param cchName The name length. 618 */ 619 MY_INLINE struct variable * 620 kbuild_lookup_variable_defpath_n(struct variable *pDefPath, const char *pszName, size_t cchName) 621 { 622 struct variable *pVar = kbuild_lookup_variable_n(pszName, cchName); 623 if (pVar && pDefPath) 624 kbuild_apply_defpath(pDefPath, &pVar->value, &pVar->value_length, &pVar->value_alloc_len, 1); 625 return pVar; 626 } 627 628 629 /** 572 630 * Looks up a variable and applies default a path to all relative paths. 573 631 * The value_length field is valid upon successful return. … … 577 635 * @param pszName The variable name. 578 636 */ 579 staticstruct variable *637 MY_INLINE struct variable * 580 638 kbuild_lookup_variable_defpath(struct variable *pDefPath, const char *pszName) 581 639 { … … 589 647 /** Same as kbuild_lookup_variable except that a '%s' in the name string 590 648 * will be substituted with the values of the variables in the va list. */ 591 st atic struct variable *649 struct variable * 592 650 kbuild_lookup_variable_fmt_va(struct variable *pDefPath, size_t cchName, const char *pszNameFmt, va_list va) 593 651 { … … 618 676 assert(*pszFmt == '%'); 619 677 }; 620 pszName = alloca(cchName );678 pszName = alloca(cchName + 1); 621 679 622 680 /* second pass format it. */ … … 646 704 647 705 if (pDefPath) 648 return kbuild_lookup_variable_defpath(pDefPath, pszName); 649 return kbuild_lookup_variable(pszName); 650 } 651 652 653 /** Helper for use with kbuild_lookup_variable_fmt. */ 654 #define ST(strconst) sizeof(strconst), strconst 706 return kbuild_lookup_variable_defpath_n(pDefPath, pszName, psz - pszName - 1); 707 return kbuild_lookup_variable_n(pszName, psz - pszName - 1); 708 } 709 710 711 /** Helper for passing a string constant to kbuild_lookup_variable_fmt or 712 * kbuild_lookup_variable_NN. */ 713 #define ST(strconst) strconst, sizeof(strconst) - 1 714 /** Helper for passing a variable to kbuild_lookup_variable_NN. */ 715 #define VT(var) (var)->value_length, (var)->value 655 716 656 717 657 718 /** Same as kbuild_lookup_variable except that a '%s' in the name string 658 719 * will be substituted with the values of the variables in the ellipsis. */ 659 #ifdef _MSC_VER 660 _inline struct variable * 661 #else 662 static __inline__ struct variable * 663 #endif 664 kbuild_lookup_variable_fmt(struct variable *pDefPath, size_t cchNameFmt, const char *pszNameFmt, ...) 720 MY_INLINE struct variable * 721 kbuild_lookup_variable_fmt(struct variable *pDefPath, const char *pszNameFmt, size_t cchNameFmt, ...) 665 722 { 666 723 struct variable *pVar; 667 724 va_list va; 668 va_start(va, pszNameFmt);725 va_start(va, cchNameFmt); 669 726 pVar = kbuild_lookup_variable_fmt_va(pDefPath, cchNameFmt, pszNameFmt, va); 670 727 va_end(va); … … 680 737 struct variable *pTool, struct variable *pType, 681 738 struct variable *pBldTrg, struct variable *pBldTrgArch, 682 const char *pszPropF1, const char *pszPropF2, const char *pszVarName) 739 const char *pszPropF1, char cchPropF1, 740 const char *pszPropF2, char cchPropF2, 741 const char *pszVarName) 683 742 { 684 743 struct variable *pVar; 685 struct variable PropF1, PropF2; 686 687 PropF1.value = (char *)pszPropF1; 688 PropF1.value_length = strlen(pszPropF1); 689 690 PropF2.value = (char *)pszPropF2; 691 PropF2.value_length = strlen(pszPropF2); 692 693 if ( (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%_%%.%.%"),pTarget, pSource, pType, &PropF2, pBldTrg, pBldTrgArch)) 694 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%_%%.%"), pTarget, pSource, pType, &PropF2, pBldTrg)) 695 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%_%%"), pTarget, pSource, pType, &PropF2)) 696 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%_%.%.%"), pTarget, pSource, &PropF2, pBldTrg, pBldTrgArch)) 697 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%_%.%"), pTarget, pSource, &PropF2, pBldTrg)) 698 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%_%"), pTarget, pSource, &PropF2)) 699 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%%.%.%"), pSource, pType, &PropF2, pBldTrg, pBldTrgArch)) 700 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%%.%"), pSource, pType, &PropF2, pBldTrg)) 701 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%%"), pSource, pType, &PropF2)) 702 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%.%.%"), pSource, &PropF2, pBldTrg, pBldTrgArch)) 703 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%.%"), pSource, &PropF2, pBldTrg)) 704 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%"), pSource, &PropF2)) 705 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%%.%.%"), pTarget, pType, &PropF2, pBldTrg, pBldTrgArch)) 706 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%%.%"), pTarget, pType, &PropF2, pBldTrg)) 707 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%%"), pTarget, pType, &PropF2)) 708 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%.%.%"), pTarget, &PropF2, pBldTrg, pBldTrgArch)) 709 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%.%"), pTarget, &PropF2, pBldTrg)) 710 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%_%"), pTarget, &PropF2)) 711 712 || (pTool && (pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%%.%.%"), pTool, pType, &PropF2, pBldTrg, pBldTrgArch))) 713 || (pTool && (pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%%.%"), pTool, pType, &PropF2, pBldTrg))) 714 || (pTool && (pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%%"), pTool, pType, &PropF2))) 715 || (pTool && (pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%.%.%"), pTool, &PropF2, pBldTrg, pBldTrgArch))) 716 || (pTool && (pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%.%"), pTool, &PropF2, pBldTrg))) 717 || (pTool && (pVar = kbuild_lookup_variable_fmt(NULL, ST("TOOL_%_%"), pTool, &PropF2))) 718 719 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%%.%.%"), pType, &PropF1, pBldTrg, pBldTrgArch)) 720 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%%.%"), pType, &PropF1, pBldTrg)) 721 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%%"), pType, &PropF1)) 722 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%.%.%"), &PropF1, pBldTrg, pBldTrgArch)) 723 || (pVar = kbuild_lookup_variable_fmt(NULL, ST("%.%"), &PropF1, pBldTrg)) 724 || (pVar = kbuild_lookup_variable(pszPropF1)) 725 ) 744 size_t cchBuf; 745 char *pszBuf; 746 char *psz, *psz1, *psz2, *psz3, *psz4; 747 748 /* calc and allocate a too big name buffer. */ 749 cchBuf = cchPropF2 + 1 750 + cchPropF1 + 1 751 + pTarget->value_length + 1 752 + pSource->value_length + 1 753 + (pTool ? pTool->value_length + 1 : 0) 754 + pType->value_length + 1 755 + pBldTrg->value_length + 1 756 + pBldTrgArch->value_length + 1; 757 pszBuf = xmalloc(cchBuf); 758 759 #if 1 760 # define my_memcpy(dst, src, len) \ 761 do { \ 762 if (len > 4) \ 763 memcpy(dst, src, len); \ 764 else \ 765 switch (len) \ 766 { \ 767 case 8: dst[7] = src[7]; \ 768 case 7: dst[6] = src[6]; \ 769 case 6: dst[5] = src[5]; \ 770 case 5: dst[4] = src[4]; \ 771 case 4: dst[3] = src[3]; \ 772 case 3: dst[2] = src[2]; \ 773 case 2: dst[1] = src[1]; \ 774 case 1: dst[0] = src[0]; \ 775 case 0: break; \ 776 } \ 777 } while (0) 778 #elif defined(__GNUC__) 779 # define my_memcpy __builtin_memcpy 780 #elif defined(_MSC_VER) 781 # pragma instrinic(memcpy) 782 # define my_memcpy memcpy 783 #endif 784 #define ADD_VAR(pVar) do { my_memcpy(psz, (pVar)->value, (pVar)->value_length); psz += (pVar)->value_length; } while (0) 785 #define ADD_STR(pszStr, cchStr) do { my_memcpy(psz, (pszStr), (cchStr)); psz += (cchStr); } while (0) 786 #define ADD_CSTR(pszStr) do { my_memcpy(psz, pszStr, sizeof(pszStr) - 1); psz += sizeof(pszStr) - 1; } while (0) 787 #define ADD_CH(ch) do { *psz++ = (ch); } while (0) 788 789 /* 790 * $(target)_$(source)_$(type)$(propf2).$(bld_trg).$(bld_trg_arch) 791 */ 792 psz = pszBuf; 793 ADD_VAR(pTarget); 794 ADD_CH('_'); 795 ADD_VAR(pSource); 796 ADD_CH('_'); 797 psz2 = psz; 798 ADD_VAR(pType); 799 ADD_STR(pszPropF2, cchPropF2); 800 psz3 = psz; 801 ADD_CH('.'); 802 ADD_VAR(pBldTrg); 803 psz4 = psz; 804 ADD_CH('.'); 805 ADD_VAR(pBldTrgArch); 806 pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf); 807 808 /* $(target)_$(source)_$(type)$(propf2).$(bld_trg) */ 809 if (!pVar) 810 pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf); 811 812 /* $(target)_$(source)_$(type)$(propf2) */ 813 if (!pVar) 814 pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf); 815 816 /* 817 * $(target)_$(source)_$(propf2).$(bld_trg).$(bld_trg_arch) 818 */ 819 if (!pVar) 820 { 821 psz = psz2; 822 ADD_STR(pszPropF2, cchPropF2); 823 psz3 = psz; 824 ADD_CH('.'); 825 ADD_VAR(pBldTrg); 826 psz4 = psz; 827 ADD_CH('.'); 828 ADD_VAR(pBldTrgArch); 829 pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf); 830 831 /* $(target)_$(source)_$(propf2).$(bld_trg) */ 832 if (!pVar) 833 pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf); 834 835 /* $(target)_$(source)_$(propf2) */ 836 if (!pVar) 837 pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf); 838 } 839 840 841 /* 842 * $(source)_$(type)$(propf2).$(bld_trg).$(bld_trg_arch) 843 */ 844 if (!pVar) 845 { 846 psz = pszBuf; 847 ADD_VAR(pSource); 848 ADD_CH('_'); 849 psz2 = psz; 850 ADD_VAR(pType); 851 ADD_STR(pszPropF2, cchPropF2); 852 psz3 = psz; 853 ADD_CH('.'); 854 ADD_VAR(pBldTrg); 855 psz4 = psz; 856 ADD_CH('.'); 857 ADD_VAR(pBldTrgArch); 858 pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf); 859 860 /* $(source)_$(type)$(propf2).$(bld_trg) */ 861 if (!pVar) 862 pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf); 863 864 /* $(source)_$(type)$(propf2) */ 865 if (!pVar) 866 pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf); 867 868 /* 869 * $(source)_$(propf2).$(bld_trg).$(bld_trg_arch) 870 */ 871 if (!pVar) 872 { 873 psz = psz2; 874 ADD_STR(pszPropF2, cchPropF2); 875 psz3 = psz; 876 ADD_CH('.'); 877 ADD_VAR(pBldTrg); 878 psz4 = psz; 879 ADD_CH('.'); 880 ADD_VAR(pBldTrgArch); 881 pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf); 882 883 /* $(source)_$(propf2).$(bld_trg) */ 884 if (!pVar) 885 pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf); 886 887 /* $(source)_$(propf2) */ 888 if (!pVar) 889 pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf); 890 } 891 } 892 893 /* 894 * $(target)_$(type)$(propf2).$(bld_trg).$(bld_trg_arch) 895 */ 896 if (!pVar) 897 { 898 psz = pszBuf; 899 ADD_VAR(pTarget); 900 ADD_CH('_'); 901 psz2 = psz; 902 ADD_VAR(pType); 903 ADD_STR(pszPropF2, cchPropF2); 904 psz3 = psz; 905 ADD_CH('.'); 906 ADD_VAR(pBldTrg); 907 psz4 = psz; 908 ADD_CH('.'); 909 ADD_VAR(pBldTrgArch); 910 pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf); 911 912 /* $(target)_$(type)$(propf2).$(bld_trg) */ 913 if (!pVar) 914 pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf); 915 916 /* $(target)_$(type)$(propf2) */ 917 if (!pVar) 918 pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf); 919 920 /* $(target)_$(propf2).$(bld_trg).$(bld_trg_arch) */ 921 if (!pVar) 922 { 923 psz = psz2; 924 ADD_STR(pszPropF2, cchPropF2); 925 psz3 = psz; 926 ADD_CH('.'); 927 ADD_VAR(pBldTrg); 928 psz4 = psz; 929 ADD_CH('.'); 930 ADD_VAR(pBldTrgArch); 931 pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf); 932 } 933 934 /* $(target)_$(propf2).$(bld_trg) */ 935 if (!pVar) 936 pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf); 937 938 /* $(target)_$(propf2) */ 939 if (!pVar) 940 pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf); 941 } 942 943 /* 944 * TOOL_$(tool)_$(type)$(propf2).$(bld_trg).$(bld_trg_arch) 945 */ 946 if (!pVar && pTool) 947 { 948 psz = pszBuf; 949 ADD_CSTR("TOOL_"); 950 ADD_VAR(pTool); 951 ADD_CH('_'); 952 psz2 = psz; 953 ADD_VAR(pType); 954 ADD_STR(pszPropF2, cchPropF2); 955 psz3 = psz; 956 ADD_CH('.'); 957 ADD_VAR(pBldTrg); 958 psz4 = psz; 959 ADD_CH('.'); 960 ADD_VAR(pBldTrgArch); 961 pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf); 962 963 /* TOOL_$(tool)_$(type)$(propf2).$(bld_trg) */ 964 if (!pVar) 965 pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf); 966 967 /* TOOL_$(tool)_$(type)$(propf2) */ 968 if (!pVar) 969 pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf); 970 971 /* TOOL_$(tool)_$(propf2).$(bld_trg).$(bld_trg_arch) */ 972 if (!pVar) 973 { 974 psz = psz2; 975 ADD_STR(pszPropF2, cchPropF2); 976 psz3 = psz; 977 ADD_CH('.'); 978 ADD_VAR(pBldTrg); 979 psz4 = psz; 980 ADD_CH('.'); 981 ADD_VAR(pBldTrgArch); 982 pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf); 983 984 /* TOOL_$(tool)_$(propf2).$(bld_trg) */ 985 if (!pVar) 986 pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf); 987 988 /* TOOL_$(tool)_$(propf2) */ 989 if (!pVar) 990 pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf); 991 } 992 } 993 994 /* 995 * $(type)$(propf1).$(bld_trg).$(bld_trg_arch) 996 */ 997 if (!pVar) 998 { 999 psz = pszBuf; 1000 ADD_VAR(pType); 1001 ADD_STR(pszPropF1, cchPropF1); 1002 psz3 = psz; 1003 ADD_CH('.'); 1004 ADD_VAR(pBldTrg); 1005 psz4 = psz; 1006 ADD_CH('.'); 1007 ADD_VAR(pBldTrgArch); 1008 pVar = kbuild_lookup_variable_n(pszBuf, psz - pszBuf); 1009 1010 /* $(type)$(propf1).$(bld_trg) */ 1011 if (!pVar) 1012 pVar = kbuild_lookup_variable_n(pszBuf, psz4 - pszBuf); 1013 1014 /* $(type)$(propf1) */ 1015 if (!pVar) 1016 pVar = kbuild_lookup_variable_n(pszBuf, psz3 - pszBuf); 1017 1018 /* 1019 * $(propf1).$(bld_trg).$(bld_trg_arch) 1020 */ 1021 if (!pVar) 1022 { 1023 psz1 = pszBuf + pType->value_length; 1024 pVar = kbuild_lookup_variable_n(psz1, psz - psz1); 1025 1026 /* $(propf1).$(bld_trg) */ 1027 if (!pVar) 1028 pVar = kbuild_lookup_variable_n(psz1, psz4 - psz1); 1029 1030 /* $(propf1) */ 1031 if (!pVar) 1032 pVar = kbuild_lookup_variable_n(pszPropF1, cchPropF1); 1033 } 1034 } 1035 free(pszBuf); 1036 #undef ADD_VAR 1037 #undef ADD_STR 1038 #undef ADD_CSTR 1039 #undef ADD_CH 1040 1041 if (pVar) 726 1042 { 727 1043 /* strip it */ … … 779 1095 { 780 1096 struct variable *pVar = kbuild_first_prop(pTarget, pSource, NULL, pType, pBldTrg, pBldTrgArch, 781 "TOOL", "TOOL", pszVarName); 1097 "TOOL", sizeof("TOOL") - 1, 1098 "TOOL", sizeof("TOOL") - 1, 1099 pszVarName); 782 1100 if (!pVar) 783 1101 fatal(NILF, _("no tool for source `%s' in target `%s'!"), pSource->value, pTarget->value); … … 790 1108 func_kbuild_source_tool(char *o, char **argv, const char *pszFuncName) 791 1109 { 792 struct variable *pVar = kbuild_get_source_tool(kbuild_get_variable ("target"),793 kbuild_get_variable ("source"),794 kbuild_get_variable ("type"),795 kbuild_get_variable ("bld_trg"),796 kbuild_get_variable ("bld_trg_arch"),1110 struct variable *pVar = kbuild_get_source_tool(kbuild_get_variable_n(ST("target")), 1111 kbuild_get_variable_n(ST("source")), 1112 kbuild_get_variable_n(ST("type")), 1113 kbuild_get_variable_n(ST("bld_trg")), 1114 kbuild_get_variable_n(ST("bld_trg_arch")), 797 1115 argv[0]); 798 1116 if (pVar) … … 826 1144 { 827 1145 struct variable *pVar = kbuild_first_prop(pTarget, pSource, pTool, pType, pBldTrg, pBldTrgArch, 828 "SUFF_OBJ", "OBJSUFF", pszVarName); 1146 "SUFF_OBJ", sizeof("SUFF_OBJ") - 1, 1147 "OBJSUFF", sizeof("OBJSUFF") - 1, 1148 pszVarName); 829 1149 if (!pVar) 830 1150 fatal(NILF, _("no OBJSUFF attribute or SUFF_OBJ default for source `%s' in target `%s'!"), pSource->value, pTarget->value); … … 837 1157 func_kbuild_object_suffix(char *o, char **argv, const char *pszFuncName) 838 1158 { 839 struct variable *pVar = kbuild_get_object_suffix(kbuild_get_variable ("target"),840 kbuild_get_variable ("source"),841 kbuild_get_variable ("tool"),842 kbuild_get_variable ("type"),843 kbuild_get_variable ("bld_trg"),844 kbuild_get_variable ("bld_trg_arch"),1159 struct variable *pVar = kbuild_get_object_suffix(kbuild_get_variable_n(ST("target")), 1160 kbuild_get_variable_n(ST("source")), 1161 kbuild_get_variable_n(ST("tool")), 1162 kbuild_get_variable_n(ST("type")), 1163 kbuild_get_variable_n(ST("bld_trg")), 1164 kbuild_get_variable_n(ST("bld_trg_arch")), 845 1165 argv[0]); 846 1166 if (pVar) … … 865 1185 kbuild_get_object_base(struct variable *pTarget, struct variable *pSource, const char *pszVarName) 866 1186 { 867 struct variable *pPathTarget = kbuild_get_variable ("PATH_TARGET");868 struct variable *pPathRoot = kbuild_get_variable ("PATH_ROOT");869 struct variable *pPathSubCur = kbuild_get_variable ("PATH_SUB_CURRENT");1187 struct variable *pPathTarget = kbuild_get_variable_n(ST("PATH_TARGET")); 1188 struct variable *pPathRoot = kbuild_get_variable_n(ST("PATH_ROOT")); 1189 struct variable *pPathSubCur = kbuild_get_variable_n(ST("PATH_SUB_CURRENT")); 870 1190 const char *pszSrcPrefix = NULL; 871 1191 size_t cchSrcPrefix = 0; … … 1283 1603 struct variable *pBldTrg, struct variable *pBldTrgArch, struct variable *pBldTrgCpu, 1284 1604 struct variable *pDefPath, 1285 const char *pszProp, const char *pszVarName, int iDirection) 1605 const char *pszProp, size_t cchProp, 1606 const char *pszVarName, size_t cchVarName, 1607 int iDirection) 1286 1608 { 1287 1609 struct variable *pVar; … … 1299 1621 struct variable Prop = {0}; 1300 1622 Prop.value = (char *)pszProp; 1301 Prop.value_length = strlen(pszProp);1623 Prop.value_length = cchProp; 1302 1624 1303 1625 assert(iDirection == 1 || iDirection == -1); … … 1524 1846 cchTotal = psz - pszResult; 1525 1847 1526 pVar = define_variable_vl(pszVarName, strlen(pszVarName), pszResult, cchTotal,1848 pVar = define_variable_vl(pszVarName, cchVarName, pszResult, cchTotal, 1527 1849 0 /* take pszResult */ , o_local, 0 /* !recursive */); 1528 1850 return pVar; … … 1534 1856 func_kbuild_source_prop(char *o, char **argv, const char *pszFuncName) 1535 1857 { 1536 struct variable *pTarget = kbuild_get_variable ("target");1537 struct variable *pSource = kbuild_get_variable ("source");1858 struct variable *pTarget = kbuild_get_variable_n(ST("target")); 1859 struct variable *pSource = kbuild_get_variable_n(ST("source")); 1538 1860 struct variable *pDefPath = NULL; 1539 struct variable *pType = kbuild_get_variable ("type");1540 struct variable *pTool = kbuild_get_variable ("tool");1541 struct variable *pBldType = kbuild_get_variable ("bld_type");1542 struct variable *pBldTrg = kbuild_get_variable ("bld_trg");1543 struct variable *pBldTrgArch = kbuild_get_variable ("bld_trg_arch");1544 struct variable *pBldTrgCpu = kbuild_get_variable ("bld_trg_cpu");1861 struct variable *pType = kbuild_get_variable_n(ST("type")); 1862 struct variable *pTool = kbuild_get_variable_n(ST("tool")); 1863 struct variable *pBldType = kbuild_get_variable_n(ST("bld_type")); 1864 struct variable *pBldTrg = kbuild_get_variable_n(ST("bld_trg")); 1865 struct variable *pBldTrgArch = kbuild_get_variable_n(ST("bld_trg_arch")); 1866 struct variable *pBldTrgCpu = kbuild_get_variable_n(ST("bld_trg_cpu")); 1545 1867 struct variable *pVar; 1546 1868 struct kbuild_sdks Sdks; … … 1558 1880 psz++; 1559 1881 if (*psz) 1560 pDefPath = kbuild_get_variable ("defpath");1882 pDefPath = kbuild_get_variable_n(ST("defpath")); 1561 1883 } 1562 1884 … … 1566 1888 pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, 1567 1889 pDefPath, 1568 argv[0], argv[1], iDirection); 1890 argv[0], strlen(argv[0]), 1891 argv[1], strlen(argv[1]), 1892 iDirection); 1569 1893 if (pVar) 1570 1894 o = variable_buffer_output(o, pVar->value, pVar->value_length); … … 1588 1912 struct variable **ppDirDep) 1589 1913 { 1590 struct variable *pDepSuff = kbuild_get_variable ("SUFF_DEP");1914 struct variable *pDepSuff = kbuild_get_variable_n(ST("SUFF_DEP")); 1591 1915 struct variable *pObj; 1592 1916 size_t cch = pOutBase->value_length + pObjSuff->value_length + pDepSuff->value_length + 1; … … 1699 2023 { 1700 2024 static int s_fNoCompileCmdsDepsDefined = -1; 1701 struct variable *pTarget = kbuild_get_variable ("target");1702 struct variable *pSource = kbuild_get_variable ("source");1703 struct variable *pDefPath = kbuild_get_variable ("defpath");1704 struct variable *pType = kbuild_get_variable ("type");1705 struct variable *pBldType = kbuild_get_variable ("bld_type");1706 struct variable *pBldTrg = kbuild_get_variable ("bld_trg");1707 struct variable *pBldTrgArch= kbuild_get_variable ("bld_trg_arch");1708 struct variable *pBldTrgCpu = kbuild_get_variable ("bld_trg_cpu");2025 struct variable *pTarget = kbuild_get_variable_n(ST("target")); 2026 struct variable *pSource = kbuild_get_variable_n(ST("source")); 2027 struct variable *pDefPath = kbuild_get_variable_n(ST("defpath")); 2028 struct variable *pType = kbuild_get_variable_n(ST("type")); 2029 struct variable *pBldType = kbuild_get_variable_n(ST("bld_type")); 2030 struct variable *pBldTrg = kbuild_get_variable_n(ST("bld_trg")); 2031 struct variable *pBldTrgArch= kbuild_get_variable_n(ST("bld_trg_arch")); 2032 struct variable *pBldTrgCpu = kbuild_get_variable_n(ST("bld_trg_cpu")); 1709 2033 struct variable *pTool = kbuild_get_source_tool(pTarget, pSource, pType, pBldTrg, pBldTrgArch, "tool"); 1710 2034 struct variable *pOutBase = kbuild_get_object_base(pTarget, pSource, "outbase"); … … 1714 2038 char *pszDstVar, *pszDst, *pszSrcVar, *pszSrc, *pszVal, *psz; 1715 2039 char *pszSavedVarBuf; 1716 unsigned cchSavedVarBuf , cchVal;2040 unsigned cchSavedVarBuf; 1717 2041 size_t cch; 1718 2042 struct kbuild_sdks Sdks; … … 1761 2085 pDefPath = NULL; 1762 2086 pDefs = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, NULL, 1763 "DEFS", "defs", 1/* left-to-right */);2087 ST("DEFS"), ST("defs"), 1/* left-to-right */); 1764 2088 pIncs = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, pDefPath, 1765 "INCS", "incs", -1/* right-to-left */);2089 ST("INCS"), ST("incs"), -1/* right-to-left */); 1766 2090 pFlags = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, NULL, 1767 "FLAGS", "flags", 1/* left-to-right */);2091 ST("FLAGS"), ST("flags"), 1/* left-to-right */); 1768 2092 pDeps = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, pDefPath, 1769 "DEPS", "deps", 1/* left-to-right */);2093 ST("DEPS"), ST("deps"), 1/* left-to-right */); 1770 2094 pOrderDeps = kbuild_collect_source_prop(pTarget, pSource, pTool, &Sdks, pType, pBldType, pBldTrg, pBldTrgArch, pBldTrgCpu, pDefPath, 1771 "ORDERDEPS", "orderdeps", 1/* left-to-right */);2095 ST("ORDERDEPS"), ST("orderdeps"), 1/* left-to-right */); 1772 2096 1773 2097 /* … … 1787 2111 */ 1788 2112 if (s_fNoCompileCmdsDepsDefined == -1) 1789 s_fNoCompileCmdsDepsDefined = kbuild_lookup_variable ("NO_COMPILE_CMDS_DEPS") != NULL;2113 s_fNoCompileCmdsDepsDefined = kbuild_lookup_variable_n(ST("NO_COMPILE_CMDS_DEPS")) != NULL; 1790 2114 if (!s_fNoCompileCmdsDepsDefined) 1791 2115 { … … 1870 2194 */ 1871 2195 /** @todo use append? */ 1872 pVar = kbuild_get_variable ("_OUT_FILES");2196 pVar = kbuild_get_variable_n(ST("_OUT_FILES")); 1873 2197 psz = pszVal = xmalloc(pVar->value_length + 1 + pOutput->value_length + 1 + pOutputMaybe->value_length + 1); 1874 2198 memcpy(psz, pVar->value, pVar->value_length); psz += pVar->value_length; … … 1893 2217 */ 1894 2218 pVar = kbuild_get_recursive_variable("def_target_source_rule"); 1895 pszVal = allocated_variable_expand_2(pVar->value, pVar->value_length, &cchVal); /** @todo we can use the variable buffer here. */ 2219 pszVal = variable_expand_string_2 (o, pVar->value, pVar->value_length, &psz); 2220 assert (!((size_t)pszVal & 3)); 1896 2221 1897 2222 install_variable_buffer(&pszSavedVarBuf, &cchSavedVarBuf); 1898 eval_buffer(pszVal, psz Val + cchVal);2223 eval_buffer(pszVal, psz); 1899 2224 restore_variable_buffer(pszSavedVarBuf, cchSavedVarBuf); 1900 1901 free(pszVal);1902 2225 1903 2226 kbuild_put_sdks(&Sdks); 1904 2227 (void)pszFuncName; 1905 return variable_buffer_output(o, "", 1) - 1; /** @todo why? */ 2228 2229 *pszVal = '\0'; 2230 return pszVal; 1906 2231 } 1907 2232
Note:
See TracChangeset
for help on using the changeset viewer.