Disable tool initialization in tests which don't need it
[scons.git] / SCons / Environment.xml
blob5f152f22eec7ae9de73fd906e774aeb6f597d7c1
1 <?xml version="1.0"?>
2 <!--
3 Copyright The SCons Foundation
5 This file is processed by the bin/SConsDoc.py module.
6 See its __doc__ string for a discussion of the format.
7 -->
9 <!DOCTYPE sconsdoc [
10 <!ENTITY % scons SYSTEM '../doc/scons.mod'>
11 %scons;
12 <!ENTITY % builders-mod SYSTEM '../doc/generated/builders.mod'>
13 %builders-mod;
14 <!ENTITY % functions-mod SYSTEM '../doc/generated/functions.mod'>
15 %functions-mod;
16 <!ENTITY % tools-mod SYSTEM '../doc/generated/tools.mod'>
17 %tools-mod;
18 <!ENTITY % variables-mod SYSTEM '../doc/generated/variables.mod'>
19 %variables-mod;
22 <sconsdoc xmlns="http://www.scons.org/dbxsd/v1.0"
23           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24           xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">
27 <!-- Construction variables -->
29 <cvar name="BUILDERS">
30 <summary>
31 <para>
32 A dictionary mapping the names of the builders
33 available through the &consenv; to underlying Builder objects.
34 Custom builders need to be added to this to make them available.
35 </para>
37 <para>
38 A platform-dependent default list of builders such as
39 &b-link-Program;, &b-link-Library; etc. is used to
40 populate this &consvar; when the &consenv; is initialized
41 via the presence/absence of the tools those builders depend on.
42 &cv-BUILDERS; can be examined to learn which builders will
43 actually be available at run-time.
44 </para>
46 <para>
47 Note that if you initialize this &consvar; through
48 assignment when the &consenv; is created,
49 that value for &cv-BUILDERS; will override any defaults:
50 </para>
52 <example_commands>
53 bld = Builder(action='foobuild &lt; $SOURCE > $TARGET')
54 env = Environment(BUILDERS={'NewBuilder': bld})
55 </example_commands>
57 <para>
58 To instead use a new Builder object in addition to the default Builders,
59 add your new Builder object like this:
60 </para>
62 <example_commands>
63 env = Environment()
64 env.Append(BUILDERS={'NewBuilder': bld})
65 </example_commands>
67 <para>
68 or this:
69 </para>
71 <example_commands>
72 env = Environment()
73 env['BUILDERS']['NewBuilder'] = bld
74 </example_commands>
75 </summary>
76 </cvar>
78 <cvar name="ENV">
79 <summary>
80 <para>
81 The <firstterm>execution environment</firstterm> -
82 a dictionary of environment variables
83 used when &SCons; invokes external commands
84 to build targets defined in this &consenv;.
85 When &cv-ENV; is passed to a command,
86 all list values are assumed to be path lists and
87 are joined using the search path separator.
88 Any other non-string values are coerced to a string.
89 </para>
91 <para>
92 Note that by default
93 &SCons;
94 does
95 <emphasis>not</emphasis>
96 propagate the environment in effect when you execute
97 &scons; (the "shell environment")
98 to the execution environment.
99 This is so that builds will be guaranteed
100 repeatable regardless of the environment
101 variables set at the time
102 &scons;
103 is invoked.
104 If you want to propagate a
105 shell environment variable
106 to the commands executed
107 to build target files,
108 you must do so explicitly.
109 A common example is
110 the system &PATH;
111 environment variable,
112 so that
113 &scons;
114 will find utilities the same way
115 as the invoking shell (or other process):
116 </para>
118 <example_commands>
119 import os
120 env = Environment(ENV={'PATH': os.environ['PATH']})
121 </example_commands>
123 <para>
124 Although it is usually not recommended,
125 you can propagate the entire shell environment
126 in one go:
127 </para>
129 <example_commands>
130 import os
131 env = Environment(ENV=os.environ.copy())
132 </example_commands>
134 </summary>
135 </cvar>
137 <cvar name="SCANNERS">
138 <summary>
139 <para>
140 A list of the available implicit dependency scanners.
141 New file scanners may be added by
142 appending to this list,
143 although the more flexible approach
144 is to associate scanners
145 with a specific Builder.
146 See the manpage sections "Builder Objects"
147 and "Scanner Objects"
148 for more information.
149 </para>
150 </summary>
151 </cvar>
153 <cvar name="CHANGED_SOURCES">
154 <summary>
155 <para>
156 A reserved variable name
157 that may not be set or used in a construction environment.
158 (See the manpage section "Variable Substitution"
159 for more information).
160 </para>
161 </summary>
162 </cvar>
164 <cvar name="CHANGED_TARGETS">
165 <summary>
166 <para>
167 A reserved variable name
168 that may not be set or used in a construction environment.
169 (See the manpage section "Variable Substitution"
170 for more information).
171 </para>
172 </summary>
173 </cvar>
175 <cvar name="SOURCE">
176 <summary>
177 <para>
178 A reserved variable name
179 that may not be set or used in a construction environment.
180 (See the manpage section "Variable Substitution"
181 for more information).
182 </para>
183 </summary>
184 </cvar>
186 <cvar name="SOURCES">
187 <summary>
188 <para>
189 A reserved variable name
190 that may not be set or used in a construction environment.
191 (See the manpage section "Variable Substitution"
192 for more information).
193 </para>
194 </summary>
195 </cvar>
197 <cvar name="TARGET">
198 <summary>
199 <para>
200 A reserved variable name
201 that may not be set or used in a construction environment.
202 (See the manpage section "Variable Substitution"
203 for more information).
204 </para>
205 </summary>
206 </cvar>
208 <cvar name="TARGETS">
209 <summary>
210 <para>
211 A reserved variable name
212 that may not be set or used in a construction environment.
213 (See the manpage section "Variable Substitution"
214 for more information).
215 </para>
216 </summary>
217 </cvar>
219 <cvar name="UNCHANGED_SOURCES">
220 <summary>
221 <para>
222 A reserved variable name
223 that may not be set or used in a construction environment.
224 (See the manpage section "Variable Substitution"
225 for more information).
226 </para>
227 </summary>
228 </cvar>
230 <cvar name="UNCHANGED_TARGETS">
231 <summary>
232 <para>
233 A reserved variable name
234 that may not be set or used in a construction environment.
235 (See the manpage section "Variable Substitution"
236 for more information).
237 </para>
238 </summary>
239 </cvar>
241 <cvar name="TOOLS">
242 <summary>
243 <para>
244 A list of the names of the Tool specification modules
245 that were actually initialized in the current &consenv;.
246 This may be useful as a diagnostic aid
247 to see if a tool did (or did not) run.
248 The value is informative and is not guaranteed to be complete.
249 </para>
250 </summary>
251 </cvar>
253 <cvar name="CACHEDIR_CLASS">
254     <summary>
255         <para>
256 The class type that SCons should use when instantiating a
257 new &f-link-CacheDir; in this &consenv;. Must be
258 a subclass of the <classname>SCons.CacheDir.CacheDir</classname> class.
259         </para>
260     </summary>
261 </cvar>
263 <!-- Functions /  Construction environment methods -->
265 <scons_function name="Action">
266 <arguments>
267 (action, [output, [var, ...]] [key=value, ...])
268 </arguments>
269 <summary>
270 <para>
271 A factory function to create an Action object for
272 the specified
273 <parameter>action</parameter>.
274 See the manpage section "Action Objects"
275 for a complete explanation of the arguments and behavior.
276 </para>
278 <para>
279 Note that the &f-env-Action;
280 form of the invocation will expand
281 construction variables in any argument strings,
282 including the
283 <parameter>action</parameter>
284 argument, at the time it is called
285 using the construction variables in the
286 <replaceable>env</replaceable>
287 construction environment through which
288 &f-env-Action; was called.
289 The &f-Action; global function
290 form delays all variable expansion
291 until the Action object is actually used.
292 </para>
293 </summary>
294 </scons_function>
296 <scons_function name="AddMethod">
297 <arguments signature="global">
298 (object, function, [name])
299 </arguments>
300 <arguments signature="env">
301 (function, [name])
302 </arguments>
303 <summary>
304 <para>
305 Adds <parameter>function</parameter> to an object as a method.
306 <parameter>function</parameter> will be called with an instance
307 object as the first argument as for other methods.
308 If <parameter>name</parameter> is given, it is used as
309 the name of the new method, else the name of
310 <parameter>function</parameter> is used.
311 </para>
312 <para>
313 When the global function &f-AddMethod; is called,
314 the object to add the method to must be passed as the first argument;
315 typically this will be &Environment;,
316 in order to create a method which applies to all &consenvs;
317 subsequently constructed.
318 When called using the &f-env-AddMethod; form,
319 the method is added to the specified &consenv; only.
320 Added methods propagate through &f-env-Clone; calls.
321 </para>
323 <para>
324 More examples:
325 </para>
327 <example_commands>
328 # Function to add must accept an instance argument.
329 # The Python convention is to call this 'self'.
330 def my_method(self, arg):
331     print("my_method() got", arg)
333 # Use the global function to add a method to the Environment class:
334 AddMethod(Environment, my_method)
335 env = Environment()
336 env.my_method('arg')
338 # Use the optional name argument to set the name of the method:
339 env.AddMethod(my_method, 'other_method_name')
340 env.other_method_name('another arg')
341 </example_commands>
342 </summary>
343 </scons_function>
345 <scons_function name="AddPostAction">
346 <arguments>
347 (target, action)
348 </arguments>
349 <summary>
350 <para>
351 Arranges for the specified
352 <parameter>action</parameter>
353 to be performed
354 after the specified
355 <parameter>target</parameter>
356 has been built.
357 <parameter>action</parameter> may be
358 an Action object, or anything that
359 can be converted into an Action object.
360 See the manpage section "Action Objects"
361 for a complete explanation.
362 </para>
364 <para>
365 When multiple targets are supplied,
366 the action may be called multiple times,
367 once after each action that generates
368 one or more targets in the list.
369 </para>
371 <example_commands>
372 foo = Program('foo.c')
373 # remove execute permission from binary:
374 AddPostAction(foo, Chmod('$TARGET', "a-x"))
375 </example_commands>
377 </summary>
378 </scons_function>
380 <scons_function name="AddPreAction">
381 <arguments>
382 (target, action)
383 </arguments>
384 <summary>
385 <para>
386 Arranges for the specified
387 <parameter>action</parameter>
388 to be performed
389 before the specified
390 <parameter>target</parameter>
391 is built.
392 <parameter>action</parameter> may be
393 an Action object, or anything that
394 can be converted into an Action object.
395 See the manpage section "Action Objects"
396 for a complete explanation.
397 </para>
399 <para>
400 When multiple targets are specified,
401 the action(s) may be called multiple times,
402 once before each action that generates
403 one or more targets in the list.
404 </para>
406 <para>
407 Note that if any of the targets are built in multiple steps,
408 the action will be invoked just
409 before the "final" action that specifically
410 generates the specified target(s).
411 For example, when building an executable program
412 from a specified source
413 <filename>.c</filename>
414 file via an intermediate object file:
415 </para>
417 <example_commands>
418 foo = Program('foo.c')
419 AddPreAction(foo, 'pre_action')
420 </example_commands>
422 <para>
423 The specified
424 <literal>pre_action</literal>
425 would be executed before
426 &scons;
427 calls the link command that actually
428 generates the executable program binary
429 <filename>foo</filename>,
430 not before compiling the
431 <filename>foo.c</filename>
432 file into an object file.
433 </para>
434 </summary>
435 </scons_function>
437 <scons_function name="Alias">
438 <arguments>
439 (alias, [source, [action]])
440 </arguments>
441 <summary>
442 <para>
443 Creates an <firstterm>alias</firstterm> target that
444 can be used as a reference to zero or more other targets,
445 specified by the optional <parameter>source</parameter> parameter.
446 Aliases provide a way to give a shorter or more descriptive
447 name to specific targets,
448 and to group multiple targets under a single name.
449 The alias name, or an Alias Node object,
450 may be used as a dependency of any other target,
451 including another alias.
452 </para>
454 <para>
455 <parameter>alias</parameter> and <parameter>source</parameter>
456 may each be a string or Node object,
457 or a list of strings or Node objects;
458 if Nodes are used for
459 <parameter>alias</parameter>
460 they must be Alias nodes.
461 If <parameter>source</parameter> is omitted,
462 the alias is created but has no reference;
463 if selected for building this will result in a
464 <quote>Nothing to be done.</quote> message.
465 An empty alias can be used to define the alias
466 in a visible place in the project;
467 it can later be appended to in a subsidiary SConscript file
468 with the actual target(s) to refer to.
469 The optional
470 <parameter>action</parameter>
471 parameter specifies an action or list of actions
472 that will be executed
473 whenever the any of the alias targets are out-of-date.
474 </para>
476 <para>
477 &f-Alias; can be called for an existing alias,
478 which appends the <parameter>alias</parameter>
479 and/or <parameter>action</parameter> arguments
480 to the existing lists for that alias.
481 </para>
483 <para>
484 Returns a list of Alias Node objects representing the alias(es),
485 which exist outside of any physical file system.
486 The alias name space is separate from the name space for
487 tangible targets; to avoid confusion do not reuse
488 target names as alias names.
489 </para>
491 <para>
492 Examples:
493 </para>
495 <example_commands>
496 Alias('install')
497 Alias('install', '/usr/bin')
498 Alias(['install', 'install-lib'], '/usr/local/lib')
500 env.Alias('install', ['/usr/local/bin', '/usr/local/lib'])
501 env.Alias('install', ['/usr/local/man'])
503 env.Alias('update', ['file1', 'file2'], "update_database $SOURCES")
504 </example_commands>
505 </summary>
506 </scons_function>
508 <scons_function name="AlwaysBuild">
509 <arguments>
510 (target, ...)
511 </arguments>
512 <summary>
513 <para>
514 Marks each given
515 <parameter>target</parameter>
516 so that it is always assumed to be out of date,
517 and will always be rebuilt if needed.
518 Note, however, that
519 &f-AlwaysBuild;
520 does not add its target(s) to the default target list,
521 so the targets will only be built
522 if they are specified on the command line,
523 or are a dependent of a target specified on the command line--but
524 they will
525 <emphasis>always</emphasis>
526 be built if so specified.
527 Multiple targets can be passed in to a single call to
528 &f-AlwaysBuild;.
529 </para>
530 </summary>
531 </scons_function>
533 <scons_function name="Append">
534 <arguments signature="env">
535 (key=val, [...])
536 </arguments>
537 <summary>
538 <para>
539 Appends value(s) intelligently to &consvars; in
540 <varname>env</varname>.
541 The &consvars; and values to add to them are passed as
542 <parameter>key=val</parameter> pairs (&Python; keyword arguments).
543 &f-env-Append; is designed to allow adding values
544 without having to think about the data type of an existing &consvar;.
545 Regular &Python; syntax can also be used to manipulate the &consvar;,
546 but for that you may need to know the types involved,
547 for example pure &Python; lets you directly "add" two lists of strings,
548 but adding a string to a list or a list to a string requires
549 different syntax - things &f-Append; takes care of.
550 Some pre-defined &consvars; do have type expectations
551 based on how &SCons; will use them:
552 for example &cv-link-CPPDEFINES; is often a string or a list of strings,
553 but can also be a list of tuples or a dictionary;
554 while &cv-link-LIBEMITTER;
555 is expected to be a callable or list of callables,
556 and &cv-link-BUILDERS; is expected to be a dictionary.
557 Consult the documentation for the various &consvars; for more details.
558 </para>
560 <para>
561 The following descriptions apply to both the &f-Append;
562 and &f-Prepend; methods, as well as their
563 <emphasis role="bold">Unique</emphasis> variants,
564 with the differences being the insertion point of the added values
565 and whether duplication is allowed.
566 </para>
568 <para>
569 <parameter>val</parameter> can be almost any type.
570 If <varname>env</varname> does not have a &consvar;
571 named <parameter>key</parameter>,
572 then <parameter>key</parameter> is simply
573 stored with a value of <parameter>val</parameter>.
574 Otherwise, <parameter>val</parameter> is
575 combinined with the existing value,
576 possibly converting into an appropriate type
577 which can hold the expanded contents.
578 There are a few special cases to be aware of.
579 Normally, when two strings are combined,
580 the result is a new string containing their concatenation
581 (and you are responsible for supplying any needed separation);
582 however, the contents of &cv-link-CPPDEFINES; will
583 will be postprocessed by adding a prefix and/or suffix
584 to each entry when the command line is produced,
585 so &SCons; keeps them separate -
586 appending a string will result in a separate string entry,
587 not a combined string.
588 For &cv-CPPDEFINES;. as well as
589 &cv-link-LIBS;, and the various <literal>*PATH</literal> variables,
590 &SCons; will amend the variable by supplying the compiler-specific
591 syntax (e.g. prepending a <literal>-D</literal> or <literal>/D</literal>
592 prefix for &cv-CPPDEFINES;), so you should omit this syntax when
593 adding values to these variables.
594 Examples (gcc syntax shown in the expansion of &CPPDEFINES;):
595 </para>
597 <example_commands>
598 env = Environment(CXXFLAGS="-std=c11", CPPDEFINES="RELEASE")
599 print(f"CXXFLAGS = {env['CXXFLAGS']}, CPPDEFINES = {env['CPPDEFINES']}")
600 # notice including a leading space in CXXFLAGS addition
601 env.Append(CXXFLAGS=" -O", CPPDEFINES="EXTRA")
602 print(f"CXXFLAGS = {env['CXXFLAGS']}, CPPDEFINES = {env['CPPDEFINES']}")
603 print("CPPDEFINES will expand to", env.subst('$_CPPDEFFLAGS'))
604 </example_commands>
606 <screen>
607 $ scons -Q
608 CXXFLAGS = -std=c11, CPPDEFINES = RELEASE
609 CXXFLAGS = -std=c11 -O, CPPDEFINES = deque(['RELEASE', 'EXTRA'])
610 CPPDEFINES will expand to -DRELEASE -DEXTRA
611 scons: `.' is up to date.
612 </screen>
614 <para>
615 Because &cv-link-CPPDEFINES; is intended for command-line
616 specification of C/C++ preprocessor macros,
617 additional syntax is accepted when adding to it.
618 The preprocessor accepts arguments to predefine a macro name by itself
619 (<computeroutput>-DFOO</computeroutput> for most compilers,
620 <computeroutput>/DFOO</computeroutput> for Microsoft C++),
621 which gives it an implicit value of <constant>1</constant>,
622 or can be given with a replacement value
623 (<computeroutput>-DBAR=TEXT</computeroutput>).
624 &SCons; follows these rules when adding to &cv-CPPDEFINES;:
625 </para>
626 <itemizedlist>
627 <listitem>
628 <para>A string is split on spaces,
629 giving an easy way to enter multiple macros in one addition.
630 Use an <literal>=</literal> to specify a valued macro.</para>
631 </listitem>
632 <listitem>
633 <para>A tuple is treated as a valued macro.
634 Use the value <constant>None</constant> if the macro should not have a value.
635 It is an error to supply more than two elements in such a tuple.</para>
636 </listitem>
637 <listitem>
638 <para>A list is processed in order,
639 adding each item without further interpretation.
640 In this case, space-separated strings are not split.</para>
641 </listitem>
642 <listitem>
643 <para>A dictionary is processed in order,
644 adding each key-value pair as a valued macro.
645 Use the value <constant>None</constant> if the macro should not have a value.
646 </para>
647 </listitem>
648 </itemizedlist>
650 <para>
651 Examples:
652 </para>
654 <example_commands>
655 env = Environment(CPPDEFINES="FOO")
656 print("CPPDEFINES =", env['CPPDEFINES'])
657 env.Append(CPPDEFINES="BAR=1")
658 print("CPPDEFINES =", env['CPPDEFINES'])
659 env.Append(CPPDEFINES=[("OTHER", 2)])
660 print("CPPDEFINES =", env['CPPDEFINES'])
661 env.Append(CPPDEFINES={"EXTRA": "arg"})
662 print("CPPDEFINES =", env['CPPDEFINES'])
663 print("CPPDEFINES will expand to", env.subst('$_CPPDEFFLAGS'))
664 </example_commands>
666 <screen>
667 $ scons -Q
668 CPPDEFINES = FOO
669 CPPDEFINES = deque(['FOO', 'BAR=1'])
670 CPPDEFINES = deque(['FOO', 'BAR=1', ('OTHER', 2)])
671 CPPDEFINES = deque(['FOO', 'BAR=1', ('OTHER', 2), ('EXTRA', 'arg')])
672 CPPDEFINES will expand to -DFOO -DBAR=1 -DOTHER=2 -DEXTRA=arg
673 scons: `.' is up to date.
674 </screen>
676 <para>
677 Examples of adding multiple macros:
678 </para>
680 <example_commands>
681 env = Environment()
682 env.Append(CPPDEFINES=[("ONE", 1), "TWO", ("THREE", )])
683 print("CPPDEFINES =", env['CPPDEFINES'])
684 env.Append(CPPDEFINES={"FOUR": 4, "FIVE": None})
685 print("CPPDEFINES =", env['CPPDEFINES'])
686 print("CPPDEFINES will expand to", env.subst('$_CPPDEFFLAGS'))
687 </example_commands>
689 <screen>
690 $ scons -Q
691 CPPDEFINES = [('ONE', 1), 'TWO', ('THREE',)]
692 CPPDEFINES = deque([('ONE', 1), 'TWO', ('THREE',), ('FOUR', 4), ('FIVE', None)])
693 CPPDEFINES will expand to -DONE=1 -DTWO -DTHREE -DFOUR=4 -DFIVE
694 scons: `.' is up to date.
695 </screen>
697 <para>
698 <emphasis>Changed in version  4.5</emphasis>:
699 clarifined the use of tuples vs. other types,
700 handling is now consistent across the four functions.
701 </para>
703 <example_commands>
704 env = Environment()
705 env.Append(CPPDEFINES=("MACRO1", "MACRO2"))
706 print("CPPDEFINES =", env['CPPDEFINES'])
707 env.Append(CPPDEFINES=[("MACRO3", "MACRO4")])
708 print("CPPDEFINES =", env['CPPDEFINES'])
709 print("CPPDEFINES will expand to", env.subst('$_CPPDEFFLAGS'))
710 </example_commands>
712 <screen>
713 $ scons -Q
714 CPPDEFINES = ('MACRO1', 'MACRO2')
715 CPPDEFINES = deque(['MACRO1', 'MACRO2', ('MACRO3', 'MACRO4')])
716 CPPDEFINES will expand to -DMACRO1 -DMACRO2 -DMACRO3=MACRO4
717 scons: `.' is up to date.
718 </screen>
720 <para>
721 See &cv-link-CPPDEFINES; for more details.
722 </para>
724 <para>
725 Appending a string <parameter>val</parameter>
726 to a dictonary-typed &consvar; enters
727 <parameter>val</parameter> as the key in the dictionary,
728 and <literal>None</literal> as its value.
729 Using a tuple type to supply a key-value pair
730 only works for the special case of &cv-CPPDEFINES;
731 described above.
732 </para>
734 <para>
735 Although most combinations of types work without
736 needing to know the details, some combinations
737 do not make sense and &Python; raises an exception.
738 </para>
740 <para>
741 When using &f-env-Append; to modify &consvars;
742 which are path specifications (conventionally,
743 the names of such end in <literal>PATH</literal>),
744 it is recommended to add the values as a list of strings,
745 even if you are only adding a single string.
746 The same goes for adding library names to &cv-LIBS;.
747 </para>
749 <example_commands>
750 env.Append(CPPPATH=["#/include"])
751 </example_commands>
753 <para>
754 See also &f-link-env-AppendUnique;,
755 &f-link-env-Prepend; and &f-link-env-PrependUnique;.
756 </para>
758 </summary>
759 </scons_function>
761 <scons_function name="AppendENVPath">
762 <arguments signature="env">
763 (name, newpath, [envname, sep, delete_existing=False])
764 </arguments>
765 <summary>
766 <para>
767 Append path elements specified by <parameter>newpath</parameter>
768 to the given search path string or list <parameter>name</parameter>
769 in mapping <parameter>envname</parameter> in the &consenv;.
770 Supplying <parameter>envname</parameter> is optional:
771 the default is the execution environment &cv-link-ENV;.
772 Optional <parameter>sep</parameter> is used as the search path separator,
773 the default is the platform's separator (<systemitem>os.pathsep</systemitem>).
774 A path element will only appear once.
775 Any duplicates in <parameter>newpath</parameter> are dropped,
776 keeping the last appearing (to preserve path order).
777 If <parameter>delete_existing</parameter>
778 is <constant>False</constant> (the default)
779 any addition duplicating an existing path element is ignored;
780 if <parameter>delete_existing</parameter>
781 is <constant>True</constant> the existing value will
782 be dropped and the path element will be added at the end.
783 To help maintain uniqueness all paths are normalized (using
784 <systemitem>os.path.normpath</systemitem>
786 <systemitem>os.path.normcase</systemitem>).
787 </para>
789 <para>
790 Example:
791 </para>
793 <example_commands>
794 print('before:', env['ENV']['INCLUDE'])
795 include_path = '/foo/bar:/foo'
796 env.AppendENVPath('INCLUDE', include_path)
797 print('after:', env['ENV']['INCLUDE'])
798 </example_commands>
800 <para>Yields:</para>
801 <screen>
802 before: /foo:/biz
803 after: /biz:/foo/bar:/foo
804 </screen>
806 <para>
807 See also &f-link-env-PrependENVPath;.
808 </para>
810 </summary>
811 </scons_function>
813 <scons_function name="AppendUnique">
814 <arguments signature="env">
815 (key=val, [...], [delete_existing=False])
816 </arguments>
817 <summary>
818 <para>
819 Append values to &consvars; in the current &consenv;,
820 maintaining uniqueness.
821 Works like &f-link-env-Append;,
822 except that values that would become duplicates
823 are not added.
824 If <parameter>delete_existing</parameter>
825 is set to a true value, then for any duplicate,
826 the existing instance of <parameter>val</parameter> is first removed,
827 then <parameter>val</parameter> is appended,
828 having the effect of moving it to the end.
829 </para>
831 <para>
832 Example:
833 </para>
835 <example_commands>
836 env.AppendUnique(CCFLAGS='-g', FOO=['foo.yyy'])
837 </example_commands>
839 <para>
840 See also &f-link-env-Append;,
841 &f-link-env-Prepend;
842 and &f-link-env-PrependUnique;.
843 </para>
844 </summary>
845 </scons_function>
847 <scons_function name="Builder">
848 <arguments>
849 (action, [arguments])
850 </arguments>
851 <summary>
852 <para>
853 Creates a Builder object for
854 the specified
855 <parameter>action</parameter>.
856 See the manpage section "Builder Objects"
857 for a complete explanation of the arguments and behavior.
858 </para>
860 <para>
861 Note that the
862 <function>env.Builder</function>()
863 form of the invocation will expand
864 construction variables in any arguments strings,
865 including the
866 <parameter>action</parameter>
867 argument,
868 at the time it is called
869 using the construction variables in the
870 <varname>env</varname>
871 construction environment through which
872 &f-env-Builder; was called.
874 &f-Builder;
875 form delays all variable expansion
876 until after the Builder object is actually called.
877 </para>
878 </summary>
879 </scons_function>
881 <scons_function name="CacheDir">
882 <arguments>
883 (cache_dir, custom_class=None)
884 </arguments>
885 <summary>
886 <para>
887 Direct
888 &scons;
889 to maintain a derived-file cache in
890 <parameter>cache_dir</parameter>.
891 The derived files in the cache will be shared
892 among all the builds specifying the same
893 <parameter>cache_dir</parameter>.
894 Specifying a
895 <parameter>cache_dir</parameter>
897 <constant>None</constant>
898 disables derived file caching.
899 </para>
901 <para>
902 Calling the environment method
903 &f-link-env-CacheDir;
904 limits the effect to targets built
905 through the specified construction environment.
906 Calling the global function
907 &f-link-CacheDir;
908 sets a global default
909 that will be used by all targets built
910 through construction environments
911 that do not set up environment-specific
912 caching by calling &f-env-CacheDir;.
913 </para>
915 <para>
916 Caching behavior can be configured by passing a specialized cache
917 class as the optional <parameter>custom_class</parameter> parameter.
918 This class must be a subclass of
919 <classname>SCons.CacheDir.CacheDir</classname>.
920 &SCons; will internally invoke the custom class for performing
921 caching operations.
922 If the parameter is omitted or set to
923 <constant>None</constant>, &SCons; will use the default
924 <classname>SCons.CacheDir.CacheDir</classname> class.
925 </para>
927 <para>
928 When derived-file caching
929 is being used and
930 &scons;
931 finds a derived file that needs to be rebuilt,
932 it will first look in the cache to see if a
933 file with matching &buildsig; exists
934 (indicating the input file(s) and build action(s)
935 were identical to those for the current target),
936 and if so, will retrieve the file from the cache.
937 &scons;
938 will report
939 <computeroutput>Retrieved `file' from cache</computeroutput>
940 instead of the normal build message.
941 If the derived file is not present in the cache,
942 &scons;
943 will build it and
944 then place a copy of the built file in the cache,
945 identified by its &buildsig;, for future use.
946 </para>
948 <para>
950 <computeroutput>Retrieved `file' from cache</computeroutput>
951 messages are useful for human consumption,
952 but less useful when comparing log files between
953 &scons; runs which will show differences that are
954 noisy and not actually significant.
955 To disable,
956 use the <option>--cache-show</option> option.
957 With this option, &scons; changes printing
958 to always show the action that would
959 have been used to build the file without caching.
960 </para>
962 <para>
963 Derived-file caching
964 may be disabled for any invocation
965 of &scons; by giving the
966 <option>--cache-disable</option>
967 command line option;
968 cache updating may be disabled, leaving cache
969 fetching enabled, by giving the
970 <option>--cache-readonly</option> option.
971 </para>
973 <para>
974 If the
975 <option>--cache-force</option>
976 option is used,
977 &scons;
978 will place a copy of
979 <emphasis>all</emphasis>
980 derived files into the cache,
981 even if they already existed
982 and were not built by this invocation.
983 This is useful to populate a cache
984 the first time a
985 <parameter>cache_dir</parameter>
986 is used for a build,
987 or to bring a cache up to date after
988 a build with cache updating disabled
989 (<option>--cache-disable</option>
990 or <option>--cache-readonly</option>)
991 has been done.
992 </para>
994 <para>
996 &f-link-NoCache;
997 method can be used to disable caching of specific files.  This can be
998 useful if inputs and/or outputs of some tool are impossible to
999 predict or prohibitively large.
1000 </para>
1002 <para>
1003 Note that (at this time) &SCons; provides no facilities
1004 for managing the derived-file cache. It is up to the developer
1005 to arrange for cache pruning, expiry, access control, etc. if needed.
1006 </para>
1008 </summary>
1009 </scons_function>
1011 <scons_function name="Clean">
1012 <arguments>
1013 (targets, files_or_dirs)
1014 </arguments>
1015 <summary>
1016 <para>
1017 This specifies a list of files or directories which should be removed
1018 whenever the targets are specified with the
1019 <option>-c</option>
1020 command line option.
1021 The specified targets may be a list
1022 or an individual target.
1023 Multiple calls to
1024 &f-Clean;
1025 are legal,
1026 and create new targets or add files and directories to the
1027 clean list for the specified targets.
1028 </para>
1030 <para>
1031 Multiple files or directories should be specified
1032 either as separate arguments to the
1033 &f-Clean;
1034 method, or as a list.
1035 &f-Clean;
1036 will also accept the return value of any of the construction environment
1037 Builder methods.
1038 Examples:
1039 </para>
1041 <para>
1042 The related
1043 &f-link-NoClean;
1044 function overrides calling
1045 &f-Clean;
1046 for the same target,
1047 and any targets passed to both functions will
1048 <emphasis>not</emphasis>
1049 be removed by the
1050 <option>-c</option>
1051 option.
1052 </para>
1054 <para>
1055 Examples:
1056 </para>
1058 <example_commands>
1059 Clean('foo', ['bar', 'baz'])
1060 Clean('dist', env.Program('hello', 'hello.c'))
1061 Clean(['foo', 'bar'], 'something_else_to_clean')
1062 </example_commands>
1064 <para>
1065 In this example,
1066 installing the project creates a subdirectory for the documentation.
1067 This statement causes the subdirectory to be removed
1068 if the project is deinstalled.
1069 </para>
1070 <example_commands>
1071 Clean(docdir, os.path.join(docdir, projectname))
1072 </example_commands>
1073 </summary>
1074 </scons_function>
1076 <scons_function name="Clone">
1077 <arguments signature="env">
1078 ([key=val, ...])
1079 </arguments>
1080 <summary>
1081 <para>
1082 Returns a separate copy of a construction environment.
1083 If there are any keyword arguments specified,
1084 they are added to the returned copy,
1085 overwriting any existing values
1086 for the keywords.
1087 </para>
1089 <para>
1090 Example:
1091 </para>
1093 <example_commands>
1094 env2 = env.Clone()
1095 env3 = env.Clone(CCFLAGS='-g')
1096 </example_commands>
1098 <para>
1099 Additionally, a list of tools and a toolpath may be specified, as in
1100 the &f-link-Environment; constructor:
1101 </para>
1103 <example_commands>
1104 def MyTool(env):
1105     env['FOO'] = 'bar'
1107 env4 = env.Clone(tools=['msvc', MyTool])
1108 </example_commands>
1110 <para>
1112 <parameter>parse_flags</parameter>
1113 keyword argument is also recognized to allow merging command-line
1114 style arguments into the appropriate construction
1115 variables (see &f-link-env-MergeFlags;).
1116 </para>
1118 <example_commands>
1119 # create an environment for compiling programs that use wxWidgets
1120 wx_env = env.Clone(parse_flags='!wx-config --cflags --cxxflags')
1121 </example_commands>
1122 </summary>
1123 </scons_function>
1125 <builder name="Command">
1126 <summary>
1127 <para>
1128 There is actually no Builder named &Command;,
1129 rather the term "Command Builder" refers to
1130 a function which, on each call, creates and calls
1131 an anonymous Builder.
1132 This is useful for "one-off" builds
1133 where a full Builder is not needed.
1134 Since the anonymous Builder is never hooked
1135 into the standard Builder framework,
1136 an Action must always be specfied.
1137 See the &f-link-Command; function description
1138 for the calling syntax and details.
1139 </para>
1140 </summary>
1141 </builder>
1143 <scons_function name="Command">
1144 <arguments>
1145 (target, source, action, [key=val, ...])
1146 </arguments>
1147 <summary>
1148 <para>
1149 Creates an anonymous builder and calls it,
1150 thus recording <parameter>action</parameter>
1151 to build <parameter>target</parameter>
1152 from <parameter>source</parameter>
1153 into the dependency tree.
1154 This can be more convenient for a single special-case build
1155 than having to define and add a new named Builder.
1156 </para>
1158 <para>
1160 &Command; function accepts the
1161 <parameter>source_scanner</parameter> and
1162 <parameter>target_scanner</parameter>
1163 keyword arguments which are used to specify
1164 custom scanners for the specified sources or targets.
1165 The value must be a Scanner object.
1166 For example, the global
1167 <literal>DirScanner</literal>
1168 object can be used
1169 if any of the sources will be directories
1170 that must be scanned on-disk for
1171 changes to files that aren't
1172 already specified in other Builder or function calls.
1173 </para>
1175 <para>
1177 &Command; function also accepts the
1178 <parameter>source_factory</parameter> and
1179 <parameter>target_factory</parameter>
1180 keyword arguments which are used to specify
1181 factory functions to create &SCons; Nodes
1182 from any sources or targets specified as strings.
1183 If any sources or targets are already Node objects,
1184 they are not further transformed even if
1185 a factory is specified for them.
1186 The default for each is the &Entry; factory.
1187 </para>
1189 <para>
1190 These four arguments, if given, are used
1191 in the creation of the Builder.
1192 Other Builder-specific keyword arguments
1193 are not recognized as such.
1194 See the manpage section "Builder Objects"
1195 for more information about how these
1196 arguments work in a Builder.
1197 </para>
1199 <para>
1200 Any remaining keyword arguments are passed on to the
1201 generated builder when it is called,
1202 and behave as described in the manpage section "Builder Methods",
1203 in short:
1204 recognized arguments have their specified meanings,
1205 while the rest are used to override
1206 any same-named existing &consvars;
1207 from the &consenv;.
1208 </para>
1210 <para>
1211 <parameter>action</parameter> can be an external command,
1212 specified as a string,
1213 or a callable &Python; object;
1214 see the manpage section "Action Objects"
1215 for more complete information.
1216 Also note that a string specifying an external command
1217 may be preceded by an at-sign
1218 (<literal>@</literal>)
1219 to suppress printing the command in question,
1220 or by a hyphen
1221 (<literal>-</literal>)
1222 to ignore the exit status of the external command.
1223 </para>
1225 <para>
1226 Examples:
1227 </para>
1229 <example_commands>
1230 env.Command(
1231     target='foo.out',
1232     source='foo.in',
1233     action="$FOO_BUILD &lt; $SOURCES &gt; $TARGET"
1236 env.Command(
1237     target='bar.out',
1238     source='bar.in',
1239     action=["rm -f $TARGET", "$BAR_BUILD &lt; $SOURCES &gt; $TARGET"],
1240     ENV={'PATH': '/usr/local/bin/'},
1244 import os
1245 def rename(env, target, source):
1246     os.rename('.tmp', str(target[0]))
1249 env.Command(
1250     target='baz.out',
1251     source='baz.in',
1252     action=["$BAZ_BUILD &lt; $SOURCES &gt; .tmp", rename],
1254 </example_commands>
1256 <para>
1257 Note that the
1258 &Command;
1259 function will usually assume, by default,
1260 that the specified targets and/or sources are Files,
1261 if no other part of the configuration
1262 identifies what type of entries they are.
1263 If necessary, you can explicitly specify
1264 that targets or source nodes should
1265 be treated as directories
1266 by using the
1267 &f-link-Dir;
1269 &f-link-env-Dir;
1270 functions.
1271 </para>
1273 <para>
1274 Examples:
1275 </para>
1277 <example_commands>
1278 env.Command('ddd.list', Dir('ddd'), 'ls -l $SOURCE > $TARGET')
1280 env['DISTDIR'] = 'destination/directory'
1281 env.Command(env.Dir('$DISTDIR')), None, make_distdir)
1282 </example_commands>
1284 <para>
1285 Also note that SCons will usually
1286 automatically create any directory necessary to hold a target file,
1287 so you normally don't need to create directories by hand.
1288 </para>
1289 </summary>
1290 </scons_function>
1292 <scons_function name="Configure">
1293 <arguments signature="global">
1294 (env, [custom_tests, conf_dir, log_file, config_h])
1295 </arguments>
1296 <arguments signature="env">
1297 ([custom_tests, conf_dir, log_file, config_h])
1298 </arguments>
1299 <summary>
1300 <para>
1301 Creates a &Configure; object for integrated
1302 functionality similar to GNU <command>autoconf</command>.
1303 See the manpage section "Configure Contexts"
1304 for a complete explanation of the arguments and behavior.
1305 </para>
1306 </summary>
1307 </scons_function>
1309 <scons_function name="Decider">
1310 <arguments>
1311 (function)
1312 </arguments>
1313 <summary>
1314 <para>
1315 Specifies that all up-to-date decisions for
1316 targets built through this construction environment
1317 will be handled by the specified
1318 <parameter>function</parameter>.
1319 <parameter>function</parameter> can be the name of
1320 a function or one of the following strings
1321 that specify the predefined decision function
1322 that will be applied:
1323 </para>
1325 <para>
1326 <variablelist>
1327 <varlistentry>
1328 <term><literal>"content"</literal></term>
1329 <listitem>
1330 <para>
1331 Specifies that a target shall be considered out of date and rebuilt
1332 if the dependency's content has changed since the last time
1333 the target was built,
1334 as determined by performing a checksum
1335 on the dependency's contents using the selected hash function,
1336 and comparing it to the checksum recorded the
1337 last time the target was built.
1338 <literal>content</literal> is the default decider.
1339 </para>
1340 <para>
1341 <emphasis>Changed in version 4.1:</emphasis>
1342 The decider was renamed to <literal>content</literal>
1343 since the hash function is now selectable.
1344 The former name, <literal>MD5</literal>,
1345 can still be used as a synonym, but is deprecated.
1346 </para>
1347 </listitem>
1348 </varlistentry>
1349 <varlistentry>
1350 <term><literal>"content-timestamp"</literal></term>
1351 <listitem>
1352 <para>
1353 Specifies that a target shall be considered out of date and rebuilt
1354 if the dependency's content has changed since the last time
1355 the target was built,
1356 except that dependencies with a timestamp that matches
1357 the last time the target was rebuilt will be
1358 assumed to be up-to-date and
1359 <emphasis>not</emphasis>
1360 rebuilt.
1361 This provides behavior very similar
1362 to the
1363 <literal>content</literal>
1364 behavior of always checksumming file contents,
1365 with an optimization of not checking
1366 the contents of files whose timestamps haven't changed.
1367 The drawback is that SCons will
1368 <emphasis>not</emphasis>
1369 detect if a file's content has changed
1370 but its timestamp is the same,
1371 as might happen in an automated script
1372 that runs a build,
1373 updates a file,
1374 and runs the build again,
1375 all within a single second.
1376 </para>
1377 <para>
1378 <emphasis>Changed in version 4.1:</emphasis>
1379 The decider was renamed to <literal>content-timestamp</literal>
1380 since the hash function is now selectable.
1381 The former name, <literal>MD5-timestamp</literal>,
1382 can still be used as a synonym, but is deprecated.
1383 </para>
1384 </listitem>
1385 </varlistentry>
1386 <varlistentry>
1387 <term><literal>"timestamp-newer"</literal></term>
1388 <listitem>
1389 <para>
1390 Specifies that a target shall be considered out of date and rebuilt
1391 if the dependency's timestamp is newer than the target file's timestamp.
1392 This is the behavior of the classic Make utility,
1394 <literal>make</literal>
1395 can be used a synonym for
1396 <literal>timestamp-newer</literal>.
1397 </para>
1398 </listitem>
1399 </varlistentry>
1400 <varlistentry>
1401 <term><literal>"timestamp-match"</literal></term>
1402 <listitem>
1403 <para>
1404 Specifies that a target shall be considered out of date and rebuilt
1405 if the dependency's timestamp is different than the
1406 timestamp recorded the last time the target was built.
1407 This provides behavior very similar to the classic Make utility
1408 (in particular, files are not opened up so that their
1409 contents can be checksummed)
1410 except that the target will also be rebuilt if a
1411 dependency file has been restored to a version with an
1412 <emphasis>earlier</emphasis>
1413 timestamp, such as can happen when restoring files from backup archives.
1414 </para>
1415 </listitem>
1416 </varlistentry>
1417 </variablelist>
1418 </para>
1420 <para>
1421 Examples:
1422 </para>
1424 <example_commands>
1425 # Use exact timestamp matches by default.
1426 Decider('timestamp-match')
1428 # Use hash content signatures for any targets built
1429 # with the attached construction environment.
1430 env.Decider('content')
1431 </example_commands>
1433 <para>
1434 In addition to the above already-available functions, the
1435 <parameter>function</parameter>
1436 argument may be a &Python; function you supply.
1437 Such a function must accept the following four arguments:
1438 </para>
1440 <para>
1441 <variablelist>
1442 <varlistentry>
1443 <term><parameter>dependency</parameter></term>
1444 <listitem>
1445 <para>
1446 The Node (file) which
1447 should cause the
1448 <parameter>target</parameter>
1449 to be rebuilt
1450 if it has "changed" since the last tme
1451 <parameter>target</parameter>
1452 was built.
1453 </para>
1454 </listitem>
1455 </varlistentry>
1456 <varlistentry>
1457 <term><parameter>target</parameter></term>
1458 <listitem>
1459 <para>
1460 The Node (file) being built.
1461 In the normal case,
1462 this is what should get rebuilt
1463 if the
1464 <parameter>dependency</parameter>
1465 has "changed."
1466 </para>
1467 </listitem>
1468 </varlistentry>
1469 <varlistentry>
1470 <term><parameter>prev_ni</parameter></term>
1471 <listitem>
1472 <para>
1473 Stored information about the state of the
1474 <parameter>dependency</parameter>
1475 the last time the
1476 <parameter>target</parameter>
1477 was built.
1478 This can be consulted to match various
1479 file characteristics
1480 such as the timestamp,
1481 size, or &contentsig;.
1482 </para>
1483 </listitem>
1484 </varlistentry>
1485     <varlistentry>
1486 <term><parameter>repo_node</parameter></term>
1487 <listitem>
1488 <para>
1489 If set, use this Node instead of the one specified by
1490 <parameter>dependency</parameter>
1491 to determine if the dependency has changed.
1492 This argument is optional so should be written
1493 as a default argument (typically it would be
1494 written as <parameter>repo_node=None</parameter>).
1495 A caller will normally only set this if the
1496 target only exists in a Repository.
1497 </para>
1498 </listitem>
1499 </varlistentry>
1501 </variablelist>
1502 </para>
1504 <para>
1506 <parameter>function</parameter>
1507 should return a value which evaluates
1508 <constant>True</constant>
1509 if the
1510 <parameter>dependency</parameter>
1511 has "changed" since the last time
1513 <parameter>target</parameter>
1514 was built
1515 (indicating that the target
1516 <emphasis>should</emphasis>
1517 be rebuilt),
1518 and a value which evaluates
1519 <constant>False</constant>
1520 otherwise
1521 (indicating that the target should
1522 <emphasis>not</emphasis>
1523 be rebuilt).
1524 Note that the decision can be made
1525 using whatever criteria are appopriate.
1526 Ignoring some or all of the function arguments
1527 is perfectly normal.
1528 </para>
1530 <para>
1531 Example:
1532 </para>
1534 <example_commands>
1535 def my_decider(dependency, target, prev_ni, repo_node=None):
1536     return not os.path.exists(str(target))
1538 env.Decider(my_decider)
1539 </example_commands>
1540 </summary>
1541 </scons_function>
1543 <scons_function name="Depends">
1544 <arguments>
1545 (target, dependency)
1546 </arguments>
1547 <summary>
1548 <para>
1549 Specifies an explicit dependency;
1551 <parameter>target</parameter>
1552 will be rebuilt
1553 whenever the
1554 <parameter>dependency</parameter>
1555 has changed.
1556 Both the specified
1557 <parameter>target</parameter>
1559 <parameter>dependency</parameter>
1560 can be a string
1561 (usually the path name of a file or directory)
1562 or Node objects,
1563 or a list of strings or Node objects
1564 (such as returned by a Builder call).
1565 This should only be necessary
1566 for cases where the dependency
1567 is not caught by a Scanner
1568 for the file.
1569 </para>
1571 <para>
1572 Example:
1573 </para>
1575 <example_commands>
1576 env.Depends('foo', 'other-input-file-for-foo')
1578 mylib = env.Library('mylib.c')
1579 installed_lib = env.Install('lib', mylib)
1580 bar = env.Program('bar.c')
1582 # Arrange for the library to be copied into the installation
1583 # directory before trying to build the "bar" program.
1584 # (Note that this is for example only.  A "real" library
1585 # dependency would normally be configured through the $LIBS
1586 # and $LIBPATH variables, not using an env.Depends() call.)
1588 env.Depends(bar, installed_lib)
1589 </example_commands>
1590 </summary>
1591 </scons_function>
1593 <scons_function name="Detect">
1594 <arguments signature="env">
1595 (progs)
1596 </arguments>
1597 <summary>
1598 <para>
1599 Find an executable from one or more choices:
1600 <parameter>progs</parameter> may be a string or a list of strings.
1601 Returns the first value from <parameter>progs</parameter>
1602 that was found, or <constant>None</constant>.
1603 Executable is searched by checking the paths in the execution environment
1604 (<varname>env</varname><literal>['ENV']['PATH']</literal>).
1605 On Windows systems, additionally applies the filename suffixes found in
1606 the execution environment
1607 (<varname>env</varname><literal>['ENV']['PATHEXT']</literal>)
1608 but will not include any such extension in the return value.
1609 &f-env-Detect; is a wrapper around &f-link-env-WhereIs;.
1610 </para>
1611 </summary>
1612 </scons_function>
1614 <scons_function name="Dictionary">
1615 <arguments signature="env">
1616 ([vars])
1617 </arguments>
1618 <summary>
1619 <para>
1620 Returns a dictionary object
1621 containing the &consvars; in the &consenv;.
1622 If there are any arguments specified,
1623 the values of the specified &consvars;
1624 are returned as a string (if one
1625 argument) or as a list of strings.
1626 </para>
1628 <para>
1629 Example:
1630 </para>
1632 <example_commands>
1633 cvars = env.Dictionary()
1634 cc_values = env.Dictionary('CC', 'CCFLAGS', 'CCCOM')
1635 </example_commands>
1636 </summary>
1637 </scons_function>
1639 <scons_function name="Dir">
1640 <arguments>
1641 (name, [directory])
1642 </arguments>
1643 <summary>
1644 <para>
1645 Returns Directory Node(s).
1646 A Directory Node is an object that represents a directory.
1647 <parameter>name</parameter>
1648 can be a relative or absolute path or a list of such paths.
1649 <parameter>directory</parameter>
1650 is an optional directory that will be used as the parent directory.
1651 If no
1652 <parameter>directory</parameter>
1653 is specified, the current script's directory is used as the parent.
1654 </para>
1656 <para>
1658 <parameter>name</parameter>
1659 is a single pathname, the corresponding node is returned.
1661 <parameter>name</parameter>
1662 is a list, SCons returns a list of nodes.
1663 Construction variables are expanded in
1664 <parameter>name</parameter>.
1665 </para>
1667 <para>
1668 Directory Nodes can be used anywhere you
1669 would supply a string as a directory name
1670 to a Builder method or function.
1671 Directory Nodes have attributes and methods
1672 that are useful in many situations;
1673 see manpage section "Filesystem Nodes"
1674 for more information.
1675 </para>
1676 </summary>
1677 </scons_function>
1679 <scons_function name="Dump">
1680 <arguments signature="env">
1681 ([key], [format])
1682 </arguments>
1683 <summary>
1684 <para>
1685 Serializes &consvars; to a string.
1686 The method supports the following formats specified by
1687 <parameter>format</parameter>:
1688 <variablelist>
1689 <varlistentry>
1690 <term><literal>pretty</literal></term>
1691 <listitem>
1692 <para>
1693 Returns a pretty printed representation of the environment (if
1694 <parameter>format</parameter>
1695 is not specified, this is the default).
1696 </para>
1697 </listitem>
1698 </varlistentry>
1699 <varlistentry>
1700 <term><literal>json</literal></term>
1701 <listitem>
1702 <para>
1703 Returns a JSON-formatted string representation of the environment.
1704 </para>
1705 </listitem>
1706 </varlistentry>
1707 </variablelist>
1709 If <varname>key</varname> is
1710 <constant>None</constant> (the default) the entire
1711 dictionary of &consvars; is serialized.
1712 If supplied, it is taken as the name of a &consvar;
1713 whose value is serialized.
1714 </para>
1716 <para>
1717 This SConstruct:
1718 </para>
1720 <example_commands>
1721 env=Environment()
1722 print(env.Dump('CCCOM'))
1723 </example_commands>
1725 <para>
1726 will print:
1727 </para>
1729 <example_commands>
1730 '$CC -c -o $TARGET $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS $SOURCES'
1731 </example_commands>
1733 <para>
1734 While this SConstruct:
1735 </para>
1737 <example_commands>
1738 env = Environment()
1739 print(env.Dump())
1740 </example_commands>
1742 <para>
1743 will print:
1744 </para>
1745 <example_commands>
1746 { 'AR': 'ar',
1747   'ARCOM': '$AR $ARFLAGS $TARGET $SOURCES\n$RANLIB $RANLIBFLAGS $TARGET',
1748   'ARFLAGS': ['r'],
1749   'AS': 'as',
1750   'ASCOM': '$AS $ASFLAGS -o $TARGET $SOURCES',
1751   'ASFLAGS': [],
1752   ...
1753 </example_commands>
1754 </summary>
1755 </scons_function>
1757 <scons_function name="Environment">
1758 <arguments>
1759 ([key=value, ...])
1760 </arguments>
1761 <summary>
1762 <para>
1763 Return a new construction environment
1764 initialized with the specified
1765 <parameter>key</parameter>=<replaceable>value</replaceable>
1766 pairs.
1767 The keyword arguments
1768 <parameter>parse_flags</parameter>,
1769 <parameter>platform</parameter>,
1770 <parameter>toolpath</parameter>,
1771 <parameter>tools</parameter>
1772 and <parameter>variables</parameter>
1773 are also specially recognized.
1774 See the manpage section "Construction Environments" for more details.
1775 </para>
1776 </summary>
1777 </scons_function>
1779 <scons_function name="Execute">
1780 <arguments>
1781 (action, [actionargs ...])
1782 </arguments>
1783 <summary>
1784 <para>
1785 Executes an Action.
1786 <parameter>action</parameter>
1787 may be an Action object
1788 or it may be a command-line string,
1789 list of commands,
1790 or executable &Python; function,
1791 each of which will first be converted
1792 into an Action object
1793 and then executed.
1794 Any additional arguments to &f-Execute;
1795 are passed on to the &f-link-Action; factory function
1796 which actually creates the Action object
1797 (see the manpage section <link linkend="action_objects">Action Objects</link>
1798 for a description). Example:
1799 </para>
1801 <example_commands>
1802 Execute(Copy('file.out', 'file.in'))
1803 </example_commands>
1805 <para>&f-Execute; performs its action immediately,
1806 as part of the SConscript-reading phase.
1807 There are no sources or targets declared in an
1808 &f-Execute; call, so any objects it manipulates
1809 will not be tracked as part of the &SCons; dependency graph.
1810 In the example above, neither
1811 <filename>file.out</filename> nor
1812 <filename>file.in</filename> will be tracked objects.
1813 </para>
1815 <para>
1816 &f-Execute; returns the exit value of the command
1817 or return value of the &Python; function.
1818 &scons;
1819 prints an error message if the executed
1820 <parameter>action</parameter>
1821 fails (exits with or returns a non-zero value),
1822 however it does
1823 <emphasis>not</emphasis>,
1824 automatically terminate the build for such a failure.
1825 If you want the build to stop in response to a failed
1826 &f-Execute;
1827 call,
1828 you must explicitly check for a non-zero return value:
1829 </para>
1831 <example_commands>
1832 if Execute("mkdir sub/dir/ectory"):
1833     # The mkdir failed, don't try to build.
1834     Exit(1)
1835 </example_commands>
1836 </summary>
1837 </scons_function>
1839 <scons_function name="File">
1840 <arguments>
1841 (name, [directory])
1842 </arguments>
1843 <summary>
1844 <para>
1845 Returns File Node(s).
1846 A File Node is an object that represents a file.
1847 <parameter>name</parameter>
1848 can be a relative or absolute path or a list of such paths.
1849 <parameter>directory</parameter>
1850 is an optional directory that will be used as the parent directory.
1851 If no
1852 <parameter>directory</parameter>
1853 is specified, the current script's directory is used as the parent.
1854 </para>
1856 <para>
1858 <parameter>name</parameter>
1859 is a single pathname, the corresponding node is returned.
1861 <parameter>name</parameter>
1862 is a list, SCons returns a list of nodes.
1863 Construction variables are expanded in
1864 <parameter>name</parameter>.
1865 </para>
1867 <para>
1868 File Nodes can be used anywhere you
1869 would supply a string as a file name
1870 to a Builder method or function.
1871 File Nodes have attributes and methods
1872 that are useful in many situations;
1873 see manpage section "Filesystem Nodes"
1874 for more information.
1875 </para>
1876 </summary>
1877 </scons_function>
1879 <scons_function name="FindFile">
1880 <arguments>
1881 (file, dirs)
1882 </arguments>
1883 <summary>
1884 <para>
1885 Search for
1886 <parameter>file</parameter>
1887 in the path specified by
1888 <parameter>dirs</parameter>.
1889 <parameter>dirs</parameter>
1890 may be a list of directory names or a single directory name.
1891 In addition to searching for files that exist in the filesystem,
1892 this function also searches for derived files
1893 that have not yet been built.
1894 </para>
1896 <para>
1897 Example:
1898 </para>
1900 <example_commands>
1901 foo = env.FindFile('foo', ['dir1', 'dir2'])
1902 </example_commands>
1903 </summary>
1904 </scons_function>
1906 <scons_function name="FindInstalledFiles">
1907 <arguments>
1909 </arguments>
1910 <summary>
1911 <para>
1912 Returns the list of targets set up by the
1913 &b-link-Install;
1915 &b-link-InstallAs;
1916 builders.
1917 </para>
1919 <para>
1920 This function serves as a convenient method to select the contents of
1921 a binary package.
1922 </para>
1924 <para>
1925 Example:
1926 </para>
1928 <example_commands>
1929 Install('/bin', ['executable_a', 'executable_b'])
1931 # will return the file node list
1932 # ['/bin/executable_a', '/bin/executable_b']
1933 FindInstalledFiles()
1935 Install('/lib', ['some_library'])
1937 # will return the file node list
1938 # ['/bin/executable_a', '/bin/executable_b', '/lib/some_library']
1939 FindInstalledFiles()
1940 </example_commands>
1941 </summary>
1942 </scons_function>
1944 <scons_function name="FindSourceFiles">
1945 <arguments>
1946 (node='"."')
1947 </arguments>
1948 <summary>
1949 <para>
1950 Returns the list of nodes which serve as the source of the built files.
1951 It does so by inspecting the dependency tree starting at the optional
1952 argument
1953 <parameter>node</parameter>
1954 which defaults to the '"."'-node. It will then return all leaves of
1955 <parameter>node</parameter>.
1956 These are all children which have no further children.
1957 </para>
1959 <para>
1960 This function is a convenient method to select the contents of a Source
1961 Package.
1962 </para>
1964 <para>
1965 Example:
1966 </para>
1968 <example_commands>
1969 Program('src/main_a.c')
1970 Program('src/main_b.c')
1971 Program('main_c.c')
1973 # returns ['main_c.c', 'src/main_a.c', 'SConstruct', 'src/main_b.c']
1974 FindSourceFiles()
1976 # returns ['src/main_b.c', 'src/main_a.c' ]
1977 FindSourceFiles('src')
1978 </example_commands>
1980 <para>
1981 As you can see build support files (SConstruct in the above example)
1982 will also be returned by this function.
1983 </para>
1984 </summary>
1985 </scons_function>
1987 <scons_function name="Flatten">
1988 <arguments>
1989 (sequence)
1990 </arguments>
1991 <summary>
1992 <para>
1993 Takes a sequence (that is, a &Python; list or tuple)
1994 that may contain nested sequences
1995 and returns a flattened list containing
1996 all of the individual elements in any sequence.
1997 This can be helpful for collecting
1998 the lists returned by calls to Builders;
1999 other Builders will automatically
2000 flatten lists specified as input,
2001 but direct &Python; manipulation of
2002 these lists does not.
2003 </para>
2005 <para>
2006 Examples:
2007 </para>
2009 <example_commands>
2010 foo = Object('foo.c')
2011 bar = Object('bar.c')
2013 # Because `foo' and `bar' are lists returned by the Object() Builder,
2014 # `objects' will be a list containing nested lists:
2015 objects = ['f1.o', foo, 'f2.o', bar, 'f3.o']
2017 # Passing such a list to another Builder is all right because
2018 # the Builder will flatten the list automatically:
2019 Program(source = objects)
2021 # If you need to manipulate the list directly using &Python;, you need to
2022 # call Flatten() yourself, or otherwise handle nested lists:
2023 for object in Flatten(objects):
2024     print(str(object))
2025 </example_commands>
2026 </summary>
2027 </scons_function>
2029 <scons_function name="GetBuildPath">
2030 <arguments>
2031 (file, [...])
2032 </arguments>
2033 <summary>
2034 <para>
2035 Returns the
2036 &scons;
2037 path name (or names) for the specified
2038 <parameter>file</parameter>
2039 (or files).
2040 The specified
2041 <parameter>file</parameter>
2042 or files
2043 may be
2044 &scons;
2045 Nodes or strings representing path names.
2046 </para>
2047 </summary>
2048 </scons_function>
2050 <scons_function name="Glob">
2051 <arguments>
2052 (pattern, [ondisk=True, source=False, strings=False, exclude=None])
2053 </arguments>
2054 <summary>
2055 <para>
2056 Returns a possibly empty list of Nodes (or strings) that match
2057 pathname specification <parameter>pattern</parameter>.
2058 <parameter>pattern</parameter> can be absolute,
2059 top-relative,
2060 or (most commonly) relative to the directory of the current
2061 &SConscript; file.
2062 &f-Glob; matches both files stored on disk and Nodes
2063 which &SCons; already knows about, even if any corresponding
2064 file is not currently stored on disk.
2065 The evironment method form (&f-env-Glob;)
2066 performs string substition on
2067 <parameter>pattern</parameter>
2068 and returns whatever matches the resulting expanded pattern.
2069 The results are sorted, unlike for the similar &Python;
2070 <systemitem>glob.glob</systemitem> function,
2071 to ensure build order will be stable.
2072 </para>
2074 <para>
2075 <parameter>pattern</parameter>
2076 can contain POSIX-style shell metacharacters for matching:
2077 </para>
2079 <informaltable rowsep="1" colsep="1" frame="topbot">
2080 <tgroup cols="2">
2081 <thead>
2082   <row>
2083     <entry>Pattern</entry>
2084     <entry>Meaning</entry>
2085   </row>
2086 </thead>
2087 <tbody>
2088   <row>
2089     <entry><literal>*</literal></entry>
2090     <entry>matches everything</entry>
2091   </row>
2092   <row>
2093       <entry><literal>?</literal></entry>
2094       <entry>matches any single character</entry>
2095   </row>
2096   <row>
2097       <entry><literal>[seq]</literal></entry>
2098       <entry>matches any character in <emphasis>seq</emphasis>
2099       (can be a list or a range).</entry>
2100   </row>
2101   <row>
2102       <entry><literal>[!seq]</literal></entry>
2103       <entry>matches any character not in <emphasis>seq</emphasis></entry>
2104   </row>
2105 </tbody>
2106 </tgroup>
2107 </informaltable>
2109 <para>
2110 For a literal match, wrap the metacharacter in brackets to
2111 escape the normal behavior.
2112 For example, <literal>'[?]'</literal> matches the character
2113 <literal>'?'</literal>.
2114 </para>
2116 <para>
2117 Filenames starting with a dot are specially handled -
2118 they can only be matched by patterns that start with a dot
2119 (or have a dot immediately following a pathname separator
2120 character, or slash), they are not not matched by the metacharacters.
2121 Metacharacter matches also do not span directory separators.
2122 </para>
2124 <para>
2125 &f-Glob;
2126 understands repositories
2127 (see the
2128 &f-link-Repository;
2129 function)
2130 and source directories
2131 (see the
2132 &f-link-VariantDir;
2133 function)
2134 and returns a Node (or string, if so configured) match
2135 in the local (SConscript) directory
2136 if a matching Node is found
2137 anywhere in a corresponding
2138 repository or source directory.
2139 </para>
2141 <para>
2142 If the optional
2143 <parameter>ondisk</parameter>
2144 argument evaluates false,
2145 the search for matches on disk is disabled,
2146 and only matches from
2147 already-configured File or Dir Nodes are returned.
2148 The default is to return Nodes for
2149 matches on disk as well.
2150 </para>
2152 <para>
2153 If the optional
2154 <parameter>source</parameter>
2155 argument evaluates true,
2156 and the local directory is a variant directory,
2157 then &f-Glob; returnes Nodes from
2158 the corresponding source directory,
2159 rather than the local directory.
2160 <!-- XXX what about generated files that don't exist in src but will be sources? -->
2161 </para>
2163 <para>
2164 If the optional
2165 <parameter>strings</parameter>
2166 argument evaluates true,
2167 &f-Glob;
2168 returns matches as strings, rather than Nodes.
2169 The returned strings will be relative to
2170 the local (SConscript) directory.
2171 (Note that while this may make it easier to perform
2172 arbitrary manipulation of file names,
2173 it loses the context &SCons; would have in the Node,
2174 so if the returned strings are
2175 passed to a different
2176 &SConscript;
2177 file,
2178 any Node translation there will be relative
2179 to that
2180 &SConscript;
2181 directory,
2182 not to the original
2183 &SConscript;
2184 directory.)
2185 </para>
2187 <para>
2188 The optional
2189 <parameter>exclude</parameter>
2190 argument may be set to a pattern or a list of patterns
2191 descibing files or directories
2192 to filter out of the match list.
2193 Elements matching a least one specified pattern will be excluded.
2194 These patterns use the same syntax as for
2195 <parameter>pattern</parameter>.
2196 </para>
2198 <para>
2199 Examples:
2200 </para>
2202 <example_commands>
2203 Program("foo", Glob("*.c"))
2204 Zip("/tmp/everything", Glob(".??*") + Glob("*"))
2205 sources = Glob("*.cpp", exclude=["os_*_specific_*.cpp"]) \
2206     + Glob("os_%s_specific_*.cpp" % currentOS)
2207 </example_commands>
2209 </summary>
2210 </scons_function>
2212 <!--
2213 <scons_function name="GlobalBuilders">
2214 <arguments signature="global">
2215 (flag)
2216 </arguments>
2217 <summary>
2218 <para>
2219 When
2220 <parameter>flag</parameter>
2221 is non-zero,
2222 adds the names of the default builders
2223 (Program, Library, etc.)
2224 to the global name space
2225 so they can be called without an explicit construction environment.
2226 (This is the default.)
2227 When
2228 <parameter>flag</parameter>
2229 is zero,
2230 the names of the default builders are removed
2231 from the global name space
2232 so that an explicit construction environment is required
2233 to call all builders.
2234 </para>
2235 </summary>
2236 </scons_function>
2239 <scons_function name="Ignore">
2240 <arguments>
2241 (target, dependency)
2242 </arguments>
2243 <summary>
2244 <para>
2245 Ignores <parameter>dependency</parameter>
2246 when deciding if
2247 <parameter>target</parameter> needs to be rebuilt.
2248 <parameter>target</parameter> and
2249 <parameter>dependency</parameter>
2250 can each be a single filename or Node
2251 or a list of filenames or Nodes.
2252 </para>
2254 <para>
2255 &f-Ignore; can also be used to
2256 remove a target from the default build
2257 by specifying the directory the target will be built in as
2258 <parameter>target</parameter>
2259 and the file you want to skip selecting for building as
2260 <parameter>dependency</parameter>.
2261 Note that this only removes the target from
2262 the default target selection algorithm:
2263 if it is a dependency of another object being
2264 built &SCons; still builds it normally.
2265 See the third and forth examples below.
2266 </para>
2268 <para>
2269 Examples:
2270 </para>
2272 <example_commands>
2273 env.Ignore('foo', 'foo.c')
2274 env.Ignore('bar', ['bar1.h', 'bar2.h'])
2275 env.Ignore('.', 'foobar.obj')
2276 env.Ignore('bar', 'bar/foobar.obj')
2277 </example_commands>
2278 </summary>
2279 </scons_function>
2281 <scons_function name="Literal">
2282 <arguments>
2283 (string)
2284 </arguments>
2285 <summary>
2286 <para>
2287 The specified
2288 <parameter>string</parameter>
2289 will be preserved as-is
2290 and not have construction variables expanded.
2291 </para>
2292 </summary>
2293 </scons_function>
2295 <scons_function name="Local">
2296 <arguments>
2297 (targets)
2298 </arguments>
2299 <summary>
2300 <para>
2301 The specified
2302 <parameter>targets</parameter>
2303 will have copies made in the local tree,
2304 even if an already up-to-date copy
2305 exists in a repository.
2306 Returns a list of the target Node or Nodes.
2307 </para>
2308 </summary>
2309 </scons_function>
2311 <!--
2312 <scons_function name="MergeShellPaths">
2313 <arguments signature="env">
2314 ( arg ", [" prepend ])
2315 </arguments>
2316 <summary>
2317 <para>
2318 Merges the elements of the specified
2319 <parameter>arg</parameter>,
2320 which must be a dictionary, to the construction
2321 environment's copy of the shell environment
2322 in env['ENV'].
2323 (This is the environment which is passed
2324 to subshells spawned by SCons.)
2325 Note that
2326 <parameter>arg</parameter>
2327 must be a single value,
2328 so multiple strings must
2329 be passed in as a list,
2330 not as separate arguments to
2331 &f-MergeShellPaths;.
2332 </para>
2334 <para>
2335 New values are prepended to the environment variable by default,
2336 unless prepend=0 is specified.
2337 Duplicate values are always eliminated,
2338 since this function calls
2339 &f-link-AppendENVPath;
2341 &f-link-PrependENVPath;
2342 depending on the
2343 <parameter>prepend</parameter>
2344 argument.  See those functions for more details.
2345 </para>
2347 <para>
2348 Examples:
2349 </para>
2351 <example_commands>
2352 # Prepend a path to the shell PATH.
2353 env.MergeShellPaths({'PATH': '/usr/local/bin'})
2354 # Append two dirs to the shell INCLUDE.
2355 env.MergeShellPaths({'INCLUDE': ['c:/inc1', 'c:/inc2']}, prepend=0)
2356 </example_commands>
2357 </summary>
2358 </scons_function>
2361 <scons_function name="MergeFlags">
2362 <arguments signature="env">
2363 (arg, [unique])
2364 </arguments>
2365 <summary>
2366 <para>
2367 Merges values from
2368 <parameter>arg</parameter>
2369 into &consvars; in <parameter>env</parameter>.
2370 If <parameter>arg</parameter> is a dictionary,
2371 each key-value pair represents a
2372 &consvar; name and the corresponding flags to merge.
2373 If <parameter>arg</parameter>
2374 is not a dictionary,
2375 &MergeFlags; attempts to convert it to one
2376 before the values are merged.
2377 &f-link-env-ParseFlags; is used for this,
2378 so values to be converted are subject to the
2379 same limitations:
2380 &ParseFlags; has knowledge of which &consvars; certain
2381 flags should go to, but not all;
2382 and only for GCC and compatible compiler chains.
2383 <parameter>arg</parameter>
2384 must be a single object,
2385 so to pass multiple strings,
2386 enclose them in a list.
2387 </para>
2389 <para>
2390 If <literal>unique</literal> is true (the default),
2391 duplicate values are not retained.
2392 In case of duplication,
2393 any &consvar; names that end in
2394 <literal>PATH</literal>
2395 keep the left-most value so the
2396 path searcb order is not altered.
2397 All other &consvars; keep
2398 the right-most value.
2399 If <literal>unique</literal> is false,
2400 values are appended even if they are duplicates.
2401 </para>
2403 <para>
2404 Examples:
2405 </para>
2407 <example_commands>
2408 # Add an optimization flag to $CCFLAGS.
2409 env.MergeFlags({'CCFLAGS': '-O3'})
2411 # Combine the flags returned from running pkg-config with an optimization
2412 # flag and merge the result into the construction variables.
2413 env.MergeFlags(['!pkg-config gtk+-2.0 --cflags', '-O3'])
2415 # Combine an optimization flag with the flags returned from running pkg-config
2416 # for two distinct packages and merge into the construction variables.
2417 env.MergeFlags(
2418     [
2419         '-O3',
2420         '!pkg-config gtk+-2.0 --cflags --libs',
2421         '!pkg-config libpng12 --cflags --libs',
2422     ]
2424 </example_commands>
2425 </summary>
2426 </scons_function>
2428 <scons_function name="NoCache">
2429 <arguments>
2430 (target, ...)
2431 </arguments>
2432 <summary>
2433 <para>
2434 Specifies a list of files which should
2435 <emphasis>not</emphasis>
2436 be cached whenever the
2437 &f-link-CacheDir;
2438 method has been activated.
2439 The specified targets may be a list
2440 or an individual target.
2441 </para>
2443 <para>
2444 Multiple files should be specified
2445 either as separate arguments to the
2446 &f-NoCache;
2447 method, or as a list.
2448 &f-NoCache;
2449 will also accept the return value of any of the construction environment
2450 Builder methods.
2451 </para>
2453 <para>
2454 Calling
2455 &f-NoCache;
2456 on directories and other non-File Node types has no effect because
2457 only File Nodes are cached.
2458 </para>
2460 <para>
2461 Examples:
2462 </para>
2464 <example_commands>
2465 NoCache('foo.elf')
2466 NoCache(env.Program('hello', 'hello.c'))
2467 </example_commands>
2468 </summary>
2469 </scons_function>
2471 <scons_function name="NoClean">
2472 <arguments>
2473 (target, ...)
2474 </arguments>
2475 <summary>
2476 <para>
2477 Specifies a list of files or directories which should
2478 <emphasis>not</emphasis>
2479 be removed whenever the targets (or their dependencies)
2480 are specified with the
2481 <option>-c</option>
2482 command line option.
2483 The specified targets may be a list
2484 or an individual target.
2485 Multiple calls to
2486 &f-NoClean;
2487 are legal,
2488 and prevent each specified target
2489 from being removed by calls to the
2490 <option>-c</option>
2491 option.
2492 </para>
2494 <para>
2495 Multiple files or directories should be specified
2496 either as separate arguments to the
2497 &f-NoClean;
2498 method, or as a list.
2499 &f-NoClean;
2500 will also accept the return value of any of the construction environment
2501 Builder methods.
2502 </para>
2504 <para>
2505 Calling
2506 &f-NoClean;
2507 for a target overrides calling
2508 &f-link-Clean;
2509 for the same target,
2510 and any targets passed to both functions will
2511 <emphasis>not</emphasis>
2512 be removed by the
2513 <option>-c</option>
2514 option.
2515 </para>
2517 <para>
2518 Examples:
2519 </para>
2521 <example_commands>
2522 NoClean('foo.elf')
2523 NoClean(env.Program('hello', 'hello.c'))
2524 </example_commands>
2525 </summary>
2526 </scons_function>
2528 <scons_function name="ParseConfig">
2529 <arguments signature="env">
2530 (command, [function, unique])
2531 </arguments>
2532 <summary>
2533 <para>
2534 Updates the current &consenv; with the values extracted
2535 from the output of running external <parameter>command</parameter>,
2536 by passing it to a helper <parameter>function</parameter>.
2537 <parameter>command</parameter> may be a string
2538 or a list of strings representing the command and
2539 its arguments.
2540 If <parameter>function</parameter>
2541 is omitted or <constant>None</constant>,
2542 &f-link-env-MergeFlags; is used.
2543 By default,
2544 duplicate values are not
2545 added to any construction variables;
2546 you can specify
2547 <parameter>unique=False</parameter>
2548 to allow duplicate values to be added.
2549 </para>
2551 <para>
2552 <parameter>command</parameter> is executed using the
2553 SCons execution environment (that is, the &consvar;
2554 &cv-link-ENV; in the current &consenv;).
2555 If <parameter>command</parameter> needs additional information
2556 to operate properly, that needs to be set in the execution environment.
2557 For example, <command>pkg-config</command>
2558 may need a custom value set in the <envar>PKG_CONFIG_PATH</envar>
2559 environment variable.
2560 </para>
2562 <para>
2563 &f-env-MergeFlags; needs to understand
2564 the output produced by <parameter>command</parameter>
2565 in order to distribute it to appropriate &consvars;.
2566 &f-env-MergeFlags; uses a separate function to
2567 do that processing -
2568 see &f-link-env-ParseFlags; for the details, including a
2569 a table of options and corresponding construction variables.
2570 To provide alternative processing of the output of
2571 <parameter>command</parameter>,
2572 you can suppply a custom
2573 <parameter>function</parameter>,
2574 which must accept three arguments:
2575 the &consenv; to modify,
2576 a string argument containing the output from running
2577 <parameter>command</parameter>,
2578 and the optional
2579 <parameter>unique</parameter> flag.
2580 </para>
2581 </summary>
2582 </scons_function>
2584 <scons_function name="ParseDepends">
2585 <arguments>
2586 (filename, [must_exist, only_one])
2587 </arguments>
2588 <summary>
2589 <para>
2590 Parses the contents of <parameter>filename</parameter>
2591 as a list of dependencies in the style of
2592 &Make;
2594 <application>mkdep</application>,
2595 and explicitly establishes all of the listed dependencies.
2596 </para>
2598 <para>
2599 By default,
2600 it is not an error
2601 if <parameter>filename</parameter>
2602 does not exist.
2603 The optional
2604 <parameter>must_exist</parameter>
2605 argument may be set to <constant>True</constant>
2606 to have &SCons;
2607 raise an exception if the file does not exist,
2608 or is otherwise inaccessible.
2609 </para>
2611 <para>
2612 The optional
2613 <parameter>only_one</parameter>
2614 argument may be set to <constant>True</constant>
2615 to have &SCons; raise an exception
2616 if the file contains dependency
2617 information for more than one target.
2618 This can provide a small sanity check
2619 for files intended to be generated
2620 by, for example, the
2621 <literal>gcc -M</literal>
2622 flag,
2623 which should typically only
2624 write dependency information for
2625 one output file into a corresponding
2626 <filename>.d</filename>
2627 file.
2628 </para>
2630 <para>
2631 <parameter>filename</parameter>
2632 and all of the files listed therein
2633 will be interpreted relative to
2634 the directory of the
2635 &SConscript;
2636 file which calls the
2637 &f-ParseDepends;
2638 function.
2639 </para>
2640 </summary>
2641 </scons_function>
2643 <scons_function name="ParseFlags">
2644 <arguments signature="env">
2645 (flags, ...)
2646 </arguments>
2647 <summary>
2648 <para>
2649 Parses one or more strings containing
2650 typical command-line flags for GCC-style tool chains
2651 and returns a dictionary with the flag values
2652 separated into the appropriate SCons construction variables.
2653 Intended as a companion to the
2654 &f-link-env-MergeFlags;
2655 method, but allows for the values in the returned dictionary
2656 to be modified, if necessary,
2657 before merging them into the construction environment.
2658 (Note that
2659 &f-env-MergeFlags;
2660 will call this method if its argument is not a dictionary,
2661 so it is usually not necessary to call
2662 &f-env-ParseFlags;
2663 directly unless you want to manipulate the values.)
2664 </para>
2666 <para>
2667 If the first character in any string is
2668 an exclamation mark (<literal>!</literal>),
2669 the rest of the string is executed as a command,
2670 and the output from the command is
2671 parsed as GCC tool chain command-line flags
2672 and added to the resulting dictionary.
2673 This can be used to call a <filename>*-config</filename>
2674 command typical of the POSIX programming environment
2675 (for example,
2676 <command>pkg-config</command>).
2677 Note that such a command is executed using the
2678 SCons execution environment;
2679 if the command needs additional information,
2680 that information needs to be explicitly provided.
2681 See &f-link-ParseConfig; for more details.
2682 </para>
2684 <para>
2685 Flag values are translated according to the prefix found,
2686 and added to the following construction variables:
2687 </para>
2689 <example_commands>
2690 -arch                   CCFLAGS, LINKFLAGS
2691 -D                      CPPDEFINES
2692 -framework              FRAMEWORKS
2693 -frameworkdir=          FRAMEWORKPATH
2694 -fmerge-all-constants   CCFLAGS, LINKFLAGS
2695 -fopenmp                CCFLAGS, LINKFLAGS
2696 -fsanitize              CCFLAGS, LINKFLAGS
2697 -include                CCFLAGS
2698 -imacros                CCFLAGS
2699 -isysroot               CCFLAGS, LINKFLAGS
2700 -isystem                CCFLAGS
2701 -iquote                 CCFLAGS
2702 -idirafter              CCFLAGS
2703 -I                      CPPPATH
2704 -l                      LIBS
2705 -L                      LIBPATH
2706 -mno-cygwin             CCFLAGS, LINKFLAGS
2707 -mwindows               LINKFLAGS
2708 -openmp                 CCFLAGS, LINKFLAGS
2709 -pthread                CCFLAGS, LINKFLAGS
2710 -std=                   CFLAGS
2711 -stdlib=                CXXFLAGS
2712 -Wa,                    ASFLAGS, CCFLAGS
2713 -Wl,-rpath=             RPATH
2714 -Wl,-R,                 RPATH
2715 -Wl,-R                  RPATH
2716 -Wl,                    LINKFLAGS
2717 -Wp,                    CPPFLAGS
2718 -                       CCFLAGS
2719 +                       CCFLAGS, LINKFLAGS
2720 </example_commands>
2722 <para>
2723 Any other strings not associated with options
2724 are assumed to be the names of libraries
2725 and added to the
2726 &cv-LIBS;
2727 construction variable.
2728 </para>
2730 <para>
2731 Examples (all of which produce the same result):
2732 </para>
2734 <example_commands>
2735 dict = env.ParseFlags('-O2 -Dfoo -Dbar=1')
2736 dict = env.ParseFlags('-O2', '-Dfoo', '-Dbar=1')
2737 dict = env.ParseFlags(['-O2', '-Dfoo -Dbar=1'])
2738 dict = env.ParseFlags('-O2', '!echo -Dfoo -Dbar=1')
2739 </example_commands>
2740 </summary>
2741 </scons_function>
2743 <scons_function name="Platform">
2744 <arguments signature="global">
2745 (plat)
2746 </arguments>
2747 <arguments signature="env">
2748 (plat)
2749 </arguments>
2750 <summary>
2751 <para>
2752 When called as a global function,
2753 returns a callable platform object
2754 selected by <parameter>plat</parameter>
2755 (defaults to the detected platform for the
2756 current system)
2757 that can be used to initialize
2758 a construction environment by passing it as the
2759 <parameter>platform</parameter> keyword argument to the
2760 &f-link-Environment; function.
2761 </para>
2763 <para>
2764 Example:
2765 </para>
2767 <example_commands>
2768 env = Environment(platform=Platform('win32'))
2769 </example_commands>
2771 <para>
2772 When called as a method of an environment,
2773 calls the platform object indicated by
2774 <parameter>plat</parameter>
2775 to update that environment.
2776 </para>
2778 <example_commands>
2779 env.Platform('posix')
2780 </example_commands>
2782 <para>
2783 See the manpage section "Construction Environments" for more details.
2784 </para>
2785 </summary>
2786 </scons_function>
2788 <scons_function name="Prepend">
2789 <arguments signature="env">
2790 (key=val, [...])
2791 </arguments>
2792 <summary>
2793 <para>
2794 Prepend values to &consvars; in the current &consenv;,
2795 Works like &f-link-env-Append; (see for details),
2796 except that values are added to the front,
2797 rather than the end, of any existing value of the &consvar;
2798 </para>
2800 <para>
2801 Example:
2802 </para>
2804 <example_commands>
2805 env.Prepend(CCFLAGS='-g ', FOO=['foo.yyy'])
2806 </example_commands>
2808 <para>
2809 See also &f-link-env-Append;,
2810 &f-link-env-AppendUnique;
2811 and &f-link-env-PrependUnique;.
2812 </para>
2813 </summary>
2814 </scons_function>
2816 <scons_function name="PrependENVPath">
2817 <arguments signature="env">
2818 (name, newpath, [envname, sep, delete_existing=True])
2819 </arguments>
2820 <summary>
2821 <para>
2822 Prepend path elements specified by <parameter>newpath</parameter>
2823 to the given search path string or list <parameter>name</parameter>
2824 in mapping <parameter>envname</parameter> in the &consenv;.
2825 Supplying <parameter>envname</parameter> is optional:
2826 the default is the execution environment &cv-link-ENV;.
2827 Optional <parameter>sep</parameter> is used as the search path separator,
2828 the default is the platform's separator (<systemitem>os.pathsep</systemitem>).
2829 A path element will only appear once.
2830 Any duplicates in <parameter>newpath</parameter> are dropped,
2831 keeping the first appearing (to preserve path order).
2832 If <parameter>delete_existing</parameter>
2833 is <constant>False</constant>
2834 any addition duplicating an existing path element is ignored;
2835 if <parameter>delete_existing</parameter>
2836 is <constant>True</constant> (the default) the existing value will
2837 be dropped and the path element will be inserted at the beginning.
2838 To help maintain uniqueness all paths are normalized (using
2839 <systemitem>os.path.normpath</systemitem>
2841 <systemitem>os.path.normcase</systemitem>).
2842 </para>
2844 <para>
2845 Example:
2846 </para>
2848 <example_commands>
2849 print('before:', env['ENV']['INCLUDE'])
2850 include_path = '/foo/bar:/foo'
2851 env.PrependENVPath('INCLUDE', include_path)
2852 print('after:', env['ENV']['INCLUDE'])
2853 </example_commands>
2855 <para>Yields:</para>
2857 <screen>
2858 before: /biz:/foo
2859 after: /foo/bar:/foo:/biz
2860 </screen>
2862 <para>
2863 See also &f-link-env-AppendENVPath;.
2864 </para>
2866 </summary>
2867 </scons_function>
2869 <scons_function name="PrependUnique">
2870 <arguments signature="env">
2871 (key=val, [...], [delete_existing=False])
2872 </arguments>
2873 <summary>
2874 <para>
2875 Prepend values to &consvars; in the current &consenv;,
2876 maintaining uniqueness.
2877 Works like &f-link-env-Append;,
2878 except that values are added to the front,
2879 rather than the end, of the &consvar;,
2880 and values that would become duplicates
2881 are not added.
2882 If <parameter>delete_existing</parameter>
2883 is set to a true value, then for any duplicate,
2884 the existing instance of <parameter>val</parameter> is first removed,
2885 then <parameter>val</parameter> is inserted,
2886 having the effect of moving it to the front.
2887 </para>
2889 <para>
2890 Example:
2891 </para>
2893 <example_commands>
2894 env.PrependUnique(CCFLAGS='-g', FOO=['foo.yyy'])
2895 </example_commands>
2897 <para>
2898 See also &f-link-env-Append;,
2899 &f-link-env-AppendUnique;
2900 and &f-link-env-Prepend;.
2901 </para>
2902 </summary>
2903 </scons_function>
2905 <scons_function name="PyPackageDir">
2906 <arguments>
2907 (modulename)
2908 </arguments>
2909 <summary>
2910 <para>
2911 Finds the location of <parameter>modulename</parameter>,
2912 which can be a string or a sequence of strings,
2913 each representing the name of a &Python; module.
2914 Construction variables are expanded in
2915 <parameter>modulename</parameter>.
2916 Returns a Directory Node (see &f-link-Dir;),
2917 or a list of Directory Nodes if
2918 <parameter>modulename</parameter> is a sequence.
2919 <literal>None</literal> is returned for any module not found.
2920 </para>
2922 <para>
2923 When a Tool module which is installed as a
2924 &Python; module is used, you need
2925 to specify a <parameter>toolpath</parameter> argument to
2926 &f-link-Tool;,
2927 &f-link-Environment;
2928 or &f-link-Clone;,
2929 as tools outside the standard project locations
2930 (<filename>site_scons/site_tools</filename>)
2931 will not be found otherwise.
2932 Using &f-PyPackageDir; allows this path to be
2933 discovered at runtime instead of hardcoding the path.
2934 </para>
2936 <para>
2937 Example:
2938 </para>
2940 <example_commands>
2941 env = Environment(
2942     tools=["default", "ExampleTool"],
2943     toolpath=[PyPackageDir("example_tool")]
2945 </example_commands>
2946 </summary>
2947 </scons_function>
2949 <scons_function name="Replace">
2950 <arguments signature="env">
2951 (key=val, [...])
2952 </arguments>
2953 <summary>
2954 <para>
2955 Replaces construction variables in the Environment
2956 with the specified keyword arguments.
2957 </para>
2959 <para>
2960 Example:
2961 </para>
2963 <example_commands>
2964 env.Replace(CCFLAGS='-g', FOO='foo.xxx')
2965 </example_commands>
2966 </summary>
2967 </scons_function>
2969 <scons_function name="Repository">
2970 <arguments>
2971 (directory)
2972 </arguments>
2973 <summary>
2974 <para>
2975 Specifies that
2976 <parameter>directory</parameter>
2977 is a repository to be searched for files.
2978 Multiple calls to
2979 &f-Repository;
2980 are legal,
2981 and each one adds to the list of
2982 repositories that will be searched.
2983 </para>
2985 <para>
2987 &scons;,
2988 a repository is a copy of the source tree,
2989 from the top-level directory on down,
2990 which may contain
2991 both source files and derived files
2992 that can be used to build targets in
2993 the local source tree.
2994 The canonical example would be an
2995 official source tree maintained by an integrator.
2996 If the repository contains derived files,
2997 then the derived files should have been built using
2998 &scons;,
2999 so that the repository contains the necessary
3000 signature information to allow
3001 &scons;
3002 to figure out when it is appropriate to
3003 use the repository copy of a derived file,
3004 instead of building one locally.
3005 </para>
3007 <para>
3008 Note that if an up-to-date derived file
3009 already exists in a repository,
3010 &scons;
3011 will
3012 <emphasis>not</emphasis>
3013 make a copy in the local directory tree.
3014 In order to guarantee that a local copy
3015 will be made,
3016 use the
3017 &f-link-Local;
3018 method.
3019 </para>
3020 </summary>
3021 </scons_function>
3023 <scons_function name="Requires">
3024 <arguments>
3025 (target, prerequisite)
3026 </arguments>
3027 <summary>
3028 <para>
3029 Specifies an order-only relationship
3030 between <parameter>target</parameter>
3031 and <parameter>prerequisite</parameter>.
3032 The prerequisites
3033 will be (re)built, if necessary,
3034 <emphasis>before</emphasis>
3035 the target file(s),
3036 but the target file(s) do not actually
3037 depend on the prerequisites
3038 and will not be rebuilt simply because
3039 the prerequisite file(s) change.
3040 <parameter>target</parameter> and
3041 <parameter>prerequisite</parameter> may each
3042 be a string or Node, or a list of strings or Nodes.
3043 If there are multiple
3044 <parameter>target</parameter> values,
3045 the prerequisite(s) are added to each one.
3046 Returns a list of the affected target nodes.
3047 </para>
3049 <para>
3050 Example:
3051 </para>
3053 <example_commands>
3054 env.Requires('foo', 'file-that-must-be-built-before-foo')
3055 </example_commands>
3056 </summary>
3057 </scons_function>
3059 <scons_function name="Scanner">
3060 <arguments>
3061 (function, [name, argument, skeys, path_function, node_class, node_factory, scan_check, recursive])
3062 </arguments>
3063 <summary>
3064 <para>
3065 Creates a Scanner object for
3066 the specified
3067 <parameter>function</parameter>.
3068 See manpage section "Scanner Objects"
3069 for a complete explanation of the arguments and behavior.
3070 </para>
3071 </summary>
3072 </scons_function>
3074 <scons_function name="SConscriptChdir">
3075 <arguments signature="global">
3076 (value)
3077 </arguments>
3078 <summary>
3079 <para>
3080 By default,
3081 &scons;
3082 changes its working directory
3083 to the directory in which each
3084 subsidiary SConscript file lives
3085 while reading and processing that script.
3086 This behavior may be disabled
3087 by specifying an argument which
3088 evaluates false, in which case
3089 &scons;
3090 will stay in the top-level directory
3091 while reading all SConscript files.
3092 (This may be necessary when building from repositories,
3093 when all the directories in which SConscript files may be found
3094 don't necessarily exist locally.)
3095 You may enable and disable
3096 this ability by calling
3097 &f-SConscriptChdir;
3098 multiple times.
3099 </para>
3101 <para>
3102 Example:
3103 </para>
3105 <example_commands>
3106 SConscriptChdir(False)
3107 SConscript('foo/SConscript')    # will not chdir to foo
3108 SConscriptChdir(True)
3109 SConscript('bar/SConscript')    # will chdir to bar
3110 </example_commands>
3111 </summary>
3112 </scons_function>
3114 <scons_function name="SConsignFile">
3115 <arguments>
3116 ([name, dbm_module])
3117 </arguments>
3118 <summary>
3119 <para>
3120 Specify where to store the &SCons; file signature database,
3121 and which database format to use.
3122 This may be useful to specify alternate
3123 database files and/or file locations for different types of builds.
3124 </para>
3125 <para>
3126 The optional <parameter>name</parameter> argument
3127 is the base name of the database file(s).
3128 If not an absolute path name,
3129 these are placed relative to the directory containing the
3130 top-level &SConstruct; file.
3131 The default is
3132 <filename>.sconsign</filename>.
3133 The actual database file(s) stored on disk
3134 may have an appropriate suffix appended
3135 by the chosen
3136 <parameter>dbm_module</parameter>
3137 </para>
3138 <para>
3139 The optional <parameter>dbm_module</parameter>
3140 argument specifies which
3141 &Python; database module to use
3142 for reading/writing the file.
3143 The module must be imported first;
3144 then the imported module name
3145 is passed as the argument.
3146 The default is a custom
3147 <systemitem>SCons.dblite</systemitem>
3148 module that uses pickled
3149 &Python; data structures,
3150 which works on all &Python; versions.
3151 See documentation of the &Python;
3152 <systemitem>dbm</systemitem> module
3153 for other available types.
3154 </para>
3155 <para>
3156 If called with no arguments,
3157 the database will default to
3158 <filename>.sconsign.dblite</filename>
3159 in the top directory of the project,
3160 which is also the default if
3161 if &f-SConsignFile; is not called.
3162 </para>
3163 <para>
3164 The setting is global, so the only difference
3165 between the global function and the environment method form
3166 is variable expansion on <parameter>name</parameter>.
3167 There should only be one active call to this
3168 function/method in a given build setup.
3169 </para>
3170 <para>
3172 <parameter>name</parameter>
3173 is set to
3174 <constant>None</constant>,
3175 &scons;
3176 will store file signatures
3177 in a separate
3178 <filename>.sconsign</filename>
3179 file in each directory,
3180 not in a single combined database file.
3181 This is a backwards-compatibility meaure to support
3182 what was the default behavior
3183 prior to &SCons; 0.97 (i.e. before 2008).
3184 Use of this mode is discouraged and may be
3185 deprecated in a future &SCons; release.
3186 </para>
3188 <para>
3189 Examples:
3190 </para>
3192 <example_commands>
3193 # Explicitly stores signatures in ".sconsign.dblite"
3194 # in the top-level SConstruct directory (the default behavior).
3195 SConsignFile()
3197 # Stores signatures in the file "etc/scons-signatures"
3198 # relative to the top-level SConstruct directory.
3199 # SCons will add a database suffix to this name.
3200 SConsignFile("etc/scons-signatures")
3202 # Stores signatures in the specified absolute file name.
3203 # SCons will add a database suffix to this name.
3204 SConsignFile("/home/me/SCons/signatures")
3206 # Stores signatures in a separate .sconsign file
3207 # in each directory.
3208 SConsignFile(None)
3210 # Stores signatures in a GNU dbm format .sconsign file
3211 import dbm.gnu
3212 SConsignFile(dbm_module=dbm.gnu)
3213 </example_commands>
3214 </summary>
3215 </scons_function>
3217 <scons_function name="SetDefault">
3218 <arguments signature="env">
3219 (key=val, [...])
3220 </arguments>
3221 <summary>
3222 <para>
3223 Sets construction variables to default values specified with the keyword
3224 arguments if (and only if) the variables are not already set.
3225 The following statements are equivalent:
3226 </para>
3228 <example_commands>
3229 env.SetDefault(FOO='foo')
3230 if 'FOO' not in env:
3231     env['FOO'] = 'foo'
3232 </example_commands>
3233 </summary>
3234 </scons_function>
3236 <scons_function name="SideEffect">
3237 <arguments>
3238 (side_effect, target)
3239 </arguments>
3240 <summary>
3241 <para>
3242 Declares
3243 <parameter>side_effect</parameter>
3244 as a side effect of building
3245 <parameter>target</parameter>.
3246 Both
3247 <parameter>side_effect</parameter>
3249 <parameter>target</parameter>
3250 can be a list, a file name, or a node.
3251 A side effect is a target file that is created or updated
3252 as a side effect of building other targets.
3253 For example, a Windows PDB
3254 file is created as a side effect of building the .obj
3255 files for a static library,
3256 and various log files are created updated
3257 as side effects of various TeX commands.
3258 If a target is a side effect of multiple build commands,
3259 &scons;
3260 will ensure that only one set of commands
3261 is executed at a time.
3262 Consequently, you only need to use this method
3263 for side-effect targets that are built as a result of
3264 multiple build commands.
3265 </para>
3267 <para>
3268 Because multiple build commands may update
3269 the same side effect file,
3270 by default the
3271 <parameter>side_effect</parameter>
3272 target is
3273 <emphasis>not</emphasis>
3274 automatically removed
3275 when the
3276 <parameter>target</parameter>
3277 is removed by the
3278 <option>-c</option>
3279 option.
3280 (Note, however, that the
3281 <parameter>side_effect</parameter>
3282 might be removed as part of
3283 cleaning the directory in which it lives.)
3284 If you want to make sure the
3285 <parameter>side_effect</parameter>
3286 is cleaned whenever a specific
3287 <parameter>target</parameter>
3288 is cleaned,
3289 you must specify this explicitly
3290 with the
3291 &f-link-Clean;
3293 &f-env-Clean;
3294 function.
3295 </para>
3297 <para>
3298 This function returns the list of side effect Node objects that were successfully added.
3299 If the list of side effects contained any side effects that had already been added,
3300 they are not added and included in the returned list.
3301 </para>
3302 </summary>
3303 </scons_function>
3305 <scons_function name="Split">
3306 <arguments>(arg)</arguments>
3307 <summary>
3308 <para>
3309 If <parameter>arg</parameter> is a string,
3310 splits on whitespace and returns a list of
3311 strings without whitespace.
3312 This mode is the most common case,
3313 and can be used to split a list of filenames
3314 (for example) rather than having to type them as a
3315 list of individually quoted words.
3316 If <parameter>arg</parameter> is a list or tuple
3317 returns the list or tuple unchanged.
3318 If <parameter>arg</parameter> is any other type of object,
3319 returns a list containing just the object.
3320 These non-string cases do not actually do any spliting,
3321 but allow an argument variable to be passed to
3322 &f-Split; without having to first check its type.
3323 </para>
3325 <para>
3326 Example:
3327 </para>
3329 <example_commands>
3330 files = Split("f1.c f2.c f3.c")
3331 files = env.Split("f4.c f5.c f6.c")
3332 files = Split("""
3333     f7.c
3334     f8.c
3335     f9.c
3336 """)
3337 </example_commands>
3338 </summary>
3339 </scons_function>
3341 <scons_function name="subst">
3342 <arguments signature="env">
3343 (input, [raw, target, source, conv])
3344 </arguments>
3345 <summary>
3346 <para>
3347 Performs &consvar; interpolation
3348 (<firstterm>substitution</firstterm>)
3349 on <parameter>input</parameter>,
3350 which can be a string or a sequence.
3351 Substitutable elements take the form
3352 <literal>${<replaceable>expression</replaceable>}</literal>,
3353 although if there is no ambiguity in recognizing the element,
3354 the braces can be omitted.
3355 A literal <emphasis role="bold">$</emphasis> can be entered by
3356 using <emphasis role="bold">$$</emphasis>.
3357 </para>
3359 <para>
3360 By default,
3361 leading or trailing white space will
3362 be removed from the result,
3363 and all sequences of white space
3364 will be compressed to a single space character.
3365 Additionally, any
3366 <literal>$(</literal>
3368 <literal>$)</literal>
3369 character sequences will be stripped from the returned string,
3370 The optional
3371 <parameter>raw</parameter>
3372 argument may be set to
3373 <literal>1</literal>
3374 if you want to preserve white space and
3375 <literal>$(</literal>-<literal>$)</literal>
3376 sequences.
3378 <parameter>raw</parameter>
3379 argument may be set to
3380 <literal>2</literal>
3381 if you want to additionally discard
3382 all characters between any
3383 <literal>$(</literal>
3385 <literal>$)</literal>
3386 pairs
3387 (as is done for signature calculation).
3388 </para>
3390 <para>
3391 If <parameter>input</parameter> is a sequence
3392 (list or tuple),
3393 the individual elements of
3394 the sequence will be expanded,
3395 and the results will be returned as a list.
3396 </para>
3398 <para>
3399 The optional
3400 <parameter>target</parameter>
3402 <parameter>source</parameter>
3403 keyword arguments
3404 must be set to lists of
3405 target and source nodes, respectively,
3406 if you want the
3407 &cv-TARGET;,
3408 &cv-TARGETS;,
3409 &cv-SOURCE;
3411 &cv-SOURCES;
3412 to be available for expansion.
3413 This is usually necessary if you are
3414 calling
3415 &f-env-subst;
3416 from within a &Python; function used
3417 as an SCons action.
3418 </para>
3420 <para>
3421 Returned string values or sequence elements
3422 are converted to their string representation by default.
3423 The optional
3424 <parameter>conv</parameter>
3425 argument
3426 may specify a conversion function
3427 that will be used in place of
3428 the default.
3429 For example, if you want &Python; objects
3430 (including SCons Nodes)
3431 to be returned as &Python; objects,
3432 you can use a &Python;
3433 lambda expression to pass in an unnamed function
3434 that simply returns its unconverted argument.
3435 </para>
3437 <para>
3438 Example:
3439 </para>
3441 <example_commands>
3442 print(env.subst("The C compiler is: $CC"))
3444 def compile(target, source, env):
3445     sourceDir = env.subst(
3446         "${SOURCE.srcdir}",
3447         target=target,
3448         source=source
3449     )
3451 source_nodes = env.subst('$EXPAND_TO_NODELIST', conv=lambda x: x)
3452 </example_commands>
3453 </summary>
3454 </scons_function>
3456 <scons_function name="Tool">
3457 <arguments>
3458 (name, [toolpath, **kwargs])
3459 </arguments>
3460 <summary>
3462 <para>
3463 Locates the tool specification module <parameter>name</parameter>
3464 and returns a callable tool object for that tool.
3465 When the environment method (&f-env-Tool;) form is used,
3466 the tool object is automatically called before the method returns
3467 to update <varname>env</varname>,
3468 and <parameter>name</parameter> is
3469 appended to the &cv-link-TOOLS;
3470 &consvar; in that environment.
3471 When the global function &f-Tool; form is used,
3472 the tool object is constructed but not called,
3473 as it lacks the context of an environment to update,
3474 and the returned object needs to be used to arrange for the call.
3475 </para>
3477 <para>
3478 The tool module is searched for in the tool search paths (see the
3479 <emphasis role="bold">Tools</emphasis> section in the manual page
3480 for details)
3481 and in any paths specified by the optional
3482 <parameter>toolpath</parameter> parameter,
3483 which must be a list of strings.
3484 If <parameter>toolpath</parameter> is omitted,
3485 the <parameter>toolpath</parameter>
3486 supplied when the environment was created,
3487 if any, is used.
3488 </para>
3490 <para>
3491 Any remaining keyword arguments are saved in
3492 the tool object,
3493 and will be passed to the tool module's
3494 <function>generate</function> function
3495 when the tool object is actually called.
3496 The <function>generate</function> function
3497 can update the &consenv; with &consvars; and arrange
3498 any other initialization
3499 needed to use the mechanisms that tool describes,
3500 and can use these extra arguments to help
3501 guide its actions.
3502 </para>
3504 <para>
3505 <emphasis>Changed in version  4.2:</emphasis>
3506 &f-env-Tool; now returns the tool object,
3507 previously it did not return (i.e. returned <constant>None</constant>).
3508 </para>
3510 <para>
3511 Examples:
3512 </para>
3514 <example_commands>
3515 env.Tool('gcc')
3516 env.Tool('opengl', toolpath=['build/tools'])
3517 </example_commands>
3519 <para>
3520 The returned tool object can be passed to an
3521 &f-link-Environment; or &f-link-Clone; call
3522 as part of the <parameter>tools</parameter> keyword argument,
3523 in which case the tool is applied to the environment being constructed,
3524 or it can be called directly,
3525 in which case a &consenv; to update must be
3526 passed as the argument.
3527 Either approach will also update the
3528 &cv-TOOLS; &consvar;.
3529 </para>
3531 <para>
3532 Examples:
3533 </para>
3535 <example_commands>
3536 env = Environment(tools=[Tool('msvc')])
3538 env = Environment()
3539 msvctool = Tool('msvc')
3540 msvctool(env)  # adds 'msvc' to the TOOLS variable
3541 gltool = Tool('opengl', toolpath = ['tools'])
3542 gltool(env)  # adds 'opengl' to the TOOLS variable
3543 </example_commands>
3544 </summary>
3545 </scons_function>
3547 <scons_function name="Value">
3548 <arguments>
3549 (value, [built_value], [name])
3550 </arguments>
3551 <summary>
3552 <para>
3553 Returns a Node object representing the specified &Python;
3554 <parameter>value</parameter>.
3555 Value Nodes can be used as dependencies of targets.
3556 If the string representation of the Value Node
3557 changes between &SCons; runs, it is considered
3558 out of date and any targets depending it will be rebuilt.
3559 Since Value Nodes have no filesystem representation,
3560 timestamps are not used; the timestamp deciders
3561 perform the same content-based up to date check.
3562 </para>
3563 <para>
3564 The optional
3565 <parameter>built_value</parameter>
3566 argument can be specified
3567 when the Value Node is created
3568 to indicate the Node should already be considered "built."
3569 </para>
3571 <para>
3572 The optional <parameter>name</parameter> parameter can be provided as an
3573 alternative name for the resulting <literal>Value</literal> node;
3574 this is advised if the <parameter>value</parameter> parameter
3575 cannot be converted to a string.
3576 </para>
3578 <para>
3579 Value Nodes have a
3580 <methodname>write</methodname>
3581 method that can be used to "build" a Value Node
3582 by setting a new value.
3583 The corresponding
3584 <methodname>read</methodname>
3585 method returns the built value of the Node.
3586 </para>
3588 <para>
3589 <emphasis>Changed in version 4.0:</emphasis>
3590 the <parameter>name</parameter> parameter was added.
3591 </para>
3593 <para>
3594 Examples:
3595 </para>
3597 <!-- TODO fix second example or replace - still doesn't work -->
3598 <example_commands>
3599 env = Environment()
3601 def create(target, source, env):
3602     """Action function to create a file from a Value.
3604     Writes 'prefix=$SOURCE' into the file name given as $TARGET.
3605     """
3606     with open(str(target[0]), 'wb') as f:
3607         f.write(b'prefix=' + source[0].get_contents() + b'\n')
3609 # Fetch the prefix= argument, if any, from the command line.
3610 # Use /usr/local as the default.
3611 prefix = ARGUMENTS.get('prefix', '/usr/local')
3613 # Attach builder named Config to the construction environment
3614 # using the 'create' action function above.
3615 env['BUILDERS']['Config'] = Builder(action=create)
3616 env.Config(target='package-config', source=Value(prefix))
3618 def build_value(target, source, env):
3619     """Action function to "build" a Value.
3621     Writes contents of $SOURCE into $TARGET, thus updating if it existed.
3622     """
3623     target[0].write(source[0].get_contents())
3625 output = env.Value('before')
3626 input = env.Value('after')
3628 # Attach a builder named UpdateValue to the construction environment
3629 # using the 'build_value' action function above.
3630 env['BUILDERS']['UpdateValue'] = Builder(action=build_value)
3631 env.UpdateValue(target=Value(output), source=Value(input))
3632 </example_commands>
3633 </summary>
3634 </scons_function>
3636 <scons_function name="VariantDir">
3637 <arguments>
3638 (variant_dir, src_dir, [duplicate])
3639 </arguments>
3640 <summary>
3641 <para>
3642 Sets up a mapping to define a variant build directory in
3643 <parameter>variant_dir</parameter>.
3644 <parameter>src_dir</parameter> must not be underneath
3645 <parameter>variant_dir</parameter>.
3646 A &f-VariantDir; mapping is global, even if called using the
3647 &f-env-VariantDir; form.
3648 &f-VariantDir;
3649 can be called multiple times with the same
3650 <parameter>src_dir</parameter>
3651 to set up multiple variant builds with different options.
3652 </para>
3654 <para>
3655 Note if <parameter>variant_dir</parameter>
3656 is not under the project top directory,
3657 target selection rules will not pick targets in the
3658 variant directory unless they are explicitly specified.
3659 </para>
3661 <para>
3662 When files in <parameter>variant_dir</parameter> are referenced,
3663 &SCons; backfills as needed with files from <parameter>src_dir</parameter>
3664 to create a complete build directory.
3665 By default, &SCons;
3666 physically duplicates the source files, SConscript files,
3667 and directory structure as needed into the variant directory.
3668 Thus, a build performed in the variant directory is guaranteed to be identical
3669 to a build performed in the source directory even if
3670 intermediate source files are generated during the build,
3671 or if preprocessors or other scanners search for included files
3672 using paths relative to the source file,
3673 or if individual compilers or other invoked tools are hard-coded
3674 to put derived files in the same directory as source files.
3675 Only the files &SCons; calculates are needed for the build are
3676 duplicated into <parameter>variant_dir</parameter>.
3677 If possible on the platform,
3678 the duplication is performed by linking rather than copying.
3679 This behavior is affected by the
3680 <option>--duplicate</option>
3681 command-line option.
3682 </para>
3684 <para>
3685 Duplicating the source files may be disabled by setting the
3686 <parameter>duplicate</parameter>
3687 argument to
3688 <constant>False</constant>.
3689 This will cause
3690 &SCons;
3691 to invoke Builders using the path names of source files in
3692 <parameter>src_dir</parameter>
3693 and the path names of derived files within
3694 <parameter>variant_dir</parameter>.
3695 This is more efficient than duplicating,
3696 and is safe for most builds;
3697 revert to <literal>duplicate=True</literal>
3698 if it causes problems.
3699 </para>
3701 <para>
3702 &f-VariantDir;
3703 works most naturally when used with a subsidiary SConscript file.
3704 The subsidiary SConscript file must be called as if it were in
3705 <parameter>variant_dir</parameter>,
3706 regardless of the value of
3707 <parameter>duplicate</parameter>.
3708 When calling an SConscript file, you can use the
3709 <parameter>exports</parameter> keyword argument
3710 to pass parameters (individually or as an appropriately set up environment)
3711 so the SConscript can pick up the right settings for that variant build.
3712 The SConscript must &f-link-Import; these to use them. Example:
3713 </para>
3715 <example_commands>
3716 env1 = Environment(...settings for variant1...)
3717 env2 = Environment(...settings for variant2...)
3719 # run src/SConscript in two variant directories
3720 VariantDir('build/variant1', 'src')
3721 SConscript('build/variant1/SConscript', exports={"env": env1})
3722 VariantDir('build/variant2', 'src')
3723 SConscript('build/variant2/SConscript', exports={"env": env2})
3724 </example_commands>
3726 <para>
3727 See also the
3728 &f-link-SConscript; function
3729 for another way to specify a variant directory
3730 in conjunction with calling a subsidiary SConscript file.
3731 </para>
3733 <para>
3734 More examples:
3735 </para>
3737 <example_commands>
3738 # use names in the build directory, not the source directory
3739 VariantDir('build', 'src', duplicate=0)
3740 Program('build/prog', 'build/source.c')
3742 # this builds both the source and docs in a separate subtree
3743 VariantDir('build', '.', duplicate=0)
3744 SConscript(dirs=['build/src','build/doc'])
3746 # same as previous example, but only uses SConscript
3747 SConscript(dirs='src', variant_dir='build/src', duplicate=0)
3748 SConscript(dirs='doc', variant_dir='build/doc', duplicate=0)
3749 </example_commands>
3750 </summary>
3751 </scons_function>
3753 <scons_function name="WhereIs">
3754 <arguments>
3755 (program, [path, pathext, reject])
3756 </arguments>
3757 <summary>
3758 <para>
3759 Searches for the specified executable
3760 <parameter>program</parameter>,
3761 returning the full path to the program
3762 or <constant>None</constant>.
3763 </para>
3764 <para>
3765 When called as a &consenv; method,
3766 searches the paths in the
3767 <parameter>path</parameter> keyword argument,
3768 or if <constant>None</constant> (the default)
3769 the paths listed in the &consenv;
3770 (<varname>env</varname><literal>['ENV']['PATH']</literal>).
3771 The external environment's path list
3772 (<literal>os.environ['PATH']</literal>)
3773 is used as a fallback if the key
3774 <varname>env</varname><literal>['ENV']['PATH']</literal>
3775 does not exist.
3776 </para>
3777 <para>
3778 On Windows systems, searches for executable
3779 programs with any of the file extensions listed in the
3780 <parameter>pathext</parameter> keyword argument,
3781 or if <constant>None</constant> (the default)
3782 the pathname extensions listed in the &consenv;
3783 (<varname>env</varname><literal>['ENV']['PATHEXT']</literal>).
3784 The external environment's pathname extensions list
3785 (<literal>os.environ['PATHEXT']</literal>)
3786 is used as a fallback if the key
3787 <varname>env</varname><literal>['ENV']['PATHEXT']</literal>
3788 does not exist.
3789 </para>
3790 <para>
3791 When called as a global function, uses the external
3792 environment's path
3793 <literal>os.environ['PATH']</literal>
3794 and path extensions
3795 <literal>os.environ['PATHEXT']</literal>,
3796 respectively, if
3797 <parameter>path</parameter> and
3798 <parameter>pathext</parameter> are
3799 <constant>None</constant>.
3800 </para>
3801 <para>
3802 Will not select any
3803 path name or names
3804 in the optional
3805 <parameter>reject</parameter>
3806 list.
3807 </para>
3809 </summary>
3810 </scons_function>
3812 </sconsdoc>