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')
1653 <scons_function name="Dir">
1659 Returns Directory Node(s).
1660 A Directory Node is an object that represents a directory.
1661 <parameter>name</parameter>
1662 can be a relative or absolute path or a list of such paths.
1663 <parameter>directory</parameter>
1664 is an optional directory that will be used as the parent directory.
1666 <parameter>directory</parameter>
1667 is specified, the current script's directory is used as the parent.
1672 <parameter>name</parameter>
1673 is a single pathname, the corresponding node is returned.
1675 <parameter>name</parameter>
1676 is a list, SCons returns a list of nodes.
1677 Construction variables are expanded in
1678 <parameter>name</parameter>.
1682 Directory Nodes can be used anywhere you
1683 would supply a string as a directory name
1684 to a Builder method or function.
1685 Directory Nodes have attributes and methods
1686 that are useful in many situations;
1687 see manpage section "Filesystem Nodes"
1688 for more information.
1693 <scons_function name="Dump">
1694 <arguments signature="env">
1695 ([key, ...], [format=])
1699 Serializes &consvars; from the current &consenv;
1701 The method supports the following formats specified by
1702 <parameter>format</parameter>,
1703 which must be used a a keyword argument:
1707 <term><literal>pretty</literal></term>
1710 Returns a pretty-printed representation of the variables
1711 (this is the default).
1712 The variables will be presented in &Python; dict form.
1717 <term><literal>json</literal></term>
1720 Returns a JSON-formatted string representation of the variables.
1721 The variables will be presented as a JSON object literal,
1722 the JSON equivalent of a &Python; dict.
1729 If no <varname>key</varname> is supplied,
1730 all the &consvars; are serialized.
1731 If one or more keys are supplied,
1732 only those keys and their values are serialized.
1736 <emphasis>Changed in NEXT_VERSION</emphasis>:
1737 More than one <parameter>key</parameter> can be specified.
1738 The returned string always looks like a dict (or JSON equivalent);
1739 previously a single key serialized only the value,
1740 not the key with the value.
1749 print(env.Dump('CCCOM'))
1750 print(env.Dump('CC', 'CCFLAGS', format='json'))
1754 will print something like:
1758 {'CCCOM': '$CC -o $TARGET -c $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES'}
1766 While this SConstruct:
1775 will print something like:
1779 'ARCOM': '$AR $ARFLAGS $TARGET $SOURCES\n$RANLIB $RANLIBFLAGS $TARGET',
1782 'ASCOM': '$AS $ASFLAGS -o $TARGET $SOURCES',
1790 <scons_function name="Environment">
1796 Return a new &consenv;
1797 initialized with the specified
1798 <parameter>key</parameter>=<replaceable>value</replaceable>
1800 The keyword arguments
1801 <parameter>parse_flags</parameter>,
1802 <parameter>platform</parameter>,
1803 <parameter>toolpath</parameter>,
1804 <parameter>tools</parameter>
1805 and <parameter>variables</parameter>
1806 are specially recognized and do not lead to
1808 See the manpage section "Construction Environments" for more details.
1813 <scons_function name="Execute">
1815 (action, [actionargs ...])
1820 <parameter>action</parameter>
1821 may be an Action object
1822 or it may be a command-line string,
1824 or executable &Python; function,
1825 each of which will first be converted
1826 into an Action object
1828 Any additional arguments to &f-Execute;
1829 are passed on to the &f-link-Action; factory function
1830 which actually creates the Action object
1831 (see the manpage section <link linkend="action_objects">Action Objects</link>
1832 for a description). Example:
1836 Execute(Copy('file.out', 'file.in'))
1839 <para>&f-Execute; performs its action immediately,
1840 as part of the SConscript-reading phase.
1841 There are no sources or targets declared in an
1842 &f-Execute; call, so any objects it manipulates
1843 will not be tracked as part of the &SCons; dependency graph.
1844 In the example above, neither
1845 <filename>file.out</filename> nor
1846 <filename>file.in</filename> will be tracked objects.
1850 &f-Execute; returns the exit value of the command
1851 or return value of the &Python; function.
1853 prints an error message if the executed
1854 <parameter>action</parameter>
1855 fails (exits with or returns a non-zero value),
1857 <emphasis>not</emphasis>,
1858 automatically terminate the build for such a failure.
1859 If you want the build to stop in response to a failed
1862 you must explicitly check for a non-zero return value:
1866 if Execute("mkdir sub/dir/ectory"):
1867 # The mkdir failed, don't try to build.
1873 <scons_function name="File">
1879 Returns File Node(s).
1880 A File Node is an object that represents a file.
1881 <parameter>name</parameter>
1882 can be a relative or absolute path or a list of such paths.
1883 <parameter>directory</parameter>
1884 is an optional directory that will be used as the parent directory.
1886 <parameter>directory</parameter>
1887 is specified, the current script's directory is used as the parent.
1892 <parameter>name</parameter>
1893 is a single pathname, the corresponding node is returned.
1895 <parameter>name</parameter>
1896 is a list, SCons returns a list of nodes.
1897 Construction variables are expanded in
1898 <parameter>name</parameter>.
1902 File Nodes can be used anywhere you
1903 would supply a string as a file name
1904 to a Builder method or function.
1905 File Nodes have attributes and methods
1906 that are useful in many situations;
1907 see manpage section "Filesystem Nodes"
1908 for more information.
1913 <scons_function name="FindFile">
1920 <parameter>file</parameter>
1921 in the path specified by
1922 <parameter>dirs</parameter>.
1923 <parameter>dirs</parameter>
1924 may be a list of directory names or a single directory name.
1925 In addition to searching for files that exist in the filesystem,
1926 this function also searches for derived files
1927 that have not yet been built.
1935 foo = env.FindFile('foo', ['dir1', 'dir2'])
1940 <scons_function name="FindInstalledFiles">
1946 Returns the list of targets set up by the
1954 This function serves as a convenient method to select the contents of
1963 Install('/bin', ['executable_a', 'executable_b'])
1965 # will return the file node list
1966 # ['/bin/executable_a', '/bin/executable_b']
1967 FindInstalledFiles()
1969 Install('/lib', ['some_library'])
1971 # will return the file node list
1972 # ['/bin/executable_a', '/bin/executable_b', '/lib/some_library']
1973 FindInstalledFiles()
1978 <scons_function name="FindSourceFiles">
1984 Returns the list of nodes which serve as the source of the built files.
1985 It does so by inspecting the dependency tree starting at the optional
1987 <parameter>node</parameter>
1988 which defaults to the '"."'-node. It will then return all leaves of
1989 <parameter>node</parameter>.
1990 These are all children which have no further children.
1994 This function is a convenient method to select the contents of a Source
2003 Program('src/main_a.c')
2004 Program('src/main_b.c')
2007 # returns ['main_c.c', 'src/main_a.c', 'SConstruct', 'src/main_b.c']
2010 # returns ['src/main_b.c', 'src/main_a.c' ]
2011 FindSourceFiles('src')
2015 As you can see build support files (SConstruct in the above example)
2016 will also be returned by this function.
2021 <scons_function name="Flatten">
2027 Takes a sequence (that is, a &Python; list or tuple)
2028 that may contain nested sequences
2029 and returns a flattened list containing
2030 all of the individual elements in any sequence.
2031 This can be helpful for collecting
2032 the lists returned by calls to Builders;
2033 other Builders will automatically
2034 flatten lists specified as input,
2035 but direct &Python; manipulation of
2036 these lists does not.
2044 foo = Object('foo.c')
2045 bar = Object('bar.c')
2047 # Because `foo' and `bar' are lists returned by the Object() Builder,
2048 # `objects' will be a list containing nested lists:
2049 objects = ['f1.o', foo, 'f2.o', bar, 'f3.o']
2051 # Passing such a list to another Builder is all right because
2052 # the Builder will flatten the list automatically:
2053 Program(source = objects)
2055 # If you need to manipulate the list directly using &Python;, you need to
2056 # call Flatten() yourself, or otherwise handle nested lists:
2057 for object in Flatten(objects):
2063 <scons_function name="GetBuildPath">
2071 path name (or names) for the specified
2072 <parameter>file</parameter>
2075 <parameter>file</parameter>
2079 Nodes or strings representing path names.
2084 <scons_function name="Glob">
2086 (pattern, [ondisk=True, source=False, strings=False, exclude=None])
2090 Returns a possibly empty list of Nodes (or strings) that match
2091 pathname specification <parameter>pattern</parameter>.
2092 <parameter>pattern</parameter> can be absolute,
2094 or (most commonly) relative to the directory of the current
2096 &f-Glob; matches both files stored on disk and Nodes
2097 which &SCons; already knows about, even if any corresponding
2098 file is not currently stored on disk.
2099 The evironment method form (&f-env-Glob;)
2100 performs string substition on
2101 <parameter>pattern</parameter>
2102 and returns whatever matches the resulting expanded pattern.
2103 The results are sorted, unlike for the similar &Python;
2104 <systemitem>glob.glob</systemitem> function,
2105 to ensure build order will be stable.
2109 <parameter>pattern</parameter>
2110 can contain POSIX-style shell metacharacters for matching:
2113 <informaltable rowsep="1" colsep="1" frame="topbot">
2117 <entry>Pattern</entry>
2118 <entry>Meaning</entry>
2123 <entry><literal>*</literal></entry>
2124 <entry>matches everything</entry>
2127 <entry><literal>?</literal></entry>
2128 <entry>matches any single character</entry>
2131 <entry><literal>[seq]</literal></entry>
2132 <entry>matches any character in <emphasis>seq</emphasis>
2133 (can be a list or a range).</entry>
2136 <entry><literal>[!seq]</literal></entry>
2137 <entry>matches any character not in <emphasis>seq</emphasis></entry>
2144 For a literal match, wrap the metacharacter in brackets to
2145 escape the normal behavior.
2146 For example, <literal>'[?]'</literal> matches the character
2147 <literal>'?'</literal>.
2151 Filenames starting with a dot are specially handled -
2152 they can only be matched by patterns that start with a dot
2153 (or have a dot immediately following a pathname separator
2154 character, or slash), they are not not matched by the metacharacters.
2155 Metacharacter matches also do not span directory separators.
2160 understands repositories
2164 and source directories
2168 and returns a Node (or string, if so configured) match
2169 in the local (SConscript) directory
2170 if a matching Node is found
2171 anywhere in a corresponding
2172 repository or source directory.
2177 <parameter>ondisk</parameter>
2178 argument evaluates false,
2179 the search for matches on disk is disabled,
2180 and only matches from
2181 already-configured File or Dir Nodes are returned.
2182 The default is to return Nodes for
2183 matches on disk as well.
2188 <parameter>source</parameter>
2189 argument evaluates true,
2190 and the local directory is a variant directory,
2191 then &f-Glob; returnes Nodes from
2192 the corresponding source directory,
2193 rather than the local directory.
2194 <!-- XXX what about generated files that don't exist in src but will be sources? -->
2199 <parameter>strings</parameter>
2200 argument evaluates true,
2202 returns matches as strings, rather than Nodes.
2203 The returned strings will be relative to
2204 the local (SConscript) directory.
2205 (Note that while this may make it easier to perform
2206 arbitrary manipulation of file names,
2207 it loses the context &SCons; would have in the Node,
2208 so if the returned strings are
2209 passed to a different
2212 any Node translation there will be relative
2223 <parameter>exclude</parameter>
2224 argument may be set to a pattern or a list of patterns
2225 descibing files or directories
2226 to filter out of the match list.
2227 Elements matching a least one specified pattern will be excluded.
2228 These patterns use the same syntax as for
2229 <parameter>pattern</parameter>.
2237 Program("foo", Glob("*.c"))
2238 Zip("/tmp/everything", Glob(".??*") + Glob("*"))
2239 sources = Glob("*.cpp", exclude=["os_*_specific_*.cpp"]) \
2240 + Glob("os_%s_specific_*.cpp" % currentOS)
2247 <scons_function name="GlobalBuilders">
2248 <arguments signature="global">
2254 <parameter>flag</parameter>
2256 adds the names of the default builders
2257 (Program, Library, etc.)
2258 to the global name space
2259 so they can be called without an explicit construction environment.
2260 (This is the default.)
2262 <parameter>flag</parameter>
2264 the names of the default builders are removed
2265 from the global name space
2266 so that an explicit construction environment is required
2267 to call all builders.
2273 <scons_function name="Ignore">
2275 (target, dependency)
2279 Ignores <parameter>dependency</parameter>
2281 <parameter>target</parameter> needs to be rebuilt.
2282 <parameter>target</parameter> and
2283 <parameter>dependency</parameter>
2284 can each be a single filename or Node
2285 or a list of filenames or Nodes.
2289 &f-Ignore; can also be used to
2290 remove a target from the default build
2291 by specifying the directory the target will be built in as
2292 <parameter>target</parameter>
2293 and the file you want to skip selecting for building as
2294 <parameter>dependency</parameter>.
2295 Note that this only removes the target from
2296 the default target selection algorithm:
2297 if it is a dependency of another object being
2298 built &SCons; still builds it normally.
2299 See the third and forth examples below.
2307 env.Ignore('foo', 'foo.c')
2308 env.Ignore('bar', ['bar1.h', 'bar2.h'])
2309 env.Ignore('.', 'foobar.obj')
2310 env.Ignore('bar', 'bar/foobar.obj')
2315 <scons_function name="Literal">
2322 <parameter>string</parameter>
2323 will be preserved as-is
2324 and not have construction variables expanded.
2329 <scons_function name="Local">
2336 <parameter>targets</parameter>
2337 will have copies made in the local tree,
2338 even if an already up-to-date copy
2339 exists in a repository.
2340 Returns a list of the target Node or Nodes.
2346 <scons_function name="MergeShellPaths">
2347 <arguments signature="env">
2348 ( arg ", [" prepend ])
2352 Merges the elements of the specified
2353 <parameter>arg</parameter>,
2354 which must be a dictionary, to the construction
2355 environment's copy of the shell environment
2357 (This is the environment which is passed
2358 to subshells spawned by SCons.)
2360 <parameter>arg</parameter>
2361 must be a single value,
2362 so multiple strings must
2363 be passed in as a list,
2364 not as separate arguments to
2365 &f-MergeShellPaths;.
2369 New values are prepended to the environment variable by default,
2370 unless prepend=0 is specified.
2371 Duplicate values are always eliminated,
2372 since this function calls
2373 &f-link-AppendENVPath;
2375 &f-link-PrependENVPath;
2377 <parameter>prepend</parameter>
2378 argument. See those functions for more details.
2386 # Prepend a path to the shell PATH.
2387 env.MergeShellPaths({'PATH': '/usr/local/bin'})
2388 # Append two dirs to the shell INCLUDE.
2389 env.MergeShellPaths({'INCLUDE': ['c:/inc1', 'c:/inc2']}, prepend=0)
2395 <scons_function name="MergeFlags">
2396 <arguments signature="env">
2402 <parameter>arg</parameter>
2403 into &consvars; in <parameter>env</parameter>.
2404 If <parameter>arg</parameter> is a dictionary,
2405 each key-value pair represents a
2406 &consvar; name and the corresponding flags to merge.
2407 If <parameter>arg</parameter>
2408 is not a dictionary,
2409 &MergeFlags; attempts to convert it to one
2410 before the values are merged.
2411 &f-link-env-ParseFlags; is used for this,
2412 so values to be converted are subject to the
2414 &ParseFlags; has knowledge of which &consvars; certain
2415 flags should go to, but not all;
2416 and only for GCC and compatible compiler chains.
2417 <parameter>arg</parameter>
2418 must be a single object,
2419 so to pass multiple strings,
2420 enclose them in a list.
2424 If <literal>unique</literal> is true (the default),
2425 duplicate values are not retained.
2426 In case of duplication,
2427 any &consvar; names that end in
2428 <literal>PATH</literal>
2429 keep the left-most value so the
2430 path searcb order is not altered.
2431 All other &consvars; keep
2432 the right-most value.
2433 If <literal>unique</literal> is false,
2434 values are appended even if they are duplicates.
2442 # Add an optimization flag to $CCFLAGS.
2443 env.MergeFlags({'CCFLAGS': '-O3'})
2445 # Combine the flags returned from running pkg-config with an optimization
2446 # flag and merge the result into the construction variables.
2447 env.MergeFlags(['!pkg-config gtk+-2.0 --cflags', '-O3'])
2449 # Combine an optimization flag with the flags returned from running pkg-config
2450 # for two distinct packages and merge into the construction variables.
2454 '!pkg-config gtk+-2.0 --cflags --libs',
2455 '!pkg-config libpng12 --cflags --libs',
2462 <scons_function name="NoCache">
2468 Specifies a list of files which should
2469 <emphasis>not</emphasis>
2470 be cached whenever the
2472 method has been activated.
2473 The specified targets may be a list
2474 or an individual target.
2478 Multiple files should be specified
2479 either as separate arguments to the
2481 method, or as a list.
2483 will also accept the return value of any of the construction environment
2490 on directories and other non-File Node types has no effect because
2491 only File Nodes are cached.
2500 NoCache(env.Program('hello', 'hello.c'))
2505 <scons_function name="NoClean">
2511 Specifies a list of files or directories which should
2512 <emphasis>not</emphasis>
2513 be removed whenever the targets (or their dependencies)
2514 are specified with the
2516 command line option.
2517 The specified targets may be a list
2518 or an individual target.
2522 and prevent each specified target
2523 from being removed by calls to the
2529 Multiple files or directories should be specified
2530 either as separate arguments to the
2532 method, or as a list.
2534 will also accept the return value of any of the construction environment
2541 for a target overrides calling
2543 for the same target,
2544 and any targets passed to both functions will
2545 <emphasis>not</emphasis>
2557 NoClean(env.Program('hello', 'hello.c'))
2562 <scons_function name="ParseConfig">
2563 <arguments signature="env">
2564 (command, [function, unique])
2568 Updates the current &consenv; with the values extracted
2569 from the output of running external <parameter>command</parameter>,
2570 by passing it to a helper <parameter>function</parameter>.
2571 <parameter>command</parameter> may be a string
2572 or a list of strings representing the command and
2574 If <parameter>function</parameter>
2575 is omitted or <constant>None</constant>,
2576 &f-link-env-MergeFlags; is used.
2578 duplicate values are not
2579 added to any construction variables;
2581 <parameter>unique=False</parameter>
2582 to allow duplicate values to be added.
2586 <parameter>command</parameter> is executed using the
2587 SCons execution environment (that is, the &consvar;
2588 &cv-link-ENV; in the current &consenv;).
2589 If <parameter>command</parameter> needs additional information
2590 to operate properly, that needs to be set in the execution environment.
2591 For example, <command>pkg-config</command>
2592 may need a custom value set in the <envar>PKG_CONFIG_PATH</envar>
2593 environment variable.
2597 &f-env-MergeFlags; needs to understand
2598 the output produced by <parameter>command</parameter>
2599 in order to distribute it to appropriate &consvars;.
2600 &f-env-MergeFlags; uses a separate function to
2601 do that processing -
2602 see &f-link-env-ParseFlags; for the details, including a
2603 a table of options and corresponding construction variables.
2604 To provide alternative processing of the output of
2605 <parameter>command</parameter>,
2606 you can suppply a custom
2607 <parameter>function</parameter>,
2608 which must accept three arguments:
2609 the &consenv; to modify,
2610 a string argument containing the output from running
2611 <parameter>command</parameter>,
2613 <parameter>unique</parameter> flag.
2618 <scons_function name="ParseDepends">
2620 (filename, [must_exist, only_one])
2624 Parses the contents of <parameter>filename</parameter>
2625 as a list of dependencies in the style of
2628 <application>mkdep</application>,
2629 and explicitly establishes all of the listed dependencies.
2635 if <parameter>filename</parameter>
2638 <parameter>must_exist</parameter>
2639 argument may be set to <constant>True</constant>
2641 raise an exception if the file does not exist,
2642 or is otherwise inaccessible.
2647 <parameter>only_one</parameter>
2648 argument may be set to <constant>True</constant>
2649 to have &SCons; raise an exception
2650 if the file contains dependency
2651 information for more than one target.
2652 This can provide a small sanity check
2653 for files intended to be generated
2654 by, for example, the
2655 <literal>gcc -M</literal>
2657 which should typically only
2658 write dependency information for
2659 one output file into a corresponding
2660 <filename>.d</filename>
2665 <parameter>filename</parameter>
2666 and all of the files listed therein
2667 will be interpreted relative to
2668 the directory of the
2670 file which calls the
2677 <scons_function name="ParseFlags">
2678 <arguments signature="env">
2683 Parses one or more strings containing
2684 typical command-line flags for GCC-style tool chains
2685 and returns a dictionary with the flag values
2686 separated into the appropriate SCons construction variables.
2687 Intended as a companion to the
2688 &f-link-env-MergeFlags;
2689 method, but allows for the values in the returned dictionary
2690 to be modified, if necessary,
2691 before merging them into the construction environment.
2694 will call this method if its argument is not a dictionary,
2695 so it is usually not necessary to call
2697 directly unless you want to manipulate the values.)
2701 If the first character in any string is
2702 an exclamation mark (<literal>!</literal>),
2703 the rest of the string is executed as a command,
2704 and the output from the command is
2705 parsed as GCC tool chain command-line flags
2706 and added to the resulting dictionary.
2707 This can be used to call a <filename>*-config</filename>
2708 command typical of the POSIX programming environment
2710 <command>pkg-config</command>).
2711 Note that such a command is executed using the
2712 SCons execution environment;
2713 if the command needs additional information,
2714 that information needs to be explicitly provided.
2715 See &f-link-ParseConfig; for more details.
2719 Flag values are translated according to the prefix found,
2720 and added to the following construction variables:
2724 -arch CCFLAGS, LINKFLAGS
2726 -framework FRAMEWORKS
2727 -frameworkdir= FRAMEWORKPATH
2728 -fmerge-all-constants CCFLAGS, LINKFLAGS
2729 -fopenmp CCFLAGS, LINKFLAGS
2730 -fsanitize CCFLAGS, LINKFLAGS
2733 -isysroot CCFLAGS, LINKFLAGS
2740 -mno-cygwin CCFLAGS, LINKFLAGS
2742 -openmp CCFLAGS, LINKFLAGS
2743 -pthread CCFLAGS, LINKFLAGS
2746 -Wa, ASFLAGS, CCFLAGS
2753 + CCFLAGS, LINKFLAGS
2757 Any other strings not associated with options
2758 are assumed to be the names of libraries
2761 construction variable.
2765 Examples (all of which produce the same result):
2769 dict = env.ParseFlags('-O2 -Dfoo -Dbar=1')
2770 dict = env.ParseFlags('-O2', '-Dfoo', '-Dbar=1')
2771 dict = env.ParseFlags(['-O2', '-Dfoo -Dbar=1'])
2772 dict = env.ParseFlags('-O2', '!echo -Dfoo -Dbar=1')
2777 <scons_function name="Platform">
2778 <arguments signature="global">
2781 <arguments signature="env">
2786 When called as a global function,
2787 returns a callable platform object
2788 selected by <parameter>plat</parameter>
2789 (defaults to the detected platform for the
2791 that can be used to initialize
2792 a construction environment by passing it as the
2793 <parameter>platform</parameter> keyword argument to the
2794 &f-link-Environment; function.
2802 env = Environment(platform=Platform('win32'))
2806 When called as a method of an environment,
2807 calls the platform object indicated by
2808 <parameter>plat</parameter>
2809 to update that environment.
2813 env.Platform('posix')
2817 See the manpage section "Construction Environments" for more details.
2822 <scons_function name="Prepend">
2823 <arguments signature="env">
2828 Prepend values to &consvars; in the current &consenv;,
2829 Works like &f-link-env-Append; (see for details),
2830 except that values are added to the front,
2831 rather than the end, of any existing value of the &consvar;
2839 env.Prepend(CCFLAGS='-g ', FOO=['foo.yyy'])
2843 See also &f-link-env-Append;,
2844 &f-link-env-AppendUnique;
2845 and &f-link-env-PrependUnique;.
2850 <scons_function name="PrependENVPath">
2851 <arguments signature="env">
2852 (name, newpath, [envname, sep, delete_existing=True])
2856 Prepend path elements specified by <parameter>newpath</parameter>
2857 to the given search path string or list <parameter>name</parameter>
2858 in mapping <parameter>envname</parameter> in the &consenv;.
2859 Supplying <parameter>envname</parameter> is optional:
2860 the default is the execution environment &cv-link-ENV;.
2861 Optional <parameter>sep</parameter> is used as the search path separator,
2862 the default is the platform's separator (<systemitem>os.pathsep</systemitem>).
2863 A path element will only appear once.
2864 Any duplicates in <parameter>newpath</parameter> are dropped,
2865 keeping the first appearing (to preserve path order).
2866 If <parameter>delete_existing</parameter>
2867 is <constant>False</constant>
2868 any addition duplicating an existing path element is ignored;
2869 if <parameter>delete_existing</parameter>
2870 is <constant>True</constant> (the default) the existing value will
2871 be dropped and the path element will be inserted at the beginning.
2872 To help maintain uniqueness all paths are normalized (using
2873 <systemitem>os.path.normpath</systemitem>
2875 <systemitem>os.path.normcase</systemitem>).
2883 print('before:', env['ENV']['INCLUDE'])
2884 include_path = '/foo/bar:/foo'
2885 env.PrependENVPath('INCLUDE', include_path)
2886 print('after:', env['ENV']['INCLUDE'])
2889 <para>Yields:</para>
2893 after: /foo/bar:/foo:/biz
2897 See also &f-link-env-AppendENVPath;.
2903 <scons_function name="PrependUnique">
2904 <arguments signature="env">
2905 (key=val, [...], [delete_existing=False])
2909 Prepend values to &consvars; in the current &consenv;,
2910 maintaining uniqueness.
2911 Works like &f-link-env-Append;,
2912 except that values are added to the front,
2913 rather than the end, of the &consvar;,
2914 and values that would become duplicates
2916 If <parameter>delete_existing</parameter>
2917 is set to a true value, then for any duplicate,
2918 the existing instance of <parameter>val</parameter> is first removed,
2919 then <parameter>val</parameter> is inserted,
2920 having the effect of moving it to the front.
2928 env.PrependUnique(CCFLAGS='-g', FOO=['foo.yyy'])
2932 See also &f-link-env-Append;,
2933 &f-link-env-AppendUnique;
2934 and &f-link-env-Prepend;.
2939 <scons_function name="PyPackageDir">
2945 Finds the location of <parameter>modulename</parameter>,
2946 which can be a string or a sequence of strings,
2947 each representing the name of a &Python; module.
2948 Construction variables are expanded in
2949 <parameter>modulename</parameter>.
2950 Returns a Directory Node (see &f-link-Dir;),
2951 or a list of Directory Nodes if
2952 <parameter>modulename</parameter> is a sequence.
2953 <literal>None</literal> is returned for any module not found.
2957 When a Tool module which is installed as a
2958 &Python; module is used, you need
2959 to specify a <parameter>toolpath</parameter> argument to
2961 &f-link-Environment;
2963 as tools outside the standard project locations
2964 (<filename>site_scons/site_tools</filename>)
2965 will not be found otherwise.
2966 Using &f-PyPackageDir; allows this path to be
2967 discovered at runtime instead of hardcoding the path.
2976 tools=["default", "ExampleTool"],
2977 toolpath=[PyPackageDir("example_tool")]
2983 <scons_function name="Replace">
2984 <arguments signature="env">
2989 Replaces construction variables in the Environment
2990 with the specified keyword arguments.
2998 env.Replace(CCFLAGS='-g', FOO='foo.xxx')
3003 <scons_function name="Repository">
3010 <parameter>directory</parameter>
3011 is a repository to be searched for files.
3015 and each one adds to the list of
3016 repositories that will be searched.
3022 a repository is a copy of the source tree,
3023 from the top-level directory on down,
3025 both source files and derived files
3026 that can be used to build targets in
3027 the local source tree.
3028 The canonical example would be an
3029 official source tree maintained by an integrator.
3030 If the repository contains derived files,
3031 then the derived files should have been built using
3033 so that the repository contains the necessary
3034 signature information to allow
3036 to figure out when it is appropriate to
3037 use the repository copy of a derived file,
3038 instead of building one locally.
3042 Note that if an up-to-date derived file
3043 already exists in a repository,
3046 <emphasis>not</emphasis>
3047 make a copy in the local directory tree.
3048 In order to guarantee that a local copy
3057 <scons_function name="Requires">
3059 (target, prerequisite)
3063 Specifies an order-only relationship
3064 between <parameter>target</parameter>
3065 and <parameter>prerequisite</parameter>.
3067 will be (re)built, if necessary,
3068 <emphasis>before</emphasis>
3070 but the target file(s) do not actually
3071 depend on the prerequisites
3072 and will not be rebuilt simply because
3073 the prerequisite file(s) change.
3074 <parameter>target</parameter> and
3075 <parameter>prerequisite</parameter> may each
3076 be a string or Node, or a list of strings or Nodes.
3077 If there are multiple
3078 <parameter>target</parameter> values,
3079 the prerequisite(s) are added to each one.
3080 Returns a list of the affected target nodes.
3088 env.Requires('foo', 'file-that-must-be-built-before-foo')
3093 <scons_function name="Scanner">
3095 (function, [name, argument, skeys, path_function, node_class, node_factory, scan_check, recursive])
3099 Creates a Scanner object for
3101 <parameter>function</parameter>.
3102 See manpage section "Scanner Objects"
3103 for a complete explanation of the arguments and behavior.
3108 <scons_function name="SConscriptChdir">
3109 <arguments signature="global">
3116 changes its working directory
3117 to the directory in which each
3118 subsidiary SConscript file lives
3119 while reading and processing that script.
3120 This behavior may be disabled
3121 by specifying an argument which
3122 evaluates false, in which case
3124 will stay in the top-level directory
3125 while reading all SConscript files.
3126 (This may be necessary when building from repositories,
3127 when all the directories in which SConscript files may be found
3128 don't necessarily exist locally.)
3129 You may enable and disable
3130 this ability by calling
3140 SConscriptChdir(False)
3141 SConscript('foo/SConscript') # will not chdir to foo
3142 SConscriptChdir(True)
3143 SConscript('bar/SConscript') # will chdir to bar
3148 <scons_function name="SConsignFile">
3150 ([name, dbm_module])
3154 Specify where to store the &SCons; file signature database,
3155 and which database format to use.
3156 This may be useful to specify alternate
3157 database files and/or file locations for different types of builds.
3160 The optional <parameter>name</parameter> argument
3161 is the base name of the database file(s).
3162 If not an absolute path name,
3163 these are placed relative to the directory containing the
3164 top-level &SConstruct; file.
3166 <filename>.sconsign</filename>.
3167 The actual database file(s) stored on disk
3168 may have an appropriate suffix appended
3170 <parameter>dbm_module</parameter>
3173 The optional <parameter>dbm_module</parameter>
3174 argument specifies which
3175 &Python; database module to use
3176 for reading/writing the file.
3177 The module must be imported first;
3178 then the imported module name
3179 is passed as the argument.
3180 The default is a custom
3181 <systemitem>SCons.dblite</systemitem>
3182 module that uses pickled
3183 &Python; data structures,
3184 which works on all &Python; versions.
3185 See documentation of the &Python;
3186 <systemitem>dbm</systemitem> module
3187 for other available types.
3190 If called with no arguments,
3191 the database will default to
3192 <filename>.sconsign.dblite</filename>
3193 in the top directory of the project,
3194 which is also the default if
3195 if &f-SConsignFile; is not called.
3198 The setting is global, so the only difference
3199 between the global function and the environment method form
3200 is variable expansion on <parameter>name</parameter>.
3201 There should only be one active call to this
3202 function/method in a given build setup.
3206 <parameter>name</parameter>
3208 <constant>None</constant>,
3210 will store file signatures
3212 <filename>.sconsign</filename>
3213 file in each directory,
3214 not in a single combined database file.
3215 This is a backwards-compatibility meaure to support
3216 what was the default behavior
3217 prior to &SCons; 0.97 (i.e. before 2008).
3218 Use of this mode is discouraged and may be
3219 deprecated in a future &SCons; release.
3227 # Explicitly stores signatures in ".sconsign.dblite"
3228 # in the top-level SConstruct directory (the default behavior).
3231 # Stores signatures in the file "etc/scons-signatures"
3232 # relative to the top-level SConstruct directory.
3233 # SCons will add a database suffix to this name.
3234 SConsignFile("etc/scons-signatures")
3236 # Stores signatures in the specified absolute file name.
3237 # SCons will add a database suffix to this name.
3238 SConsignFile("/home/me/SCons/signatures")
3240 # Stores signatures in a separate .sconsign file
3241 # in each directory.
3244 # Stores signatures in a GNU dbm format .sconsign file
3246 SConsignFile(dbm_module=dbm.gnu)
3251 <scons_function name="SetDefault">
3252 <arguments signature="env">
3257 Sets construction variables to default values specified with the keyword
3258 arguments if (and only if) the variables are not already set.
3259 The following statements are equivalent:
3263 env.SetDefault(FOO='foo')
3264 if 'FOO' not in env:
3270 <scons_function name="SideEffect">
3272 (side_effect, target)
3277 <parameter>side_effect</parameter>
3278 as a side effect of building
3279 <parameter>target</parameter>.
3281 <parameter>side_effect</parameter>
3283 <parameter>target</parameter>
3284 can be a list, a file name, or a node.
3285 A side effect is a target file that is created or updated
3286 as a side effect of building other targets.
3287 For example, a Windows PDB
3288 file is created as a side effect of building the .obj
3289 files for a static library,
3290 and various log files are created updated
3291 as side effects of various TeX commands.
3292 If a target is a side effect of multiple build commands,
3294 will ensure that only one set of commands
3295 is executed at a time.
3296 Consequently, you only need to use this method
3297 for side-effect targets that are built as a result of
3298 multiple build commands.
3302 Because multiple build commands may update
3303 the same side effect file,
3305 <parameter>side_effect</parameter>
3307 <emphasis>not</emphasis>
3308 automatically removed
3310 <parameter>target</parameter>
3314 (Note, however, that the
3315 <parameter>side_effect</parameter>
3316 might be removed as part of
3317 cleaning the directory in which it lives.)
3318 If you want to make sure the
3319 <parameter>side_effect</parameter>
3320 is cleaned whenever a specific
3321 <parameter>target</parameter>
3323 you must specify this explicitly
3332 This function returns the list of side effect Node objects that were successfully added.
3333 If the list of side effects contained any side effects that had already been added,
3334 they are not added and included in the returned list.
3339 <scons_function name="Split">
3340 <arguments>(arg)</arguments>
3343 If <parameter>arg</parameter> is a string,
3344 splits on whitespace and returns a list of
3345 strings without whitespace.
3346 This mode is the most common case,
3347 and can be used to split a list of filenames
3348 (for example) rather than having to type them as a
3349 list of individually quoted words.
3350 If <parameter>arg</parameter> is a list or tuple
3351 returns the list or tuple unchanged.
3352 If <parameter>arg</parameter> is any other type of object,
3353 returns a list containing just the object.
3354 These non-string cases do not actually do any spliting,
3355 but allow an argument variable to be passed to
3356 &f-Split; without having to first check its type.
3364 files = Split("f1.c f2.c f3.c")
3365 files = env.Split("f4.c f5.c f6.c")
3375 <scons_function name="subst">
3376 <arguments signature="env">
3377 (input, [raw, target, source, conv])
3381 Performs &consvar; interpolation
3382 (<firstterm>substitution</firstterm>)
3383 on <parameter>input</parameter>,
3384 which can be a string or a sequence.
3385 Substitutable elements take the form
3386 <literal>${<replaceable>expression</replaceable>}</literal>,
3387 although if there is no ambiguity in recognizing the element,
3388 the braces can be omitted.
3389 A literal <emphasis role="bold">$</emphasis> can be entered by
3390 using <emphasis role="bold">$$</emphasis>.
3395 leading or trailing white space will
3396 be removed from the result,
3397 and all sequences of white space
3398 will be compressed to a single space character.
3400 <literal>$(</literal>
3402 <literal>$)</literal>
3403 character sequences will be stripped from the returned string,
3405 <parameter>raw</parameter>
3406 argument may be set to
3407 <literal>1</literal>
3408 if you want to preserve white space and
3409 <literal>$(</literal>-<literal>$)</literal>
3412 <parameter>raw</parameter>
3413 argument may be set to
3414 <literal>2</literal>
3415 if you want to additionally discard
3416 all characters between any
3417 <literal>$(</literal>
3419 <literal>$)</literal>
3421 (as is done for signature calculation).
3425 If <parameter>input</parameter> is a sequence
3427 the individual elements of
3428 the sequence will be expanded,
3429 and the results will be returned as a list.
3434 <parameter>target</parameter>
3436 <parameter>source</parameter>
3438 must be set to lists of
3439 target and source nodes, respectively,
3446 to be available for expansion.
3447 This is usually necessary if you are
3450 from within a &Python; function used
3455 Returned string values or sequence elements
3456 are converted to their string representation by default.
3458 <parameter>conv</parameter>
3460 may specify a conversion function
3461 that will be used in place of
3463 For example, if you want &Python; objects
3464 (including SCons Nodes)
3465 to be returned as &Python; objects,
3466 you can use a &Python;
3467 lambda expression to pass in an unnamed function
3468 that simply returns its unconverted argument.
3476 print(env.subst("The C compiler is: $CC"))
3478 def compile(target, source, env):
3479 sourceDir = env.subst(
3485 source_nodes = env.subst('$EXPAND_TO_NODELIST', conv=lambda x: x)
3490 <scons_function name="Tool">
3492 (name, [toolpath, key=value, ...])
3497 Locates the tool specification module <parameter>name</parameter>
3498 and returns a callable tool object for that tool.
3499 When the environment method (&f-env-Tool;) form is used,
3500 the tool object is automatically called before the method returns
3501 to update <varname>env</varname>,
3502 and <parameter>name</parameter> is
3503 appended to the &cv-link-TOOLS;
3504 &consvar; in that environment.
3505 When the global function &f-Tool; form is used,
3506 the tool object is constructed but not called,
3507 as it lacks the context of an environment to update,
3508 and the returned object needs to be used to arrange for the call.
3512 The tool module is searched for in the tool search paths (see the
3513 <emphasis role="bold">Tools</emphasis> section in the manual page
3515 and in any paths specified by the optional
3516 <parameter>toolpath</parameter> parameter,
3517 which must be a list of strings.
3518 If <parameter>toolpath</parameter> is omitted,
3519 the <parameter>toolpath</parameter>
3520 supplied when the environment was created,
3525 Any remaining keyword arguments are saved in
3527 and will be passed to the tool module's
3528 <function>generate</function> function
3529 when the tool object is actually called.
3530 The <function>generate</function> function
3531 can update the &consenv; with &consvars; and arrange
3532 any other initialization
3533 needed to use the mechanisms that tool describes,
3534 and can use these extra arguments to help
3539 <emphasis>Changed in version 4.2:</emphasis>
3540 &f-env-Tool; now returns the tool object,
3541 previously it did not return (i.e. returned <constant>None</constant>).
3550 env.Tool('opengl', toolpath=['build/tools'])
3554 The returned tool object can be passed to an
3555 &f-link-Environment; or &f-link-Clone; call
3556 as part of the <parameter>tools</parameter> keyword argument,
3557 in which case the tool is applied to the environment being constructed,
3558 or it can be called directly,
3559 in which case a &consenv; to update must be
3560 passed as the argument.
3561 Either approach will also update the
3562 &cv-TOOLS; &consvar;.
3570 env = Environment(tools=[Tool('msvc')])
3573 msvctool = Tool('msvc')
3574 msvctool(env) # adds 'msvc' to the TOOLS variable
3575 gltool = Tool('opengl', toolpath = ['tools'])
3576 gltool(env) # adds 'opengl' to the TOOLS variable
3581 <scons_function name="Value">
3583 (value, [built_value], [name])
3587 Returns a Node object representing the specified &Python;
3588 <parameter>value</parameter>.
3589 Value Nodes can be used as dependencies of targets.
3590 If the string representation of the Value Node
3591 changes between &SCons; runs, it is considered
3592 out of date and any targets depending it will be rebuilt.
3593 Since Value Nodes have no filesystem representation,
3594 timestamps are not used; the timestamp deciders
3595 perform the same content-based up to date check.
3599 <parameter>built_value</parameter>
3600 argument can be specified
3601 when the Value Node is created
3602 to indicate the Node should already be considered "built."
3606 The optional <parameter>name</parameter> parameter can be provided as an
3607 alternative name for the resulting <literal>Value</literal> node;
3608 this is advised if the <parameter>value</parameter> parameter
3609 cannot be converted to a string.
3614 <methodname>write</methodname>
3615 method that can be used to "build" a Value Node
3616 by setting a new value.
3618 <methodname>read</methodname>
3619 method returns the built value of the Node.
3623 <emphasis>Changed in version 4.0:</emphasis>
3624 the <parameter>name</parameter> parameter was added.
3631 <!-- TODO fix second example or replace - still doesn't work -->
3635 def create(target, source, env):
3636 """Action function to create a file from a Value.
3638 Writes 'prefix=$SOURCE' into the file name given as $TARGET.
3640 with open(str(target[0]), 'wb') as f:
3641 f.write(b'prefix=' + source[0].get_contents() + b'\n')
3643 # Fetch the prefix= argument, if any, from the command line.
3644 # Use /usr/local as the default.
3645 prefix = ARGUMENTS.get('prefix', '/usr/local')
3647 # Attach builder named Config to the construction environment
3648 # using the 'create' action function above.
3649 env['BUILDERS']['Config'] = Builder(action=create)
3650 env.Config(target='package-config', source=Value(prefix))
3652 def build_value(target, source, env):
3653 """Action function to "build" a Value.
3655 Writes contents of $SOURCE into $TARGET, thus updating if it existed.
3657 target[0].write(source[0].get_contents())
3659 output = env.Value('before')
3660 input = env.Value('after')
3662 # Attach a builder named UpdateValue to the construction environment
3663 # using the 'build_value' action function above.
3664 env['BUILDERS']['UpdateValue'] = Builder(action=build_value)
3665 env.UpdateValue(target=Value(output), source=Value(input))
3670 <scons_function name="VariantDir">
3672 (variant_dir, src_dir, [duplicate])
3676 Sets up a mapping to define a variant build directory in
3677 <parameter>variant_dir</parameter>.
3678 <parameter>src_dir</parameter> must not be underneath
3679 <parameter>variant_dir</parameter>.
3680 A &f-VariantDir; mapping is global, even if called using the
3681 &f-env-VariantDir; form.
3683 can be called multiple times with the same
3684 <parameter>src_dir</parameter>
3685 to set up multiple variant builds with different options.
3689 Note if <parameter>variant_dir</parameter>
3690 is not under the project top directory,
3691 target selection rules will not pick targets in the
3692 variant directory unless they are explicitly specified.
3696 When files in <parameter>variant_dir</parameter> are referenced,
3697 &SCons; backfills as needed with files from <parameter>src_dir</parameter>
3698 to create a complete build directory.
3700 physically duplicates the source files, SConscript files,
3701 and directory structure as needed into the variant directory.
3702 Thus, a build performed in the variant directory is guaranteed to be identical
3703 to a build performed in the source directory even if
3704 intermediate source files are generated during the build,
3705 or if preprocessors or other scanners search for included files
3706 using paths relative to the source file,
3707 or if individual compilers or other invoked tools are hard-coded
3708 to put derived files in the same directory as source files.
3709 Only the files &SCons; calculates are needed for the build are
3710 duplicated into <parameter>variant_dir</parameter>.
3711 If possible on the platform,
3712 the duplication is performed by linking rather than copying.
3713 This behavior is affected by the
3714 <option>--duplicate</option>
3715 command-line option.
3719 Duplicating the source files may be disabled by setting the
3720 <parameter>duplicate</parameter>
3722 <constant>False</constant>.
3725 to invoke Builders using the path names of source files in
3726 <parameter>src_dir</parameter>
3727 and the path names of derived files within
3728 <parameter>variant_dir</parameter>.
3729 This is more efficient than duplicating,
3730 and is safe for most builds;
3731 revert to <literal>duplicate=True</literal>
3732 if it causes problems.
3737 works most naturally when used with a subsidiary SConscript file.
3738 The subsidiary SConscript file must be called as if it were in
3739 <parameter>variant_dir</parameter>,
3740 regardless of the value of
3741 <parameter>duplicate</parameter>.
3742 When calling an SConscript file, you can use the
3743 <parameter>exports</parameter> keyword argument
3744 to pass parameters (individually or as an appropriately set up environment)
3745 so the SConscript can pick up the right settings for that variant build.
3746 The SConscript must &f-link-Import; these to use them. Example:
3750 env1 = Environment(...settings for variant1...)
3751 env2 = Environment(...settings for variant2...)
3753 # run src/SConscript in two variant directories
3754 VariantDir('build/variant1', 'src')
3755 SConscript('build/variant1/SConscript', exports={"env": env1})
3756 VariantDir('build/variant2', 'src')
3757 SConscript('build/variant2/SConscript', exports={"env": env2})
3762 &f-link-SConscript; function
3763 for another way to specify a variant directory
3764 in conjunction with calling a subsidiary SConscript file.
3772 # use names in the build directory, not the source directory
3773 VariantDir('build', 'src', duplicate=0)
3774 Program('build/prog', 'build/source.c')
3776 # this builds both the source and docs in a separate subtree
3777 VariantDir('build', '.', duplicate=0)
3778 SConscript(dirs=['build/src','build/doc'])
3780 # same as previous example, but only uses SConscript
3781 SConscript(dirs='src', variant_dir='build/src', duplicate=0)
3782 SConscript(dirs='doc', variant_dir='build/doc', duplicate=0)
3787 <scons_function name="WhereIs">
3789 (program, [path, pathext, reject])
3793 Searches for the specified executable
3794 <parameter>program</parameter>,
3795 returning the full path to the program
3796 or <constant>None</constant>.
3799 When called as a &consenv; method,
3800 searches the paths in the
3801 <parameter>path</parameter> keyword argument,
3802 or if <constant>None</constant> (the default)
3803 the paths listed in the &consenv;
3804 (<varname>env</varname><literal>['ENV']['PATH']</literal>).
3805 The external environment's path list
3806 (<literal>os.environ['PATH']</literal>)
3807 is used as a fallback if the key
3808 <varname>env</varname><literal>['ENV']['PATH']</literal>
3812 On Windows systems, searches for executable
3813 programs with any of the file extensions listed in the
3814 <parameter>pathext</parameter> keyword argument,
3815 or if <constant>None</constant> (the default)
3816 the pathname extensions listed in the &consenv;
3817 (<varname>env</varname><literal>['ENV']['PATHEXT']</literal>).
3818 The external environment's pathname extensions list
3819 (<literal>os.environ['PATHEXT']</literal>)
3820 is used as a fallback if the key
3821 <varname>env</varname><literal>['ENV']['PATHEXT']</literal>
3825 When called as a global function, uses the external
3827 <literal>os.environ['PATH']</literal>
3829 <literal>os.environ['PATHEXT']</literal>,
3831 <parameter>path</parameter> and
3832 <parameter>pathext</parameter> are
3833 <constant>None</constant>.
3839 <parameter>reject</parameter>