source: trunk/kBuild/doc/QuickReference-kmk.txt@ 2247

Last change on this file since 2247 was 2243, checked in by bird, 17 years ago

*: Updated copyright to 2009 and normalized name & email.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.4 KB
Line 
1
2kmk Quick Reference
3===================
4
5This is an attempt at summarizing all directives, functions, special variables,
6special targets, built-in commands, external commands, and ``kmk``-expressions.
7Since *all* the features are included, the quickness of this reference can be
8disputed. ;-)
9
10
11
12Directives
13----------
14
15Here is a summary of the directives ``kmk`` recognizes:
16
17 Define a multi-line, recursively-expanded variable::
18
19 define variable
20 endef
21
22 Conditionally evaluate part of the makefile::
23
24 ifdef variable
25 ifndef variable
26 ifeq (a,b)
27 ifeq "a" "b"
28 ifeq 'a' 'b'
29 ifneq (a,b)
30 ifneq "a" "b"
31 ifneq 'a' 'b'
32 if1of (set-a,set-b) [1]
33 ifn1of (set-a,set-b) [1]
34 if expression [1]
35 else
36 endif
37
38 Include another makefile::
39
40 include file
41 -include file
42 sinclude file
43
44 Include another dependency file [1]_::
45
46 includedep file
47
48 Define a variable, overriding any previous definition, even one from the
49 command line::
50
51 override variable = value
52 override variable := value
53 override variable += value
54 override variable <= value [1]
55 override variable ?= value
56 override define variable
57 endef
58
59 Tell ``kmk`` to export all variables to child processes by default::
60
61 export
62
63 Tell ``kmk`` whether or not to export a particular variable to child
64 processes::
65
66 export variable
67 export variable = value
68 export variable := value
69 export variable += value
70 export variable <= value [1]
71 export variable ?= value
72 unexport variable
73
74 Define a variable in the local context instead of the global one [1]_::
75
76 local variable = value
77 local variable := value
78 local variable += value
79 local variable <= value
80 local variable ?= value
81 local define variable
82 endef
83
84 Specify a search path for files matching a ``%`` pattern::
85
86 vpath pattern path
87
88 Remove all search paths previously specified for pattern::
89
90 vpath pattern
91
92 Remove all search paths previously specified in any vpath directive::
93
94 vpath
95
96
97
98Automatic variables
99-------------------
100
101Here is a summary of the automatic variables.
102
103+-----------+-----------------------------------------------------------------+
104| Variable | Description |
105+===========+=================================================================+
106| ``$@`` | The file name of the target. |
107+-----------+-----------------------------------------------------------------+
108| ``$<`` | The name of the first prerequisite. |
109+-----------+-----------------------------------------------------------------+
110| ``$?`` | The names of all the prerequisites that are newer than the |
111| | target, with spaces between them. |
112+-----------+-----------------------------------------------------------------+
113| ``$^`` | The names of all the prerequisites, duplicates omitted. |
114+-----------+-----------------------------------------------------------------+
115| ``$+`` | The names of all the prerequisites, duplicates and order |
116| | preserved |
117+-----------+-----------------------------------------------------------------+
118| ``$*`` | The stem with which an implicit rule matches. |
119+-----------+-----------------------------------------------------------------+
120| ``$|`` | The name of all the order only prerequisites. |
121+-----------+-----------------------------------------------------------------+
122| ``$(@D)`` | The directory part of ``$@``. |
123+-----------+-----------------------------------------------------------------+
124| ``$(<D)`` | The directory part of ``$<``. |
125+-----------+-----------------------------------------------------------------+
126| ``$(?D)`` | The directory part of ``$?``. |
127+-----------+-----------------------------------------------------------------+
128| ``$(^D)`` | The directory part of ``%^``. |
129+-----------+-----------------------------------------------------------------+
130| ``$(+D)`` | The directory part of ``$+``. |
131+-----------+-----------------------------------------------------------------+
132| ``$(*D)`` | The directory part of ``$*``. |
133+-----------+-----------------------------------------------------------------+
134| ``$(|D)`` | The directory part of ``$|``. |
135+-----------+-----------------------------------------------------------------+
136| ``$(@F)`` | The file-within-directory part of ``$@``. |
137+-----------+-----------------------------------------------------------------+
138| ``$(<F)`` | The file-within-directory part of ``$<``. |
139+-----------+-----------------------------------------------------------------+
140| ``$(?F)`` | The file-within-directory part of ``$?``. |
141+-----------+-----------------------------------------------------------------+
142| ``$(^F)`` | The file-within-directory part of ``$^``. |
143+-----------+-----------------------------------------------------------------+
144| ``$(+F)`` | The file-within-directory part of ``$+``. |
145+-----------+-----------------------------------------------------------------+
146| ``$(*F)`` | The file-within-directory part of ``$*``. |
147+-----------+-----------------------------------------------------------------+
148| ``$(|F)`` | The file-within-directory part of ``$|``. |
149+-----------+-----------------------------------------------------------------+
150
151
152
153Special variables
154-----------------
155
156All variables starting with a ``.`` is reserved by ``kmk``. The following
157variables are specially used or/and defined by ``kmk``:
158
159+--------------------------+--------------------------------------------------+
160| Variable | Description |
161+==========================+==================================================+
162| ``.DEFAULT_GOAL`` | The makefile default goal. You can set this in |
163| | the makefile, if you don't it will default to |
164| | the first target that is encountered. |
165+--------------------------+--------------------------------------------------+
166| ``.FEATURES`` | List of GNU ``make`` features. Do not set this. |
167+--------------------------+--------------------------------------------------+
168| ``.INCLUDE_DIRS`` | List of include directories, ``-I`` arguments |
169| | and defaults. Do not set this. |
170+--------------------------+--------------------------------------------------+
171| ``.RECIPEPREFIX`` | Recipe prefix, defaults to tab. |
172+--------------------------+--------------------------------------------------+
173| ``.VARIABLES`` | Special variable which exands to the list of |
174| | variable. Do not set this. |
175+--------------------------+--------------------------------------------------+
176| ``CURDIR`` | Set to the pathname of the current working |
177| | directory (after all ``-C`` options are |
178| | processed, if any). Do not set this. |
179+--------------------------+--------------------------------------------------+
180| ``KBUILD_VERSION``, | The kBuild version string and the break down |
181| ``KBUILD_VERSION_MAJOR``,| into individual components. [1]_ |
182| ``KBUILD_VERSION_MINOR``,| |
183| ``KBUILD_VERSION_PATCH``,| |
184| ``KBUILD_KMK_REVISION`` | |
185+--------------------------+--------------------------------------------------+
186| ``KBUILD_HOST`` [1]_ | The host operating system. |
187+--------------------------+--------------------------------------------------+
188| ``KBUILD_HOST_ARCH`` [1]_| The host architecture. |
189+--------------------------+--------------------------------------------------+
190| ``KBUILD_HOST_CPU`` [1]_ | The host CPU ``kmk`` is built for, set to |
191| | ``blend`` if not any particular CPU. |
192+--------------------------+--------------------------------------------------+
193| ``KBUILD_PATH`` [1]_ | Where the kBuild scripts are. |
194+--------------------------+--------------------------------------------------+
195| ``KBUILD_BIN_PATH`` [1]_ | Where the host specific kBuild binaries are. |
196+--------------------------+--------------------------------------------------+
197| ``KMK`` [1]_, | The name with which ``kmk`` was invoked. Using |
198| ``MAKE`` | this variable in recipes has special meaning. |
199+--------------------------+--------------------------------------------------+
200| ``KMK_BUILTIN`` [1]_ | List of built-in commands. |
201+--------------------------+--------------------------------------------------+
202| ``KMK_FEATURES`` [1]_ | List of ``kmk`` specific features. |
203+--------------------------+--------------------------------------------------+
204| ``KMK_FLAGS`` [1]_ | The flags given to ``kmk``. You can set this in |
205| | the environment or a makefile to set flags. |
206| | |
207| | It is never appropriate to use ``KMK_FLAGS`` |
208| | directly in a recipe line: its contents may not |
209| | be quoted correctly for use in the shell. Always |
210| | allow recursive ``kmk``'s to obtain these values |
211| | through the environment from its parent. |
212+--------------------------+--------------------------------------------------+
213| ``KMK_LEVEL`` [1]_ | The number of levels of recursion (sub-makes). |
214+--------------------------+--------------------------------------------------+
215| ``KMK_VERSION`` [1]_ | The GNU ``make`` version number. |
216+--------------------------+--------------------------------------------------+
217| ``MAKECMDGOALS`` | The targets given to ``kmk`` on the command line.|
218| | Do not set this. |
219+--------------------------+--------------------------------------------------+
220| ``MAKEFILES`` | Makefiles to be read on every invocation of |
221| | ``kmk``. |
222+--------------------------+--------------------------------------------------+
223| ``MAKEFILE_LIST`` | List of the makefiles that ``kmk`` has opened. |
224+--------------------------+--------------------------------------------------+
225| ``MAKESHELL`` | OS/2 and MS-DOS only, the name of the command |
226| | interpreter that is to be used by ``kmk``. This |
227| | value takes precedence over the value of SHELL. |
228+--------------------------+--------------------------------------------------+
229| ``SHELL`` | The name of the default command interpreter, |
230| | kmk_ash. You can set SHELL in the makefile to |
231| | change the shell used to run recipes. The SHELL |
232| | variable is handled specially when importing |
233| | from and exporting to the environment. |
234+--------------------------+--------------------------------------------------+
235| ``SUFFIXES`` | The default list of suffixes before ``kmk`` |
236| | reads any makefiles (always empty). |
237+--------------------------+--------------------------------------------------+
238| ``VPATH`` | Directory search path for files not found in the |
239| | current directory. |
240+--------------------------+--------------------------------------------------+
241
242
243The following variables reflects ``kmk`` options. Do not set these. [1]_
244
245+-------------------------------------+---------------------------------------+
246| Variable | Description |
247+=====================================+=======================================+
248| ``KMK_OPTS_JOBS`` | -j slots, ``0`` if not given. |
249+-------------------------------------+---------------------------------------+
250| ``KMK_OPTS_KEEP_GOING`` | -k indictor (``0``/``1``). |
251+-------------------------------------+---------------------------------------+
252| ``KMK_OPTS_JUST_PRINT`` | -n indicator (``0``/``1``). |
253+-------------------------------------+---------------------------------------+
254| ``KMK_OPTS_PRORITY`` | --priority level, ``0`` if not given. |
255+-------------------------------------+---------------------------------------+
256| ``KMK_OPTS_AFFINITY`` | --affinity mask, ``0`` if not given. |
257+-------------------------------------+---------------------------------------+
258| ``KMK_OPTS_STATISTICS`` | --statistics indicator (``0``/``1``). |
259+-------------------------------------+---------------------------------------+
260| ``KMK_OPTS_PRINT_TIME`` | The --print-time value. |
261+-------------------------------------+---------------------------------------+
262| ``KMK_OPTS_PRETTY_COMMAND_PRINTING``| --pretty-command-printing indicator. |
263+-------------------------------------+---------------------------------------+
264
265
266
267Special Targets
268---------------
269
270Certain names have special meanings if they appear as targets.
271
272+-------------------------------+---------------------------------------------+
273| Target | Description |
274+===============================+=============================================+
275| ``.DEFAULT`` | The recipe is used for any target for which |
276| | no rules are found. |
277+-------------------------------+---------------------------------------------+
278| ``.DELETE_ON_ERROR`` | If mentioned, ``kmk`` will delete the |
279| | targets of a rule if it has changed and its |
280| | recipe fails or is interrupted. |
281+-------------------------------+---------------------------------------------+
282| ``.EXPORT_ALL_VARIABLES`` | If mentioned, all variables will by default |
283| | be exported to child processes. |
284+-------------------------------+---------------------------------------------+
285| ``.IGNORE`` | Ignore errors in the execution of the recipe|
286| | for the targets ``.IGNORE`` depends on, if |
287| | no prequisites all targets are affected. |
288+-------------------------------+---------------------------------------------+
289| ``.INTERMEDIATE`` | The prerequisites are treated as |
290| | intermediate files (implicite rules). |
291+-------------------------------+---------------------------------------------+
292| ``.LOW_RESOLUTION_TIME`` | ``kmk`` will assume prerequisite files are |
293| | created with low resolution time stamps. |
294+-------------------------------+---------------------------------------------+
295| ``.NOTPARALLEL`` | If mentioned without any prerequisites, |
296| | ``kmk`` will run serially as if -j1 was |
297| | given. If it has prerequisites ``kmk`` [1]_ |
298| | will only do this for the targets among |
299| | them. |
300+-------------------------------+---------------------------------------------+
301| ``.PHONY`` | The prerequisites are considered phony and |
302| | will be rebuilt unconditionally. |
303+-------------------------------+---------------------------------------------+
304| ``.PRECIOUS`` | The targets which ``.PRECIOUS`` depends |
305| | will to be deleted if ``kmk`` is killed or |
306| | interrupted while their building. |
307+-------------------------------+---------------------------------------------+
308| ``.SECONDARY`` | The prerequisites are treated as |
309| | intermediate files, except that they are |
310| | never automatically deleted. If used with |
311| | no prerequisites all targets gets this |
312| | treatement. |
313+-------------------------------+---------------------------------------------+
314| ``.SECONDEXPANSION`` | If mentioned, all prerequisite lists after |
315| | it will be expanded a second time after all |
316| | makefiles have been read. |
317+-------------------------------+---------------------------------------------+
318| ``.SECONDTARGETEXPANSION`` | If mentioned, all targets after it will be |
319| [1]_ | expanded a second time after all makefiles |
320| | have been read. |
321+-------------------------------+---------------------------------------------+
322| ``.SILENT`` | ``kmk`` will not print the recipe for |
323| | targets listed as prerequisites, if none |
324| | then it applies to all targets. |
325+-------------------------------+---------------------------------------------+
326| ``.SUFFIXES`` | The prerequisites are the list of suffixes |
327| | used in checking for suffix rules. If it |
328| | appears without prerequisites it the suffix |
329| | will be cleared. |
330+-------------------------------+---------------------------------------------+
331
332
333
334Commands
335--------
336
337Builtin commands [1]_ all start with ``kmk_builtin_``, so in order to save
338space this prefix has been omitted in the table below. All commands comes in an
339external edition that can be used by/in the shell, these are prefixed ``kmk_``.
340
341+---------------+-------------------------------------------------------------+
342| Command | Description |
343+===============+=============================================================+
344| ``append`` | Append text to a file. The builtin version can output the |
345| | value of a variable or the commands of a target. |
346+---------------+-------------------------------------------------------------+
347| ``cat`` | The BSD ``cat`` command. |
348+---------------+-------------------------------------------------------------+
349| ``chmod`` | The BSD ``chmod`` command. |
350+---------------+-------------------------------------------------------------+
351| ``cmp`` | The BSD ``cmp`` command. |
352+---------------+-------------------------------------------------------------+
353| ``cp`` | The BSD ``cp`` command with some twaking. |
354+---------------+-------------------------------------------------------------+
355| ``echo`` | The BSD ``echo`` command. |
356+---------------+-------------------------------------------------------------+
357| ``expr`` | The BSD ``expr`` command. |
358+---------------+-------------------------------------------------------------+
359| ``install`` | The BSD ``install`` command with some tweaking. |
360+---------------+-------------------------------------------------------------+
361| ``kDepIDB`` | Extract dependencies from a Visual C++ .IDB file. |
362+---------------+-------------------------------------------------------------+
363| ``ln`` | The BSD ``ln`` command. |
364+---------------+-------------------------------------------------------------+
365| ``md5sum`` | Typical MD5 sum program, custom kBuild version. |
366+---------------+-------------------------------------------------------------+
367| ``mkdir`` | The BSD ``mkdir`` command. |
368+---------------+-------------------------------------------------------------+
369| ``mv`` | The BSD ``mv`` command with some tweaking. |
370+---------------+-------------------------------------------------------------+
371| ``printf`` | The BSD ``printf`` command. |
372+---------------+-------------------------------------------------------------+
373| ``rm`` | The BSD ``rm`` command with some tweaking. |
374+---------------+-------------------------------------------------------------+
375| ``rmdir`` | The BSD ``rmdir`` command with some tweaking. |
376+---------------+-------------------------------------------------------------+
377| ``sleep`` | Typical ``sleep`` program, custom kBuild version. |
378+---------------+-------------------------------------------------------------+
379| ``test`` | The BSD ``test`` program with some tweaking. |
380+---------------+-------------------------------------------------------------+
381
382Some additional external commands are available in the ``kmk`` / ``kBuild``
383environment (``kSomething`` command are not prefixed with ``kmk_``):
384
385+---------------+-------------------------------------------------------------+
386| Command | Description |
387+===============+=============================================================+
388| ``kDepPre`` | Extract dependencies from the C/C++ preprocessor output. |
389+---------------+-------------------------------------------------------------+
390| ``kObjCache`` | Simple object file cache program. |
391+---------------+-------------------------------------------------------------+
392| ``ash`` | Almquist's shell (NetBSD variant). |
393+---------------+-------------------------------------------------------------+
394| ``gmake`` | Vanilla GNU ``make`` from same sources as ``kmk``. |
395+---------------+-------------------------------------------------------------+
396| ``redirect`` | Shell avoidance tool. Sets up file descriptors, environment |
397| | variables and current directory before kicking of program. |
398+---------------+-------------------------------------------------------------+
399| ``sed`` | GNU ``sed`` with some tweaks to avoid involving the shell. |
400+---------------+-------------------------------------------------------------+
401| ``time`` | Stopwatch utility for measuring program execution time(s). |
402+---------------+-------------------------------------------------------------+
403
404
405
406kmk-expression
407--------------
408
409``kmk``-expressions [1]_ are related to the C/C++ preprocessor in some ways as
410well as ``nmake`` and BSD ``make``. There are however some peculiarities
411because of the way GNU ``make`` choose to represent booleans in its function
412library, so, strings can be turned into boolean by taking any non-empty string
413as true.
414
415Quoting using single quotes results in hard strings, while double quotes and
416unquoted string results in soft strings that can be converted to number or
417boolean to fit the situation.
418
419Here's the operator table in decending precedence order:
420
421+---------------+--------+-----------------------------------------------------+
422| Operator | Type | Description |
423+===============+========+=====================================================+
424| ``defined`` | Unary | Checks if the following variable exists. |
425+---------------+ +-----------------------------------------------------+
426| ``exists`` | | Checks if the following file exists. |
427+---------------+ +-----------------------------------------------------+
428| ``target`` | | Checks if the following target exists. |
429+---------------+ +-----------------------------------------------------+
430| ``bool`` | | Casts the following value to boolean. |
431+---------------+ +-----------------------------------------------------+
432| ``num`` | | Casts the following value to a number. |
433+---------------+ +-----------------------------------------------------+
434| ``str`` | | Casts the following value to a string. |
435+---------------+--------+-----------------------------------------------------+
436| ``!`` | Unary | Logical NOT. |
437+---------------+ +-----------------------------------------------------+
438| ``+`` | | Pluss prefix. |
439+---------------+ +-----------------------------------------------------+
440| ``-`` | | Minus prefix. |
441+---------------+ +-----------------------------------------------------+
442| ``~`` | | Bitwise one's complement. |
443+---------------+--------+-----------------------------------------------------+
444| ``*`` | Binary | Multiplication (product). |
445+---------------+ +-----------------------------------------------------+
446| ``/`` | | Division (quotient). |
447+---------------+ +-----------------------------------------------------+
448| ``%`` | | Modulus (remainder). |
449+---------------+--------+-----------------------------------------------------+
450| ``+`` | Binary | Addition (sum). |
451+---------------+ +-----------------------------------------------------+
452| ``-`` | | Subtraction (difference). |
453+---------------+--------+-----------------------------------------------------+
454| ``<<`` | Binary | Bitwise left shift. |
455+---------------+ +-----------------------------------------------------+
456| ``>>`` | | Bitwise right shift. |
457+---------------+--------+-----------------------------------------------------+
458| ``<=`` | Binary | Less or equal than. |
459+---------------+ +-----------------------------------------------------+
460| ``<`` | | Less than. |
461+---------------+ +-----------------------------------------------------+
462| ``>=`` | | Greater or equal than. |
463+---------------+ +-----------------------------------------------------+
464| ``>`` | | Greater than. |
465+---------------+--------+-----------------------------------------------------+
466| ``==`` | Binary | Equal to. |
467+---------------+ +-----------------------------------------------------+
468| ``!=`` | | Not equal to. |
469+---------------+--------+-----------------------------------------------------+
470| ``&`` | Binary | Bitwise AND. |
471+---------------+--------+-----------------------------------------------------+
472| ``^`` | Binary | Bitwise XOR. |
473+---------------+--------+-----------------------------------------------------+
474| ``|`` | Binary | Bitwise OR. |
475+---------------+--------+-----------------------------------------------------+
476| ``&&`` | Binary | Logical AND. |
477+---------------+--------+-----------------------------------------------------+
478| ``||`` | Binary | Logical OR. |
479+---------------+--------+-----------------------------------------------------+
480
481
482
483Built-in functions
484------------------
485
486
487String Manipulation Functions:
488
489 Replace ``from`` with ``to`` in ``text``::
490
491 $(subst from,to,text)
492
493 Replace words matching ``pattern`` with ``replacement`` in ``text``::
494
495 $(patsubst pattern,replacement,text)
496
497 Remove excess whitespace characters from ``string``::
498
499 $(strip string)
500
501 Locate ``find`` in ``text``, returning ``find`` if found::
502
503 $(findstring find,text)
504
505 Select words in ``text`` that match one of the ``pattern`` words::
506
507 $(filter pattern...,text)
508
509 Select words in ``text`` that do not match any of the ``pattern`` words::
510
511 $(filter-out pattern...,text)
512
513 Sort the words in ``list`` lexicographically, removing duplicates::
514
515 $(sort list)
516
517 Sort the words in ``list`` lexicographically in reserve order, removing
518 duplicates [1]_::
519
520 $(rsort list)
521
522 Count the number of words in ``text``::
523
524 $(words text)
525
526 Extract the ``n``\th word (one-origin) of ``text``::
527
528 $(word n,text)
529
530 Returns the list of words in ``text`` from ``s`` to ``e`` (one-origin)::
531
532 $(wordlist s,e,text)
533
534 Extract the first word of ``names``::
535
536 $(firstword names...)
537
538 Extract the last word of ``names``::
539
540 $(lastword names...)
541
542 Join two parallel lists of words::
543
544 $(join list1,list2)
545
546 Fold ``text`` to upper case [1]_::
547
548 $(toupper text)
549
550 Fold ``text`` to lower case [1]_::
551
552 $(tolower text)
553
554 String formatting a la the unix ``printf`` command [1]_::
555
556 $(printf fmt, arg...)
557
558 Return the length of a string or a (unexpanded) variable [1]_::
559
560 $(length string)
561 $(length-var var)
562
563 Find the position of ``needle`` in ``haystack``, returns 0 if not found.
564 Negative ``start`` indices are relative to the end of ``haystack``, while
565 positive ones are one based [1]_::
566
567 $(pos needle, haystack[, start])
568 $(lastpos needle, haystack[, start])
569
570 Returns the specified substring. The ``start`` works like with ``$(pos )``.
571 If the substring is partially outside the ``string`` the result will be
572 padded with ``pad`` if present [1]_::
573
574 $(substr string, start[, length[, pad]])
575
576 Insert ``in`` into ``str`` at the specified position. ``n`` works like with
577 ``$(pos )``, except that ``0`` is the end of the string [1]_::
578
579 $(insert in, str[, n[, length[, pad]]])
580
581 Translate ``string`` exchanging characters in ``from-set`` with ``to-set``,
582 optionally completing ``to-set`` with ``pad-char`` if specified. If no
583 ``pad-char`` characters absent in ``to-set`` will be deleted [1]_::
584
585 $(translate string, from-set[, to-set[, pad-char]])
586
587
588Functions for file names:
589
590 Extract the directory part of each file ``name``::
591
592 $(dir names...)
593
594 Extract the non-directory part of each file ``name``::
595
596 $(notdir names...)
597
598 Extract the suffix (the last ``.`` and following characters) of each file
599 ``name``::
600
601 $(suffix names...)
602
603 Extract the base name (name without suffix) of each file name::
604
605 $(basename names...)
606
607 Extract the root specification of each file name (a bit complicated on
608 Windows & OS/2) [1]_::
609
610 $(root names...)
611
612 Append ``suffix`` to each word in ``names``::
613
614 $(addsuffix suffix,names...)
615
616 Prepend ``prefix`` to each word in ``names``::
617
618 $(addprefix prefix,names...)
619
620 Find file names matching a shell file name ``pattern`` (not a ``%``
621 pattern)::
622
623 $(wildcard pattern...)
624
625 For each file name in ``names``, expand to an absolute name that does not
626 contain any ``.``, ``..``, nor symlinks::
627
628 $(realpath names...)
629
630 For each file name in ``names``, expand to an absolute name that does not
631 contain any ``.`` or ``..`` components, but preserves symlinks::
632
633 $(abspath names...)
634
635 Same as ``$(abspath )`` except that the current directory can be
636 specified as ``curdir`` [1]_::
637
638 $(abspathex names...[, curdir])
639
640
641Arithmetic Functions:
642
643 Returns the sum of the arguments [1]_::
644
645 $(int-add addend1, addend2[, addendN])
646
647 Returns the difference between the first argument and the sum of the
648 rest [1]_::
649
650 $(int-sub minuend, subtrahend[, subtrahendN])
651
652 Returns the product of the arguments [1]_::
653
654 $(int-mul factor1, factor2[, factorN])
655
656 Returns the quotient of first argument and the rest [1]_::
657
658 $(int-div dividend, divisor[, divisorN])
659
660 Returns the modulus of the two arguments [1]_::
661
662 $(int-mod dividend, divisor)
663
664 Returns the bitwise two-complement of argument [1]_::
665
666 $(int-not val)
667
668 Returns the result of a bitwise AND of the arguments [1]_::
669
670 $(int-and val1, val2[, valN])
671
672 Returns the result of a bitwise OR of the arguments [1]_::
673
674 $(int-or val1, val2[, valN])
675
676 Returns the result of a bitwise XOR of the arguments [1]_::
677
678 $(int-xor val1, val2[, valN])
679
680 Returns the ``kmk`` boolean (true = non-empty, false = empty) result
681 of ``val1 == val2`` [1]_::
682
683 $(int-eq val1, val2)
684
685 Returns the ``kmk`` boolean result of ``val1 != val2`` [1]_::
686
687 $(int-ne val1, val2)
688
689 Returns the ``kmk`` boolean result of ``val1 > val2`` [1]_::
690
691 $(int-gt val1, val2)
692
693 Returns the ``kmk`` boolean result of ``val1 >= val2`` [1]_::
694
695 $(int-ge val1, val2)
696
697 Returns the ``kmk`` boolean result of ``val1 < val2`` [1]_::
698
699 $(int-lt val1, val2)
700
701 Returns the ``kmk`` boolean result of ``val1 <= val2`` [1]_::
702
703 $(int-le val1, val2)
704
705
706Boolean and Conditional Functions:
707
708 Condition is false if the ``condition`` evaluates to an empty string
709 (stripped). Evaluate the ``true-part`` if the condition is true, otherwise
710 the ``false-part``::
711
712 $(if condition,true-part[,false-part])
713
714 Test if any of the conditions evalues to non-empty string, returning the
715 first one::
716
717 $(or condition1[,condition2[,condition3[...]]])
718
719 Test if all of the conditions evaluates to non-empty strings, returning the
720 last one::
721
722 $(and condition1[,condition2[,condition3[...]]])
723
724
725 Test if the two strings are identical, returning ``kmk`` boolean (true =
726 non-empty, false = empty) [2]_::
727
728 $(eq str1, str2)
729
730 Invert a ``kmk`` boolean value [2]_::
731
732 $(not val)
733
734 Test if ``variable`` is defined, returning a ``kmk`` boolean value [1]_::
735
736 $(defined variable)
737
738 Test if ``set-a`` and ``set-b`` intersects, returning a ``kmk`` boolean
739 value [1]_::
740
741 $(intersects set-a, set-b)
742
743 Same as ``$(if )`` execpt that the condition is a ``kmk``-expression [1]_::
744
745 $(if-expr kmk-expression,true-part[,false-part])
746
747 Select the first true condition (``kmk``-expression) and expand the
748 following body. Special condition strings ``default`` and
749 ``otherwise`` [1]_::
750
751 $(select when1-cond, when1-body[, whenN-cond, whenN-body])
752
753 Evalutate the ``kmk-expression`` returning what it evalues as. This is
754 the preferred way of doing arithmentic now [1]_::
755
756 $(expr kmk-expression)
757
758
759Stack Fuctions:
760
761 Push ``item`` onto the ``stack-var``, returning the empty string [1]_::
762
763 $(stack-push stack-var, item)
764
765 Pop the top item off the ``stack-var`` [1]_::
766
767 $(stack-pop stack-var)
768
769 Pop the top item off the ``stack-var``, returning the empty string [1]_::
770
771 $(stack-popv stack-var)
772
773 Get the top item of the ``stack-var``, returning the empty string [1]_::
774
775 $(stack-top stack-var)
776
777
778Advanced Functions:
779
780 Evaluates to the contents of the variable ``var``, with no expansion
781 performed on it::
782
783 $(value var)
784
785 Evaluate ``body`` with ``var`` bound to each word in ``words``, and
786 concatenate the results (spaced)::
787
788 $(foreach var,words,body)
789
790 C-style for-loop. Start by evaluating ``init``. Each iteration will
791 first check whether the ``condition`` (``kmk``-expression) is true,
792 then expand ``body`` concatenating the result to the previous iterations
793 (spaced), and finally evaluate ``next`` [1]_::
794
795 $(for init,conditions,next,body)
796
797 C-style while-loop. Each iteration will check whether the ``condition``
798 (``kmk``-expression) is true, then expand ``body`` concatenating the
799 result to the previous iterations [1]_::
800
801 $(while conditions,body)
802
803 Evaluate the variable ``var`` replacing any references to ``$(1)``,
804 ``$(2)`` with the first, second, etc. ``param`` values::
805
806 $(call var,param,...)
807
808 Evaluate ``text`` then read the results as makefile commands. Expands
809 to the empty string::
810
811 $(eval text)
812
813 Same as ``$(eval text)`` except that the ``text`` is expanded in its
814 own variable context [1]_::
815
816 $(evalctx text)
817
818 Same as ``$(eval $(value var))`` [1]_::
819
820 $(evalval var)
821
822 Same as ``$(evalctx $(value var))`` [1]_::
823
824 $(evalvalctx var)
825
826 A combination of ``$(eval )``, ``$(call )`` and ``$(value )`` [1]_::
827
828 $(evalcall var)
829
830 A combination of ``$(eval )`` and ``$(call )`` [1]_::
831
832 $(evalcall var)
833
834 Remove comments and blank lines from the variable ``var``. Expands to
835 the empty string [1]_::
836
837 $(eval-opt-var var)
838
839 Returns accessing ``$<`` of ``target``, either retriving the whole thing
840 or the file at ``pos`` (one-origin) [1]_::
841
842 $(deps target[, pos])
843
844 Returns accessing ``$+`` (order + duplicates) of ``target``, either
845 retriving the whole thing or the file at ``pos`` (one-origin) [1]_::
846
847 $(deps-all target[, pos])
848
849 Returns accessing ``$?`` of ``target``, either retriving the whole
850 thing or the file at ``pos`` (one-origin) [1]_::
851
852 $(deps-newer target[, pos])
853
854 Returns accessing ``$|`` (order only) of ``target``, either retriving the
855 whole thing or the file at ``pos`` (one-origin) [1]_::
856
857 $(deps-oo target[, pos])
858
859
860Command Functions:
861
862 Create one or more command lines avoiding the max argument
863 length restriction of the host OS [1]_::
864
865 $(xargs ar cas mylib.a,$(objects))
866 $(xargs ar cas mylib.a,ar as mylib.a,$(objects))
867
868
869 Returns the commands for the specified target separated by new-line, space,
870 or a user defined string. Note that this might not produce the 100% correct
871 result if any of the prerequisite automatic variables are used [1]_::
872
873 $(commands target)
874 $(commands-sc target)
875 $(commands-usr target,sep)
876
877 Compares two commands returning the empty string if equal and the 3rd
878 argument if not. This differs from ``$(comp-vars v1,v2,ne)`` in that
879 line by line is stripped of leading spaces, command prefixes and
880 trailing spaces before comparing [1]_::
881
882 $(comp-cmds cmds-var1, cmds-var2, ne)
883 $(comp-cmds-ex cmds1, cmd2, ne)
884
885
886 Compares the values of the two variables returning the empty string if
887 equal and the 3rd argument if not. Leading and trailing spaces is
888 ignored [1]_::
889
890 $(comp-var var1, var2, ne)
891
892
893Utility functions:
894
895 When this function is evaluated, ``kmk`` generates a fatal error with the
896 message ``text``::
897
898 $(error text...)
899
900 When this function is evaluated, ``kmk`` generates a warning with the
901 message ``text``::
902
903 $(warning text...)
904
905 When this function is evaluated, ``kmk`` generates a info with the
906 message ``text``::
907
908 $(info text...)
909
910 Execute a shell ``command`` and return its output::
911
912 $(shell command)
913
914 Return a string describing how the ``kmk`` variable ``variable`` was defined::
915
916 $(origin variable)
917
918 Return a string describing the flavor of the ``kmk`` variable ``variable``::
919
920 $(flavor variable)
921
922 Returns the current local time and date formatted in the ``strftime``
923 style specifier ``fmt``. ``fmt`` defaults to ``%Y-%m-%dT%H:%M:%S`` when
924 not specified [1]_::
925
926 $(date fmt)
927
928 Returns the current UTC time and date formatted in the ``strftime``
929 style specifier ``fmt``. ``fmt`` defaults to ``%Y-%m-%dT%H:%M:%SZ`` when
930 not specified [1]_::
931
932 $(date-utc fmt)
933
934 Reformats the ``in`` time and date using ``fmt``. The ``in-fmt`` defaults
935 to ``fmt`` if not specified. While ``fmt`` defaults to
936 ``%Y-%m-%dT%H:%M:%SZ`` if not specified [1]_::
937
938 $(date-utc fmt,time,in-fmt)
939
940 Returns the current nanosecond timestamp (monotonic when possible) [1]_::
941
942 $(nanots )
943
944 Returns the size of the specified file, or -1 if the size could not
945 be obtained. This can be used to check if a file exist or not [1]_::
946
947 $(file-size file)
948
949 Searches the ``PATH`` ``kmk`` variable for the specified ``files`` [1]_::
950
951 $(which files...)
952
953 OS/2: Returns the specified LIBPATH variable value [1]_::
954
955 $(libpath var)
956
957 OS/2: Sets the specified LIBPATH variable value, returning the empty
958 string [1]_::
959
960 $(libpath var,value)
961
962
963Debugging Functions:
964
965 Returns various make statistics, if no item is specified a default
966 selection is returned [1]_::
967
968 $(make-stats item[,itemN])
969
970 Raise a debug breakpoint. Used for debugging ``kmk`` makefile
971 parsing [1]_::
972
973 $(breakpoint )
974
975
976-----
977
978.. [1] ``kmk`` only feature.
979.. [2] Experimental GNU ``make`` feature that is not enabled by default.
980
981-----
982
983:Status: $Id: QuickReference-kmk.txt 2243 2009-01-10 02:24:02Z bird $
984:Copyright: Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
985 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
986 2007 Free Software Foundation, Inc.
987
988 Copyright (c) 2008-2009 knut st. osmundsen
Note: See TracBrowser for help on using the repository browser.