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

Last change on this file since 2488 was 2475, checked in by bird, 14 years ago

kBuild/footer+header.kmk: Reworking installation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 43.9 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 Extract the non-root part of each file name (a bit complicated on
613 Windows & OS/2) [1]_::
614
615 $(notroot names...)
616
617 Append ``suffix`` to each word in ``names``::
618
619 $(addsuffix suffix,names...)
620
621 Prepend ``prefix`` to each word in ``names``::
622
623 $(addprefix prefix,names...)
624
625 Find file names matching a shell file name ``pattern`` (not a ``%``
626 pattern)::
627
628 $(wildcard pattern...)
629
630 For each file name in ``names``, expand to an absolute name that does not
631 contain any ``.``, ``..``, nor symlinks::
632
633 $(realpath names...)
634
635 For each file name in ``names``, expand to an absolute name that does not
636 contain any ``.`` or ``..`` components, but preserves symlinks::
637
638 $(abspath names...)
639
640 Same as ``$(abspath )`` except that the current directory can be
641 specified as ``curdir`` [1]_::
642
643 $(abspathex names...[, curdir])
644
645
646Arithmetic Functions:
647
648 Returns the sum of the arguments [1]_::
649
650 $(int-add addend1, addend2[, addendN])
651
652 Returns the difference between the first argument and the sum of the
653 rest [1]_::
654
655 $(int-sub minuend, subtrahend[, subtrahendN])
656
657 Returns the product of the arguments [1]_::
658
659 $(int-mul factor1, factor2[, factorN])
660
661 Returns the quotient of first argument and the rest [1]_::
662
663 $(int-div dividend, divisor[, divisorN])
664
665 Returns the modulus of the two arguments [1]_::
666
667 $(int-mod dividend, divisor)
668
669 Returns the bitwise two-complement of argument [1]_::
670
671 $(int-not val)
672
673 Returns the result of a bitwise AND of the arguments [1]_::
674
675 $(int-and val1, val2[, valN])
676
677 Returns the result of a bitwise OR of the arguments [1]_::
678
679 $(int-or val1, val2[, valN])
680
681 Returns the result of a bitwise XOR of the arguments [1]_::
682
683 $(int-xor val1, val2[, valN])
684
685 Returns the ``kmk`` boolean (true = non-empty, false = empty) result
686 of ``val1 == val2`` [1]_::
687
688 $(int-eq val1, val2)
689
690 Returns the ``kmk`` boolean result of ``val1 != val2`` [1]_::
691
692 $(int-ne val1, val2)
693
694 Returns the ``kmk`` boolean result of ``val1 > val2`` [1]_::
695
696 $(int-gt val1, val2)
697
698 Returns the ``kmk`` boolean result of ``val1 >= val2`` [1]_::
699
700 $(int-ge val1, val2)
701
702 Returns the ``kmk`` boolean result of ``val1 < val2`` [1]_::
703
704 $(int-lt val1, val2)
705
706 Returns the ``kmk`` boolean result of ``val1 <= val2`` [1]_::
707
708 $(int-le val1, val2)
709
710
711Boolean and Conditional Functions:
712
713 Condition is false if the ``condition`` evaluates to an empty string
714 (stripped). Evaluate the ``true-part`` if the condition is true, otherwise
715 the ``false-part``::
716
717 $(if condition,true-part[,false-part])
718
719 Test if any of the conditions evalues to non-empty string, returning the
720 first one::
721
722 $(or condition1[,condition2[,condition3[...]]])
723
724 Test if all of the conditions evaluates to non-empty strings, returning the
725 last one::
726
727 $(and condition1[,condition2[,condition3[...]]])
728
729
730 Test if the two strings are identical, returning ``kmk`` boolean (true =
731 non-empty, false = empty) [2]_::
732
733 $(eq str1, str2)
734
735 Invert a ``kmk`` boolean value [2]_::
736
737 $(not val)
738
739 Test if ``variable`` is defined, returning a ``kmk`` boolean value [1]_::
740
741 $(defined variable)
742
743 Test if ``set-a`` and ``set-b`` intersects, returning a ``kmk`` boolean
744 value [1]_::
745
746 $(intersects set-a, set-b)
747
748 Same as ``$(if )`` execpt that the condition is a ``kmk``-expression [1]_::
749
750 $(if-expr kmk-expression,true-part[,false-part])
751
752 Select the first true condition (``kmk``-expression) and expand the
753 following body. Special condition strings ``default`` and
754 ``otherwise`` [1]_::
755
756 $(select when1-cond, when1-body[, whenN-cond, whenN-body])
757
758 Evalutate the ``kmk-expression`` returning what it evalues as. This is
759 the preferred way of doing arithmentic now [1]_::
760
761 $(expr kmk-expression)
762
763
764Stack Fuctions:
765
766 Push ``item`` onto the ``stack-var``, returning the empty string [1]_::
767
768 $(stack-push stack-var, item)
769
770 Pop the top item off the ``stack-var`` [1]_::
771
772 $(stack-pop stack-var)
773
774 Pop the top item off the ``stack-var``, returning the empty string [1]_::
775
776 $(stack-popv stack-var)
777
778 Get the top item of the ``stack-var``, returning the empty string [1]_::
779
780 $(stack-top stack-var)
781
782
783Advanced Functions:
784
785 Evaluates to the contents of the variable ``var``, with no expansion
786 performed on it::
787
788 $(value var)
789
790 Evaluate ``body`` with ``var`` bound to each word in ``words``, and
791 concatenate the results (spaced)::
792
793 $(foreach var,words,body)
794
795 C-style for-loop. Start by evaluating ``init``. Each iteration will
796 first check whether the ``condition`` (``kmk``-expression) is true,
797 then expand ``body`` concatenating the result to the previous iterations
798 (spaced), and finally evaluate ``next`` [1]_::
799
800 $(for init,conditions,next,body)
801
802 C-style while-loop. Each iteration will check whether the ``condition``
803 (``kmk``-expression) is true, then expand ``body`` concatenating the
804 result to the previous iterations [1]_::
805
806 $(while conditions,body)
807
808 Evaluate the variable ``var`` replacing any references to ``$(1)``,
809 ``$(2)`` with the first, second, etc. ``param`` values::
810
811 $(call var,param,...)
812
813 Evaluate ``text`` then read the results as makefile commands. Expands
814 to the empty string::
815
816 $(eval text)
817
818 Same as ``$(eval text)`` except that the ``text`` is expanded in its
819 own variable context [1]_::
820
821 $(evalctx text)
822
823 Same as ``$(eval $(value var))`` [1]_::
824
825 $(evalval var)
826
827 Same as ``$(evalctx $(value var))`` [1]_::
828
829 $(evalvalctx var)
830
831 A combination of ``$(eval )``, ``$(call )`` and ``$(value )`` [1]_::
832
833 $(evalcall var)
834
835 A combination of ``$(eval )`` and ``$(call )`` [1]_::
836
837 $(evalcall2 var)
838
839 Remove comments and blank lines from the variable ``var``. Expands to
840 the empty string [1]_::
841
842 $(eval-opt-var var)
843
844 Returns accessing ``$<`` of ``target``, either retriving the whole thing
845 or the file at ``pos`` (one-origin) [1]_::
846
847 $(deps target[, pos])
848
849 Returns accessing ``$+`` (order + duplicates) of ``target``, either
850 retriving the whole thing or the file at ``pos`` (one-origin) [1]_::
851
852 $(deps-all target[, pos])
853
854 Returns accessing ``$?`` of ``target``, either retriving the whole
855 thing or the file at ``pos`` (one-origin) [1]_::
856
857 $(deps-newer target[, pos])
858
859 Returns accessing ``$|`` (order only) of ``target``, either retriving the
860 whole thing or the file at ``pos`` (one-origin) [1]_::
861
862 $(deps-oo target[, pos])
863
864
865Command Functions:
866
867 Create one or more command lines avoiding the max argument
868 length restriction of the host OS [1]_::
869
870 $(xargs ar cas mylib.a,$(objects))
871 $(xargs ar cas mylib.a,ar as mylib.a,$(objects))
872
873
874 Returns the commands for the specified target separated by new-line, space,
875 or a user defined string. Note that this might not produce the 100% correct
876 result if any of the prerequisite automatic variables are used [1]_::
877
878 $(commands target)
879 $(commands-sc target)
880 $(commands-usr target,sep)
881
882 Compares two commands returning the empty string if equal and the 3rd
883 argument if not. This differs from ``$(comp-vars v1,v2,ne)`` in that
884 line by line is stripped of leading spaces, command prefixes and
885 trailing spaces before comparing [1]_::
886
887 $(comp-cmds cmds-var1, cmds-var2, ne)
888 $(comp-cmds-ex cmds1, cmd2, ne)
889
890
891 Compares the values of the two variables returning the empty string if
892 equal and the 3rd argument if not. Leading and trailing spaces is
893 ignored [1]_::
894
895 $(comp-var var1, var2, ne)
896
897
898Utility functions:
899
900 When this function is evaluated, ``kmk`` generates a fatal error with the
901 message ``text``::
902
903 $(error text...)
904
905 When this function is evaluated, ``kmk`` generates a warning with the
906 message ``text``::
907
908 $(warning text...)
909
910 When this function is evaluated, ``kmk`` generates a info with the
911 message ``text``::
912
913 $(info text...)
914
915 Execute a shell ``command`` and return its output::
916
917 $(shell command)
918
919 Return a string describing how the ``kmk`` variable ``variable`` was defined::
920
921 $(origin variable)
922
923 Return a string describing the flavor of the ``kmk`` variable ``variable``::
924
925 $(flavor variable)
926
927 Returns the current local time and date formatted in the ``strftime``
928 style specifier ``fmt``. ``fmt`` defaults to ``%Y-%m-%dT%H:%M:%S`` when
929 not specified [1]_::
930
931 $(date fmt)
932
933 Returns the current UTC time and date formatted in the ``strftime``
934 style specifier ``fmt``. ``fmt`` defaults to ``%Y-%m-%dT%H:%M:%SZ`` when
935 not specified [1]_::
936
937 $(date-utc fmt)
938
939 Reformats the ``in`` time and date using ``fmt``. The ``in-fmt`` defaults
940 to ``fmt`` if not specified. While ``fmt`` defaults to
941 ``%Y-%m-%dT%H:%M:%SZ`` if not specified [1]_::
942
943 $(date-utc fmt,time,in-fmt)
944
945 Returns the current nanosecond timestamp (monotonic when possible) [1]_::
946
947 $(nanots )
948
949 Returns the size of the specified file, or -1 if the size could not
950 be obtained. This can be used to check if a file exist or not [1]_::
951
952 $(file-size file)
953
954 Searches the ``PATH`` ``kmk`` variable for the specified ``files`` [1]_::
955
956 $(which files...)
957
958 OS/2: Returns the specified LIBPATH variable value [1]_::
959
960 $(libpath var)
961
962 OS/2: Sets the specified LIBPATH variable value, returning the empty
963 string [1]_::
964
965 $(libpath var,value)
966
967
968Debugging Functions:
969
970 Returns various make statistics, if no item is specified a default
971 selection is returned [1]_::
972
973 $(make-stats item[,itemN])
974
975 Raise a debug breakpoint. Used for debugging ``kmk`` makefile
976 parsing [1]_::
977
978 $(breakpoint )
979
980
981Recipes
982-------
983
984 A typical recipe takes one of the two following forms::
985
986 targets : normal-prerequisites | order-only-prerequisites
987 command
988 ...
989
990 targets : normal-prerequisites | order-only-prerequisites ; command
991 command
992 ...
993
994 Specifying more than one file in the ``targets`` lists is the same as
995 repeating the recipe for each of the files.
996
997 Use ``+`` and ``+|`` in the list of ``targets`` to tell ``kmk`` that the
998 recipe has more than one output. [1]_ The files after a ``+`` will
999 always be remade, while the files after a ``+|`` don't have to be remade.
1000 The latter is frequently employed to update files which prerequisites
1001 change wihtout the output files necessarily changing. See also
1002 ``kmk_cp --changed``.
1003
1004
1005Double colon recipes
1006
1007 Double colon recipes are written with ``::`` instead of ``:`` and are
1008 handled differently from ordinary recipes if the target appears in more
1009 than one recipe. First, all the recipes must be of the double colon type.
1010 Second, the recipes are executed individually and may be omitted depending
1011 on the state of their prerequisites. Double colon recipes without any
1012 prerequisites will always be executed.
1013
1014
1015Pattern rules
1016
1017 A couple of examples::
1018
1019 %.o : %.c
1020 gcc -o $@ $<
1021 %.tab.c %.tab.h : %.y
1022 bison -d $<
1023
1024 The latter has two outputs.
1025
1026
1027-----
1028
1029.. [1] ``kmk`` only feature.
1030.. [2] Experimental GNU ``make`` feature that is not enabled by default.
1031
1032-----
1033
1034:Status: $Id: QuickReference-kmk.txt 2475 2011-07-16 20:08:07Z bird $
1035:Copyright: Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
1036 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
1037 2007 Free Software Foundation, Inc.
1038
1039 Copyright (c) 2008-2009 knut st. osmundsen
Note: See TracBrowser for help on using the repository browser.