3 SPDX-FileCopyrightText: Copyright The SCons Foundation (https://scons.org)
4 SPDX-License-Identifier: MIT
5 SPDX-FileType: DOCUMENTATION
7 This file is processed by the bin/SConsDoc.py module.
11 <!ENTITY % scons SYSTEM '../doc/scons.mod'>
13 <!ENTITY % builders-mod SYSTEM '../doc/generated/builders.mod'>
15 <!ENTITY % functions-mod SYSTEM '../doc/generated/functions.mod'>
17 <!ENTITY % tools-mod SYSTEM '../doc/generated/tools.mod'>
19 <!ENTITY % variables-mod SYSTEM '../doc/generated/variables.mod'>
23 <sconsdoc xmlns="http://www.scons.org/dbxsd/v1.0"
24 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
25 xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">
28 <!-- Construction variables -->
30 <cvar name="BUILDERS">
33 A dictionary mapping the names of the builders
34 available through the &consenv; to underlying Builder objects.
35 Custom builders need to be added to this to make them available.
39 A platform-dependent default list of builders such as
40 &b-link-Program;, &b-link-Library; etc. is used to
41 populate this &consvar; when the &consenv; is initialized
42 via the presence/absence of the tools those builders depend on.
43 &cv-BUILDERS; can be examined to learn which builders will
44 actually be available at run-time.
48 Note that if you initialize this &consvar; through
49 assignment when the &consenv; is created,
50 that value for &cv-BUILDERS; will override any defaults:
54 bld = Builder(action='foobuild < $SOURCE > $TARGET')
55 env = Environment(BUILDERS={'NewBuilder': bld})
59 To instead use a new Builder object in addition to the default Builders,
60 add your new Builder object like this:
65 env.Append(BUILDERS={'NewBuilder': bld})
74 env['BUILDERS']['NewBuilder'] = bld
82 The <firstterm>execution environment</firstterm> -
83 a dictionary of environment variables
84 used when &SCons; invokes external commands
85 to build targets defined in this &consenv;.
86 When &cv-ENV; is passed to a command,
87 all list values are assumed to be path lists and
88 are joined using the search path separator.
89 Any other non-string values are coerced to a string.
96 <emphasis>not</emphasis>
97 propagate the environment in effect when you execute
98 &scons; (the "shell environment")
99 to the execution environment.
100 This is so that builds will be guaranteed
101 repeatable regardless of the environment
102 variables set at the time
105 If you want to propagate a
106 shell environment variable
107 to the commands executed
108 to build target files,
109 you must do so explicitly.
112 environment variable,
115 will find utilities the same way
116 as the invoking shell (or other process):
121 env = Environment(ENV={'PATH': os.environ['PATH']})
125 Although it is usually not recommended,
126 you can propagate the entire shell environment
132 env = Environment(ENV=os.environ.copy())
138 <cvar name="SCANNERS">
141 A list of the available implicit dependency scanners.
142 New file scanners may be added by
143 appending to this list,
144 although the more flexible approach
145 is to associate scanners
146 with a specific Builder.
147 See the manpage sections "Builder Objects"
148 and "Scanner Objects"
149 for more information.
154 <cvar name="CHANGED_SOURCES">
157 A reserved variable name
158 that may not be set or used in a construction environment.
159 (See the manpage section "Variable Substitution"
160 for more information).
165 <cvar name="CHANGED_TARGETS">
168 A reserved variable name
169 that may not be set or used in a construction environment.
170 (See the manpage section "Variable Substitution"
171 for more information).
179 A reserved variable name
180 that may not be set or used in a construction environment.
181 (See the manpage section "Variable Substitution"
182 for more information).
187 <cvar name="SOURCES">
190 A reserved variable name
191 that may not be set or used in a construction environment.
192 (See the manpage section "Variable Substitution"
193 for more information).
201 A reserved variable name
202 that may not be set or used in a construction environment.
203 (See the manpage section "Variable Substitution"
204 for more information).
209 <cvar name="TARGETS">
212 A reserved variable name
213 that may not be set or used in a construction environment.
214 (See the manpage section "Variable Substitution"
215 for more information).
220 <cvar name="UNCHANGED_SOURCES">
223 A reserved variable name
224 that may not be set or used in a construction environment.
225 (See the manpage section "Variable Substitution"
226 for more information).
231 <cvar name="UNCHANGED_TARGETS">
234 A reserved variable name
235 that may not be set or used in a construction environment.
236 (See the manpage section "Variable Substitution"
237 for more information).
245 A list of the names of the Tool specification modules
246 that were actually initialized in the current &consenv;.
247 This may be useful as a diagnostic aid
248 to see if a tool did (or did not) run.
249 The value is informative and is not guaranteed to be complete.
254 <cvar name="CACHEDIR_CLASS">
257 The class type that SCons should use when instantiating a
258 new &f-link-CacheDir; in this &consenv;. Must be
259 a subclass of the <classname>SCons.CacheDir.CacheDir</classname> class.
264 <!-- Functions / Construction environment methods -->
266 <scons_function name="Action">
268 (action, [output, [var, ...]] [key=value, ...])
272 A factory function to create an Action object for
274 <parameter>action</parameter>.
275 See the manpage section "Action Objects"
276 for a complete explanation of the arguments and behavior.
280 Note that the &f-env-Action;
281 form of the invocation will expand
282 construction variables in any argument strings,
284 <parameter>action</parameter>
285 argument, at the time it is called
286 using the construction variables in the
287 <replaceable>env</replaceable>
288 construction environment through which
289 &f-env-Action; was called.
290 The &f-Action; global function
291 form delays all variable expansion
292 until the Action object is actually used.
297 <scons_function name="AddMethod">
298 <arguments signature="global">
299 (object, function, [name])
301 <arguments signature="env">
306 Adds <parameter>function</parameter> to an object as a method.
307 <parameter>function</parameter> will be called with an instance
308 object as the first argument as for other methods.
309 If <parameter>name</parameter> is given, it is used as
310 the name of the new method, else the name of
311 <parameter>function</parameter> is used.
314 When the global function &f-AddMethod; is called,
315 the object to add the method to must be passed as the first argument;
316 typically this will be &Environment;,
317 in order to create a method which applies to all &consenvs;
318 subsequently constructed.
319 When called using the &f-env-AddMethod; form,
320 the method is added to the specified &consenv; only.
321 Added methods propagate through &f-env-Clone; calls.
329 # Function to add must accept an instance argument.
330 # The Python convention is to call this 'self'.
331 def my_method(self, arg):
332 print("my_method() got", arg)
334 # Use the global function to add a method to the Environment class:
335 AddMethod(Environment, my_method)
339 # Use the optional name argument to set the name of the method:
340 env.AddMethod(my_method, 'other_method_name')
341 env.other_method_name('another arg')
346 <scons_function name="AddPostAction">
352 Arranges for the specified
353 <parameter>action</parameter>
356 <parameter>target</parameter>
358 <parameter>action</parameter> may be
359 an Action object, or anything that
360 can be converted into an Action object.
361 See the manpage section "Action Objects"
362 for a complete explanation.
366 When multiple targets are supplied,
367 the action may be called multiple times,
368 once after each action that generates
369 one or more targets in the list.
373 foo = Program('foo.c')
374 # remove execute permission from binary:
375 AddPostAction(foo, Chmod('$TARGET', "a-x"))
381 <scons_function name="AddPreAction">
387 Arranges for the specified
388 <parameter>action</parameter>
391 <parameter>target</parameter>
393 <parameter>action</parameter> may be
394 an Action object, or anything that
395 can be converted into an Action object.
396 See the manpage section "Action Objects"
397 for a complete explanation.
401 When multiple targets are specified,
402 the action(s) may be called multiple times,
403 once before each action that generates
404 one or more targets in the list.
408 Note that if any of the targets are built in multiple steps,
409 the action will be invoked just
410 before the "final" action that specifically
411 generates the specified target(s).
412 For example, when building an executable program
413 from a specified source
414 <filename>.c</filename>
415 file via an intermediate object file:
419 foo = Program('foo.c')
420 AddPreAction(foo, 'pre_action')
425 <literal>pre_action</literal>
426 would be executed before
428 calls the link command that actually
429 generates the executable program binary
430 <filename>foo</filename>,
431 not before compiling the
432 <filename>foo.c</filename>
433 file into an object file.
438 <scons_function name="Alias">
440 (alias, [source, [action]])
444 Creates an <firstterm>alias</firstterm> target that
445 can be used as a reference to zero or more other targets,
446 specified by the optional <parameter>source</parameter> parameter.
447 Aliases provide a way to give a shorter or more descriptive
448 name to specific targets,
449 and to group multiple targets under a single name.
450 The alias name, or an Alias Node object,
451 may be used as a dependency of any other target,
452 including another alias.
456 <parameter>alias</parameter> and <parameter>source</parameter>
457 may each be a string or Node object,
458 or a list of strings or Node objects;
459 if Nodes are used for
460 <parameter>alias</parameter>
461 they must be Alias nodes.
462 If <parameter>source</parameter> is omitted,
463 the alias is created but has no reference;
464 if selected for building this will result in a
465 <quote>Nothing to be done.</quote> message.
466 An empty alias can be used to define the alias
467 in a visible place in the project;
468 it can later be appended to in a subsidiary SConscript file
469 with the actual target(s) to refer to.
471 <parameter>action</parameter>
472 parameter specifies an action or list of actions
473 that will be executed
474 whenever the any of the alias targets are out-of-date.
478 &f-Alias; can be called for an existing alias,
479 which appends the <parameter>alias</parameter>
480 and/or <parameter>action</parameter> arguments
481 to the existing lists for that alias.
485 Returns a list of Alias Node objects representing the alias(es),
486 which exist outside of any physical file system.
487 The alias name space is separate from the name space for
488 tangible targets; to avoid confusion do not reuse
489 target names as alias names.
498 Alias('install', '/usr/bin')
499 Alias(['install', 'install-lib'], '/usr/local/lib')
501 env.Alias('install', ['/usr/local/bin', '/usr/local/lib'])
502 env.Alias('install', ['/usr/local/man'])
504 env.Alias('update', ['file1', 'file2'], "update_database $SOURCES")
509 <scons_function name="AlwaysBuild">
516 <parameter>target</parameter>
517 so that it is always assumed to be out of date,
518 and will always be rebuilt if needed.
521 does not add its target(s) to the default target list,
522 so the targets will only be built
523 if they are specified on the command line,
524 or are a dependent of a target specified on the command line--but
526 <emphasis>always</emphasis>
527 be built if so specified.
528 Multiple targets can be passed in to a single call to
534 <scons_function name="Append">
535 <arguments signature="env">
540 Appends value(s) intelligently to &consvars; in
541 <varname>env</varname>.
542 The &consvars; and values to add to them are passed as
543 <parameter>key=val</parameter> pairs (&Python; keyword arguments).
544 &f-env-Append; is designed to allow adding values
545 without having to think about the data type of an existing &consvar;.
546 Regular &Python; syntax can also be used to manipulate the &consvar;,
547 but for that you may need to know the types involved,
548 for example pure &Python; lets you directly "add" two lists of strings,
549 but adding a string to a list or a list to a string requires
550 different syntax - things &f-Append; takes care of.
551 Some pre-defined &consvars; do have type expectations
552 based on how &SCons; will use them:
553 for example &cv-link-CPPDEFINES; is often a string or a list of strings,
554 but can also be a list of tuples or a dictionary;
555 while &cv-link-LIBEMITTER;
556 is expected to be a callable or list of callables,
557 and &cv-link-BUILDERS; is expected to be a dictionary.
558 Consult the documentation for the various &consvars; for more details.
562 The following descriptions apply to both the &f-Append;
563 and &f-Prepend; methods, as well as their
564 <emphasis role="bold">Unique</emphasis> variants,
565 with the differences being the insertion point of the added values
566 and whether duplication is allowed.
570 <parameter>val</parameter> can be almost any type.
571 If <varname>env</varname> does not have a &consvar;
572 named <parameter>key</parameter>,
573 then <parameter>key</parameter> is simply
574 stored with a value of <parameter>val</parameter>.
575 Otherwise, <parameter>val</parameter> is
576 combinined with the existing value,
577 possibly converting into an appropriate type
578 which can hold the expanded contents.
579 There are a few special cases to be aware of.
580 Normally, when two strings are combined,
581 the result is a new string containing their concatenation
582 (and you are responsible for supplying any needed separation);
583 however, the contents of &cv-link-CPPDEFINES; will
584 will be postprocessed by adding a prefix and/or suffix
585 to each entry when the command line is produced,
586 so &SCons; keeps them separate -
587 appending a string will result in a separate string entry,
588 not a combined string.
589 For &cv-CPPDEFINES;. as well as
590 &cv-link-LIBS;, and the various <literal>*PATH</literal> variables,
591 &SCons; will amend the variable by supplying the compiler-specific
592 syntax (e.g. prepending a <literal>-D</literal> or <literal>/D</literal>
593 prefix for &cv-CPPDEFINES;), so you should omit this syntax when
594 adding values to these variables.
595 Examples (gcc syntax shown in the expansion of &CPPDEFINES;):
599 env = Environment(CXXFLAGS="-std=c11", CPPDEFINES="RELEASE")
600 print(f"CXXFLAGS = {env['CXXFLAGS']}, CPPDEFINES = {env['CPPDEFINES']}")
601 # notice including a leading space in CXXFLAGS addition
602 env.Append(CXXFLAGS=" -O", CPPDEFINES="EXTRA")
603 print(f"CXXFLAGS = {env['CXXFLAGS']}, CPPDEFINES = {env['CPPDEFINES']}")
604 print("CPPDEFINES will expand to", env.subst('$_CPPDEFFLAGS'))
609 CXXFLAGS = -std=c11, CPPDEFINES = RELEASE
610 CXXFLAGS = -std=c11 -O, CPPDEFINES = deque(['RELEASE', 'EXTRA'])
611 CPPDEFINES will expand to -DRELEASE -DEXTRA
612 scons: `.' is up to date.
616 Because &cv-link-CPPDEFINES; is intended for command-line
617 specification of C/C++ preprocessor macros,
618 additional syntax is accepted when adding to it.
619 The preprocessor accepts arguments to predefine a macro name by itself
620 (<computeroutput>-DFOO</computeroutput> for most compilers,
621 <computeroutput>/DFOO</computeroutput> for Microsoft C++),
622 which gives it an implicit value of <constant>1</constant>,
623 or can be given with a replacement value
624 (<computeroutput>-DBAR=TEXT</computeroutput>).
625 &SCons; follows these rules when adding to &cv-CPPDEFINES;:
629 <para>A string is split on spaces,
630 giving an easy way to enter multiple macros in one addition.
631 Use an <literal>=</literal> to specify a valued macro.</para>
634 <para>A tuple is treated as a valued macro.
635 Use the value <constant>None</constant> if the macro should not have a value.
636 It is an error to supply more than two elements in such a tuple.</para>
639 <para>A list is processed in order,
640 adding each item without further interpretation.
641 In this case, space-separated strings are not split.</para>
644 <para>A dictionary is processed in order,
645 adding each key-value pair as a valued macro.
646 Use the value <constant>None</constant> if the macro should not have a value.
656 env = Environment(CPPDEFINES="FOO")
657 print("CPPDEFINES =", env['CPPDEFINES'])
658 env.Append(CPPDEFINES="BAR=1")
659 print("CPPDEFINES =", env['CPPDEFINES'])
660 env.Append(CPPDEFINES=[("OTHER", 2)])
661 print("CPPDEFINES =", env['CPPDEFINES'])
662 env.Append(CPPDEFINES={"EXTRA": "arg"})
663 print("CPPDEFINES =", env['CPPDEFINES'])
664 print("CPPDEFINES will expand to", env.subst('$_CPPDEFFLAGS'))
670 CPPDEFINES = deque(['FOO', 'BAR=1'])
671 CPPDEFINES = deque(['FOO', 'BAR=1', ('OTHER', 2)])
672 CPPDEFINES = deque(['FOO', 'BAR=1', ('OTHER', 2), ('EXTRA', 'arg')])
673 CPPDEFINES will expand to -DFOO -DBAR=1 -DOTHER=2 -DEXTRA=arg
674 scons: `.' is up to date.
678 Examples of adding multiple macros:
683 env.Append(CPPDEFINES=[("ONE", 1), "TWO", ("THREE", )])
684 print("CPPDEFINES =", env['CPPDEFINES'])
685 env.Append(CPPDEFINES={"FOUR": 4, "FIVE": None})
686 print("CPPDEFINES =", env['CPPDEFINES'])
687 print("CPPDEFINES will expand to", env.subst('$_CPPDEFFLAGS'))
692 CPPDEFINES = [('ONE', 1), 'TWO', ('THREE',)]
693 CPPDEFINES = deque([('ONE', 1), 'TWO', ('THREE',), ('FOUR', 4), ('FIVE', None)])
694 CPPDEFINES will expand to -DONE=1 -DTWO -DTHREE -DFOUR=4 -DFIVE
695 scons: `.' is up to date.
699 <emphasis>Changed in version 4.5</emphasis>:
700 clarifined the use of tuples vs. other types,
701 handling is now consistent across the four functions.
706 env.Append(CPPDEFINES=("MACRO1", "MACRO2"))
707 print("CPPDEFINES =", env['CPPDEFINES'])
708 env.Append(CPPDEFINES=[("MACRO3", "MACRO4")])
709 print("CPPDEFINES =", env['CPPDEFINES'])
710 print("CPPDEFINES will expand to", env.subst('$_CPPDEFFLAGS'))
715 CPPDEFINES = ('MACRO1', 'MACRO2')
716 CPPDEFINES = deque(['MACRO1', 'MACRO2', ('MACRO3', 'MACRO4')])
717 CPPDEFINES will expand to -DMACRO1 -DMACRO2 -DMACRO3=MACRO4
718 scons: `.' is up to date.
722 See &cv-link-CPPDEFINES; for more details.
726 Appending a string <parameter>val</parameter>
727 to a dictonary-typed &consvar; enters
728 <parameter>val</parameter> as the key in the dictionary,
729 and <literal>None</literal> as its value.
730 Using a tuple type to supply a key-value pair
731 only works for the special case of &cv-CPPDEFINES;
736 Although most combinations of types work without
737 needing to know the details, some combinations
738 do not make sense and &Python; raises an exception.
742 When using &f-env-Append; to modify &consvars;
743 which are path specifications (conventionally,
744 the names of such end in <literal>PATH</literal>),
745 it is recommended to add the values as a list of strings,
746 even if you are only adding a single string.
747 The same goes for adding library names to &cv-LIBS;.
751 env.Append(CPPPATH=["#/include"])
755 See also &f-link-env-AppendUnique;,
756 &f-link-env-Prepend; and &f-link-env-PrependUnique;.
762 <scons_function name="AppendENVPath">
763 <arguments signature="env">
764 (name, newpath, [envname, sep, delete_existing=False])
768 Append path elements specified by <parameter>newpath</parameter>
769 to the given search path string or list <parameter>name</parameter>
770 in mapping <parameter>envname</parameter> in the &consenv;.
771 Supplying <parameter>envname</parameter> is optional:
772 the default is the execution environment &cv-link-ENV;.
773 Optional <parameter>sep</parameter> is used as the search path separator,
774 the default is the platform's separator (<systemitem>os.pathsep</systemitem>).
775 A path element will only appear once.
776 Any duplicates in <parameter>newpath</parameter> are dropped,
777 keeping the last appearing (to preserve path order).
778 If <parameter>delete_existing</parameter>
779 is <constant>False</constant> (the default)
780 any addition duplicating an existing path element is ignored;
781 if <parameter>delete_existing</parameter>
782 is <constant>True</constant> the existing value will
783 be dropped and the path element will be added at the end.
784 To help maintain uniqueness all paths are normalized (using
785 <systemitem>os.path.normpath</systemitem>
787 <systemitem>os.path.normcase</systemitem>).
795 print('before:', env['ENV']['INCLUDE'])
796 include_path = '/foo/bar:/foo'
797 env.AppendENVPath('INCLUDE', include_path)
798 print('after:', env['ENV']['INCLUDE'])
804 after: /biz:/foo/bar:/foo
808 See also &f-link-env-PrependENVPath;.
814 <scons_function name="AppendUnique">
815 <arguments signature="env">
816 (key=val, [...], [delete_existing=False])
820 Append values to &consvars; in the current &consenv;,
821 maintaining uniqueness.
822 Works like &f-link-env-Append;,
823 except that values that would become duplicates
825 If <parameter>delete_existing</parameter>
826 is set to a true value, then for any duplicate,
827 the existing instance of <parameter>val</parameter> is first removed,
828 then <parameter>val</parameter> is appended,
829 having the effect of moving it to the end.
837 env.AppendUnique(CCFLAGS='-g', FOO=['foo.yyy'])
841 See also &f-link-env-Append;,
843 and &f-link-env-PrependUnique;.
848 <scons_function name="Builder">
850 (action, [arguments])
854 Creates a Builder object for
856 <parameter>action</parameter>.
857 See the manpage section "Builder Objects"
858 for a complete explanation of the arguments and behavior.
863 <function>env.Builder</function>()
864 form of the invocation will expand
865 construction variables in any arguments strings,
867 <parameter>action</parameter>
869 at the time it is called
870 using the construction variables in the
871 <varname>env</varname>
872 construction environment through which
873 &f-env-Builder; was called.
876 form delays all variable expansion
877 until after the Builder object is actually called.
882 <scons_function name="CacheDir">
884 (cache_dir, custom_class=None)
890 to maintain a derived-file cache in
891 <parameter>cache_dir</parameter>.
892 The derived files in the cache will be shared
893 among all the builds specifying the same
894 <parameter>cache_dir</parameter>.
896 <parameter>cache_dir</parameter>
898 <constant>None</constant>
899 disables derived file caching.
903 Calling the environment method
904 &f-link-env-CacheDir;
905 limits the effect to targets built
906 through the specified construction environment.
907 Calling the global function
909 sets a global default
910 that will be used by all targets built
911 through construction environments
912 that do not set up environment-specific
913 caching by calling &f-env-CacheDir;.
917 Caching behavior can be configured by passing a specialized cache
918 class as the optional <parameter>custom_class</parameter> parameter.
919 This class must be a subclass of
920 <classname>SCons.CacheDir.CacheDir</classname>.
921 &SCons; will internally invoke the custom class for performing
923 If the parameter is omitted or set to
924 <constant>None</constant>, &SCons; will use the default
925 <classname>SCons.CacheDir.CacheDir</classname> class.
929 When derived-file caching
932 finds a derived file that needs to be rebuilt,
933 it will first look in the cache to see if a
934 file with matching &buildsig; exists
935 (indicating the input file(s) and build action(s)
936 were identical to those for the current target),
937 and if so, will retrieve the file from the cache.
940 <computeroutput>Retrieved `file' from cache</computeroutput>
941 instead of the normal build message.
942 If the derived file is not present in the cache,
945 then place a copy of the built file in the cache,
946 identified by its &buildsig;, for future use.
951 <computeroutput>Retrieved `file' from cache</computeroutput>
952 messages are useful for human consumption,
953 but less useful when comparing log files between
954 &scons; runs which will show differences that are
955 noisy and not actually significant.
957 use the <option>--cache-show</option> option.
958 With this option, &scons; changes printing
959 to always show the action that would
960 have been used to build the file without caching.
965 may be disabled for any invocation
966 of &scons; by giving the
967 <option>--cache-disable</option>
969 cache updating may be disabled, leaving cache
970 fetching enabled, by giving the
971 <option>--cache-readonly</option> option.
976 <option>--cache-force</option>
980 <emphasis>all</emphasis>
981 derived files into the cache,
982 even if they already existed
983 and were not built by this invocation.
984 This is useful to populate a cache
986 <parameter>cache_dir</parameter>
988 or to bring a cache up to date after
989 a build with cache updating disabled
990 (<option>--cache-disable</option>
991 or <option>--cache-readonly</option>)
998 method can be used to disable caching of specific files. This can be
999 useful if inputs and/or outputs of some tool are impossible to
1000 predict or prohibitively large.
1004 Note that (at this time) &SCons; provides no facilities
1005 for managing the derived-file cache. It is up to the developer
1006 to arrange for cache pruning, expiry, access control, etc. if needed.
1012 <scons_function name="Clean">
1014 (targets, files_or_dirs)
1018 This specifies a list of files or directories which should be removed
1019 whenever the targets are specified with the
1021 command line option.
1022 The specified targets may be a list
1023 or an individual target.
1027 and create new targets or add files and directories to the
1028 clean list for the specified targets.
1032 Multiple files or directories should be specified
1033 either as separate arguments to the
1035 method, or as a list.
1037 will also accept the return value of any of the construction environment
1045 function overrides calling
1047 for the same target,
1048 and any targets passed to both functions will
1049 <emphasis>not</emphasis>
1060 Clean('foo', ['bar', 'baz'])
1061 Clean('dist', env.Program('hello', 'hello.c'))
1062 Clean(['foo', 'bar'], 'something_else_to_clean')
1067 installing the project creates a subdirectory for the documentation.
1068 This statement causes the subdirectory to be removed
1069 if the project is deinstalled.
1072 Clean(docdir, os.path.join(docdir, projectname))
1077 <scons_function name="Clone">
1078 <arguments signature="env">
1083 Returns an independent copy of a &consenv;.
1084 If there are any unrecognized keyword arguments specified,
1085 they are added as &consvars; in the copy,
1086 overwriting any existing values
1088 See the manpage section "Construction Environments" for more details.
1097 env3 = env.Clone(CCFLAGS='-g')
1101 A list of <parameter>tools</parameter>
1102 and a <parameter>toolpath</parameter> may be specified,
1103 as in the &f-link-Environment; constructor:
1110 env4 = env.Clone(tools=['msvc', MyTool])
1115 <parameter>parse_flags</parameter>
1116 keyword argument is also recognized, to allow merging command-line
1117 style arguments into the appropriate construction
1118 variables (see &f-link-env-MergeFlags;).
1122 # create an environment for compiling programs that use wxWidgets
1123 wx_env = env.Clone(parse_flags='!wx-config --cflags --cxxflags')
1127 The <parameter>variables</parameter>
1128 keyword argument is also recognized, to allow (re)initializing
1129 &consvars; from a <literal>Variables</literal> object.
1133 <emphasis>Changed in version 4.8.0:</emphasis>
1134 the <parameter>variables</parameter> parameter was added.
1139 <builder name="Command">
1142 There is actually no Builder named &Command;,
1143 rather the term "Command Builder" refers to
1144 a function which, on each call, creates and calls
1145 an anonymous Builder.
1146 This is useful for "one-off" builds
1147 where a full Builder is not needed.
1148 Since the anonymous Builder is never hooked
1149 into the standard Builder framework,
1150 an Action must always be specfied.
1151 See the &f-link-Command; function description
1152 for the calling syntax and details.
1157 <scons_function name="Command">
1159 (target, source, action, [key=val, ...])
1163 Creates an anonymous builder and calls it,
1164 thus recording <parameter>action</parameter>
1165 to build <parameter>target</parameter>
1166 from <parameter>source</parameter>
1167 into the dependency tree.
1168 This can be more convenient for a single special-case build
1169 than having to define and add a new named Builder.
1174 &Command; function accepts the
1175 <parameter>source_scanner</parameter> and
1176 <parameter>target_scanner</parameter>
1177 keyword arguments which are used to specify
1178 custom scanners for the specified sources or targets.
1179 The value must be a Scanner object.
1180 For example, the global
1181 <literal>DirScanner</literal>
1183 if any of the sources will be directories
1184 that must be scanned on-disk for
1185 changes to files that aren't
1186 already specified in other Builder or function calls.
1191 &Command; function also accepts the
1192 <parameter>source_factory</parameter> and
1193 <parameter>target_factory</parameter>
1194 keyword arguments which are used to specify
1195 factory functions to create &SCons; Nodes
1196 from any sources or targets specified as strings.
1197 If any sources or targets are already Node objects,
1198 they are not further transformed even if
1199 a factory is specified for them.
1200 The default for each is the &Entry; factory.
1204 These four arguments, if given, are used
1205 in the creation of the Builder.
1206 Other Builder-specific keyword arguments
1207 are not recognized as such.
1208 See the manpage section "Builder Objects"
1209 for more information about how these
1210 arguments work in a Builder.
1214 Any remaining keyword arguments are passed on to the
1215 generated builder when it is called,
1216 and behave as described in the manpage section "Builder Methods",
1218 recognized arguments have their specified meanings,
1219 while the rest are used to override
1220 any same-named existing &consvars;
1225 <parameter>action</parameter> can be an external command,
1226 specified as a string,
1227 or a callable &Python; object;
1228 see the manpage section "Action Objects"
1229 for more complete information.
1230 Also note that a string specifying an external command
1231 may be preceded by an at-sign
1232 (<literal>@</literal>)
1233 to suppress printing the command in question,
1235 (<literal>-</literal>)
1236 to ignore the exit status of the external command.
1247 action="$FOO_BUILD < $SOURCES > $TARGET"
1253 action=["rm -f $TARGET", "$BAR_BUILD < $SOURCES > $TARGET"],
1254 ENV={'PATH': '/usr/local/bin/'},
1259 def rename(env, target, source):
1260 os.rename('.tmp', str(target[0]))
1266 action=["$BAZ_BUILD < $SOURCES > .tmp", rename],
1273 function will usually assume, by default,
1274 that the specified targets and/or sources are Files,
1275 if no other part of the configuration
1276 identifies what type of entries they are.
1277 If necessary, you can explicitly specify
1278 that targets or source nodes should
1279 be treated as directories
1292 env.Command('ddd.list', Dir('ddd'), 'ls -l $SOURCE > $TARGET')
1294 env['DISTDIR'] = 'destination/directory'
1295 env.Command(env.Dir('$DISTDIR')), None, make_distdir)
1299 Also note that SCons will usually
1300 automatically create any directory necessary to hold a target file,
1301 so you normally don't need to create directories by hand.
1306 <scons_function name="Configure">
1307 <arguments signature="global">
1308 (env, [custom_tests, conf_dir, log_file, config_h])
1310 <arguments signature="env">
1311 ([custom_tests, conf_dir, log_file, config_h])
1315 Creates a &Configure; object for integrated
1316 functionality similar to GNU <command>autoconf</command>.
1317 See the manpage section "Configure Contexts"
1318 for a complete explanation of the arguments and behavior.
1323 <scons_function name="Decider">
1329 Specifies that all up-to-date decisions for
1330 targets built through this construction environment
1331 will be handled by the specified
1332 <parameter>function</parameter>.
1333 <parameter>function</parameter> can be the name of
1334 a function or one of the following strings
1335 that specify the predefined decision function
1336 that will be applied:
1342 <term><literal>"content"</literal></term>
1345 Specifies that a target shall be considered out of date and rebuilt
1346 if the dependency's content has changed since the last time
1347 the target was built,
1348 as determined by performing a checksum
1349 on the dependency's contents using the selected hash function,
1350 and comparing it to the checksum recorded the
1351 last time the target was built.
1352 <literal>content</literal> is the default decider.
1355 <emphasis>Changed in version 4.1:</emphasis>
1356 The decider was renamed to <literal>content</literal>
1357 since the hash function is now selectable.
1358 The former name, <literal>MD5</literal>,
1359 can still be used as a synonym, but is deprecated.
1364 <term><literal>"content-timestamp"</literal></term>
1367 Specifies that a target shall be considered out of date and rebuilt
1368 if the dependency's content has changed since the last time
1369 the target was built,
1370 except that dependencies with a timestamp that matches
1371 the last time the target was rebuilt will be
1372 assumed to be up-to-date and
1373 <emphasis>not</emphasis>
1375 This provides behavior very similar
1377 <literal>content</literal>
1378 behavior of always checksumming file contents,
1379 with an optimization of not checking
1380 the contents of files whose timestamps haven't changed.
1381 The drawback is that SCons will
1382 <emphasis>not</emphasis>
1383 detect if a file's content has changed
1384 but its timestamp is the same,
1385 as might happen in an automated script
1388 and runs the build again,
1389 all within a single second.
1392 <emphasis>Changed in version 4.1:</emphasis>
1393 The decider was renamed to <literal>content-timestamp</literal>
1394 since the hash function is now selectable.
1395 The former name, <literal>MD5-timestamp</literal>,
1396 can still be used as a synonym, but is deprecated.
1401 <term><literal>"timestamp-newer"</literal></term>
1404 Specifies that a target shall be considered out of date and rebuilt
1405 if the dependency's timestamp is newer than the target file's timestamp.
1406 This is the behavior of the classic Make utility,
1408 <literal>make</literal>
1409 can be used a synonym for
1410 <literal>timestamp-newer</literal>.
1415 <term><literal>"timestamp-match"</literal></term>
1418 Specifies that a target shall be considered out of date and rebuilt
1419 if the dependency's timestamp is different than the
1420 timestamp recorded the last time the target was built.
1421 This provides behavior very similar to the classic Make utility
1422 (in particular, files are not opened up so that their
1423 contents can be checksummed)
1424 except that the target will also be rebuilt if a
1425 dependency file has been restored to a version with an
1426 <emphasis>earlier</emphasis>
1427 timestamp, such as can happen when restoring files from backup archives.
1439 # Use exact timestamp matches by default.
1440 Decider('timestamp-match')
1442 # Use hash content signatures for any targets built
1443 # with the attached construction environment.
1444 env.Decider('content')
1448 In addition to the above already-available functions, the
1449 <parameter>function</parameter>
1450 argument may be a &Python; function you supply.
1451 Such a function must accept the following four arguments:
1457 <term><parameter>dependency</parameter></term>
1460 The Node (file) which
1462 <parameter>target</parameter>
1464 if it has "changed" since the last tme
1465 <parameter>target</parameter>
1471 <term><parameter>target</parameter></term>
1474 The Node (file) being built.
1476 this is what should get rebuilt
1478 <parameter>dependency</parameter>
1484 <term><parameter>prev_ni</parameter></term>
1487 Stored information about the state of the
1488 <parameter>dependency</parameter>
1490 <parameter>target</parameter>
1492 This can be consulted to match various
1493 file characteristics
1494 such as the timestamp,
1495 size, or &contentsig;.
1500 <term><parameter>repo_node</parameter></term>
1503 If set, use this Node instead of the one specified by
1504 <parameter>dependency</parameter>
1505 to determine if the dependency has changed.
1506 This argument is optional so should be written
1507 as a default argument (typically it would be
1508 written as <parameter>repo_node=None</parameter>).
1509 A caller will normally only set this if the
1510 target only exists in a Repository.
1520 <parameter>function</parameter>
1521 should return a value which evaluates
1522 <constant>True</constant>
1524 <parameter>dependency</parameter>
1525 has "changed" since the last time
1527 <parameter>target</parameter>
1529 (indicating that the target
1530 <emphasis>should</emphasis>
1532 and a value which evaluates
1533 <constant>False</constant>
1535 (indicating that the target should
1536 <emphasis>not</emphasis>
1538 Note that the decision can be made
1539 using whatever criteria are appopriate.
1540 Ignoring some or all of the function arguments
1541 is perfectly normal.
1549 def my_decider(dependency, target, prev_ni, repo_node=None):
1550 return not os.path.exists(str(target))
1552 env.Decider(my_decider)
1557 <scons_function name="Depends">
1559 (target, dependency)
1563 Specifies an explicit dependency;
1565 <parameter>target</parameter>
1568 <parameter>dependency</parameter>
1571 <parameter>target</parameter>
1573 <parameter>dependency</parameter>
1575 (usually the path name of a file or directory)
1577 or a list of strings or Node objects
1578 (such as returned by a Builder call).
1579 This should only be necessary
1580 for cases where the dependency
1581 is not caught by a Scanner
1590 env.Depends('foo', 'other-input-file-for-foo')
1592 mylib = env.Library('mylib.c')
1593 installed_lib = env.Install('lib', mylib)
1594 bar = env.Program('bar.c')
1596 # Arrange for the library to be copied into the installation
1597 # directory before trying to build the "bar" program.
1598 # (Note that this is for example only. A "real" library
1599 # dependency would normally be configured through the $LIBS
1600 # and $LIBPATH variables, not using an env.Depends() call.)
1602 env.Depends(bar, installed_lib)
1607 <scons_function name="Detect">
1608 <arguments signature="env">
1613 Find an executable from one or more choices:
1614 <parameter>progs</parameter> may be a string or a list of strings.
1615 Returns the first value from <parameter>progs</parameter>
1616 that was found, or <constant>None</constant>.
1617 Executable is searched by checking the paths in the execution environment
1618 (<varname>env</varname><literal>['ENV']['PATH']</literal>).
1619 On Windows systems, additionally applies the filename suffixes found in
1620 the execution environment
1621 (<varname>env</varname><literal>['ENV']['PATHEXT']</literal>)
1622 but will not include any such extension in the return value.
1623 &f-env-Detect; is a wrapper around &f-link-env-WhereIs;.
1628 <scons_function name="Dictionary">
1629 <arguments signature="env">
1634 Returns a dictionary object
1635 containing the &consvars; in the &consenv;.
1636 If there are any arguments specified,
1637 the values of the specified &consvars;
1638 are returned as a string (if one
1639 argument) or as a list of strings.
1647 cvars = env.Dictionary()
1648 cc_values = env.Dictionary('CC', 'CCFLAGS', 'CCCOM')
1652 The object returned by &f-link-env-Dictionary; should be treated
1653 as a read-only view into the &consvars;.
1654 Some &consvars; have special internal handling,
1655 and making changes through the &f-env-Dictionary; object can bypass
1656 that handling and cause data inconsistencies.
1657 The primary use of &f-env-Dictionary; is for diagnostic purposes -
1658 it is used widely by test cases specifically because
1659 it bypasses the special handling so that behavior
1666 <scons_function name="Dir">
1672 Returns Directory Node(s).
1673 A Directory Node is an object that represents a directory.
1674 <parameter>name</parameter>
1675 can be a relative or absolute path or a list of such paths.
1676 <parameter>directory</parameter>
1677 is an optional directory that will be used as the parent directory.
1679 <parameter>directory</parameter>
1680 is specified, the current script's directory is used as the parent.
1685 <parameter>name</parameter>
1686 is a single pathname, the corresponding node is returned.
1688 <parameter>name</parameter>
1689 is a list, SCons returns a list of nodes.
1690 Construction variables are expanded in
1691 <parameter>name</parameter>.
1695 Directory Nodes can be used anywhere you
1696 would supply a string as a directory name
1697 to a Builder method or function.
1698 Directory Nodes have attributes and methods
1699 that are useful in many situations;
1700 see manpage section "Filesystem Nodes"
1701 for more information.
1706 <scons_function name="Dump">
1707 <arguments signature="env">
1708 ([key, ...], [format=])
1712 Serializes &consvars; from the current &consenv;
1714 The method supports the following formats specified by
1715 <parameter>format</parameter>,
1716 which must be used a a keyword argument:
1720 <term><literal>pretty</literal></term>
1723 Returns a pretty-printed representation of the variables
1724 (this is the default).
1725 The variables will be presented in &Python; dict form.
1730 <term><literal>json</literal></term>
1733 Returns a JSON-formatted string representation of the variables.
1734 The variables will be presented as a JSON object literal,
1735 the JSON equivalent of a &Python; dict.
1742 If no <varname>key</varname> is supplied,
1743 all the &consvars; are serialized.
1744 If one or more keys are supplied,
1745 only those keys and their values are serialized.
1749 <emphasis>Changed in NEXT_VERSION</emphasis>:
1750 More than one <parameter>key</parameter> can be specified.
1751 The returned string always looks like a dict (or JSON equivalent);
1752 previously a single key serialized only the value,
1753 not the key with the value.
1762 print(env.Dump('CCCOM'))
1763 print(env.Dump('CC', 'CCFLAGS', format='json'))
1767 will print something like:
1771 {'CCCOM': '$CC -o $TARGET -c $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES'}
1779 While this SConstruct:
1788 will print something like:
1792 'ARCOM': '$AR $ARFLAGS $TARGET $SOURCES\n$RANLIB $RANLIBFLAGS $TARGET',
1795 'ASCOM': '$AS $ASFLAGS -o $TARGET $SOURCES',
1803 <scons_function name="Environment">
1809 Return a new &consenv;
1810 initialized with the specified
1811 <parameter>key</parameter>=<replaceable>value</replaceable>
1813 The keyword arguments
1814 <parameter>parse_flags</parameter>,
1815 <parameter>platform</parameter>,
1816 <parameter>toolpath</parameter>,
1817 <parameter>tools</parameter>
1818 and <parameter>variables</parameter>
1819 are specially recognized and do not lead to
1821 See the manpage section "Construction Environments" for more details.
1826 <scons_function name="Execute">
1828 (action, [actionargs ...])
1833 <parameter>action</parameter>
1834 may be an Action object
1835 or it may be a command-line string,
1837 or executable &Python; function,
1838 each of which will first be converted
1839 into an Action object
1841 Any additional arguments to &f-Execute;
1842 are passed on to the &f-link-Action; factory function
1843 which actually creates the Action object
1844 (see the manpage section <link linkend="action_objects">Action Objects</link>
1845 for a description). Example:
1849 Execute(Copy('file.out', 'file.in'))
1852 <para>&f-Execute; performs its action immediately,
1853 as part of the SConscript-reading phase.
1854 There are no sources or targets declared in an
1855 &f-Execute; call, so any objects it manipulates
1856 will not be tracked as part of the &SCons; dependency graph.
1857 In the example above, neither
1858 <filename>file.out</filename> nor
1859 <filename>file.in</filename> will be tracked objects.
1863 &f-Execute; returns the exit value of the command
1864 or return value of the &Python; function.
1866 prints an error message if the executed
1867 <parameter>action</parameter>
1868 fails (exits with or returns a non-zero value),
1870 <emphasis>not</emphasis>,
1871 automatically terminate the build for such a failure.
1872 If you want the build to stop in response to a failed
1875 you must explicitly check for a non-zero return value:
1879 if Execute("mkdir sub/dir/ectory"):
1880 # The mkdir failed, don't try to build.
1886 <scons_function name="File">
1892 Returns File Node(s).
1893 A File Node is an object that represents a file.
1894 <parameter>name</parameter>
1895 can be a relative or absolute path or a list of such paths.
1896 <parameter>directory</parameter>
1897 is an optional directory that will be used as the parent directory.
1899 <parameter>directory</parameter>
1900 is specified, the current script's directory is used as the parent.
1905 <parameter>name</parameter>
1906 is a single pathname, the corresponding node is returned.
1908 <parameter>name</parameter>
1909 is a list, SCons returns a list of nodes.
1910 Construction variables are expanded in
1911 <parameter>name</parameter>.
1915 File Nodes can be used anywhere you
1916 would supply a string as a file name
1917 to a Builder method or function.
1918 File Nodes have attributes and methods
1919 that are useful in many situations;
1920 see manpage section "Filesystem Nodes"
1921 for more information.
1926 <scons_function name="FindFile">
1933 <parameter>file</parameter>
1934 in the path specified by
1935 <parameter>dirs</parameter>.
1936 <parameter>dirs</parameter>
1937 may be a list of directory names or a single directory name.
1938 In addition to searching for files that exist in the filesystem,
1939 this function also searches for derived files
1940 that have not yet been built.
1948 foo = env.FindFile('foo', ['dir1', 'dir2'])
1953 <scons_function name="FindInstalledFiles">
1959 Returns the list of targets set up by the
1967 This function serves as a convenient method to select the contents of
1976 Install('/bin', ['executable_a', 'executable_b'])
1978 # will return the file node list
1979 # ['/bin/executable_a', '/bin/executable_b']
1980 FindInstalledFiles()
1982 Install('/lib', ['some_library'])
1984 # will return the file node list
1985 # ['/bin/executable_a', '/bin/executable_b', '/lib/some_library']
1986 FindInstalledFiles()
1991 <scons_function name="FindSourceFiles">
1997 Returns the list of nodes which serve as the source of the built files.
1998 It does so by inspecting the dependency tree starting at the optional
2000 <parameter>node</parameter>
2001 which defaults to the '"."'-node. It will then return all leaves of
2002 <parameter>node</parameter>.
2003 These are all children which have no further children.
2007 This function is a convenient method to select the contents of a Source
2016 Program('src/main_a.c')
2017 Program('src/main_b.c')
2020 # returns ['main_c.c', 'src/main_a.c', 'SConstruct', 'src/main_b.c']
2023 # returns ['src/main_b.c', 'src/main_a.c' ]
2024 FindSourceFiles('src')
2028 As you can see build support files (SConstruct in the above example)
2029 will also be returned by this function.
2034 <scons_function name="Flatten">
2040 Takes a sequence (that is, a &Python; list or tuple)
2041 that may contain nested sequences
2042 and returns a flattened list containing
2043 all of the individual elements in any sequence.
2044 This can be helpful for collecting
2045 the lists returned by calls to Builders;
2046 other Builders will automatically
2047 flatten lists specified as input,
2048 but direct &Python; manipulation of
2049 these lists does not.
2057 foo = Object('foo.c')
2058 bar = Object('bar.c')
2060 # Because `foo' and `bar' are lists returned by the Object() Builder,
2061 # `objects' will be a list containing nested lists:
2062 objects = ['f1.o', foo, 'f2.o', bar, 'f3.o']
2064 # Passing such a list to another Builder is all right because
2065 # the Builder will flatten the list automatically:
2066 Program(source = objects)
2068 # If you need to manipulate the list directly using &Python;, you need to
2069 # call Flatten() yourself, or otherwise handle nested lists:
2070 for object in Flatten(objects):
2076 <scons_function name="GetBuildPath">
2084 path name (or names) for the specified
2085 <parameter>file</parameter>
2088 <parameter>file</parameter>
2092 Nodes or strings representing path names.
2097 <scons_function name="Glob">
2099 (pattern, [ondisk=True, source=False, strings=False, exclude=None])
2103 Returns a possibly empty list of Nodes (or strings) that match
2104 pathname specification <parameter>pattern</parameter>.
2105 <parameter>pattern</parameter> can be absolute,
2107 or (most commonly) relative to the directory of the current
2109 &f-Glob; matches both files stored on disk and Nodes
2110 which &SCons; already knows about, even if any corresponding
2111 file is not currently stored on disk.
2112 The evironment method form (&f-env-Glob;)
2113 performs string substition on
2114 <parameter>pattern</parameter>
2115 and returns whatever matches the resulting expanded pattern.
2116 The results are sorted, unlike for the similar &Python;
2117 <systemitem>glob.glob</systemitem> function,
2118 to ensure build order will be stable.
2122 <parameter>pattern</parameter>
2123 can contain POSIX-style shell metacharacters for matching:
2126 <informaltable rowsep="1" colsep="1" frame="topbot">
2130 <entry>Pattern</entry>
2131 <entry>Meaning</entry>
2136 <entry><literal>*</literal></entry>
2137 <entry>matches everything</entry>
2140 <entry><literal>?</literal></entry>
2141 <entry>matches any single character</entry>
2144 <entry><literal>[seq]</literal></entry>
2145 <entry>matches any character in <emphasis>seq</emphasis>
2146 (can be a list or a range).</entry>
2149 <entry><literal>[!seq]</literal></entry>
2150 <entry>matches any character not in <emphasis>seq</emphasis></entry>
2157 For a literal match, wrap the metacharacter in brackets to
2158 escape the normal behavior.
2159 For example, <literal>'[?]'</literal> matches the character
2160 <literal>'?'</literal>.
2164 Filenames starting with a dot are specially handled -
2165 they can only be matched by patterns that start with a dot
2166 (or have a dot immediately following a pathname separator
2167 character, or slash), they are not not matched by the metacharacters.
2168 Metacharacter matches also do not span directory separators.
2173 understands repositories
2177 and source directories
2181 and returns a Node (or string, if so configured) match
2182 in the local (SConscript) directory
2183 if a matching Node is found
2184 anywhere in a corresponding
2185 repository or source directory.
2190 <parameter>ondisk</parameter>
2191 argument evaluates false,
2192 the search for matches on disk is disabled,
2193 and only matches from
2194 already-configured File or Dir Nodes are returned.
2195 The default is to return Nodes for
2196 matches on disk as well.
2201 <parameter>source</parameter>
2202 argument evaluates true,
2203 and the local directory is a variant directory,
2204 then &f-Glob; returnes Nodes from
2205 the corresponding source directory,
2206 rather than the local directory.
2207 <!-- XXX what about generated files that don't exist in src but will be sources? -->
2212 <parameter>strings</parameter>
2213 argument evaluates true,
2215 returns matches as strings, rather than Nodes.
2216 The returned strings will be relative to
2217 the local (SConscript) directory.
2218 (Note that while this may make it easier to perform
2219 arbitrary manipulation of file names,
2220 it loses the context &SCons; would have in the Node,
2221 so if the returned strings are
2222 passed to a different
2225 any Node translation there will be relative
2236 <parameter>exclude</parameter>
2237 argument may be set to a pattern or a list of patterns
2238 descibing files or directories
2239 to filter out of the match list.
2240 Elements matching a least one specified pattern will be excluded.
2241 These patterns use the same syntax as for
2242 <parameter>pattern</parameter>.
2250 Program("foo", Glob("*.c"))
2251 Zip("/tmp/everything", Glob(".??*") + Glob("*"))
2252 sources = Glob("*.cpp", exclude=["os_*_specific_*.cpp"]) \
2253 + Glob("os_%s_specific_*.cpp" % currentOS)
2260 <scons_function name="GlobalBuilders">
2261 <arguments signature="global">
2267 <parameter>flag</parameter>
2269 adds the names of the default builders
2270 (Program, Library, etc.)
2271 to the global name space
2272 so they can be called without an explicit construction environment.
2273 (This is the default.)
2275 <parameter>flag</parameter>
2277 the names of the default builders are removed
2278 from the global name space
2279 so that an explicit construction environment is required
2280 to call all builders.
2286 <scons_function name="Ignore">
2288 (target, dependency)
2292 Ignores <parameter>dependency</parameter>
2294 <parameter>target</parameter> needs to be rebuilt.
2295 <parameter>target</parameter> and
2296 <parameter>dependency</parameter>
2297 can each be a single filename or Node
2298 or a list of filenames or Nodes.
2302 &f-Ignore; can also be used to
2303 remove a target from the default build
2304 by specifying the directory the target will be built in as
2305 <parameter>target</parameter>
2306 and the file you want to skip selecting for building as
2307 <parameter>dependency</parameter>.
2308 Note that this only removes the target from
2309 the default target selection algorithm:
2310 if it is a dependency of another object being
2311 built &SCons; still builds it normally.
2312 See the third and forth examples below.
2320 env.Ignore('foo', 'foo.c')
2321 env.Ignore('bar', ['bar1.h', 'bar2.h'])
2322 env.Ignore('.', 'foobar.obj')
2323 env.Ignore('bar', 'bar/foobar.obj')
2328 <scons_function name="Literal">
2335 <parameter>string</parameter>
2336 will be preserved as-is
2337 and not have construction variables expanded.
2342 <scons_function name="Local">
2349 <parameter>targets</parameter>
2350 will have copies made in the local tree,
2351 even if an already up-to-date copy
2352 exists in a repository.
2353 Returns a list of the target Node or Nodes.
2359 <scons_function name="MergeShellPaths">
2360 <arguments signature="env">
2361 ( arg ", [" prepend ])
2365 Merges the elements of the specified
2366 <parameter>arg</parameter>,
2367 which must be a dictionary, to the construction
2368 environment's copy of the shell environment
2370 (This is the environment which is passed
2371 to subshells spawned by SCons.)
2373 <parameter>arg</parameter>
2374 must be a single value,
2375 so multiple strings must
2376 be passed in as a list,
2377 not as separate arguments to
2378 &f-MergeShellPaths;.
2382 New values are prepended to the environment variable by default,
2383 unless prepend=0 is specified.
2384 Duplicate values are always eliminated,
2385 since this function calls
2386 &f-link-AppendENVPath;
2388 &f-link-PrependENVPath;
2390 <parameter>prepend</parameter>
2391 argument. See those functions for more details.
2399 # Prepend a path to the shell PATH.
2400 env.MergeShellPaths({'PATH': '/usr/local/bin'})
2401 # Append two dirs to the shell INCLUDE.
2402 env.MergeShellPaths({'INCLUDE': ['c:/inc1', 'c:/inc2']}, prepend=0)
2408 <scons_function name="MergeFlags">
2409 <arguments signature="env">
2415 <parameter>arg</parameter>
2416 into &consvars; in <parameter>env</parameter>.
2417 If <parameter>arg</parameter> is a dictionary,
2418 each key-value pair represents a
2419 &consvar; name and the corresponding flags to merge.
2420 If <parameter>arg</parameter>
2421 is not a dictionary,
2422 &MergeFlags; attempts to convert it to one
2423 before the values are merged.
2424 &f-link-env-ParseFlags; is used for this,
2425 so values to be converted are subject to the
2427 &ParseFlags; has knowledge of which &consvars; certain
2428 flags should go to, but not all;
2429 and only for GCC and compatible compiler chains.
2430 <parameter>arg</parameter>
2431 must be a single object,
2432 so to pass multiple strings,
2433 enclose them in a list.
2437 If <literal>unique</literal> is true (the default),
2438 duplicate values are not retained.
2439 In case of duplication,
2440 any &consvar; names that end in
2441 <literal>PATH</literal>
2442 keep the left-most value so the
2443 path searcb order is not altered.
2444 All other &consvars; keep
2445 the right-most value.
2446 If <literal>unique</literal> is false,
2447 values are appended even if they are duplicates.
2455 # Add an optimization flag to $CCFLAGS.
2456 env.MergeFlags({'CCFLAGS': '-O3'})
2458 # Combine the flags returned from running pkg-config with an optimization
2459 # flag and merge the result into the construction variables.
2460 env.MergeFlags(['!pkg-config gtk+-2.0 --cflags', '-O3'])
2462 # Combine an optimization flag with the flags returned from running pkg-config
2463 # for two distinct packages and merge into the construction variables.
2467 '!pkg-config gtk+-2.0 --cflags --libs',
2468 '!pkg-config libpng12 --cflags --libs',
2475 <scons_function name="NoCache">
2481 Specifies a list of files which should
2482 <emphasis>not</emphasis>
2483 be cached whenever the
2485 method has been activated.
2486 The specified targets may be a list
2487 or an individual target.
2491 Multiple files should be specified
2492 either as separate arguments to the
2494 method, or as a list.
2496 will also accept the return value of any of the construction environment
2503 on directories and other non-File Node types has no effect because
2504 only File Nodes are cached.
2513 NoCache(env.Program('hello', 'hello.c'))
2518 <scons_function name="NoClean">
2524 Specifies a list of files or directories which should
2525 <emphasis>not</emphasis>
2526 be removed whenever the targets (or their dependencies)
2527 are specified with the
2529 command line option.
2530 The specified targets may be a list
2531 or an individual target.
2535 and prevent each specified target
2536 from being removed by calls to the
2542 Multiple files or directories should be specified
2543 either as separate arguments to the
2545 method, or as a list.
2547 will also accept the return value of any of the construction environment
2554 for a target overrides calling
2556 for the same target,
2557 and any targets passed to both functions will
2558 <emphasis>not</emphasis>
2570 NoClean(env.Program('hello', 'hello.c'))
2575 <scons_function name="ParseConfig">
2576 <arguments signature="env">
2577 (command, [function, unique])
2581 Updates the current &consenv; with the values extracted
2582 from the output of running external <parameter>command</parameter>,
2583 by passing it to a helper <parameter>function</parameter>.
2584 <parameter>command</parameter> may be a string
2585 or a list of strings representing the command and
2587 If <parameter>function</parameter>
2588 is omitted or <constant>None</constant>,
2589 &f-link-env-MergeFlags; is used.
2591 duplicate values are not
2592 added to any construction variables;
2594 <parameter>unique=False</parameter>
2595 to allow duplicate values to be added.
2599 <parameter>command</parameter> is executed using the
2600 SCons execution environment (that is, the &consvar;
2601 &cv-link-ENV; in the current &consenv;).
2602 If <parameter>command</parameter> needs additional information
2603 to operate properly, that needs to be set in the execution environment.
2604 For example, <command>pkg-config</command>
2605 may need a custom value set in the <envar>PKG_CONFIG_PATH</envar>
2606 environment variable.
2610 &f-env-MergeFlags; needs to understand
2611 the output produced by <parameter>command</parameter>
2612 in order to distribute it to appropriate &consvars;.
2613 &f-env-MergeFlags; uses a separate function to
2614 do that processing -
2615 see &f-link-env-ParseFlags; for the details, including a
2616 a table of options and corresponding construction variables.
2617 To provide alternative processing of the output of
2618 <parameter>command</parameter>,
2619 you can suppply a custom
2620 <parameter>function</parameter>,
2621 which must accept three arguments:
2622 the &consenv; to modify,
2623 a string argument containing the output from running
2624 <parameter>command</parameter>,
2626 <parameter>unique</parameter> flag.
2631 <scons_function name="ParseDepends">
2633 (filename, [must_exist, only_one])
2637 Parses the contents of <parameter>filename</parameter>
2638 as a list of dependencies in the style of
2641 <application>mkdep</application>,
2642 and explicitly establishes all of the listed dependencies.
2648 if <parameter>filename</parameter>
2651 <parameter>must_exist</parameter>
2652 argument may be set to <constant>True</constant>
2654 raise an exception if the file does not exist,
2655 or is otherwise inaccessible.
2660 <parameter>only_one</parameter>
2661 argument may be set to <constant>True</constant>
2662 to have &SCons; raise an exception
2663 if the file contains dependency
2664 information for more than one target.
2665 This can provide a small sanity check
2666 for files intended to be generated
2667 by, for example, the
2668 <literal>gcc -M</literal>
2670 which should typically only
2671 write dependency information for
2672 one output file into a corresponding
2673 <filename>.d</filename>
2678 <parameter>filename</parameter>
2679 and all of the files listed therein
2680 will be interpreted relative to
2681 the directory of the
2683 file which calls the
2690 <scons_function name="ParseFlags">
2691 <arguments signature="env">
2696 Parses one or more strings containing
2697 typical command-line flags for GCC-style tool chains
2698 and returns a dictionary with the flag values
2699 separated into the appropriate SCons construction variables.
2700 Intended as a companion to the
2701 &f-link-env-MergeFlags;
2702 method, but allows for the values in the returned dictionary
2703 to be modified, if necessary,
2704 before merging them into the construction environment.
2707 will call this method if its argument is not a dictionary,
2708 so it is usually not necessary to call
2710 directly unless you want to manipulate the values.)
2714 If the first character in any string is
2715 an exclamation mark (<literal>!</literal>),
2716 the rest of the string is executed as a command,
2717 and the output from the command is
2718 parsed as GCC tool chain command-line flags
2719 and added to the resulting dictionary.
2720 This can be used to call a <filename>*-config</filename>
2721 command typical of the POSIX programming environment
2723 <command>pkg-config</command>).
2724 Note that such a command is executed using the
2725 SCons execution environment;
2726 if the command needs additional information,
2727 that information needs to be explicitly provided.
2728 See &f-link-ParseConfig; for more details.
2732 Flag values are translated according to the prefix found,
2733 and added to the following construction variables:
2737 -arch CCFLAGS, LINKFLAGS
2739 -framework FRAMEWORKS
2740 -frameworkdir= FRAMEWORKPATH
2741 -fmerge-all-constants CCFLAGS, LINKFLAGS
2742 -fopenmp CCFLAGS, LINKFLAGS
2743 -fsanitize CCFLAGS, LINKFLAGS
2746 -isysroot CCFLAGS, LINKFLAGS
2753 -mno-cygwin CCFLAGS, LINKFLAGS
2755 -openmp CCFLAGS, LINKFLAGS
2756 -pthread CCFLAGS, LINKFLAGS
2759 -Wa, ASFLAGS, CCFLAGS
2766 + CCFLAGS, LINKFLAGS
2770 Any other strings not associated with options
2771 are assumed to be the names of libraries
2774 construction variable.
2778 Examples (all of which produce the same result):
2782 dict = env.ParseFlags('-O2 -Dfoo -Dbar=1')
2783 dict = env.ParseFlags('-O2', '-Dfoo', '-Dbar=1')
2784 dict = env.ParseFlags(['-O2', '-Dfoo -Dbar=1'])
2785 dict = env.ParseFlags('-O2', '!echo -Dfoo -Dbar=1')
2790 <scons_function name="Platform">
2791 <arguments signature="global">
2794 <arguments signature="env">
2799 When called as a global function,
2800 returns a callable platform object
2801 selected by <parameter>plat</parameter>
2802 (defaults to the detected platform for the
2804 that can be used to initialize
2805 a construction environment by passing it as the
2806 <parameter>platform</parameter> keyword argument to the
2807 &f-link-Environment; function.
2815 env = Environment(platform=Platform('win32'))
2819 When called as a method of an environment,
2820 calls the platform object indicated by
2821 <parameter>plat</parameter>
2822 to update that environment.
2826 env.Platform('posix')
2830 See the manpage section "Construction Environments" for more details.
2835 <scons_function name="Prepend">
2836 <arguments signature="env">
2841 Prepend values to &consvars; in the current &consenv;,
2842 Works like &f-link-env-Append; (see for details),
2843 except that values are added to the front,
2844 rather than the end, of any existing value of the &consvar;
2852 env.Prepend(CCFLAGS='-g ', FOO=['foo.yyy'])
2856 See also &f-link-env-Append;,
2857 &f-link-env-AppendUnique;
2858 and &f-link-env-PrependUnique;.
2863 <scons_function name="PrependENVPath">
2864 <arguments signature="env">
2865 (name, newpath, [envname, sep, delete_existing=True])
2869 Prepend path elements specified by <parameter>newpath</parameter>
2870 to the given search path string or list <parameter>name</parameter>
2871 in mapping <parameter>envname</parameter> in the &consenv;.
2872 Supplying <parameter>envname</parameter> is optional:
2873 the default is the execution environment &cv-link-ENV;.
2874 Optional <parameter>sep</parameter> is used as the search path separator,
2875 the default is the platform's separator (<systemitem>os.pathsep</systemitem>).
2876 A path element will only appear once.
2877 Any duplicates in <parameter>newpath</parameter> are dropped,
2878 keeping the first appearing (to preserve path order).
2879 If <parameter>delete_existing</parameter>
2880 is <constant>False</constant>
2881 any addition duplicating an existing path element is ignored;
2882 if <parameter>delete_existing</parameter>
2883 is <constant>True</constant> (the default) the existing value will
2884 be dropped and the path element will be inserted at the beginning.
2885 To help maintain uniqueness all paths are normalized (using
2886 <systemitem>os.path.normpath</systemitem>
2888 <systemitem>os.path.normcase</systemitem>).
2896 print('before:', env['ENV']['INCLUDE'])
2897 include_path = '/foo/bar:/foo'
2898 env.PrependENVPath('INCLUDE', include_path)
2899 print('after:', env['ENV']['INCLUDE'])
2902 <para>Yields:</para>
2906 after: /foo/bar:/foo:/biz
2910 See also &f-link-env-AppendENVPath;.
2916 <scons_function name="PrependUnique">
2917 <arguments signature="env">
2918 (key=val, [...], [delete_existing=False])
2922 Prepend values to &consvars; in the current &consenv;,
2923 maintaining uniqueness.
2924 Works like &f-link-env-Append;,
2925 except that values are added to the front,
2926 rather than the end, of the &consvar;,
2927 and values that would become duplicates
2929 If <parameter>delete_existing</parameter>
2930 is set to a true value, then for any duplicate,
2931 the existing instance of <parameter>val</parameter> is first removed,
2932 then <parameter>val</parameter> is inserted,
2933 having the effect of moving it to the front.
2941 env.PrependUnique(CCFLAGS='-g', FOO=['foo.yyy'])
2945 See also &f-link-env-Append;,
2946 &f-link-env-AppendUnique;
2947 and &f-link-env-Prepend;.
2952 <scons_function name="PyPackageDir">
2958 Finds the location of <parameter>modulename</parameter>,
2959 which can be a string or a sequence of strings,
2960 each representing the name of a &Python; module.
2961 Construction variables are expanded in
2962 <parameter>modulename</parameter>.
2963 Returns a Directory Node (see &f-link-Dir;),
2964 or a list of Directory Nodes if
2965 <parameter>modulename</parameter> is a sequence.
2966 <literal>None</literal> is returned for any module not found.
2970 When a Tool module which is installed as a
2971 &Python; module is used, you need
2972 to specify a <parameter>toolpath</parameter> argument to
2974 &f-link-Environment;
2976 as tools outside the standard project locations
2977 (<filename>site_scons/site_tools</filename>)
2978 will not be found otherwise.
2979 Using &f-PyPackageDir; allows this path to be
2980 discovered at runtime instead of hardcoding the path.
2989 tools=["default", "ExampleTool"],
2990 toolpath=[PyPackageDir("example_tool")]
2996 <scons_function name="Replace">
2997 <arguments signature="env">
3002 Replaces construction variables in the Environment
3003 with the specified keyword arguments.
3011 env.Replace(CCFLAGS='-g', FOO='foo.xxx')
3016 <scons_function name="Repository">
3023 <parameter>directory</parameter>
3024 is a repository to be searched for files.
3028 and each one adds to the list of
3029 repositories that will be searched.
3035 a repository is a copy of the source tree,
3036 from the top-level directory on down,
3038 both source files and derived files
3039 that can be used to build targets in
3040 the local source tree.
3041 The canonical example would be an
3042 official source tree maintained by an integrator.
3043 If the repository contains derived files,
3044 then the derived files should have been built using
3046 so that the repository contains the necessary
3047 signature information to allow
3049 to figure out when it is appropriate to
3050 use the repository copy of a derived file,
3051 instead of building one locally.
3055 Note that if an up-to-date derived file
3056 already exists in a repository,
3059 <emphasis>not</emphasis>
3060 make a copy in the local directory tree.
3061 In order to guarantee that a local copy
3070 <scons_function name="Requires">
3072 (target, prerequisite)
3076 Specifies an order-only relationship
3077 between <parameter>target</parameter>
3078 and <parameter>prerequisite</parameter>.
3080 will be (re)built, if necessary,
3081 <emphasis>before</emphasis>
3083 but the target file(s) do not actually
3084 depend on the prerequisites
3085 and will not be rebuilt simply because
3086 the prerequisite file(s) change.
3087 <parameter>target</parameter> and
3088 <parameter>prerequisite</parameter> may each
3089 be a string or Node, or a list of strings or Nodes.
3090 If there are multiple
3091 <parameter>target</parameter> values,
3092 the prerequisite(s) are added to each one.
3093 Returns a list of the affected target nodes.
3101 env.Requires('foo', 'file-that-must-be-built-before-foo')
3106 <scons_function name="Scanner">
3108 (function, [name, argument, skeys, path_function, node_class, node_factory, scan_check, recursive])
3112 Creates a Scanner object for
3114 <parameter>function</parameter>.
3115 See manpage section "Scanner Objects"
3116 for a complete explanation of the arguments and behavior.
3121 <scons_function name="SConscriptChdir">
3122 <arguments signature="global">
3129 changes its working directory
3130 to the directory in which each
3131 subsidiary SConscript file lives
3132 while reading and processing that script.
3133 This behavior may be disabled
3134 by specifying an argument which
3135 evaluates false, in which case
3137 will stay in the top-level directory
3138 while reading all SConscript files.
3139 (This may be necessary when building from repositories,
3140 when all the directories in which SConscript files may be found
3141 don't necessarily exist locally.)
3142 You may enable and disable
3143 this ability by calling
3153 SConscriptChdir(False)
3154 SConscript('foo/SConscript') # will not chdir to foo
3155 SConscriptChdir(True)
3156 SConscript('bar/SConscript') # will chdir to bar
3161 <scons_function name="SConsignFile">
3163 ([name, dbm_module])
3167 Specify where to store the &SCons; file signature database,
3168 and which database format to use.
3169 This may be useful to specify alternate
3170 database files and/or file locations for different types of builds.
3173 The optional <parameter>name</parameter> argument
3174 is the base name of the database file(s).
3175 If not an absolute path name,
3176 these are placed relative to the directory containing the
3177 top-level &SConstruct; file.
3179 <filename>.sconsign</filename>.
3180 The actual database file(s) stored on disk
3181 may have an appropriate suffix appended
3183 <parameter>dbm_module</parameter>
3186 The optional <parameter>dbm_module</parameter>
3187 argument specifies which
3188 &Python; database module to use
3189 for reading/writing the file.
3190 The module must be imported first;
3191 then the imported module name
3192 is passed as the argument.
3193 The default is a custom
3194 <systemitem>SCons.dblite</systemitem>
3195 module that uses pickled
3196 &Python; data structures,
3197 which works on all &Python; versions.
3198 See documentation of the &Python;
3199 <systemitem>dbm</systemitem> module
3200 for other available types.
3203 If called with no arguments,
3204 the database will default to
3205 <filename>.sconsign.dblite</filename>
3206 in the top directory of the project,
3207 which is also the default if
3208 if &f-SConsignFile; is not called.
3211 The setting is global, so the only difference
3212 between the global function and the environment method form
3213 is variable expansion on <parameter>name</parameter>.
3214 There should only be one active call to this
3215 function/method in a given build setup.
3219 <parameter>name</parameter>
3221 <constant>None</constant>,
3223 will store file signatures
3225 <filename>.sconsign</filename>
3226 file in each directory,
3227 not in a single combined database file.
3228 This is a backwards-compatibility meaure to support
3229 what was the default behavior
3230 prior to &SCons; 0.97 (i.e. before 2008).
3231 Use of this mode is discouraged and may be
3232 deprecated in a future &SCons; release.
3240 # Explicitly stores signatures in ".sconsign.dblite"
3241 # in the top-level SConstruct directory (the default behavior).
3244 # Stores signatures in the file "etc/scons-signatures"
3245 # relative to the top-level SConstruct directory.
3246 # SCons will add a database suffix to this name.
3247 SConsignFile("etc/scons-signatures")
3249 # Stores signatures in the specified absolute file name.
3250 # SCons will add a database suffix to this name.
3251 SConsignFile("/home/me/SCons/signatures")
3253 # Stores signatures in a separate .sconsign file
3254 # in each directory.
3257 # Stores signatures in a GNU dbm format .sconsign file
3259 SConsignFile(dbm_module=dbm.gnu)
3264 <scons_function name="SetDefault">
3265 <arguments signature="env">
3270 Sets construction variables to default values specified with the keyword
3271 arguments if (and only if) the variables are not already set.
3272 The following statements are equivalent:
3276 env.SetDefault(FOO='foo')
3277 if 'FOO' not in env:
3283 <scons_function name="SideEffect">
3285 (side_effect, target)
3290 <parameter>side_effect</parameter>
3291 as a side effect of building
3292 <parameter>target</parameter>.
3294 <parameter>side_effect</parameter>
3296 <parameter>target</parameter>
3297 can be a list, a file name, or a node.
3298 A side effect is a target file that is created or updated
3299 as a side effect of building other targets.
3300 For example, a Windows PDB
3301 file is created as a side effect of building the .obj
3302 files for a static library,
3303 and various log files are created updated
3304 as side effects of various TeX commands.
3305 If a target is a side effect of multiple build commands,
3307 will ensure that only one set of commands
3308 is executed at a time.
3309 Consequently, you only need to use this method
3310 for side-effect targets that are built as a result of
3311 multiple build commands.
3315 Because multiple build commands may update
3316 the same side effect file,
3318 <parameter>side_effect</parameter>
3320 <emphasis>not</emphasis>
3321 automatically removed
3323 <parameter>target</parameter>
3327 (Note, however, that the
3328 <parameter>side_effect</parameter>
3329 might be removed as part of
3330 cleaning the directory in which it lives.)
3331 If you want to make sure the
3332 <parameter>side_effect</parameter>
3333 is cleaned whenever a specific
3334 <parameter>target</parameter>
3336 you must specify this explicitly
3345 This function returns the list of side effect Node objects that were successfully added.
3346 If the list of side effects contained any side effects that had already been added,
3347 they are not added and included in the returned list.
3352 <scons_function name="Split">
3353 <arguments>(arg)</arguments>
3356 If <parameter>arg</parameter> is a string,
3357 splits on whitespace and returns a list of
3358 strings without whitespace.
3359 This mode is the most common case,
3360 and can be used to split a list of filenames
3361 (for example) rather than having to type them as a
3362 list of individually quoted words.
3363 If <parameter>arg</parameter> is a list or tuple
3364 returns the list or tuple unchanged.
3365 If <parameter>arg</parameter> is any other type of object,
3366 returns a list containing just the object.
3367 These non-string cases do not actually do any spliting,
3368 but allow an argument variable to be passed to
3369 &f-Split; without having to first check its type.
3377 files = Split("f1.c f2.c f3.c")
3378 files = env.Split("f4.c f5.c f6.c")
3388 <scons_function name="subst">
3389 <arguments signature="env">
3390 (input, [raw, target, source, conv])
3394 Performs &consvar; interpolation
3395 (<firstterm>substitution</firstterm>)
3396 on <parameter>input</parameter>,
3397 which can be a string or a sequence.
3398 Substitutable elements take the form
3399 <literal>${<replaceable>expression</replaceable>}</literal>,
3400 although if there is no ambiguity in recognizing the element,
3401 the braces can be omitted.
3402 A literal <emphasis role="bold">$</emphasis> can be entered by
3403 using <emphasis role="bold">$$</emphasis>.
3408 leading or trailing white space will
3409 be removed from the result,
3410 and all sequences of white space
3411 will be compressed to a single space character.
3413 <literal>$(</literal>
3415 <literal>$)</literal>
3416 character sequences will be stripped from the returned string,
3418 <parameter>raw</parameter>
3419 argument may be set to
3420 <literal>1</literal>
3421 if you want to preserve white space and
3422 <literal>$(</literal>-<literal>$)</literal>
3425 <parameter>raw</parameter>
3426 argument may be set to
3427 <literal>2</literal>
3428 if you want to additionally discard
3429 all characters between any
3430 <literal>$(</literal>
3432 <literal>$)</literal>
3434 (as is done for signature calculation).
3438 If <parameter>input</parameter> is a sequence
3440 the individual elements of
3441 the sequence will be expanded,
3442 and the results will be returned as a list.
3447 <parameter>target</parameter>
3449 <parameter>source</parameter>
3451 must be set to lists of
3452 target and source nodes, respectively,
3459 to be available for expansion.
3460 This is usually necessary if you are
3463 from within a &Python; function used
3468 Returned string values or sequence elements
3469 are converted to their string representation by default.
3471 <parameter>conv</parameter>
3473 may specify a conversion function
3474 that will be used in place of
3476 For example, if you want &Python; objects
3477 (including SCons Nodes)
3478 to be returned as &Python; objects,
3479 you can use a &Python;
3480 lambda expression to pass in an unnamed function
3481 that simply returns its unconverted argument.
3489 print(env.subst("The C compiler is: $CC"))
3491 def compile(target, source, env):
3492 sourceDir = env.subst(
3498 source_nodes = env.subst('$EXPAND_TO_NODELIST', conv=lambda x: x)
3503 <scons_function name="Tool">
3505 (name, [toolpath, key=value, ...])
3510 Locates the tool specification module <parameter>name</parameter>
3511 and returns a callable tool object for that tool.
3512 When the environment method (&f-env-Tool;) form is used,
3513 the tool object is automatically called before the method returns
3514 to update <varname>env</varname>,
3515 and <parameter>name</parameter> is
3516 appended to the &cv-link-TOOLS;
3517 &consvar; in that environment.
3518 When the global function &f-Tool; form is used,
3519 the tool object is constructed but not called,
3520 as it lacks the context of an environment to update,
3521 and the returned object needs to be used to arrange for the call.
3525 The tool module is searched for in the tool search paths (see the
3526 <emphasis role="bold">Tools</emphasis> section in the manual page
3528 and in any paths specified by the optional
3529 <parameter>toolpath</parameter> parameter,
3530 which must be a list of strings.
3531 If <parameter>toolpath</parameter> is omitted,
3532 the <parameter>toolpath</parameter>
3533 supplied when the environment was created,
3538 Any remaining keyword arguments are saved in
3540 and will be passed to the tool module's
3541 <function>generate</function> function
3542 when the tool object is actually called.
3543 The <function>generate</function> function
3544 can update the &consenv; with &consvars; and arrange
3545 any other initialization
3546 needed to use the mechanisms that tool describes,
3547 and can use these extra arguments to help
3552 <emphasis>Changed in version 4.2:</emphasis>
3553 &f-env-Tool; now returns the tool object,
3554 previously it did not return (i.e. returned <constant>None</constant>).
3563 env.Tool('opengl', toolpath=['build/tools'])
3567 The returned tool object can be passed to an
3568 &f-link-Environment; or &f-link-Clone; call
3569 as part of the <parameter>tools</parameter> keyword argument,
3570 in which case the tool is applied to the environment being constructed,
3571 or it can be called directly,
3572 in which case a &consenv; to update must be
3573 passed as the argument.
3574 Either approach will also update the
3575 &cv-TOOLS; &consvar;.
3583 env = Environment(tools=[Tool('msvc')])
3586 msvctool = Tool('msvc')
3587 msvctool(env) # adds 'msvc' to the TOOLS variable
3588 gltool = Tool('opengl', toolpath = ['tools'])
3589 gltool(env) # adds 'opengl' to the TOOLS variable
3594 <scons_function name="Value">
3596 (value, [built_value], [name])
3600 Returns a Node object representing the specified &Python;
3601 <parameter>value</parameter>.
3602 Value Nodes can be used as dependencies of targets.
3603 If the string representation of the Value Node
3604 changes between &SCons; runs, it is considered
3605 out of date and any targets depending it will be rebuilt.
3606 Since Value Nodes have no filesystem representation,
3607 timestamps are not used; the timestamp deciders
3608 perform the same content-based up to date check.
3612 <parameter>built_value</parameter>
3613 argument can be specified
3614 when the Value Node is created
3615 to indicate the Node should already be considered "built."
3619 The optional <parameter>name</parameter> parameter can be provided as an
3620 alternative name for the resulting <literal>Value</literal> node;
3621 this is advised if the <parameter>value</parameter> parameter
3622 cannot be converted to a string.
3627 <methodname>write</methodname>
3628 method that can be used to "build" a Value Node
3629 by setting a new value.
3631 <methodname>read</methodname>
3632 method returns the built value of the Node.
3636 <emphasis>Changed in version 4.0:</emphasis>
3637 the <parameter>name</parameter> parameter was added.
3644 <!-- TODO fix second example or replace - still doesn't work -->
3648 def create(target, source, env):
3649 """Action function to create a file from a Value.
3651 Writes 'prefix=$SOURCE' into the file name given as $TARGET.
3653 with open(str(target[0]), 'wb') as f:
3654 f.write(b'prefix=' + source[0].get_contents() + b'\n')
3656 # Fetch the prefix= argument, if any, from the command line.
3657 # Use /usr/local as the default.
3658 prefix = ARGUMENTS.get('prefix', '/usr/local')
3660 # Attach builder named Config to the construction environment
3661 # using the 'create' action function above.
3662 env['BUILDERS']['Config'] = Builder(action=create)
3663 env.Config(target='package-config', source=Value(prefix))
3665 def build_value(target, source, env):
3666 """Action function to "build" a Value.
3668 Writes contents of $SOURCE into $TARGET, thus updating if it existed.
3670 target[0].write(source[0].get_contents())
3672 output = env.Value('before')
3673 input = env.Value('after')
3675 # Attach a builder named UpdateValue to the construction environment
3676 # using the 'build_value' action function above.
3677 env['BUILDERS']['UpdateValue'] = Builder(action=build_value)
3678 env.UpdateValue(target=Value(output), source=Value(input))
3683 <scons_function name="VariantDir">
3685 (variant_dir, src_dir, [duplicate])
3689 Sets up a mapping to define a variant build directory in
3690 <parameter>variant_dir</parameter>.
3691 <parameter>src_dir</parameter> must not be underneath
3692 <parameter>variant_dir</parameter>.
3693 A &f-VariantDir; mapping is global, even if called using the
3694 &f-env-VariantDir; form.
3696 can be called multiple times with the same
3697 <parameter>src_dir</parameter>
3698 to set up multiple variant builds with different options.
3702 Note if <parameter>variant_dir</parameter>
3703 is not under the project top directory,
3704 target selection rules will not pick targets in the
3705 variant directory unless they are explicitly specified.
3709 When files in <parameter>variant_dir</parameter> are referenced,
3710 &SCons; backfills as needed with files from <parameter>src_dir</parameter>
3711 to create a complete build directory.
3713 physically duplicates the source files, SConscript files,
3714 and directory structure as needed into the variant directory.
3715 Thus, a build performed in the variant directory is guaranteed to be identical
3716 to a build performed in the source directory even if
3717 intermediate source files are generated during the build,
3718 or if preprocessors or other scanners search for included files
3719 using paths relative to the source file,
3720 or if individual compilers or other invoked tools are hard-coded
3721 to put derived files in the same directory as source files.
3722 Only the files &SCons; calculates are needed for the build are
3723 duplicated into <parameter>variant_dir</parameter>.
3724 If possible on the platform,
3725 the duplication is performed by linking rather than copying.
3726 This behavior is affected by the
3727 <option>--duplicate</option>
3728 command-line option.
3732 Duplicating the source files may be disabled by setting the
3733 <parameter>duplicate</parameter>
3735 <constant>False</constant>.
3738 to invoke Builders using the path names of source files in
3739 <parameter>src_dir</parameter>
3740 and the path names of derived files within
3741 <parameter>variant_dir</parameter>.
3742 This is more efficient than duplicating,
3743 and is safe for most builds;
3744 revert to <literal>duplicate=True</literal>
3745 if it causes problems.
3750 works most naturally when used with a subsidiary SConscript file.
3751 The subsidiary SConscript file must be called as if it were in
3752 <parameter>variant_dir</parameter>,
3753 regardless of the value of
3754 <parameter>duplicate</parameter>.
3755 When calling an SConscript file, you can use the
3756 <parameter>exports</parameter> keyword argument
3757 to pass parameters (individually or as an appropriately set up environment)
3758 so the SConscript can pick up the right settings for that variant build.
3759 The SConscript must &f-link-Import; these to use them. Example:
3763 env1 = Environment(...settings for variant1...)
3764 env2 = Environment(...settings for variant2...)
3766 # run src/SConscript in two variant directories
3767 VariantDir('build/variant1', 'src')
3768 SConscript('build/variant1/SConscript', exports={"env": env1})
3769 VariantDir('build/variant2', 'src')
3770 SConscript('build/variant2/SConscript', exports={"env": env2})
3775 &f-link-SConscript; function
3776 for another way to specify a variant directory
3777 in conjunction with calling a subsidiary SConscript file.
3785 # use names in the build directory, not the source directory
3786 VariantDir('build', 'src', duplicate=0)
3787 Program('build/prog', 'build/source.c')
3789 # this builds both the source and docs in a separate subtree
3790 VariantDir('build', '.', duplicate=0)
3791 SConscript(dirs=['build/src','build/doc'])
3793 # same as previous example, but only uses SConscript
3794 SConscript(dirs='src', variant_dir='build/src', duplicate=0)
3795 SConscript(dirs='doc', variant_dir='build/doc', duplicate=0)
3800 <scons_function name="WhereIs">
3802 (program, [path, pathext, reject])
3806 Searches for the specified executable
3807 <parameter>program</parameter>,
3808 returning the full path to the program
3809 or <constant>None</constant>.
3812 When called as a &consenv; method,
3813 searches the paths in the
3814 <parameter>path</parameter> keyword argument,
3815 or if <constant>None</constant> (the default)
3816 the paths listed in the &consenv;
3817 (<varname>env</varname><literal>['ENV']['PATH']</literal>).
3818 The external environment's path list
3819 (<literal>os.environ['PATH']</literal>)
3820 is used as a fallback if the key
3821 <varname>env</varname><literal>['ENV']['PATH']</literal>
3825 On Windows systems, searches for executable
3826 programs with any of the file extensions listed in the
3827 <parameter>pathext</parameter> keyword argument,
3828 or if <constant>None</constant> (the default)
3829 the pathname extensions listed in the &consenv;
3830 (<varname>env</varname><literal>['ENV']['PATHEXT']</literal>).
3831 The external environment's pathname extensions list
3832 (<literal>os.environ['PATHEXT']</literal>)
3833 is used as a fallback if the key
3834 <varname>env</varname><literal>['ENV']['PATHEXT']</literal>
3838 When called as a global function, uses the external
3840 <literal>os.environ['PATH']</literal>
3842 <literal>os.environ['PATHEXT']</literal>,
3844 <parameter>path</parameter> and
3845 <parameter>pathext</parameter> are
3846 <constant>None</constant>.
3852 <parameter>reject</parameter>