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

Last change on this file was 2532, checked in by bird, 14 years ago

kmk: Implemented the where function. Fixes #108.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 44.3 KB
RevLine 
[2146]1
2kmk Quick Reference
3===================
4
[2166]5This is an attempt at summarizing all directives, functions, special variables,
[2167]6special targets, built-in commands, external commands, and ``kmk``-expressions.
[2166]7Since *all* the features are included, the quickness of this reference can be
8disputed. ;-)
[2146]9
10
[2170]11
[2146]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'
[2169]32 if1of (set-a,set-b) [1]
33 ifn1of (set-a,set-b) [1]
34 if expression [1]
[2146]35 else
36 endif
37
38 Include another makefile::
39
40 include file
41 -include file
42 sinclude file
43
[2169]44 Include another dependency file [1]_::
[2146]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
[2169]54 override variable <= value [1]
[2146]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
[2169]70 export variable <= value [1]
[2146]71 export variable ?= value
72 unexport variable
73
[2169]74 Define a variable in the local context instead of the global one [1]_::
[2146]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 |
[2169]181| ``KBUILD_VERSION_MAJOR``,| into individual components. [1]_ |
[2146]182| ``KBUILD_VERSION_MINOR``,| |
183| ``KBUILD_VERSION_PATCH``,| |
184| ``KBUILD_KMK_REVISION`` | |
185+--------------------------+--------------------------------------------------+
[2169]186| ``KBUILD_HOST`` [1]_ | The host operating system. |
[2146]187+--------------------------+--------------------------------------------------+
[2169]188| ``KBUILD_HOST_ARCH`` [1]_| The host architecture. |
[2146]189+--------------------------+--------------------------------------------------+
[2169]190| ``KBUILD_HOST_CPU`` [1]_ | The host CPU ``kmk`` is built for, set to |
[2146]191| | ``blend`` if not any particular CPU. |
192+--------------------------+--------------------------------------------------+
[2169]193| ``KBUILD_PATH`` [1]_ | Where the kBuild scripts are. |
[2146]194+--------------------------+--------------------------------------------------+
[2169]195| ``KBUILD_BIN_PATH`` [1]_ | Where the host specific kBuild binaries are. |
[2146]196+--------------------------+--------------------------------------------------+
[2169]197| ``KMK`` [1]_, | The name with which ``kmk`` was invoked. Using |
[2146]198| ``MAKE`` | this variable in recipes has special meaning. |
199+--------------------------+--------------------------------------------------+
[2169]200| ``KMK_BUILTIN`` [1]_ | List of built-in commands. |
[2146]201+--------------------------+--------------------------------------------------+
[2169]202| ``KMK_FEATURES`` [1]_ | List of ``kmk`` specific features. |
[2146]203+--------------------------+--------------------------------------------------+
[2169]204| ``KMK_FLAGS`` [1]_ | The flags given to ``kmk``. You can set this in |
[2146]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+--------------------------+--------------------------------------------------+
[2169]213| ``KMK_LEVEL`` [1]_ | The number of levels of recursion (sub-makes). |
[2146]214+--------------------------+--------------------------------------------------+
[2169]215| ``KMK_VERSION`` [1]_ | The GNU ``make`` version number. |
[2146]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
[2170]243The following variables reflects ``kmk`` options. Do not set these. [1]_
[2146]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
[2168]267Special Targets
268---------------
269
[2171]270Certain names have special meanings if they appear as targets.
[2168]271
[2171]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+-------------------------------+---------------------------------------------+
[2168]331
332
[2171]333
[2168]334Commands
335--------
336
[2170]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
[2168]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
[2170]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.
[2168]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
[2146]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
[2170]518 duplicates [1]_::
[2146]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
[2490]546 Extract the first defined variable from ``variables``, returning its name
547 (default) or value::
548
549 $(firstdefined variables[, name|value])
550
551 Extract the last defined variable from ``variables``, returning its name
552 (default) or value::
553
554 $(lastdefined variables[, name|value])
555
[2170]556 Fold ``text`` to upper case [1]_::
[2146]557
558 $(toupper text)
559
[2170]560 Fold ``text`` to lower case [1]_::
[2146]561
562 $(tolower text)
563
[2170]564 String formatting a la the unix ``printf`` command [1]_::
[2146]565
566 $(printf fmt, arg...)
567
[2170]568 Return the length of a string or a (unexpanded) variable [1]_::
[2146]569
[2155]570 $(length string)
571 $(length-var var)
572
573 Find the position of ``needle`` in ``haystack``, returns 0 if not found.
574 Negative ``start`` indices are relative to the end of ``haystack``, while
[2170]575 positive ones are one based [1]_::
[2155]576
577 $(pos needle, haystack[, start])
578 $(lastpos needle, haystack[, start])
579
580 Returns the specified substring. The ``start`` works like with ``$(pos )``.
581 If the substring is partially outside the ``string`` the result will be
[2170]582 padded with ``pad`` if present [1]_::
[2155]583
584 $(substr string, start[, length[, pad]])
585
586 Insert ``in`` into ``str`` at the specified position. ``n`` works like with
[2170]587 ``$(pos )``, except that ``0`` is the end of the string [1]_::
[2155]588
589 $(insert in, str[, n[, length[, pad]]])
590
591 Translate ``string`` exchanging characters in ``from-set`` with ``to-set``,
592 optionally completing ``to-set`` with ``pad-char`` if specified. If no
[2170]593 ``pad-char`` characters absent in ``to-set`` will be deleted [1]_::
[2155]594
595 $(translate string, from-set[, to-set[, pad-char]])
596
597
[2146]598Functions for file names:
599
600 Extract the directory part of each file ``name``::
601
602 $(dir names...)
603
604 Extract the non-directory part of each file ``name``::
605
606 $(notdir names...)
607
608 Extract the suffix (the last ``.`` and following characters) of each file
609 ``name``::
610
611 $(suffix names...)
612
613 Extract the base name (name without suffix) of each file name::
614
615 $(basename names...)
616
[2172]617 Extract the root specification of each file name (a bit complicated on
618 Windows & OS/2) [1]_::
619
620 $(root names...)
621
[2475]622 Extract the non-root part of each file name (a bit complicated on
623 Windows & OS/2) [1]_::
624
625 $(notroot names...)
626
[2146]627 Append ``suffix`` to each word in ``names``::
628
629 $(addsuffix suffix,names...)
630
631 Prepend ``prefix`` to each word in ``names``::
632
633 $(addprefix prefix,names...)
634
635 Find file names matching a shell file name ``pattern`` (not a ``%``
636 pattern)::
637
638 $(wildcard pattern...)
639
640 For each file name in ``names``, expand to an absolute name that does not
641 contain any ``.``, ``..``, nor symlinks::
642
643 $(realpath names...)
644
645 For each file name in ``names``, expand to an absolute name that does not
646 contain any ``.`` or ``..`` components, but preserves symlinks::
647
648 $(abspath names...)
649
650 Same as ``$(abspath )`` except that the current directory can be
[2170]651 specified as ``curdir`` [1]_::
[2146]652
653 $(abspathex names...[, curdir])
654
655
656Arithmetic Functions:
657
[2170]658 Returns the sum of the arguments [1]_::
[2146]659
660 $(int-add addend1, addend2[, addendN])
661
[2170]662 Returns the difference between the first argument and the sum of the
663 rest [1]_::
[2146]664
665 $(int-sub minuend, subtrahend[, subtrahendN])
666
[2170]667 Returns the product of the arguments [1]_::
[2146]668
669 $(int-mul factor1, factor2[, factorN])
670
[2170]671 Returns the quotient of first argument and the rest [1]_::
[2146]672
673 $(int-div dividend, divisor[, divisorN])
674
[2170]675 Returns the modulus of the two arguments [1]_::
[2146]676
677 $(int-mod dividend, divisor)
678
[2170]679 Returns the bitwise two-complement of argument [1]_::
[2146]680
681 $(int-not val)
682
[2170]683 Returns the result of a bitwise AND of the arguments [1]_::
[2146]684
685 $(int-and val1, val2[, valN])
686
[2170]687 Returns the result of a bitwise OR of the arguments [1]_::
[2146]688
689 $(int-or val1, val2[, valN])
690
[2170]691 Returns the result of a bitwise XOR of the arguments [1]_::
[2146]692
693 $(int-xor val1, val2[, valN])
694
695 Returns the ``kmk`` boolean (true = non-empty, false = empty) result
[2170]696 of ``val1 == val2`` [1]_::
[2146]697
698 $(int-eq val1, val2)
699
[2170]700 Returns the ``kmk`` boolean result of ``val1 != val2`` [1]_::
[2146]701
702 $(int-ne val1, val2)
703
[2170]704 Returns the ``kmk`` boolean result of ``val1 > val2`` [1]_::
[2146]705
706 $(int-gt val1, val2)
707
[2170]708 Returns the ``kmk`` boolean result of ``val1 >= val2`` [1]_::
[2146]709
710 $(int-ge val1, val2)
711
[2170]712 Returns the ``kmk`` boolean result of ``val1 < val2`` [1]_::
[2146]713
714 $(int-lt val1, val2)
715
[2170]716 Returns the ``kmk`` boolean result of ``val1 <= val2`` [1]_::
[2146]717
718 $(int-le val1, val2)
719
720
[2163]721Boolean and Conditional Functions:
[2146]722
723 Condition is false if the ``condition`` evaluates to an empty string
724 (stripped). Evaluate the ``true-part`` if the condition is true, otherwise
725 the ``false-part``::
726
727 $(if condition,true-part[,false-part])
728
729 Test if any of the conditions evalues to non-empty string, returning the
730 first one::
731
732 $(or condition1[,condition2[,condition3[...]]])
733
734 Test if all of the conditions evaluates to non-empty strings, returning the
735 last one::
736
737 $(and condition1[,condition2[,condition3[...]]])
738
739
740 Test if the two strings are identical, returning ``kmk`` boolean (true =
[2170]741 non-empty, false = empty) [2]_::
[2146]742
743 $(eq str1, str2)
744
[2170]745 Invert a ``kmk`` boolean value [2]_::
[2146]746
747 $(not val)
748
[2170]749 Test if ``variable`` is defined, returning a ``kmk`` boolean value [1]_::
[2146]750
751 $(defined variable)
752
753 Test if ``set-a`` and ``set-b`` intersects, returning a ``kmk`` boolean
[2170]754 value [1]_::
[2146]755
756 $(intersects set-a, set-b)
757
[2170]758 Same as ``$(if )`` execpt that the condition is a ``kmk``-expression [1]_::
[2146]759
[2163]760 $(if-expr kmk-expression,true-part[,false-part])
[2146]761
[2167]762 Select the first true condition (``kmk``-expression) and expand the
[2170]763 following body. Special condition strings ``default`` and
764 ``otherwise`` [1]_::
[2163]765
766 $(select when1-cond, when1-body[, whenN-cond, whenN-body])
767
[2167]768 Evalutate the ``kmk-expression`` returning what it evalues as. This is
[2170]769 the preferred way of doing arithmentic now [1]_::
[2146]770
771 $(expr kmk-expression)
772
773
774Stack Fuctions:
775
[2170]776 Push ``item`` onto the ``stack-var``, returning the empty string [1]_::
[2146]777
778 $(stack-push stack-var, item)
779
[2170]780 Pop the top item off the ``stack-var`` [1]_::
[2146]781
782 $(stack-pop stack-var)
783
[2170]784 Pop the top item off the ``stack-var``, returning the empty string [1]_::
[2146]785
786 $(stack-popv stack-var)
787
[2170]788 Get the top item of the ``stack-var``, returning the empty string [1]_::
[2146]789
790 $(stack-top stack-var)
791
792
793Advanced Functions:
794
795 Evaluates to the contents of the variable ``var``, with no expansion
796 performed on it::
797
798 $(value var)
799
[2161]800 Evaluate ``body`` with ``var`` bound to each word in ``words``, and
[2146]801 concatenate the results (spaced)::
802
[2161]803 $(foreach var,words,body)
[2146]804
[2161]805 C-style for-loop. Start by evaluating ``init``. Each iteration will
806 first check whether the ``condition`` (``kmk``-expression) is true,
807 then expand ``body`` concatenating the result to the previous iterations
[2170]808 (spaced), and finally evaluate ``next`` [1]_::
[2161]809
810 $(for init,conditions,next,body)
811
812 C-style while-loop. Each iteration will check whether the ``condition``
813 (``kmk``-expression) is true, then expand ``body`` concatenating the
[2170]814 result to the previous iterations [1]_::
[2161]815
816 $(while conditions,body)
817
[2146]818 Evaluate the variable ``var`` replacing any references to ``$(1)``,
819 ``$(2)`` with the first, second, etc. ``param`` values::
820
821 $(call var,param,...)
822
823 Evaluate ``text`` then read the results as makefile commands. Expands
824 to the empty string::
825
826 $(eval text)
827
828 Same as ``$(eval text)`` except that the ``text`` is expanded in its
[2170]829 own variable context [1]_::
[2146]830
831 $(evalctx text)
832
[2170]833 Same as ``$(eval $(value var))`` [1]_::
[2146]834
835 $(evalval var)
836
[2170]837 Same as ``$(evalctx $(value var))`` [1]_::
[2146]838
839 $(evalvalctx var)
840
[2170]841 A combination of ``$(eval )``, ``$(call )`` and ``$(value )`` [1]_::
[2146]842
843 $(evalcall var)
844
[2170]845 A combination of ``$(eval )`` and ``$(call )`` [1]_::
[2146]846
[2475]847 $(evalcall2 var)
[2146]848
849 Remove comments and blank lines from the variable ``var``. Expands to
[2170]850 the empty string [1]_::
[2146]851
852 $(eval-opt-var var)
853
854 Returns accessing ``$<`` of ``target``, either retriving the whole thing
[2170]855 or the file at ``pos`` (one-origin) [1]_::
[2146]856
857 $(deps target[, pos])
858
859 Returns accessing ``$+`` (order + duplicates) of ``target``, either
[2170]860 retriving the whole thing or the file at ``pos`` (one-origin) [1]_::
[2146]861
862 $(deps-all target[, pos])
863
864 Returns accessing ``$?`` of ``target``, either retriving the whole
[2170]865 thing or the file at ``pos`` (one-origin) [1]_::
[2146]866
867 $(deps-newer target[, pos])
868
869 Returns accessing ``$|`` (order only) of ``target``, either retriving the
[2170]870 whole thing or the file at ``pos`` (one-origin) [1]_::
[2146]871
872 $(deps-oo target[, pos])
873
874
875Command Functions:
876
877 Create one or more command lines avoiding the max argument
[2170]878 length restriction of the host OS [1]_::
[2146]879
880 $(xargs ar cas mylib.a,$(objects))
881 $(xargs ar cas mylib.a,ar as mylib.a,$(objects))
882
883
884 Returns the commands for the specified target separated by new-line, space,
885 or a user defined string. Note that this might not produce the 100% correct
[2170]886 result if any of the prerequisite automatic variables are used [1]_::
[2146]887
888 $(commands target)
889 $(commands-sc target)
890 $(commands-usr target,sep)
891
892 Compares two commands returning the empty string if equal and the 3rd
893 argument if not. This differs from ``$(comp-vars v1,v2,ne)`` in that
894 line by line is stripped of leading spaces, command prefixes and
[2170]895 trailing spaces before comparing [1]_::
[2146]896
897 $(comp-cmds cmds-var1, cmds-var2, ne)
898 $(comp-cmds-ex cmds1, cmd2, ne)
899
900
901 Compares the values of the two variables returning the empty string if
[2170]902 equal and the 3rd argument if not. Leading and trailing spaces is
903 ignored [1]_::
[2146]904
905 $(comp-var var1, var2, ne)
906
907
908Utility functions:
909
910 When this function is evaluated, ``kmk`` generates a fatal error with the
911 message ``text``::
912
913 $(error text...)
914
915 When this function is evaluated, ``kmk`` generates a warning with the
916 message ``text``::
917
918 $(warning text...)
919
920 When this function is evaluated, ``kmk`` generates a info with the
921 message ``text``::
922
923 $(info text...)
924
925 Execute a shell ``command`` and return its output::
926
927 $(shell command)
928
[2532]929 Return a string with the location where the ``kmk`` variable ``variable``
930 was defined::
931
932 $(where variable)
933
[2146]934 Return a string describing how the ``kmk`` variable ``variable`` was defined::
935
936 $(origin variable)
937
938 Return a string describing the flavor of the ``kmk`` variable ``variable``::
939
940 $(flavor variable)
941
942 Returns the current local time and date formatted in the ``strftime``
943 style specifier ``fmt``. ``fmt`` defaults to ``%Y-%m-%dT%H:%M:%S`` when
[2170]944 not specified [1]_::
[2146]945
946 $(date fmt)
947
948 Returns the current UTC time and date formatted in the ``strftime``
949 style specifier ``fmt``. ``fmt`` defaults to ``%Y-%m-%dT%H:%M:%SZ`` when
[2170]950 not specified [1]_::
[2146]951
952 $(date-utc fmt)
953
954 Reformats the ``in`` time and date using ``fmt``. The ``in-fmt`` defaults
955 to ``fmt`` if not specified. While ``fmt`` defaults to
[2170]956 ``%Y-%m-%dT%H:%M:%SZ`` if not specified [1]_::
[2146]957
958 $(date-utc fmt,time,in-fmt)
959
[2170]960 Returns the current nanosecond timestamp (monotonic when possible) [1]_::
[2146]961
962 $(nanots )
963
964 Returns the size of the specified file, or -1 if the size could not
[2170]965 be obtained. This can be used to check if a file exist or not [1]_::
[2146]966
967 $(file-size file)
968
[2170]969 Searches the ``PATH`` ``kmk`` variable for the specified ``files`` [1]_::
[2146]970
971 $(which files...)
972
[2170]973 OS/2: Returns the specified LIBPATH variable value [1]_::
[2146]974
975 $(libpath var)
976
[2170]977 OS/2: Sets the specified LIBPATH variable value, returning the empty
978 string [1]_::
[2146]979
980 $(libpath var,value)
981
982
983Debugging Functions:
984
985 Returns various make statistics, if no item is specified a default
[2170]986 selection is returned [1]_::
[2146]987
988 $(make-stats item[,itemN])
989
[2170]990 Raise a debug breakpoint. Used for debugging ``kmk`` makefile
991 parsing [1]_::
[2146]992
993 $(breakpoint )
994
995
[2340]996Recipes
997-------
998
999 A typical recipe takes one of the two following forms::
1000
1001 targets : normal-prerequisites | order-only-prerequisites
1002 command
1003 ...
1004
1005 targets : normal-prerequisites | order-only-prerequisites ; command
1006 command
1007 ...
1008
1009 Specifying more than one file in the ``targets`` lists is the same as
1010 repeating the recipe for each of the files.
1011
1012 Use ``+`` and ``+|`` in the list of ``targets`` to tell ``kmk`` that the
1013 recipe has more than one output. [1]_ The files after a ``+`` will
1014 always be remade, while the files after a ``+|`` don't have to be remade.
1015 The latter is frequently employed to update files which prerequisites
1016 change wihtout the output files necessarily changing. See also
1017 ``kmk_cp --changed``.
1018
1019
1020Double colon recipes
1021
1022 Double colon recipes are written with ``::`` instead of ``:`` and are
1023 handled differently from ordinary recipes if the target appears in more
1024 than one recipe. First, all the recipes must be of the double colon type.
1025 Second, the recipes are executed individually and may be omitted depending
1026 on the state of their prerequisites. Double colon recipes without any
1027 prerequisites will always be executed.
1028
1029
1030Pattern rules
1031
1032 A couple of examples::
1033
1034 %.o : %.c
1035 gcc -o $@ $<
1036 %.tab.c %.tab.h : %.y
1037 bison -d $<
1038
1039 The latter has two outputs.
1040
1041
[2146]1042-----
1043
[2169]1044.. [1] ``kmk`` only feature.
[2170]1045.. [2] Experimental GNU ``make`` feature that is not enabled by default.
[2169]1046
1047-----
1048
[2146]1049:Status: $Id: QuickReference-kmk.txt 2532 2011-08-02 13:05:37Z bird $
1050:Copyright: Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
1051 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
1052 2007 Free Software Foundation, Inc.
1053
[2243]1054 Copyright (c) 2008-2009 knut st. osmundsen
Note: See TracBrowser for help on using the repository browser.