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

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

doc dir.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 25.0 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
343Functions for file names:
344
345 Extract the directory part of each file ``name``::
346
347 $(dir names...)
348
349 Extract the non-directory part of each file ``name``::
350
351 $(notdir names...)
352
353 Extract the suffix (the last ``.`` and following characters) of each file
354 ``name``::
355
356 $(suffix names...)
357
358 Extract the base name (name without suffix) of each file name::
359
360 $(basename names...)
361
362 Append ``suffix`` to each word in ``names``::
363
364 $(addsuffix suffix,names...)
365
366 Prepend ``prefix`` to each word in ``names``::
367
368 $(addprefix prefix,names...)
369
370 Find file names matching a shell file name ``pattern`` (not a ``%``
371 pattern)::
372
373 $(wildcard pattern...)
374
375 For each file name in ``names``, expand to an absolute name that does not
376 contain any ``.``, ``..``, nor symlinks::
377
378 $(realpath names...)
379
380 For each file name in ``names``, expand to an absolute name that does not
381 contain any ``.`` or ``..`` components, but preserves symlinks::
382
383 $(abspath names...)
384
385 Same as ``$(abspath )`` except that the current directory can be
386 specified as ``curdir``::
387
388 $(abspathex names...[, curdir])
389
390
391Arithmetic Functions:
392
393 Returns the sum of the arguments::
394
395 $(int-add addend1, addend2[, addendN])
396
397 Returns the difference between the first argument and the sum of the rest::
398
399 $(int-sub minuend, subtrahend[, subtrahendN])
400
401 Returns the product of the arguments::
402
403 $(int-mul factor1, factor2[, factorN])
404
405 Returns the quotient of first argument and the rest::
406
407 $(int-div dividend, divisor[, divisorN])
408
409 Returns the modulus of the two arguments::
410
411 $(int-mod dividend, divisor)
412
413 Returns the bitwise two-complement of argument::
414
415 $(int-not val)
416
417 Returns the result of a bitwise AND of the arguments::
418
419 $(int-and val1, val2[, valN])
420
421 Returns the result of a bitwise OR of the arguments::
422
423 $(int-or val1, val2[, valN])
424
425 Returns the result of a bitwise XOR of the arguments::
426
427 $(int-xor val1, val2[, valN])
428
429 Returns the ``kmk`` boolean (true = non-empty, false = empty) result
430 of ``val1 == val2``::
431
432 $(int-eq val1, val2)
433
434 Returns the ``kmk`` boolean result of ``val1 != val2``::
435
436 $(int-ne val1, val2)
437
438 Returns the ``kmk`` boolean result of ``val1 > val2``::
439
440 $(int-gt val1, val2)
441
442 Returns the ``kmk`` boolean result of ``val1 >= val2``::
443
444 $(int-ge val1, val2)
445
446 Returns the ``kmk`` boolean result of ``val1 < val2``::
447
448 $(int-lt val1, val2)
449
450 Returns the ``kmk`` boolean result of ``val1 <= val2``::
451
452 $(int-le val1, val2)
453
454
455(Mostly) Boolean Functions:
456
457 Condition is false if the ``condition`` evaluates to an empty string
458 (stripped). Evaluate the ``true-part`` if the condition is true, otherwise
459 the ``false-part``::
460
461 $(if condition,true-part[,false-part])
462
463 Test if any of the conditions evalues to non-empty string, returning the
464 first one::
465
466 $(or condition1[,condition2[,condition3[...]]])
467
468 Test if all of the conditions evaluates to non-empty strings, returning the
469 last one::
470
471 $(and condition1[,condition2[,condition3[...]]])
472
473
474 Test if the two strings are identical, returning ``kmk`` boolean (true =
475 non-empty, false = empty)::
476
477 $(eq str1, str2)
478
479 Invert a ``kmk`` boolean value::
480
481 $(not val)
482
483 Test if ``variable`` is defined, returning a ``kmk`` boolean value::
484
485 $(defined variable)
486
487 Test if ``set-a`` and ``set-b`` intersects, returning a ``kmk`` boolean
488 value::
489
490 $(intersects set-a, set-b)
491
492 Same as ``$(if )`` execpt that the condition is a ``kmk`` expression::
493
494 $(if kmk-expression,true-part[,false-part])
495
496 Evalutate the ``kmk`` expression returning what it evalues as. This is
497 the preferred way of doing arithmentic now::
498
499 $(expr kmk-expression)
500
501
502Stack Fuctions:
503
504 Push ``item`` onto the ``stack-var``, returning the empty string::
505
506 $(stack-push stack-var, item)
507
508 Pop the top item off the ``stack-var``::
509
510 $(stack-pop stack-var)
511
512 Pop the top item off the ``stack-var``, returning the empty string::
513
514 $(stack-popv stack-var)
515
516 Get the top item of the ``stack-var``, returning the empty string::
517
518 $(stack-top stack-var)
519
520
521Advanced Functions:
522
523 Evaluates to the contents of the variable ``var``, with no expansion
524 performed on it::
525
526 $(value var)
527
528 Evaluate ``text`` with ``var`` bound to each word in ``words``, and
529 concatenate the results (spaced)::
530
531 $(foreach var,words,text)
532
533 Evaluate the variable ``var`` replacing any references to ``$(1)``,
534 ``$(2)`` with the first, second, etc. ``param`` values::
535
536 $(call var,param,...)
537
538 Evaluate ``text`` then read the results as makefile commands. Expands
539 to the empty string::
540
541 $(eval text)
542
543 Same as ``$(eval text)`` except that the ``text`` is expanded in its
544 own variable context::
545
546 $(evalctx text)
547
548 Same as ``$(eval $(value var))``::
549
550 $(evalval var)
551
552 Same as ``$(evalctx $(value var))``::
553
554 $(evalvalctx var)
555
556 A combination of ``$(eval )``, ``$(call )`` and ``$(value )``::
557
558 $(evalcall var)
559
560 A combination of ``$(eval )`` and ``$(call )``::
561
562 $(evalcall var)
563
564 Remove comments and blank lines from the variable ``var``. Expands to
565 the empty string::
566
567 $(eval-opt-var var)
568
569 Returns accessing ``$<`` of ``target``, either retriving the whole thing
570 or the file at ``pos`` (one-origin)::
571
572 $(deps target[, pos])
573
574 Returns accessing ``$+`` (order + duplicates) of ``target``, either
575 retriving the whole thing or the file at ``pos`` (one-origin)::
576
577 $(deps-all target[, pos])
578
579 Returns accessing ``$?`` of ``target``, either retriving the whole
580 thing or the file at ``pos`` (one-origin)::
581
582 $(deps-newer target[, pos])
583
584 Returns accessing ``$|`` (order only) of ``target``, either retriving the
585 whole thing or the file at ``pos`` (one-origin)::
586
587 $(deps-oo target[, pos])
588
589
590Command Functions:
591
592 Create one or more command lines avoiding the max argument
593 length restriction of the host OS::
594
595 $(xargs ar cas mylib.a,$(objects))
596 $(xargs ar cas mylib.a,ar as mylib.a,$(objects))
597
598
599 Returns the commands for the specified target separated by new-line, space,
600 or a user defined string. Note that this might not produce the 100% correct
601 result if any of the prerequisite automatic variables are used::
602
603 $(commands target)
604 $(commands-sc target)
605 $(commands-usr target,sep)
606
607 Compares two commands returning the empty string if equal and the 3rd
608 argument if not. This differs from ``$(comp-vars v1,v2,ne)`` in that
609 line by line is stripped of leading spaces, command prefixes and
610 trailing spaces before comparing::
611
612 $(comp-cmds cmds-var1, cmds-var2, ne)
613 $(comp-cmds-ex cmds1, cmd2, ne)
614
615
616 Compares the values of the two variables returning the empty string if
617 equal and the 3rd argument if not. Leading and trailing spaces is ignored::
618
619 $(comp-var var1, var2, ne)
620
621
622Utility functions:
623
624 When this function is evaluated, ``kmk`` generates a fatal error with the
625 message ``text``::
626
627 $(error text...)
628
629 When this function is evaluated, ``kmk`` generates a warning with the
630 message ``text``::
631
632 $(warning text...)
633
634 When this function is evaluated, ``kmk`` generates a info with the
635 message ``text``::
636
637 $(info text...)
638
639 Execute a shell ``command`` and return its output::
640
641 $(shell command)
642
643 Return a string describing how the ``kmk`` variable ``variable`` was defined::
644
645 $(origin variable)
646
647 Return a string describing the flavor of the ``kmk`` variable ``variable``::
648
649 $(flavor variable)
650
651 Returns the current local time and date formatted in the ``strftime``
652 style specifier ``fmt``. ``fmt`` defaults to ``%Y-%m-%dT%H:%M:%S`` when
653 not specified::
654
655 $(date fmt)
656
657 Returns the current UTC time and date formatted in the ``strftime``
658 style specifier ``fmt``. ``fmt`` defaults to ``%Y-%m-%dT%H:%M:%SZ`` when
659 not specified::
660
661 $(date-utc fmt)
662
663 Reformats the ``in`` time and date using ``fmt``. The ``in-fmt`` defaults
664 to ``fmt`` if not specified. While ``fmt`` defaults to
665 ``%Y-%m-%dT%H:%M:%SZ`` if not specified::
666
667 $(date-utc fmt,time,in-fmt)
668
669 Returns the current nanosecond timestamp (monotonic when possible)::
670
671 $(nanots )
672
673 Returns the size of the specified file, or -1 if the size could not
674 be obtained. This can be used to check if a file exist or not::
675
676 $(file-size file)
677
678 Searches the ``PATH`` ``kmk`` variable for the specified ``files``::
679
680 $(which files...)
681
682 OS/2: Returns the specified LIBPATH variable value::
683
684 $(libpath var)
685
686 OS/2: Sets the specified LIBPATH variable value, returning the empty string::
687
688 $(libpath var,value)
689
690
691Debugging Functions:
692
693 Returns various make statistics, if no item is specified a default
694 selection is returned::
695
696 $(make-stats item[,itemN])
697
698 Raise a debug breakpoint. Used for debugging ``kmk`` makefile parsing::
699
700 $(breakpoint )
701
702
703
704Special targets
705---------------
706
707todo
708
709
710-----
711
712:Status: $Id: QuickReference-kmk.txt 2146 2008-12-27 20:22:53Z bird $
713:Copyright: Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
714 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
715 2007 Free Software Foundation, Inc.
716
717 Copyright (C) 2008 Knut St. Osmundsen
Note: See TracBrowser for help on using the repository browser.