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

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

kmk: Implemented $(for ) and $(while ) loops (C-style). Fixes #73.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.7 KB
Line 
1
2kmk Quick Reference
3===================
4
5This appendix summarizes the directives, text manipulation functions, and
6special variables which ``kmk`` understands.
7
8.. See section Special Built-in Target Names and Summary of Options, for other
9 summaries.
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)
33 ifn1of (set-a,set-b)
34 if expression
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::
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
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
71 export variable ?= value
72 unexport variable
73
74 Define a variable in the local context instead of the global one::
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. |
182| ``KBUILD_VERSION_MINOR``,| |
183| ``KBUILD_VERSION_PATCH``,| |
184| ``KBUILD_KMK_REVISION`` | |
185+--------------------------+--------------------------------------------------+
186| ``KBUILD_HOST`` | The host operating system. |
187+--------------------------+--------------------------------------------------+
188| ``KBUILD_HOST_ARCH`` | The host architecture. |
189+--------------------------+--------------------------------------------------+
190| ``KBUILD_HOST_CPU`` | The host CPU ``kmk`` is built for, set to |
191| | ``blend`` if not any particular CPU. |
192+--------------------------+--------------------------------------------------+
193| ``KBUILD_PATH`` | Where the kBuild scripts are. |
194+--------------------------+--------------------------------------------------+
195| ``KBUILD_BIN_PATH`` | Where the host specific kBuild binaries are. |
196+--------------------------+--------------------------------------------------+
197| ``KMK``, | The name with which ``kmk`` was invoked. Using |
198| ``MAKE`` | this variable in recipes has special meaning. |
199+--------------------------+--------------------------------------------------+
200| ``KMK_BUILTIN`` | List of built-in commands. |
201+--------------------------+--------------------------------------------------+
202| ``KMK_FEATURES`` | List of ``kmk`` specific features. |
203+--------------------------+--------------------------------------------------+
204| ``KMK_FLAGS`` | 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`` | The number of levels of recursion (sub-makes). |
214+--------------------------+--------------------------------------------------+
215| ``KMK_VERSION`` | 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.
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
267Built-in functions
268------------------
269
270
271String Manipulation Functions:
272
273 Replace ``from`` with ``to`` in ``text``::
274
275 $(subst from,to,text)
276
277 Replace words matching ``pattern`` with ``replacement`` in ``text``::
278
279 $(patsubst pattern,replacement,text)
280
281 Remove excess whitespace characters from ``string``::
282
283 $(strip string)
284
285 Locate ``find`` in ``text``, returning ``find`` if found::
286
287 $(findstring find,text)
288
289 Select words in ``text`` that match one of the ``pattern`` words::
290
291 $(filter pattern...,text)
292
293 Select words in ``text`` that do not match any of the ``pattern`` words::
294
295 $(filter-out pattern...,text)
296
297 Sort the words in ``list`` lexicographically, removing duplicates::
298
299 $(sort list)
300
301 Sort the words in ``list`` lexicographically in reserve order, removing
302 duplicates::
303
304 $(rsort list)
305
306 Count the number of words in ``text``::
307
308 $(words text)
309
310 Extract the ``n``\th word (one-origin) of ``text``::
311
312 $(word n,text)
313
314 Returns the list of words in ``text`` from ``s`` to ``e`` (one-origin)::
315
316 $(wordlist s,e,text)
317
318 Extract the first word of ``names``::
319
320 $(firstword names...)
321
322 Extract the last word of ``names``::
323
324 $(lastword names...)
325
326 Join two parallel lists of words::
327
328 $(join list1,list2)
329
330 Fold ``text`` to upper case::
331
332 $(toupper text)
333
334 Fold ``text`` to lower case::
335
336 $(tolower text)
337
338 String formatting a la the unix ``printf`` command::
339
340 $(printf fmt, arg...)
341
342 Return the length of a string or a (unexpanded) variable::
343
344 $(length string)
345 $(length-var var)
346
347 Find the position of ``needle`` in ``haystack``, returns 0 if not found.
348 Negative ``start`` indices are relative to the end of ``haystack``, while
349 positive ones are one based::
350
351 $(pos needle, haystack[, start])
352 $(lastpos needle, haystack[, start])
353
354 Returns the specified substring. The ``start`` works like with ``$(pos )``.
355 If the substring is partially outside the ``string`` the result will be
356 padded with ``pad`` if present::
357
358 $(substr string, start[, length[, pad]])
359
360 Insert ``in`` into ``str`` at the specified position. ``n`` works like with
361 ``$(pos )``, except that ``0`` is the end of the string::
362
363 $(insert in, str[, n[, length[, pad]]])
364
365 Translate ``string`` exchanging characters in ``from-set`` with ``to-set``,
366 optionally completing ``to-set`` with ``pad-char`` if specified. If no
367 ``pad-char`` characters absent in ``to-set`` will be deleted::
368
369 $(translate string, from-set[, to-set[, pad-char]])
370
371
372Functions for file names:
373
374 Extract the directory part of each file ``name``::
375
376 $(dir names...)
377
378 Extract the non-directory part of each file ``name``::
379
380 $(notdir names...)
381
382 Extract the suffix (the last ``.`` and following characters) of each file
383 ``name``::
384
385 $(suffix names...)
386
387 Extract the base name (name without suffix) of each file name::
388
389 $(basename names...)
390
391 Append ``suffix`` to each word in ``names``::
392
393 $(addsuffix suffix,names...)
394
395 Prepend ``prefix`` to each word in ``names``::
396
397 $(addprefix prefix,names...)
398
399 Find file names matching a shell file name ``pattern`` (not a ``%``
400 pattern)::
401
402 $(wildcard pattern...)
403
404 For each file name in ``names``, expand to an absolute name that does not
405 contain any ``.``, ``..``, nor symlinks::
406
407 $(realpath names...)
408
409 For each file name in ``names``, expand to an absolute name that does not
410 contain any ``.`` or ``..`` components, but preserves symlinks::
411
412 $(abspath names...)
413
414 Same as ``$(abspath )`` except that the current directory can be
415 specified as ``curdir``::
416
417 $(abspathex names...[, curdir])
418
419
420Arithmetic Functions:
421
422 Returns the sum of the arguments::
423
424 $(int-add addend1, addend2[, addendN])
425
426 Returns the difference between the first argument and the sum of the rest::
427
428 $(int-sub minuend, subtrahend[, subtrahendN])
429
430 Returns the product of the arguments::
431
432 $(int-mul factor1, factor2[, factorN])
433
434 Returns the quotient of first argument and the rest::
435
436 $(int-div dividend, divisor[, divisorN])
437
438 Returns the modulus of the two arguments::
439
440 $(int-mod dividend, divisor)
441
442 Returns the bitwise two-complement of argument::
443
444 $(int-not val)
445
446 Returns the result of a bitwise AND of the arguments::
447
448 $(int-and val1, val2[, valN])
449
450 Returns the result of a bitwise OR of the arguments::
451
452 $(int-or val1, val2[, valN])
453
454 Returns the result of a bitwise XOR of the arguments::
455
456 $(int-xor val1, val2[, valN])
457
458 Returns the ``kmk`` boolean (true = non-empty, false = empty) result
459 of ``val1 == val2``::
460
461 $(int-eq val1, val2)
462
463 Returns the ``kmk`` boolean result of ``val1 != val2``::
464
465 $(int-ne val1, val2)
466
467 Returns the ``kmk`` boolean result of ``val1 > val2``::
468
469 $(int-gt val1, val2)
470
471 Returns the ``kmk`` boolean result of ``val1 >= val2``::
472
473 $(int-ge val1, val2)
474
475 Returns the ``kmk`` boolean result of ``val1 < val2``::
476
477 $(int-lt val1, val2)
478
479 Returns the ``kmk`` boolean result of ``val1 <= val2``::
480
481 $(int-le val1, val2)
482
483
484(Mostly) Boolean Functions:
485
486 Condition is false if the ``condition`` evaluates to an empty string
487 (stripped). Evaluate the ``true-part`` if the condition is true, otherwise
488 the ``false-part``::
489
490 $(if condition,true-part[,false-part])
491
492 Test if any of the conditions evalues to non-empty string, returning the
493 first one::
494
495 $(or condition1[,condition2[,condition3[...]]])
496
497 Test if all of the conditions evaluates to non-empty strings, returning the
498 last one::
499
500 $(and condition1[,condition2[,condition3[...]]])
501
502
503 Test if the two strings are identical, returning ``kmk`` boolean (true =
504 non-empty, false = empty)::
505
506 $(eq str1, str2)
507
508 Invert a ``kmk`` boolean value::
509
510 $(not val)
511
512 Test if ``variable`` is defined, returning a ``kmk`` boolean value::
513
514 $(defined variable)
515
516 Test if ``set-a`` and ``set-b`` intersects, returning a ``kmk`` boolean
517 value::
518
519 $(intersects set-a, set-b)
520
521 Same as ``$(if )`` execpt that the condition is a ``kmk`` expression::
522
523 $(if kmk-expression,true-part[,false-part])
524
525 Evalutate the ``kmk`` expression returning what it evalues as. This is
526 the preferred way of doing arithmentic now::
527
528 $(expr kmk-expression)
529
530
531Stack Fuctions:
532
533 Push ``item`` onto the ``stack-var``, returning the empty string::
534
535 $(stack-push stack-var, item)
536
537 Pop the top item off the ``stack-var``::
538
539 $(stack-pop stack-var)
540
541 Pop the top item off the ``stack-var``, returning the empty string::
542
543 $(stack-popv stack-var)
544
545 Get the top item of the ``stack-var``, returning the empty string::
546
547 $(stack-top stack-var)
548
549
550Advanced Functions:
551
552 Evaluates to the contents of the variable ``var``, with no expansion
553 performed on it::
554
555 $(value var)
556
557 Evaluate ``body`` with ``var`` bound to each word in ``words``, and
558 concatenate the results (spaced)::
559
560 $(foreach var,words,body)
561
562 C-style for-loop. Start by evaluating ``init``. Each iteration will
563 first check whether the ``condition`` (``kmk``-expression) is true,
564 then expand ``body`` concatenating the result to the previous iterations
565 (spaced), and finally evaluate ``next``::
566
567 $(for init,conditions,next,body)
568
569 C-style while-loop. Each iteration will check whether the ``condition``
570 (``kmk``-expression) is true, then expand ``body`` concatenating the
571 result to the previous iterations::
572
573 $(while conditions,body)
574
575 Evaluate the variable ``var`` replacing any references to ``$(1)``,
576 ``$(2)`` with the first, second, etc. ``param`` values::
577
578 $(call var,param,...)
579
580 Evaluate ``text`` then read the results as makefile commands. Expands
581 to the empty string::
582
583 $(eval text)
584
585 Same as ``$(eval text)`` except that the ``text`` is expanded in its
586 own variable context::
587
588 $(evalctx text)
589
590 Same as ``$(eval $(value var))``::
591
592 $(evalval var)
593
594 Same as ``$(evalctx $(value var))``::
595
596 $(evalvalctx var)
597
598 A combination of ``$(eval )``, ``$(call )`` and ``$(value )``::
599
600 $(evalcall var)
601
602 A combination of ``$(eval )`` and ``$(call )``::
603
604 $(evalcall var)
605
606 Remove comments and blank lines from the variable ``var``. Expands to
607 the empty string::
608
609 $(eval-opt-var var)
610
611 Returns accessing ``$<`` of ``target``, either retriving the whole thing
612 or the file at ``pos`` (one-origin)::
613
614 $(deps target[, pos])
615
616 Returns accessing ``$+`` (order + duplicates) of ``target``, either
617 retriving the whole thing or the file at ``pos`` (one-origin)::
618
619 $(deps-all target[, pos])
620
621 Returns accessing ``$?`` of ``target``, either retriving the whole
622 thing or the file at ``pos`` (one-origin)::
623
624 $(deps-newer target[, pos])
625
626 Returns accessing ``$|`` (order only) of ``target``, either retriving the
627 whole thing or the file at ``pos`` (one-origin)::
628
629 $(deps-oo target[, pos])
630
631
632Command Functions:
633
634 Create one or more command lines avoiding the max argument
635 length restriction of the host OS::
636
637 $(xargs ar cas mylib.a,$(objects))
638 $(xargs ar cas mylib.a,ar as mylib.a,$(objects))
639
640
641 Returns the commands for the specified target separated by new-line, space,
642 or a user defined string. Note that this might not produce the 100% correct
643 result if any of the prerequisite automatic variables are used::
644
645 $(commands target)
646 $(commands-sc target)
647 $(commands-usr target,sep)
648
649 Compares two commands returning the empty string if equal and the 3rd
650 argument if not. This differs from ``$(comp-vars v1,v2,ne)`` in that
651 line by line is stripped of leading spaces, command prefixes and
652 trailing spaces before comparing::
653
654 $(comp-cmds cmds-var1, cmds-var2, ne)
655 $(comp-cmds-ex cmds1, cmd2, ne)
656
657
658 Compares the values of the two variables returning the empty string if
659 equal and the 3rd argument if not. Leading and trailing spaces is ignored::
660
661 $(comp-var var1, var2, ne)
662
663
664Utility functions:
665
666 When this function is evaluated, ``kmk`` generates a fatal error with the
667 message ``text``::
668
669 $(error text...)
670
671 When this function is evaluated, ``kmk`` generates a warning with the
672 message ``text``::
673
674 $(warning text...)
675
676 When this function is evaluated, ``kmk`` generates a info with the
677 message ``text``::
678
679 $(info text...)
680
681 Execute a shell ``command`` and return its output::
682
683 $(shell command)
684
685 Return a string describing how the ``kmk`` variable ``variable`` was defined::
686
687 $(origin variable)
688
689 Return a string describing the flavor of the ``kmk`` variable ``variable``::
690
691 $(flavor variable)
692
693 Returns the current local time and date formatted in the ``strftime``
694 style specifier ``fmt``. ``fmt`` defaults to ``%Y-%m-%dT%H:%M:%S`` when
695 not specified::
696
697 $(date fmt)
698
699 Returns the current UTC time and date formatted in the ``strftime``
700 style specifier ``fmt``. ``fmt`` defaults to ``%Y-%m-%dT%H:%M:%SZ`` when
701 not specified::
702
703 $(date-utc fmt)
704
705 Reformats the ``in`` time and date using ``fmt``. The ``in-fmt`` defaults
706 to ``fmt`` if not specified. While ``fmt`` defaults to
707 ``%Y-%m-%dT%H:%M:%SZ`` if not specified::
708
709 $(date-utc fmt,time,in-fmt)
710
711 Returns the current nanosecond timestamp (monotonic when possible)::
712
713 $(nanots )
714
715 Returns the size of the specified file, or -1 if the size could not
716 be obtained. This can be used to check if a file exist or not::
717
718 $(file-size file)
719
720 Searches the ``PATH`` ``kmk`` variable for the specified ``files``::
721
722 $(which files...)
723
724 OS/2: Returns the specified LIBPATH variable value::
725
726 $(libpath var)
727
728 OS/2: Sets the specified LIBPATH variable value, returning the empty string::
729
730 $(libpath var,value)
731
732
733Debugging Functions:
734
735 Returns various make statistics, if no item is specified a default
736 selection is returned::
737
738 $(make-stats item[,itemN])
739
740 Raise a debug breakpoint. Used for debugging ``kmk`` makefile parsing::
741
742 $(breakpoint )
743
744
745
746Special Targets
747---------------
748
749todo
750
751
752
753Built-in Commands
754-----------------
755
756todo
757
758
759
760kmk-expression
761--------------
762
763todo
764
765
766
767-----
768
769:Status: $Id: QuickReference-kmk.txt 2161 2008-12-29 22:20:11Z bird $
770:Copyright: Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
771 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
772 2007 Free Software Foundation, Inc.
773
774 Copyright (C) 2008 Knut St. Osmundsen
Note: See TracBrowser for help on using the repository browser.