Changeset 2168 in kBuild
- Timestamp:
- Dec 30, 2008 4:52:13 PM (16 years ago)
- Location:
- trunk/kBuild/doc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kBuild/doc/QuickReference-kmk.html
r2167 r2168 625 625 </tbody> 626 626 </table> 627 </div>628 <div class="section">629 <h1><a id="built-in-functions" name="built-in-functions">Built-in functions</a></h1>630 <p>String Manipulation Functions:</p>631 <blockquote>632 <p>Replace <tt class="docutils literal"><span class="pre">from</span></tt> with <tt class="docutils literal"><span class="pre">to</span></tt> in <tt class="docutils literal"><span class="pre">text</span></tt>:</p>633 <pre class="literal-block">634 $(subst from,to,text)635 </pre>636 <p>Replace words matching <tt class="docutils literal"><span class="pre">pattern</span></tt> with <tt class="docutils literal"><span class="pre">replacement</span></tt> in <tt class="docutils literal"><span class="pre">text</span></tt>:</p>637 <pre class="literal-block">638 $(patsubst pattern,replacement,text)639 </pre>640 <p>Remove excess whitespace characters from <tt class="docutils literal"><span class="pre">string</span></tt>:</p>641 <pre class="literal-block">642 $(strip string)643 </pre>644 <p>Locate <tt class="docutils literal"><span class="pre">find</span></tt> in <tt class="docutils literal"><span class="pre">text</span></tt>, returning <tt class="docutils literal"><span class="pre">find</span></tt> if found:</p>645 <pre class="literal-block">646 $(findstring find,text)647 </pre>648 <p>Select words in <tt class="docutils literal"><span class="pre">text</span></tt> that match one of the <tt class="docutils literal"><span class="pre">pattern</span></tt> words:</p>649 <pre class="literal-block">650 $(filter pattern...,text)651 </pre>652 <p>Select words in <tt class="docutils literal"><span class="pre">text</span></tt> that do not match any of the <tt class="docutils literal"><span class="pre">pattern</span></tt> words:</p>653 <pre class="literal-block">654 $(filter-out pattern...,text)655 </pre>656 <p>Sort the words in <tt class="docutils literal"><span class="pre">list</span></tt> lexicographically, removing duplicates:</p>657 <pre class="literal-block">658 $(sort list)659 </pre>660 <p>Sort the words in <tt class="docutils literal"><span class="pre">list</span></tt> lexicographically in reserve order, removing661 duplicates:</p>662 <pre class="literal-block">663 $(rsort list)664 </pre>665 <p>Count the number of words in <tt class="docutils literal"><span class="pre">text</span></tt>:</p>666 <pre class="literal-block">667 $(words text)668 </pre>669 <p>Extract the <tt class="docutils literal"><span class="pre">n</span></tt>th word (one-origin) of <tt class="docutils literal"><span class="pre">text</span></tt>:</p>670 <pre class="literal-block">671 $(word n,text)672 </pre>673 <p>Returns the list of words in <tt class="docutils literal"><span class="pre">text</span></tt> from <tt class="docutils literal"><span class="pre">s</span></tt> to <tt class="docutils literal"><span class="pre">e</span></tt> (one-origin):</p>674 <pre class="literal-block">675 $(wordlist s,e,text)676 </pre>677 <p>Extract the first word of <tt class="docutils literal"><span class="pre">names</span></tt>:</p>678 <pre class="literal-block">679 $(firstword names...)680 </pre>681 <p>Extract the last word of <tt class="docutils literal"><span class="pre">names</span></tt>:</p>682 <pre class="literal-block">683 $(lastword names...)684 </pre>685 <p>Join two parallel lists of words:</p>686 <pre class="literal-block">687 $(join list1,list2)688 </pre>689 <p>Fold <tt class="docutils literal"><span class="pre">text</span></tt> to upper case:</p>690 <pre class="literal-block">691 $(toupper text)692 </pre>693 <p>Fold <tt class="docutils literal"><span class="pre">text</span></tt> to lower case:</p>694 <pre class="literal-block">695 $(tolower text)696 </pre>697 <p>String formatting a la the unix <tt class="docutils literal"><span class="pre">printf</span></tt> command:</p>698 <pre class="literal-block">699 $(printf fmt, arg...)700 </pre>701 <p>Return the length of a string or a (unexpanded) variable:</p>702 <pre class="literal-block">703 $(length string)704 $(length-var var)705 </pre>706 <p>Find the position of <tt class="docutils literal"><span class="pre">needle</span></tt> in <tt class="docutils literal"><span class="pre">haystack</span></tt>, returns 0 if not found.707 Negative <tt class="docutils literal"><span class="pre">start</span></tt> indices are relative to the end of <tt class="docutils literal"><span class="pre">haystack</span></tt>, while708 positive ones are one based:</p>709 <pre class="literal-block">710 $(pos needle, haystack[, start])711 $(lastpos needle, haystack[, start])712 </pre>713 <p>Returns the specified substring. The <tt class="docutils literal"><span class="pre">start</span></tt> works like with <tt class="docutils literal"><span class="pre">$(pos</span> <span class="pre">)</span></tt>.714 If the substring is partially outside the <tt class="docutils literal"><span class="pre">string</span></tt> the result will be715 padded with <tt class="docutils literal"><span class="pre">pad</span></tt> if present:</p>716 <pre class="literal-block">717 $(substr string, start[, length[, pad]])718 </pre>719 <p>Insert <tt class="docutils literal"><span class="pre">in</span></tt> into <tt class="docutils literal"><span class="pre">str</span></tt> at the specified position. <tt class="docutils literal"><span class="pre">n</span></tt> works like with720 <tt class="docutils literal"><span class="pre">$(pos</span> <span class="pre">)</span></tt>, except that <tt class="docutils literal"><span class="pre">0</span></tt> is the end of the string:</p>721 <pre class="literal-block">722 $(insert in, str[, n[, length[, pad]]])723 </pre>724 <p>Translate <tt class="docutils literal"><span class="pre">string</span></tt> exchanging characters in <tt class="docutils literal"><span class="pre">from-set</span></tt> with <tt class="docutils literal"><span class="pre">to-set</span></tt>,725 optionally completing <tt class="docutils literal"><span class="pre">to-set</span></tt> with <tt class="docutils literal"><span class="pre">pad-char</span></tt> if specified. If no726 <tt class="docutils literal"><span class="pre">pad-char</span></tt> characters absent in <tt class="docutils literal"><span class="pre">to-set</span></tt> will be deleted:</p>727 <pre class="literal-block">728 $(translate string, from-set[, to-set[, pad-char]])729 </pre>730 </blockquote>731 <p>Functions for file names:</p>732 <blockquote>733 <p>Extract the directory part of each file <tt class="docutils literal"><span class="pre">name</span></tt>:</p>734 <pre class="literal-block">735 $(dir names...)736 </pre>737 <p>Extract the non-directory part of each file <tt class="docutils literal"><span class="pre">name</span></tt>:</p>738 <pre class="literal-block">739 $(notdir names...)740 </pre>741 <p>Extract the suffix (the last <tt class="docutils literal"><span class="pre">.</span></tt> and following characters) of each file742 <tt class="docutils literal"><span class="pre">name</span></tt>:</p>743 <pre class="literal-block">744 $(suffix names...)745 </pre>746 <p>Extract the base name (name without suffix) of each file name:</p>747 <pre class="literal-block">748 $(basename names...)749 </pre>750 <p>Append <tt class="docutils literal"><span class="pre">suffix</span></tt> to each word in <tt class="docutils literal"><span class="pre">names</span></tt>:</p>751 <pre class="literal-block">752 $(addsuffix suffix,names...)753 </pre>754 <p>Prepend <tt class="docutils literal"><span class="pre">prefix</span></tt> to each word in <tt class="docutils literal"><span class="pre">names</span></tt>:</p>755 <pre class="literal-block">756 $(addprefix prefix,names...)757 </pre>758 <p>Find file names matching a shell file name <tt class="docutils literal"><span class="pre">pattern</span></tt> (not a <tt class="docutils literal"><span class="pre">%</span></tt>759 pattern):</p>760 <pre class="literal-block">761 $(wildcard pattern...)762 </pre>763 <p>For each file name in <tt class="docutils literal"><span class="pre">names</span></tt>, expand to an absolute name that does not764 contain any <tt class="docutils literal"><span class="pre">.</span></tt>, <tt class="docutils literal"><span class="pre">..</span></tt>, nor symlinks:</p>765 <pre class="literal-block">766 $(realpath names...)767 </pre>768 <p>For each file name in <tt class="docutils literal"><span class="pre">names</span></tt>, expand to an absolute name that does not769 contain any <tt class="docutils literal"><span class="pre">.</span></tt> or <tt class="docutils literal"><span class="pre">..</span></tt> components, but preserves symlinks:</p>770 <pre class="literal-block">771 $(abspath names...)772 </pre>773 <p>Same as <tt class="docutils literal"><span class="pre">$(abspath</span> <span class="pre">)</span></tt> except that the current directory can be774 specified as <tt class="docutils literal"><span class="pre">curdir</span></tt>:</p>775 <pre class="literal-block">776 $(abspathex names...[, curdir])777 </pre>778 </blockquote>779 <p>Arithmetic Functions:</p>780 <blockquote>781 <p>Returns the sum of the arguments:</p>782 <pre class="literal-block">783 $(int-add addend1, addend2[, addendN])784 </pre>785 <p>Returns the difference between the first argument and the sum of the rest:</p>786 <pre class="literal-block">787 $(int-sub minuend, subtrahend[, subtrahendN])788 </pre>789 <p>Returns the product of the arguments:</p>790 <pre class="literal-block">791 $(int-mul factor1, factor2[, factorN])792 </pre>793 <p>Returns the quotient of first argument and the rest:</p>794 <pre class="literal-block">795 $(int-div dividend, divisor[, divisorN])796 </pre>797 <p>Returns the modulus of the two arguments:</p>798 <pre class="literal-block">799 $(int-mod dividend, divisor)800 </pre>801 <p>Returns the bitwise two-complement of argument:</p>802 <pre class="literal-block">803 $(int-not val)804 </pre>805 <p>Returns the result of a bitwise AND of the arguments:</p>806 <pre class="literal-block">807 $(int-and val1, val2[, valN])808 </pre>809 <p>Returns the result of a bitwise OR of the arguments:</p>810 <pre class="literal-block">811 $(int-or val1, val2[, valN])812 </pre>813 <p>Returns the result of a bitwise XOR of the arguments:</p>814 <pre class="literal-block">815 $(int-xor val1, val2[, valN])816 </pre>817 <p>Returns the <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean (true = non-empty, false = empty) result818 of <tt class="docutils literal"><span class="pre">val1</span> <span class="pre">==</span> <span class="pre">val2</span></tt>:</p>819 <pre class="literal-block">820 $(int-eq val1, val2)821 </pre>822 <p>Returns the <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean result of <tt class="docutils literal"><span class="pre">val1</span> <span class="pre">!=</span> <span class="pre">val2</span></tt>:</p>823 <pre class="literal-block">824 $(int-ne val1, val2)825 </pre>826 <p>Returns the <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean result of <tt class="docutils literal"><span class="pre">val1</span> <span class="pre">></span> <span class="pre">val2</span></tt>:</p>827 <pre class="literal-block">828 $(int-gt val1, val2)829 </pre>830 <p>Returns the <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean result of <tt class="docutils literal"><span class="pre">val1</span> <span class="pre">>=</span> <span class="pre">val2</span></tt>:</p>831 <pre class="literal-block">832 $(int-ge val1, val2)833 </pre>834 <p>Returns the <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean result of <tt class="docutils literal"><span class="pre">val1</span> <span class="pre"><</span> <span class="pre">val2</span></tt>:</p>835 <pre class="literal-block">836 $(int-lt val1, val2)837 </pre>838 <p>Returns the <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean result of <tt class="docutils literal"><span class="pre">val1</span> <span class="pre"><=</span> <span class="pre">val2</span></tt>:</p>839 <pre class="literal-block">840 $(int-le val1, val2)841 </pre>842 </blockquote>843 <p>Boolean and Conditional Functions:</p>844 <blockquote>845 <p>Condition is false if the <tt class="docutils literal"><span class="pre">condition</span></tt> evaluates to an empty string846 (stripped). Evaluate the <tt class="docutils literal"><span class="pre">true-part</span></tt> if the condition is true, otherwise847 the <tt class="docutils literal"><span class="pre">false-part</span></tt>:</p>848 <pre class="literal-block">849 $(if condition,true-part[,false-part])850 </pre>851 <p>Test if any of the conditions evalues to non-empty string, returning the852 first one:</p>853 <pre class="literal-block">854 $(or condition1[,condition2[,condition3[...]]])855 </pre>856 <p>Test if all of the conditions evaluates to non-empty strings, returning the857 last one:</p>858 <pre class="literal-block">859 $(and condition1[,condition2[,condition3[...]]])860 </pre>861 <p>Test if the two strings are identical, returning <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean (true =862 non-empty, false = empty):</p>863 <pre class="literal-block">864 $(eq str1, str2)865 </pre>866 <p>Invert a <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean value:</p>867 <pre class="literal-block">868 $(not val)869 </pre>870 <p>Test if <tt class="docutils literal"><span class="pre">variable</span></tt> is defined, returning a <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean value:</p>871 <pre class="literal-block">872 $(defined variable)873 </pre>874 <p>Test if <tt class="docutils literal"><span class="pre">set-a</span></tt> and <tt class="docutils literal"><span class="pre">set-b</span></tt> intersects, returning a <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean875 value:</p>876 <pre class="literal-block">877 $(intersects set-a, set-b)878 </pre>879 <p>Same as <tt class="docutils literal"><span class="pre">$(if</span> <span class="pre">)</span></tt> execpt that the condition is a <tt class="docutils literal"><span class="pre">kmk</span></tt>-expression:</p>880 <pre class="literal-block">881 $(if-expr kmk-expression,true-part[,false-part])882 </pre>883 <p>Select the first true condition (<tt class="docutils literal"><span class="pre">kmk</span></tt>-expression) and expand the884 following body. Special condition strings <tt class="docutils literal"><span class="pre">default</span></tt> and <tt class="docutils literal"><span class="pre">otherwise</span></tt>:</p>885 <pre class="literal-block">886 $(select when1-cond, when1-body[, whenN-cond, whenN-body])887 </pre>888 <p>Evalutate the <tt class="docutils literal"><span class="pre">kmk-expression</span></tt> returning what it evalues as. This is889 the preferred way of doing arithmentic now:</p>890 <pre class="literal-block">891 $(expr kmk-expression)892 </pre>893 </blockquote>894 <p>Stack Fuctions:</p>895 <blockquote>896 <p>Push <tt class="docutils literal"><span class="pre">item</span></tt> onto the <tt class="docutils literal"><span class="pre">stack-var</span></tt>, returning the empty string:</p>897 <pre class="literal-block">898 $(stack-push stack-var, item)899 </pre>900 <p>Pop the top item off the <tt class="docutils literal"><span class="pre">stack-var</span></tt>:</p>901 <pre class="literal-block">902 $(stack-pop stack-var)903 </pre>904 <p>Pop the top item off the <tt class="docutils literal"><span class="pre">stack-var</span></tt>, returning the empty string:</p>905 <pre class="literal-block">906 $(stack-popv stack-var)907 </pre>908 <p>Get the top item of the <tt class="docutils literal"><span class="pre">stack-var</span></tt>, returning the empty string:</p>909 <pre class="literal-block">910 $(stack-top stack-var)911 </pre>912 </blockquote>913 <p>Advanced Functions:</p>914 <blockquote>915 <p>Evaluates to the contents of the variable <tt class="docutils literal"><span class="pre">var</span></tt>, with no expansion916 performed on it:</p>917 <pre class="literal-block">918 $(value var)919 </pre>920 <p>Evaluate <tt class="docutils literal"><span class="pre">body</span></tt> with <tt class="docutils literal"><span class="pre">var</span></tt> bound to each word in <tt class="docutils literal"><span class="pre">words</span></tt>, and921 concatenate the results (spaced):</p>922 <pre class="literal-block">923 $(foreach var,words,body)924 </pre>925 <p>C-style for-loop. Start by evaluating <tt class="docutils literal"><span class="pre">init</span></tt>. Each iteration will926 first check whether the <tt class="docutils literal"><span class="pre">condition</span></tt> (<tt class="docutils literal"><span class="pre">kmk</span></tt>-expression) is true,927 then expand <tt class="docutils literal"><span class="pre">body</span></tt> concatenating the result to the previous iterations928 (spaced), and finally evaluate <tt class="docutils literal"><span class="pre">next</span></tt>:</p>929 <pre class="literal-block">930 $(for init,conditions,next,body)931 </pre>932 <p>C-style while-loop. Each iteration will check whether the <tt class="docutils literal"><span class="pre">condition</span></tt>933 (<tt class="docutils literal"><span class="pre">kmk</span></tt>-expression) is true, then expand <tt class="docutils literal"><span class="pre">body</span></tt> concatenating the934 result to the previous iterations:</p>935 <pre class="literal-block">936 $(while conditions,body)937 </pre>938 <p>Evaluate the variable <tt class="docutils literal"><span class="pre">var</span></tt> replacing any references to <tt class="docutils literal"><span class="pre">$(1)</span></tt>,939 <tt class="docutils literal"><span class="pre">$(2)</span></tt> with the first, second, etc. <tt class="docutils literal"><span class="pre">param</span></tt> values:</p>940 <pre class="literal-block">941 $(call var,param,...)942 </pre>943 <p>Evaluate <tt class="docutils literal"><span class="pre">text</span></tt> then read the results as makefile commands. Expands944 to the empty string:</p>945 <pre class="literal-block">946 $(eval text)947 </pre>948 <p>Same as <tt class="docutils literal"><span class="pre">$(eval</span> <span class="pre">text)</span></tt> except that the <tt class="docutils literal"><span class="pre">text</span></tt> is expanded in its949 own variable context:</p>950 <pre class="literal-block">951 $(evalctx text)952 </pre>953 <p>Same as <tt class="docutils literal"><span class="pre">$(eval</span> <span class="pre">$(value</span> <span class="pre">var))</span></tt>:</p>954 <pre class="literal-block">955 $(evalval var)956 </pre>957 <p>Same as <tt class="docutils literal"><span class="pre">$(evalctx</span> <span class="pre">$(value</span> <span class="pre">var))</span></tt>:</p>958 <pre class="literal-block">959 $(evalvalctx var)960 </pre>961 <p>A combination of <tt class="docutils literal"><span class="pre">$(eval</span> <span class="pre">)</span></tt>, <tt class="docutils literal"><span class="pre">$(call</span> <span class="pre">)</span></tt> and <tt class="docutils literal"><span class="pre">$(value</span> <span class="pre">)</span></tt>:</p>962 <pre class="literal-block">963 $(evalcall var)964 </pre>965 <p>A combination of <tt class="docutils literal"><span class="pre">$(eval</span> <span class="pre">)</span></tt> and <tt class="docutils literal"><span class="pre">$(call</span> <span class="pre">)</span></tt>:</p>966 <pre class="literal-block">967 $(evalcall var)968 </pre>969 <p>Remove comments and blank lines from the variable <tt class="docutils literal"><span class="pre">var</span></tt>. Expands to970 the empty string:</p>971 <pre class="literal-block">972 $(eval-opt-var var)973 </pre>974 <p>Returns accessing <tt class="docutils literal"><span class="pre">$<</span></tt> of <tt class="docutils literal"><span class="pre">target</span></tt>, either retriving the whole thing975 or the file at <tt class="docutils literal"><span class="pre">pos</span></tt> (one-origin):</p>976 <pre class="literal-block">977 $(deps target[, pos])978 </pre>979 <p>Returns accessing <tt class="docutils literal"><span class="pre">$+</span></tt> (order + duplicates) of <tt class="docutils literal"><span class="pre">target</span></tt>, either980 retriving the whole thing or the file at <tt class="docutils literal"><span class="pre">pos</span></tt> (one-origin):</p>981 <pre class="literal-block">982 $(deps-all target[, pos])983 </pre>984 <p>Returns accessing <tt class="docutils literal"><span class="pre">$?</span></tt> of <tt class="docutils literal"><span class="pre">target</span></tt>, either retriving the whole985 thing or the file at <tt class="docutils literal"><span class="pre">pos</span></tt> (one-origin):</p>986 <pre class="literal-block">987 $(deps-newer target[, pos])988 </pre>989 <p>Returns accessing <tt class="docutils literal"><span class="pre">$|</span></tt> (order only) of <tt class="docutils literal"><span class="pre">target</span></tt>, either retriving the990 whole thing or the file at <tt class="docutils literal"><span class="pre">pos</span></tt> (one-origin):</p>991 <pre class="literal-block">992 $(deps-oo target[, pos])993 </pre>994 </blockquote>995 <p>Command Functions:</p>996 <blockquote>997 <p>Create one or more command lines avoiding the max argument998 length restriction of the host OS:</p>999 <pre class="literal-block">1000 $(xargs ar cas mylib.a,$(objects))1001 $(xargs ar cas mylib.a,ar as mylib.a,$(objects))1002 </pre>1003 <p>Returns the commands for the specified target separated by new-line, space,1004 or a user defined string. Note that this might not produce the 100% correct1005 result if any of the prerequisite automatic variables are used:</p>1006 <pre class="literal-block">1007 $(commands target)1008 $(commands-sc target)1009 $(commands-usr target,sep)1010 </pre>1011 <p>Compares two commands returning the empty string if equal and the 3rd1012 argument if not. This differs from <tt class="docutils literal"><span class="pre">$(comp-vars</span> <span class="pre">v1,v2,ne)</span></tt> in that1013 line by line is stripped of leading spaces, command prefixes and1014 trailing spaces before comparing:</p>1015 <pre class="literal-block">1016 $(comp-cmds cmds-var1, cmds-var2, ne)1017 $(comp-cmds-ex cmds1, cmd2, ne)1018 </pre>1019 <p>Compares the values of the two variables returning the empty string if1020 equal and the 3rd argument if not. Leading and trailing spaces is ignored:</p>1021 <pre class="literal-block">1022 $(comp-var var1, var2, ne)1023 </pre>1024 </blockquote>1025 <p>Utility functions:</p>1026 <blockquote>1027 <p>When this function is evaluated, <tt class="docutils literal"><span class="pre">kmk</span></tt> generates a fatal error with the1028 message <tt class="docutils literal"><span class="pre">text</span></tt>:</p>1029 <pre class="literal-block">1030 $(error text...)1031 </pre>1032 <p>When this function is evaluated, <tt class="docutils literal"><span class="pre">kmk</span></tt> generates a warning with the1033 message <tt class="docutils literal"><span class="pre">text</span></tt>:</p>1034 <pre class="literal-block">1035 $(warning text...)1036 </pre>1037 <p>When this function is evaluated, <tt class="docutils literal"><span class="pre">kmk</span></tt> generates a info with the1038 message <tt class="docutils literal"><span class="pre">text</span></tt>:</p>1039 <pre class="literal-block">1040 $(info text...)1041 </pre>1042 <p>Execute a shell <tt class="docutils literal"><span class="pre">command</span></tt> and return its output:</p>1043 <pre class="literal-block">1044 $(shell command)1045 </pre>1046 <p>Return a string describing how the <tt class="docutils literal"><span class="pre">kmk</span></tt> variable <tt class="docutils literal"><span class="pre">variable</span></tt> was defined:</p>1047 <pre class="literal-block">1048 $(origin variable)1049 </pre>1050 <p>Return a string describing the flavor of the <tt class="docutils literal"><span class="pre">kmk</span></tt> variable <tt class="docutils literal"><span class="pre">variable</span></tt>:</p>1051 <pre class="literal-block">1052 $(flavor variable)1053 </pre>1054 <p>Returns the current local time and date formatted in the <tt class="docutils literal"><span class="pre">strftime</span></tt>1055 style specifier <tt class="docutils literal"><span class="pre">fmt</span></tt>. <tt class="docutils literal"><span class="pre">fmt</span></tt> defaults to <tt class="docutils literal"><span class="pre">%Y-%m-%dT%H:%M:%S</span></tt> when1056 not specified:</p>1057 <pre class="literal-block">1058 $(date fmt)1059 </pre>1060 <p>Returns the current UTC time and date formatted in the <tt class="docutils literal"><span class="pre">strftime</span></tt>1061 style specifier <tt class="docutils literal"><span class="pre">fmt</span></tt>. <tt class="docutils literal"><span class="pre">fmt</span></tt> defaults to <tt class="docutils literal"><span class="pre">%Y-%m-%dT%H:%M:%SZ</span></tt> when1062 not specified:</p>1063 <pre class="literal-block">1064 $(date-utc fmt)1065 </pre>1066 <p>Reformats the <tt class="docutils literal"><span class="pre">in</span></tt> time and date using <tt class="docutils literal"><span class="pre">fmt</span></tt>. The <tt class="docutils literal"><span class="pre">in-fmt</span></tt> defaults1067 to <tt class="docutils literal"><span class="pre">fmt</span></tt> if not specified. While <tt class="docutils literal"><span class="pre">fmt</span></tt> defaults to1068 <tt class="docutils literal"><span class="pre">%Y-%m-%dT%H:%M:%SZ</span></tt> if not specified:</p>1069 <pre class="literal-block">1070 $(date-utc fmt,time,in-fmt)1071 </pre>1072 <p>Returns the current nanosecond timestamp (monotonic when possible):</p>1073 <pre class="literal-block">1074 $(nanots )1075 </pre>1076 <p>Returns the size of the specified file, or -1 if the size could not1077 be obtained. This can be used to check if a file exist or not:</p>1078 <pre class="literal-block">1079 $(file-size file)1080 </pre>1081 <p>Searches the <tt class="docutils literal"><span class="pre">PATH</span></tt> <tt class="docutils literal"><span class="pre">kmk</span></tt> variable for the specified <tt class="docutils literal"><span class="pre">files</span></tt>:</p>1082 <pre class="literal-block">1083 $(which files...)1084 </pre>1085 <p>OS/2: Returns the specified LIBPATH variable value:</p>1086 <pre class="literal-block">1087 $(libpath var)1088 </pre>1089 <p>OS/2: Sets the specified LIBPATH variable value, returning the empty string:</p>1090 <pre class="literal-block">1091 $(libpath var,value)1092 </pre>1093 </blockquote>1094 <p>Debugging Functions:</p>1095 <blockquote>1096 <p>Returns various make statistics, if no item is specified a default1097 selection is returned:</p>1098 <pre class="literal-block">1099 $(make-stats item[,itemN])1100 </pre>1101 <p>Raise a debug breakpoint. Used for debugging <tt class="docutils literal"><span class="pre">kmk</span></tt> makefile parsing:</p>1102 <pre class="literal-block">1103 $(breakpoint )1104 </pre>1105 </blockquote>1106 627 </div> 1107 628 <div class="section"> … … 1341 862 </tbody> 1342 863 </table> 864 </div> 865 <div class="section"> 866 <h1><a id="built-in-functions" name="built-in-functions">Built-in functions</a></h1> 867 <p>String Manipulation Functions:</p> 868 <blockquote> 869 <p>Replace <tt class="docutils literal"><span class="pre">from</span></tt> with <tt class="docutils literal"><span class="pre">to</span></tt> in <tt class="docutils literal"><span class="pre">text</span></tt>:</p> 870 <pre class="literal-block"> 871 $(subst from,to,text) 872 </pre> 873 <p>Replace words matching <tt class="docutils literal"><span class="pre">pattern</span></tt> with <tt class="docutils literal"><span class="pre">replacement</span></tt> in <tt class="docutils literal"><span class="pre">text</span></tt>:</p> 874 <pre class="literal-block"> 875 $(patsubst pattern,replacement,text) 876 </pre> 877 <p>Remove excess whitespace characters from <tt class="docutils literal"><span class="pre">string</span></tt>:</p> 878 <pre class="literal-block"> 879 $(strip string) 880 </pre> 881 <p>Locate <tt class="docutils literal"><span class="pre">find</span></tt> in <tt class="docutils literal"><span class="pre">text</span></tt>, returning <tt class="docutils literal"><span class="pre">find</span></tt> if found:</p> 882 <pre class="literal-block"> 883 $(findstring find,text) 884 </pre> 885 <p>Select words in <tt class="docutils literal"><span class="pre">text</span></tt> that match one of the <tt class="docutils literal"><span class="pre">pattern</span></tt> words:</p> 886 <pre class="literal-block"> 887 $(filter pattern...,text) 888 </pre> 889 <p>Select words in <tt class="docutils literal"><span class="pre">text</span></tt> that do not match any of the <tt class="docutils literal"><span class="pre">pattern</span></tt> words:</p> 890 <pre class="literal-block"> 891 $(filter-out pattern...,text) 892 </pre> 893 <p>Sort the words in <tt class="docutils literal"><span class="pre">list</span></tt> lexicographically, removing duplicates:</p> 894 <pre class="literal-block"> 895 $(sort list) 896 </pre> 897 <p>Sort the words in <tt class="docutils literal"><span class="pre">list</span></tt> lexicographically in reserve order, removing 898 duplicates:</p> 899 <pre class="literal-block"> 900 $(rsort list) 901 </pre> 902 <p>Count the number of words in <tt class="docutils literal"><span class="pre">text</span></tt>:</p> 903 <pre class="literal-block"> 904 $(words text) 905 </pre> 906 <p>Extract the <tt class="docutils literal"><span class="pre">n</span></tt>th word (one-origin) of <tt class="docutils literal"><span class="pre">text</span></tt>:</p> 907 <pre class="literal-block"> 908 $(word n,text) 909 </pre> 910 <p>Returns the list of words in <tt class="docutils literal"><span class="pre">text</span></tt> from <tt class="docutils literal"><span class="pre">s</span></tt> to <tt class="docutils literal"><span class="pre">e</span></tt> (one-origin):</p> 911 <pre class="literal-block"> 912 $(wordlist s,e,text) 913 </pre> 914 <p>Extract the first word of <tt class="docutils literal"><span class="pre">names</span></tt>:</p> 915 <pre class="literal-block"> 916 $(firstword names...) 917 </pre> 918 <p>Extract the last word of <tt class="docutils literal"><span class="pre">names</span></tt>:</p> 919 <pre class="literal-block"> 920 $(lastword names...) 921 </pre> 922 <p>Join two parallel lists of words:</p> 923 <pre class="literal-block"> 924 $(join list1,list2) 925 </pre> 926 <p>Fold <tt class="docutils literal"><span class="pre">text</span></tt> to upper case:</p> 927 <pre class="literal-block"> 928 $(toupper text) 929 </pre> 930 <p>Fold <tt class="docutils literal"><span class="pre">text</span></tt> to lower case:</p> 931 <pre class="literal-block"> 932 $(tolower text) 933 </pre> 934 <p>String formatting a la the unix <tt class="docutils literal"><span class="pre">printf</span></tt> command:</p> 935 <pre class="literal-block"> 936 $(printf fmt, arg...) 937 </pre> 938 <p>Return the length of a string or a (unexpanded) variable:</p> 939 <pre class="literal-block"> 940 $(length string) 941 $(length-var var) 942 </pre> 943 <p>Find the position of <tt class="docutils literal"><span class="pre">needle</span></tt> in <tt class="docutils literal"><span class="pre">haystack</span></tt>, returns 0 if not found. 944 Negative <tt class="docutils literal"><span class="pre">start</span></tt> indices are relative to the end of <tt class="docutils literal"><span class="pre">haystack</span></tt>, while 945 positive ones are one based:</p> 946 <pre class="literal-block"> 947 $(pos needle, haystack[, start]) 948 $(lastpos needle, haystack[, start]) 949 </pre> 950 <p>Returns the specified substring. The <tt class="docutils literal"><span class="pre">start</span></tt> works like with <tt class="docutils literal"><span class="pre">$(pos</span> <span class="pre">)</span></tt>. 951 If the substring is partially outside the <tt class="docutils literal"><span class="pre">string</span></tt> the result will be 952 padded with <tt class="docutils literal"><span class="pre">pad</span></tt> if present:</p> 953 <pre class="literal-block"> 954 $(substr string, start[, length[, pad]]) 955 </pre> 956 <p>Insert <tt class="docutils literal"><span class="pre">in</span></tt> into <tt class="docutils literal"><span class="pre">str</span></tt> at the specified position. <tt class="docutils literal"><span class="pre">n</span></tt> works like with 957 <tt class="docutils literal"><span class="pre">$(pos</span> <span class="pre">)</span></tt>, except that <tt class="docutils literal"><span class="pre">0</span></tt> is the end of the string:</p> 958 <pre class="literal-block"> 959 $(insert in, str[, n[, length[, pad]]]) 960 </pre> 961 <p>Translate <tt class="docutils literal"><span class="pre">string</span></tt> exchanging characters in <tt class="docutils literal"><span class="pre">from-set</span></tt> with <tt class="docutils literal"><span class="pre">to-set</span></tt>, 962 optionally completing <tt class="docutils literal"><span class="pre">to-set</span></tt> with <tt class="docutils literal"><span class="pre">pad-char</span></tt> if specified. If no 963 <tt class="docutils literal"><span class="pre">pad-char</span></tt> characters absent in <tt class="docutils literal"><span class="pre">to-set</span></tt> will be deleted:</p> 964 <pre class="literal-block"> 965 $(translate string, from-set[, to-set[, pad-char]]) 966 </pre> 967 </blockquote> 968 <p>Functions for file names:</p> 969 <blockquote> 970 <p>Extract the directory part of each file <tt class="docutils literal"><span class="pre">name</span></tt>:</p> 971 <pre class="literal-block"> 972 $(dir names...) 973 </pre> 974 <p>Extract the non-directory part of each file <tt class="docutils literal"><span class="pre">name</span></tt>:</p> 975 <pre class="literal-block"> 976 $(notdir names...) 977 </pre> 978 <p>Extract the suffix (the last <tt class="docutils literal"><span class="pre">.</span></tt> and following characters) of each file 979 <tt class="docutils literal"><span class="pre">name</span></tt>:</p> 980 <pre class="literal-block"> 981 $(suffix names...) 982 </pre> 983 <p>Extract the base name (name without suffix) of each file name:</p> 984 <pre class="literal-block"> 985 $(basename names...) 986 </pre> 987 <p>Append <tt class="docutils literal"><span class="pre">suffix</span></tt> to each word in <tt class="docutils literal"><span class="pre">names</span></tt>:</p> 988 <pre class="literal-block"> 989 $(addsuffix suffix,names...) 990 </pre> 991 <p>Prepend <tt class="docutils literal"><span class="pre">prefix</span></tt> to each word in <tt class="docutils literal"><span class="pre">names</span></tt>:</p> 992 <pre class="literal-block"> 993 $(addprefix prefix,names...) 994 </pre> 995 <p>Find file names matching a shell file name <tt class="docutils literal"><span class="pre">pattern</span></tt> (not a <tt class="docutils literal"><span class="pre">%</span></tt> 996 pattern):</p> 997 <pre class="literal-block"> 998 $(wildcard pattern...) 999 </pre> 1000 <p>For each file name in <tt class="docutils literal"><span class="pre">names</span></tt>, expand to an absolute name that does not 1001 contain any <tt class="docutils literal"><span class="pre">.</span></tt>, <tt class="docutils literal"><span class="pre">..</span></tt>, nor symlinks:</p> 1002 <pre class="literal-block"> 1003 $(realpath names...) 1004 </pre> 1005 <p>For each file name in <tt class="docutils literal"><span class="pre">names</span></tt>, expand to an absolute name that does not 1006 contain any <tt class="docutils literal"><span class="pre">.</span></tt> or <tt class="docutils literal"><span class="pre">..</span></tt> components, but preserves symlinks:</p> 1007 <pre class="literal-block"> 1008 $(abspath names...) 1009 </pre> 1010 <p>Same as <tt class="docutils literal"><span class="pre">$(abspath</span> <span class="pre">)</span></tt> except that the current directory can be 1011 specified as <tt class="docutils literal"><span class="pre">curdir</span></tt>:</p> 1012 <pre class="literal-block"> 1013 $(abspathex names...[, curdir]) 1014 </pre> 1015 </blockquote> 1016 <p>Arithmetic Functions:</p> 1017 <blockquote> 1018 <p>Returns the sum of the arguments:</p> 1019 <pre class="literal-block"> 1020 $(int-add addend1, addend2[, addendN]) 1021 </pre> 1022 <p>Returns the difference between the first argument and the sum of the rest:</p> 1023 <pre class="literal-block"> 1024 $(int-sub minuend, subtrahend[, subtrahendN]) 1025 </pre> 1026 <p>Returns the product of the arguments:</p> 1027 <pre class="literal-block"> 1028 $(int-mul factor1, factor2[, factorN]) 1029 </pre> 1030 <p>Returns the quotient of first argument and the rest:</p> 1031 <pre class="literal-block"> 1032 $(int-div dividend, divisor[, divisorN]) 1033 </pre> 1034 <p>Returns the modulus of the two arguments:</p> 1035 <pre class="literal-block"> 1036 $(int-mod dividend, divisor) 1037 </pre> 1038 <p>Returns the bitwise two-complement of argument:</p> 1039 <pre class="literal-block"> 1040 $(int-not val) 1041 </pre> 1042 <p>Returns the result of a bitwise AND of the arguments:</p> 1043 <pre class="literal-block"> 1044 $(int-and val1, val2[, valN]) 1045 </pre> 1046 <p>Returns the result of a bitwise OR of the arguments:</p> 1047 <pre class="literal-block"> 1048 $(int-or val1, val2[, valN]) 1049 </pre> 1050 <p>Returns the result of a bitwise XOR of the arguments:</p> 1051 <pre class="literal-block"> 1052 $(int-xor val1, val2[, valN]) 1053 </pre> 1054 <p>Returns the <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean (true = non-empty, false = empty) result 1055 of <tt class="docutils literal"><span class="pre">val1</span> <span class="pre">==</span> <span class="pre">val2</span></tt>:</p> 1056 <pre class="literal-block"> 1057 $(int-eq val1, val2) 1058 </pre> 1059 <p>Returns the <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean result of <tt class="docutils literal"><span class="pre">val1</span> <span class="pre">!=</span> <span class="pre">val2</span></tt>:</p> 1060 <pre class="literal-block"> 1061 $(int-ne val1, val2) 1062 </pre> 1063 <p>Returns the <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean result of <tt class="docutils literal"><span class="pre">val1</span> <span class="pre">></span> <span class="pre">val2</span></tt>:</p> 1064 <pre class="literal-block"> 1065 $(int-gt val1, val2) 1066 </pre> 1067 <p>Returns the <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean result of <tt class="docutils literal"><span class="pre">val1</span> <span class="pre">>=</span> <span class="pre">val2</span></tt>:</p> 1068 <pre class="literal-block"> 1069 $(int-ge val1, val2) 1070 </pre> 1071 <p>Returns the <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean result of <tt class="docutils literal"><span class="pre">val1</span> <span class="pre"><</span> <span class="pre">val2</span></tt>:</p> 1072 <pre class="literal-block"> 1073 $(int-lt val1, val2) 1074 </pre> 1075 <p>Returns the <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean result of <tt class="docutils literal"><span class="pre">val1</span> <span class="pre"><=</span> <span class="pre">val2</span></tt>:</p> 1076 <pre class="literal-block"> 1077 $(int-le val1, val2) 1078 </pre> 1079 </blockquote> 1080 <p>Boolean and Conditional Functions:</p> 1081 <blockquote> 1082 <p>Condition is false if the <tt class="docutils literal"><span class="pre">condition</span></tt> evaluates to an empty string 1083 (stripped). Evaluate the <tt class="docutils literal"><span class="pre">true-part</span></tt> if the condition is true, otherwise 1084 the <tt class="docutils literal"><span class="pre">false-part</span></tt>:</p> 1085 <pre class="literal-block"> 1086 $(if condition,true-part[,false-part]) 1087 </pre> 1088 <p>Test if any of the conditions evalues to non-empty string, returning the 1089 first one:</p> 1090 <pre class="literal-block"> 1091 $(or condition1[,condition2[,condition3[...]]]) 1092 </pre> 1093 <p>Test if all of the conditions evaluates to non-empty strings, returning the 1094 last one:</p> 1095 <pre class="literal-block"> 1096 $(and condition1[,condition2[,condition3[...]]]) 1097 </pre> 1098 <p>Test if the two strings are identical, returning <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean (true = 1099 non-empty, false = empty):</p> 1100 <pre class="literal-block"> 1101 $(eq str1, str2) 1102 </pre> 1103 <p>Invert a <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean value:</p> 1104 <pre class="literal-block"> 1105 $(not val) 1106 </pre> 1107 <p>Test if <tt class="docutils literal"><span class="pre">variable</span></tt> is defined, returning a <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean value:</p> 1108 <pre class="literal-block"> 1109 $(defined variable) 1110 </pre> 1111 <p>Test if <tt class="docutils literal"><span class="pre">set-a</span></tt> and <tt class="docutils literal"><span class="pre">set-b</span></tt> intersects, returning a <tt class="docutils literal"><span class="pre">kmk</span></tt> boolean 1112 value:</p> 1113 <pre class="literal-block"> 1114 $(intersects set-a, set-b) 1115 </pre> 1116 <p>Same as <tt class="docutils literal"><span class="pre">$(if</span> <span class="pre">)</span></tt> execpt that the condition is a <tt class="docutils literal"><span class="pre">kmk</span></tt>-expression:</p> 1117 <pre class="literal-block"> 1118 $(if-expr kmk-expression,true-part[,false-part]) 1119 </pre> 1120 <p>Select the first true condition (<tt class="docutils literal"><span class="pre">kmk</span></tt>-expression) and expand the 1121 following body. Special condition strings <tt class="docutils literal"><span class="pre">default</span></tt> and <tt class="docutils literal"><span class="pre">otherwise</span></tt>:</p> 1122 <pre class="literal-block"> 1123 $(select when1-cond, when1-body[, whenN-cond, whenN-body]) 1124 </pre> 1125 <p>Evalutate the <tt class="docutils literal"><span class="pre">kmk-expression</span></tt> returning what it evalues as. This is 1126 the preferred way of doing arithmentic now:</p> 1127 <pre class="literal-block"> 1128 $(expr kmk-expression) 1129 </pre> 1130 </blockquote> 1131 <p>Stack Fuctions:</p> 1132 <blockquote> 1133 <p>Push <tt class="docutils literal"><span class="pre">item</span></tt> onto the <tt class="docutils literal"><span class="pre">stack-var</span></tt>, returning the empty string:</p> 1134 <pre class="literal-block"> 1135 $(stack-push stack-var, item) 1136 </pre> 1137 <p>Pop the top item off the <tt class="docutils literal"><span class="pre">stack-var</span></tt>:</p> 1138 <pre class="literal-block"> 1139 $(stack-pop stack-var) 1140 </pre> 1141 <p>Pop the top item off the <tt class="docutils literal"><span class="pre">stack-var</span></tt>, returning the empty string:</p> 1142 <pre class="literal-block"> 1143 $(stack-popv stack-var) 1144 </pre> 1145 <p>Get the top item of the <tt class="docutils literal"><span class="pre">stack-var</span></tt>, returning the empty string:</p> 1146 <pre class="literal-block"> 1147 $(stack-top stack-var) 1148 </pre> 1149 </blockquote> 1150 <p>Advanced Functions:</p> 1151 <blockquote> 1152 <p>Evaluates to the contents of the variable <tt class="docutils literal"><span class="pre">var</span></tt>, with no expansion 1153 performed on it:</p> 1154 <pre class="literal-block"> 1155 $(value var) 1156 </pre> 1157 <p>Evaluate <tt class="docutils literal"><span class="pre">body</span></tt> with <tt class="docutils literal"><span class="pre">var</span></tt> bound to each word in <tt class="docutils literal"><span class="pre">words</span></tt>, and 1158 concatenate the results (spaced):</p> 1159 <pre class="literal-block"> 1160 $(foreach var,words,body) 1161 </pre> 1162 <p>C-style for-loop. Start by evaluating <tt class="docutils literal"><span class="pre">init</span></tt>. Each iteration will 1163 first check whether the <tt class="docutils literal"><span class="pre">condition</span></tt> (<tt class="docutils literal"><span class="pre">kmk</span></tt>-expression) is true, 1164 then expand <tt class="docutils literal"><span class="pre">body</span></tt> concatenating the result to the previous iterations 1165 (spaced), and finally evaluate <tt class="docutils literal"><span class="pre">next</span></tt>:</p> 1166 <pre class="literal-block"> 1167 $(for init,conditions,next,body) 1168 </pre> 1169 <p>C-style while-loop. Each iteration will check whether the <tt class="docutils literal"><span class="pre">condition</span></tt> 1170 (<tt class="docutils literal"><span class="pre">kmk</span></tt>-expression) is true, then expand <tt class="docutils literal"><span class="pre">body</span></tt> concatenating the 1171 result to the previous iterations:</p> 1172 <pre class="literal-block"> 1173 $(while conditions,body) 1174 </pre> 1175 <p>Evaluate the variable <tt class="docutils literal"><span class="pre">var</span></tt> replacing any references to <tt class="docutils literal"><span class="pre">$(1)</span></tt>, 1176 <tt class="docutils literal"><span class="pre">$(2)</span></tt> with the first, second, etc. <tt class="docutils literal"><span class="pre">param</span></tt> values:</p> 1177 <pre class="literal-block"> 1178 $(call var,param,...) 1179 </pre> 1180 <p>Evaluate <tt class="docutils literal"><span class="pre">text</span></tt> then read the results as makefile commands. Expands 1181 to the empty string:</p> 1182 <pre class="literal-block"> 1183 $(eval text) 1184 </pre> 1185 <p>Same as <tt class="docutils literal"><span class="pre">$(eval</span> <span class="pre">text)</span></tt> except that the <tt class="docutils literal"><span class="pre">text</span></tt> is expanded in its 1186 own variable context:</p> 1187 <pre class="literal-block"> 1188 $(evalctx text) 1189 </pre> 1190 <p>Same as <tt class="docutils literal"><span class="pre">$(eval</span> <span class="pre">$(value</span> <span class="pre">var))</span></tt>:</p> 1191 <pre class="literal-block"> 1192 $(evalval var) 1193 </pre> 1194 <p>Same as <tt class="docutils literal"><span class="pre">$(evalctx</span> <span class="pre">$(value</span> <span class="pre">var))</span></tt>:</p> 1195 <pre class="literal-block"> 1196 $(evalvalctx var) 1197 </pre> 1198 <p>A combination of <tt class="docutils literal"><span class="pre">$(eval</span> <span class="pre">)</span></tt>, <tt class="docutils literal"><span class="pre">$(call</span> <span class="pre">)</span></tt> and <tt class="docutils literal"><span class="pre">$(value</span> <span class="pre">)</span></tt>:</p> 1199 <pre class="literal-block"> 1200 $(evalcall var) 1201 </pre> 1202 <p>A combination of <tt class="docutils literal"><span class="pre">$(eval</span> <span class="pre">)</span></tt> and <tt class="docutils literal"><span class="pre">$(call</span> <span class="pre">)</span></tt>:</p> 1203 <pre class="literal-block"> 1204 $(evalcall var) 1205 </pre> 1206 <p>Remove comments and blank lines from the variable <tt class="docutils literal"><span class="pre">var</span></tt>. Expands to 1207 the empty string:</p> 1208 <pre class="literal-block"> 1209 $(eval-opt-var var) 1210 </pre> 1211 <p>Returns accessing <tt class="docutils literal"><span class="pre">$<</span></tt> of <tt class="docutils literal"><span class="pre">target</span></tt>, either retriving the whole thing 1212 or the file at <tt class="docutils literal"><span class="pre">pos</span></tt> (one-origin):</p> 1213 <pre class="literal-block"> 1214 $(deps target[, pos]) 1215 </pre> 1216 <p>Returns accessing <tt class="docutils literal"><span class="pre">$+</span></tt> (order + duplicates) of <tt class="docutils literal"><span class="pre">target</span></tt>, either 1217 retriving the whole thing or the file at <tt class="docutils literal"><span class="pre">pos</span></tt> (one-origin):</p> 1218 <pre class="literal-block"> 1219 $(deps-all target[, pos]) 1220 </pre> 1221 <p>Returns accessing <tt class="docutils literal"><span class="pre">$?</span></tt> of <tt class="docutils literal"><span class="pre">target</span></tt>, either retriving the whole 1222 thing or the file at <tt class="docutils literal"><span class="pre">pos</span></tt> (one-origin):</p> 1223 <pre class="literal-block"> 1224 $(deps-newer target[, pos]) 1225 </pre> 1226 <p>Returns accessing <tt class="docutils literal"><span class="pre">$|</span></tt> (order only) of <tt class="docutils literal"><span class="pre">target</span></tt>, either retriving the 1227 whole thing or the file at <tt class="docutils literal"><span class="pre">pos</span></tt> (one-origin):</p> 1228 <pre class="literal-block"> 1229 $(deps-oo target[, pos]) 1230 </pre> 1231 </blockquote> 1232 <p>Command Functions:</p> 1233 <blockquote> 1234 <p>Create one or more command lines avoiding the max argument 1235 length restriction of the host OS:</p> 1236 <pre class="literal-block"> 1237 $(xargs ar cas mylib.a,$(objects)) 1238 $(xargs ar cas mylib.a,ar as mylib.a,$(objects)) 1239 </pre> 1240 <p>Returns the commands for the specified target separated by new-line, space, 1241 or a user defined string. Note that this might not produce the 100% correct 1242 result if any of the prerequisite automatic variables are used:</p> 1243 <pre class="literal-block"> 1244 $(commands target) 1245 $(commands-sc target) 1246 $(commands-usr target,sep) 1247 </pre> 1248 <p>Compares two commands returning the empty string if equal and the 3rd 1249 argument if not. This differs from <tt class="docutils literal"><span class="pre">$(comp-vars</span> <span class="pre">v1,v2,ne)</span></tt> in that 1250 line by line is stripped of leading spaces, command prefixes and 1251 trailing spaces before comparing:</p> 1252 <pre class="literal-block"> 1253 $(comp-cmds cmds-var1, cmds-var2, ne) 1254 $(comp-cmds-ex cmds1, cmd2, ne) 1255 </pre> 1256 <p>Compares the values of the two variables returning the empty string if 1257 equal and the 3rd argument if not. Leading and trailing spaces is ignored:</p> 1258 <pre class="literal-block"> 1259 $(comp-var var1, var2, ne) 1260 </pre> 1261 </blockquote> 1262 <p>Utility functions:</p> 1263 <blockquote> 1264 <p>When this function is evaluated, <tt class="docutils literal"><span class="pre">kmk</span></tt> generates a fatal error with the 1265 message <tt class="docutils literal"><span class="pre">text</span></tt>:</p> 1266 <pre class="literal-block"> 1267 $(error text...) 1268 </pre> 1269 <p>When this function is evaluated, <tt class="docutils literal"><span class="pre">kmk</span></tt> generates a warning with the 1270 message <tt class="docutils literal"><span class="pre">text</span></tt>:</p> 1271 <pre class="literal-block"> 1272 $(warning text...) 1273 </pre> 1274 <p>When this function is evaluated, <tt class="docutils literal"><span class="pre">kmk</span></tt> generates a info with the 1275 message <tt class="docutils literal"><span class="pre">text</span></tt>:</p> 1276 <pre class="literal-block"> 1277 $(info text...) 1278 </pre> 1279 <p>Execute a shell <tt class="docutils literal"><span class="pre">command</span></tt> and return its output:</p> 1280 <pre class="literal-block"> 1281 $(shell command) 1282 </pre> 1283 <p>Return a string describing how the <tt class="docutils literal"><span class="pre">kmk</span></tt> variable <tt class="docutils literal"><span class="pre">variable</span></tt> was defined:</p> 1284 <pre class="literal-block"> 1285 $(origin variable) 1286 </pre> 1287 <p>Return a string describing the flavor of the <tt class="docutils literal"><span class="pre">kmk</span></tt> variable <tt class="docutils literal"><span class="pre">variable</span></tt>:</p> 1288 <pre class="literal-block"> 1289 $(flavor variable) 1290 </pre> 1291 <p>Returns the current local time and date formatted in the <tt class="docutils literal"><span class="pre">strftime</span></tt> 1292 style specifier <tt class="docutils literal"><span class="pre">fmt</span></tt>. <tt class="docutils literal"><span class="pre">fmt</span></tt> defaults to <tt class="docutils literal"><span class="pre">%Y-%m-%dT%H:%M:%S</span></tt> when 1293 not specified:</p> 1294 <pre class="literal-block"> 1295 $(date fmt) 1296 </pre> 1297 <p>Returns the current UTC time and date formatted in the <tt class="docutils literal"><span class="pre">strftime</span></tt> 1298 style specifier <tt class="docutils literal"><span class="pre">fmt</span></tt>. <tt class="docutils literal"><span class="pre">fmt</span></tt> defaults to <tt class="docutils literal"><span class="pre">%Y-%m-%dT%H:%M:%SZ</span></tt> when 1299 not specified:</p> 1300 <pre class="literal-block"> 1301 $(date-utc fmt) 1302 </pre> 1303 <p>Reformats the <tt class="docutils literal"><span class="pre">in</span></tt> time and date using <tt class="docutils literal"><span class="pre">fmt</span></tt>. The <tt class="docutils literal"><span class="pre">in-fmt</span></tt> defaults 1304 to <tt class="docutils literal"><span class="pre">fmt</span></tt> if not specified. While <tt class="docutils literal"><span class="pre">fmt</span></tt> defaults to 1305 <tt class="docutils literal"><span class="pre">%Y-%m-%dT%H:%M:%SZ</span></tt> if not specified:</p> 1306 <pre class="literal-block"> 1307 $(date-utc fmt,time,in-fmt) 1308 </pre> 1309 <p>Returns the current nanosecond timestamp (monotonic when possible):</p> 1310 <pre class="literal-block"> 1311 $(nanots ) 1312 </pre> 1313 <p>Returns the size of the specified file, or -1 if the size could not 1314 be obtained. This can be used to check if a file exist or not:</p> 1315 <pre class="literal-block"> 1316 $(file-size file) 1317 </pre> 1318 <p>Searches the <tt class="docutils literal"><span class="pre">PATH</span></tt> <tt class="docutils literal"><span class="pre">kmk</span></tt> variable for the specified <tt class="docutils literal"><span class="pre">files</span></tt>:</p> 1319 <pre class="literal-block"> 1320 $(which files...) 1321 </pre> 1322 <p>OS/2: Returns the specified LIBPATH variable value:</p> 1323 <pre class="literal-block"> 1324 $(libpath var) 1325 </pre> 1326 <p>OS/2: Sets the specified LIBPATH variable value, returning the empty string:</p> 1327 <pre class="literal-block"> 1328 $(libpath var,value) 1329 </pre> 1330 </blockquote> 1331 <p>Debugging Functions:</p> 1332 <blockquote> 1333 <p>Returns various make statistics, if no item is specified a default 1334 selection is returned:</p> 1335 <pre class="literal-block"> 1336 $(make-stats item[,itemN]) 1337 </pre> 1338 <p>Raise a debug breakpoint. Used for debugging <tt class="docutils literal"><span class="pre">kmk</span></tt> makefile parsing:</p> 1339 <pre class="literal-block"> 1340 $(breakpoint ) 1341 </pre> 1342 </blockquote> 1343 1343 <hr class="docutils" /> 1344 1344 <table class="docutils field-list" frame="void" rules="none"> -
trunk/kBuild/doc/QuickReference-kmk.txt
r2167 r2168 264 264 265 265 266 Special Targets 267 --------------- 268 269 todo 270 271 272 273 Commands 274 -------- 275 276 Builtin commands all start with ``kmk_builtin_``, so in order to save space 277 this prefix has been omitted in the table below. All commands comes in an 278 external edition that can be used by/in the shell, these are prefixed ``kmk_``. 279 280 +---------------+-------------------------------------------------------------+ 281 | Command | Description | 282 +===============+=============================================================+ 283 | ``append`` | Append text to a file. The builtin version can output the | 284 | | value of a variable or the commands of a target. | 285 +---------------+-------------------------------------------------------------+ 286 | ``cat`` | The BSD ``cat`` command. | 287 +---------------+-------------------------------------------------------------+ 288 | ``chmod`` | The BSD ``chmod`` command. | 289 +---------------+-------------------------------------------------------------+ 290 | ``cmp`` | The BSD ``cmp`` command. | 291 +---------------+-------------------------------------------------------------+ 292 | ``cp`` | The BSD ``cp`` command with some twaking. | 293 +---------------+-------------------------------------------------------------+ 294 | ``echo`` | The BSD ``echo`` command. | 295 +---------------+-------------------------------------------------------------+ 296 | ``expr`` | The BSD ``expr`` command. | 297 +---------------+-------------------------------------------------------------+ 298 | ``install`` | The BSD ``install`` command with some tweaking. | 299 +---------------+-------------------------------------------------------------+ 300 | ``kDepIDB`` | Extract dependencies from a Visual C++ .IDB file. | 301 +---------------+-------------------------------------------------------------+ 302 | ``ln`` | The BSD ``ln`` command. | 303 +---------------+-------------------------------------------------------------+ 304 | ``md5sum`` | Typical MD5 sum program, custom kBuild version. | 305 +---------------+-------------------------------------------------------------+ 306 | ``mkdir`` | The BSD ``mkdir`` command. | 307 +---------------+-------------------------------------------------------------+ 308 | ``mv`` | The BSD ``mv`` command with some tweaking. | 309 +---------------+-------------------------------------------------------------+ 310 | ``printf`` | The BSD ``printf`` command. | 311 +---------------+-------------------------------------------------------------+ 312 | ``rm`` | The BSD ``rm`` command with some tweaking. | 313 +---------------+-------------------------------------------------------------+ 314 | ``rmdir`` | The BSD ``rmdir`` command with some tweaking. | 315 +---------------+-------------------------------------------------------------+ 316 | ``sleep`` | Typical ``sleep`` program, custom kBuild version. | 317 +---------------+-------------------------------------------------------------+ 318 | ``test`` | The BSD ``test`` program with some tweaking. | 319 +---------------+-------------------------------------------------------------+ 320 321 Some additional external commands are available in the ``kmk`` / ``kBuild`` 322 environment (``kSomething`` command are not prefixed with ``kmk_``): 323 324 +---------------+-------------------------------------------------------------+ 325 | Command | Description | 326 +===============+=============================================================+ 327 | ``kDepPre`` | Extract dependencies from the C/C++ preprocessor output. | 328 +---------------+-------------------------------------------------------------+ 329 | ``kObjCache`` | Simple object file cache program. | 330 +---------------+-------------------------------------------------------------+ 331 | ``ash`` | Almquist's shell (NetBSD variant). | 332 +---------------+-------------------------------------------------------------+ 333 | ``gmake`` | Vanilla GNU ``make`` from same sources as ``kmk``. | 334 +---------------+-------------------------------------------------------------+ 335 | ``redirect`` | Shell avoidance tool. Sets up file descriptors, environment | 336 | | variables and current directory before kicking of program. | 337 +---------------+-------------------------------------------------------------+ 338 | ``sed`` | GNU ``sed`` with some tweaks to avoid involving the shell. | 339 +---------------+-------------------------------------------------------------+ 340 | ``time`` | Stopwatch utility for measuring program execution time(s). | 341 +---------------+-------------------------------------------------------------+ 342 343 344 345 kmk-expression 346 -------------- 347 348 ``kmk``-expressions are related to the C/C++ preprocessor in some ways as well 349 as ``nmake`` and BSD ``make``. There are however some peculiarities because of 350 the way GNU ``make`` choose to represent booleans in its function library, so, 351 strings can be turned into boolean by taking any non-empty string as true. 352 353 Quoting using single quotes results in hard strings, while double quotes and 354 unquoted string results in soft strings that can be converted to number or 355 boolean to fit the situation. 356 357 Here's the operator table in decending precedence order: 358 359 +---------------+--------+-----------------------------------------------------+ 360 | Operator | Type | Description | 361 +===============+========+=====================================================+ 362 | ``defined`` | Unary | Checks if the following variable exists. | 363 +---------------+ +-----------------------------------------------------+ 364 | ``exists`` | | Checks if the following file exists. | 365 +---------------+ +-----------------------------------------------------+ 366 | ``target`` | | Checks if the following target exists. | 367 +---------------+ +-----------------------------------------------------+ 368 | ``bool`` | | Casts the following value to boolean. | 369 +---------------+ +-----------------------------------------------------+ 370 | ``num`` | | Casts the following value to a number. | 371 +---------------+ +-----------------------------------------------------+ 372 | ``str`` | | Casts the following value to a string. | 373 +---------------+--------+-----------------------------------------------------+ 374 | ``!`` | Unary | Logical NOT. | 375 +---------------+ +-----------------------------------------------------+ 376 | ``+`` | | Pluss prefix. | 377 +---------------+ +-----------------------------------------------------+ 378 | ``-`` | | Minus prefix. | 379 +---------------+ +-----------------------------------------------------+ 380 | ``~`` | | Bitwise one's complement. | 381 +---------------+--------+-----------------------------------------------------+ 382 | ``*`` | Binary | Multiplication (product). | 383 +---------------+ +-----------------------------------------------------+ 384 | ``/`` | | Division (quotient). | 385 +---------------+ +-----------------------------------------------------+ 386 | ``%`` | | Modulus (remainder). | 387 +---------------+--------+-----------------------------------------------------+ 388 | ``+`` | Binary | Addition (sum). | 389 +---------------+ +-----------------------------------------------------+ 390 | ``-`` | | Subtraction (difference). | 391 +---------------+--------+-----------------------------------------------------+ 392 | ``<<`` | Binary | Bitwise left shift. | 393 +---------------+ +-----------------------------------------------------+ 394 | ``>>`` | | Bitwise right shift. | 395 +---------------+--------+-----------------------------------------------------+ 396 | ``<=`` | Binary | Less or equal than. | 397 +---------------+ +-----------------------------------------------------+ 398 | ``<`` | | Less than. | 399 +---------------+ +-----------------------------------------------------+ 400 | ``>=`` | | Greater or equal than. | 401 +---------------+ +-----------------------------------------------------+ 402 | ``>`` | | Greater than. | 403 +---------------+--------+-----------------------------------------------------+ 404 | ``==`` | Binary | Equal to. | 405 +---------------+ +-----------------------------------------------------+ 406 | ``!=`` | | Not equal to. | 407 +---------------+--------+-----------------------------------------------------+ 408 | ``&`` | Binary | Bitwise AND. | 409 +---------------+--------+-----------------------------------------------------+ 410 | ``^`` | Binary | Bitwise XOR. | 411 +---------------+--------+-----------------------------------------------------+ 412 | ``|`` | Binary | Bitwise OR. | 413 +---------------+--------+-----------------------------------------------------+ 414 | ``&&`` | Binary | Logical AND. | 415 +---------------+--------+-----------------------------------------------------+ 416 | ``||`` | Binary | Logical OR. | 417 +---------------+--------+-----------------------------------------------------+ 418 419 420 266 421 Built-in functions 267 422 ------------------ … … 747 902 748 903 749 750 Special Targets751 ---------------752 753 todo754 755 756 757 Commands758 --------759 760 Builtin commands all start with ``kmk_builtin_``, so in order to save space761 this prefix has been omitted in the table below. All commands comes in an762 external edition that can be used by/in the shell, these are prefixed ``kmk_``.763 764 +---------------+-------------------------------------------------------------+765 | Command | Description |766 +===============+=============================================================+767 | ``append`` | Append text to a file. The builtin version can output the |768 | | value of a variable or the commands of a target. |769 +---------------+-------------------------------------------------------------+770 | ``cat`` | The BSD ``cat`` command. |771 +---------------+-------------------------------------------------------------+772 | ``chmod`` | The BSD ``chmod`` command. |773 +---------------+-------------------------------------------------------------+774 | ``cmp`` | The BSD ``cmp`` command. |775 +---------------+-------------------------------------------------------------+776 | ``cp`` | The BSD ``cp`` command with some twaking. |777 +---------------+-------------------------------------------------------------+778 | ``echo`` | The BSD ``echo`` command. |779 +---------------+-------------------------------------------------------------+780 | ``expr`` | The BSD ``expr`` command. |781 +---------------+-------------------------------------------------------------+782 | ``install`` | The BSD ``install`` command with some tweaking. |783 +---------------+-------------------------------------------------------------+784 | ``kDepIDB`` | Extract dependencies from a Visual C++ .IDB file. |785 +---------------+-------------------------------------------------------------+786 | ``ln`` | The BSD ``ln`` command. |787 +---------------+-------------------------------------------------------------+788 | ``md5sum`` | Typical MD5 sum program, custom kBuild version. |789 +---------------+-------------------------------------------------------------+790 | ``mkdir`` | The BSD ``mkdir`` command. |791 +---------------+-------------------------------------------------------------+792 | ``mv`` | The BSD ``mv`` command with some tweaking. |793 +---------------+-------------------------------------------------------------+794 | ``printf`` | The BSD ``printf`` command. |795 +---------------+-------------------------------------------------------------+796 | ``rm`` | The BSD ``rm`` command with some tweaking. |797 +---------------+-------------------------------------------------------------+798 | ``rmdir`` | The BSD ``rmdir`` command with some tweaking. |799 +---------------+-------------------------------------------------------------+800 | ``sleep`` | Typical ``sleep`` program, custom kBuild version. |801 +---------------+-------------------------------------------------------------+802 | ``test`` | The BSD ``test`` program with some tweaking. |803 +---------------+-------------------------------------------------------------+804 805 Some additional external commands are available in the ``kmk`` / ``kBuild``806 environment (``kSomething`` command are not prefixed with ``kmk_``):807 808 +---------------+-------------------------------------------------------------+809 | Command | Description |810 +===============+=============================================================+811 | ``kDepPre`` | Extract dependencies from the C/C++ preprocessor output. |812 +---------------+-------------------------------------------------------------+813 | ``kObjCache`` | Simple object file cache program. |814 +---------------+-------------------------------------------------------------+815 | ``ash`` | Almquist's shell (NetBSD variant). |816 +---------------+-------------------------------------------------------------+817 | ``gmake`` | Vanilla GNU ``make`` from same sources as ``kmk``. |818 +---------------+-------------------------------------------------------------+819 | ``redirect`` | Shell avoidance tool. Sets up file descriptors, environment |820 | | variables and current directory before kicking of program. |821 +---------------+-------------------------------------------------------------+822 | ``sed`` | GNU ``sed`` with some tweaks to avoid involving the shell. |823 +---------------+-------------------------------------------------------------+824 | ``time`` | Stopwatch utility for measuring program execution time(s). |825 +---------------+-------------------------------------------------------------+826 827 828 kmk-expression829 --------------830 831 ``kmk``-expressions are related to the C/C++ preprocessor in some ways as well832 as ``nmake`` and BSD ``make``. There are however some peculiarities because of833 the way GNU ``make`` choose to represent booleans in its function library, so,834 strings can be turned into boolean by taking any non-empty string as true.835 836 Quoting using single quotes results in hard strings, while double quotes and837 unquoted string results in soft strings that can be converted to number or838 boolean to fit the situation.839 840 Here's the operator table in decending precedence order:841 842 +---------------+--------+-----------------------------------------------------+843 | Operator | Type | Description |844 +===============+========+=====================================================+845 | ``defined`` | Unary | Checks if the following variable exists. |846 +---------------+ +-----------------------------------------------------+847 | ``exists`` | | Checks if the following file exists. |848 +---------------+ +-----------------------------------------------------+849 | ``target`` | | Checks if the following target exists. |850 +---------------+ +-----------------------------------------------------+851 | ``bool`` | | Casts the following value to boolean. |852 +---------------+ +-----------------------------------------------------+853 | ``num`` | | Casts the following value to a number. |854 +---------------+ +-----------------------------------------------------+855 | ``str`` | | Casts the following value to a string. |856 +---------------+--------+-----------------------------------------------------+857 | ``!`` | Unary | Logical NOT. |858 +---------------+ +-----------------------------------------------------+859 | ``+`` | | Pluss prefix. |860 +---------------+ +-----------------------------------------------------+861 | ``-`` | | Minus prefix. |862 +---------------+ +-----------------------------------------------------+863 | ``~`` | | Bitwise one's complement. |864 +---------------+--------+-----------------------------------------------------+865 | ``*`` | Binary | Multiplication (product). |866 +---------------+ +-----------------------------------------------------+867 | ``/`` | | Division (quotient). |868 +---------------+ +-----------------------------------------------------+869 | ``%`` | | Modulus (remainder). |870 +---------------+--------+-----------------------------------------------------+871 | ``+`` | Binary | Addition (sum). |872 +---------------+ +-----------------------------------------------------+873 | ``-`` | | Subtraction (difference). |874 +---------------+--------+-----------------------------------------------------+875 | ``<<`` | Binary | Bitwise left shift. |876 +---------------+ +-----------------------------------------------------+877 | ``>>`` | | Bitwise right shift. |878 +---------------+--------+-----------------------------------------------------+879 | ``<=`` | Binary | Less or equal than. |880 +---------------+ +-----------------------------------------------------+881 | ``<`` | | Less than. |882 +---------------+ +-----------------------------------------------------+883 | ``>=`` | | Greater or equal than. |884 +---------------+ +-----------------------------------------------------+885 | ``>`` | | Greater than. |886 +---------------+--------+-----------------------------------------------------+887 | ``==`` | Binary | Equal to. |888 +---------------+ +-----------------------------------------------------+889 | ``!=`` | | Not equal to. |890 +---------------+--------+-----------------------------------------------------+891 | ``&`` | Binary | Bitwise AND. |892 +---------------+--------+-----------------------------------------------------+893 | ``^`` | Binary | Bitwise XOR. |894 +---------------+--------+-----------------------------------------------------+895 | ``|`` | Binary | Bitwise OR. |896 +---------------+--------+-----------------------------------------------------+897 | ``&&`` | Binary | Logical AND. |898 +---------------+--------+-----------------------------------------------------+899 | ``||`` | Binary | Logical OR. |900 +---------------+--------+-----------------------------------------------------+901 902 903 904 904 ----- 905 905
Note:
See TracChangeset
for help on using the changeset viewer.