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">
1699 Serializes &consvars; to a string.
1700 The method supports the following formats specified by
1701 <parameter>format</parameter>:
1704 <term><literal>pretty</literal></term>
1707 Returns a pretty printed representation of the environment (if
1708 <parameter>format</parameter>
1709 is not specified, this is the default).
1714 <term><literal>json</literal></term>
1717 Returns a JSON-formatted string representation of the environment.
1723 If <varname>key</varname> is
1724 <constant>None</constant> (the default) the entire
1725 dictionary of &consvars; is serialized.
1726 If supplied, it is taken as the name of a &consvar;
1727 whose value is serialized.
1736 print(env.Dump('CCCOM'))
1744 '$CC -c -o $TARGET $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS $SOURCES'
1748 While this SConstruct:
1761 'ARCOM': '$AR $ARFLAGS $TARGET $SOURCES\n$RANLIB $RANLIBFLAGS $TARGET',
1764 'ASCOM': '$AS $ASFLAGS -o $TARGET $SOURCES',
1771 <scons_function name="Environment">
1777 Return a new &consenv;
1778 initialized with the specified
1779 <parameter>key</parameter>=<replaceable>value</replaceable>
1781 The keyword arguments
1782 <parameter>parse_flags</parameter>,
1783 <parameter>platform</parameter>,
1784 <parameter>toolpath</parameter>,
1785 <parameter>tools</parameter>
1786 and <parameter>variables</parameter>
1787 are specially recognized and do not lead to
1789 See the manpage section "Construction Environments" for more details.
1794 <scons_function name="Execute">
1796 (action, [actionargs ...])
1801 <parameter>action</parameter>
1802 may be an Action object
1803 or it may be a command-line string,
1805 or executable &Python; function,
1806 each of which will first be converted
1807 into an Action object
1809 Any additional arguments to &f-Execute;
1810 are passed on to the &f-link-Action; factory function
1811 which actually creates the Action object
1812 (see the manpage section <link linkend="action_objects">Action Objects</link>
1813 for a description). Example:
1817 Execute(Copy('file.out', 'file.in'))
1820 <para>&f-Execute; performs its action immediately,
1821 as part of the SConscript-reading phase.
1822 There are no sources or targets declared in an
1823 &f-Execute; call, so any objects it manipulates
1824 will not be tracked as part of the &SCons; dependency graph.
1825 In the example above, neither
1826 <filename>file.out</filename> nor
1827 <filename>file.in</filename> will be tracked objects.
1831 &f-Execute; returns the exit value of the command
1832 or return value of the &Python; function.
1834 prints an error message if the executed
1835 <parameter>action</parameter>
1836 fails (exits with or returns a non-zero value),
1838 <emphasis>not</emphasis>,
1839 automatically terminate the build for such a failure.
1840 If you want the build to stop in response to a failed
1843 you must explicitly check for a non-zero return value:
1847 if Execute("mkdir sub/dir/ectory"):
1848 # The mkdir failed, don't try to build.
1854 <scons_function name="File">
1860 Returns File Node(s).
1861 A File Node is an object that represents a file.
1862 <parameter>name</parameter>
1863 can be a relative or absolute path or a list of such paths.
1864 <parameter>directory</parameter>
1865 is an optional directory that will be used as the parent directory.
1867 <parameter>directory</parameter>
1868 is specified, the current script's directory is used as the parent.
1873 <parameter>name</parameter>
1874 is a single pathname, the corresponding node is returned.
1876 <parameter>name</parameter>
1877 is a list, SCons returns a list of nodes.
1878 Construction variables are expanded in
1879 <parameter>name</parameter>.
1883 File Nodes can be used anywhere you
1884 would supply a string as a file name
1885 to a Builder method or function.
1886 File Nodes have attributes and methods
1887 that are useful in many situations;
1888 see manpage section "Filesystem Nodes"
1889 for more information.
1894 <scons_function name="FindFile">
1901 <parameter>file</parameter>
1902 in the path specified by
1903 <parameter>dirs</parameter>.
1904 <parameter>dirs</parameter>
1905 may be a list of directory names or a single directory name.
1906 In addition to searching for files that exist in the filesystem,
1907 this function also searches for derived files
1908 that have not yet been built.
1916 foo = env.FindFile('foo', ['dir1', 'dir2'])
1921 <scons_function name="FindInstalledFiles">
1927 Returns the list of targets set up by the
1935 This function serves as a convenient method to select the contents of
1944 Install('/bin', ['executable_a', 'executable_b'])
1946 # will return the file node list
1947 # ['/bin/executable_a', '/bin/executable_b']
1948 FindInstalledFiles()
1950 Install('/lib', ['some_library'])
1952 # will return the file node list
1953 # ['/bin/executable_a', '/bin/executable_b', '/lib/some_library']
1954 FindInstalledFiles()
1959 <scons_function name="FindSourceFiles">
1965 Returns the list of nodes which serve as the source of the built files.
1966 It does so by inspecting the dependency tree starting at the optional
1968 <parameter>node</parameter>
1969 which defaults to the '"."'-node. It will then return all leaves of
1970 <parameter>node</parameter>.
1971 These are all children which have no further children.
1975 This function is a convenient method to select the contents of a Source
1984 Program('src/main_a.c')
1985 Program('src/main_b.c')
1988 # returns ['main_c.c', 'src/main_a.c', 'SConstruct', 'src/main_b.c']
1991 # returns ['src/main_b.c', 'src/main_a.c' ]
1992 FindSourceFiles('src')
1996 As you can see build support files (SConstruct in the above example)
1997 will also be returned by this function.
2002 <scons_function name="Flatten">
2008 Takes a sequence (that is, a &Python; list or tuple)
2009 that may contain nested sequences
2010 and returns a flattened list containing
2011 all of the individual elements in any sequence.
2012 This can be helpful for collecting
2013 the lists returned by calls to Builders;
2014 other Builders will automatically
2015 flatten lists specified as input,
2016 but direct &Python; manipulation of
2017 these lists does not.
2025 foo = Object('foo.c')
2026 bar = Object('bar.c')
2028 # Because `foo' and `bar' are lists returned by the Object() Builder,
2029 # `objects' will be a list containing nested lists:
2030 objects = ['f1.o', foo, 'f2.o', bar, 'f3.o']
2032 # Passing such a list to another Builder is all right because
2033 # the Builder will flatten the list automatically:
2034 Program(source = objects)
2036 # If you need to manipulate the list directly using &Python;, you need to
2037 # call Flatten() yourself, or otherwise handle nested lists:
2038 for object in Flatten(objects):
2044 <scons_function name="GetBuildPath">
2052 path name (or names) for the specified
2053 <parameter>file</parameter>
2056 <parameter>file</parameter>
2060 Nodes or strings representing path names.
2065 <scons_function name="Glob">
2067 (pattern, [ondisk=True, source=False, strings=False, exclude=None])
2071 Returns a possibly empty list of Nodes (or strings) that match
2072 pathname specification <parameter>pattern</parameter>.
2073 <parameter>pattern</parameter> can be absolute,
2075 or (most commonly) relative to the directory of the current
2077 &f-Glob; matches both files stored on disk and Nodes
2078 which &SCons; already knows about, even if any corresponding
2079 file is not currently stored on disk.
2080 The evironment method form (&f-env-Glob;)
2081 performs string substition on
2082 <parameter>pattern</parameter>
2083 and returns whatever matches the resulting expanded pattern.
2084 The results are sorted, unlike for the similar &Python;
2085 <systemitem>glob.glob</systemitem> function,
2086 to ensure build order will be stable.
2090 <parameter>pattern</parameter>
2091 can contain POSIX-style shell metacharacters for matching:
2094 <informaltable rowsep="1" colsep="1" frame="topbot">
2098 <entry>Pattern</entry>
2099 <entry>Meaning</entry>
2104 <entry><literal>*</literal></entry>
2105 <entry>matches everything</entry>
2108 <entry><literal>?</literal></entry>
2109 <entry>matches any single character</entry>
2112 <entry><literal>[seq]</literal></entry>
2113 <entry>matches any character in <emphasis>seq</emphasis>
2114 (can be a list or a range).</entry>
2117 <entry><literal>[!seq]</literal></entry>
2118 <entry>matches any character not in <emphasis>seq</emphasis></entry>
2125 For a literal match, wrap the metacharacter in brackets to
2126 escape the normal behavior.
2127 For example, <literal>'[?]'</literal> matches the character
2128 <literal>'?'</literal>.
2132 Filenames starting with a dot are specially handled -
2133 they can only be matched by patterns that start with a dot
2134 (or have a dot immediately following a pathname separator
2135 character, or slash), they are not not matched by the metacharacters.
2136 Metacharacter matches also do not span directory separators.
2141 understands repositories
2145 and source directories
2149 and returns a Node (or string, if so configured) match
2150 in the local (SConscript) directory
2151 if a matching Node is found
2152 anywhere in a corresponding
2153 repository or source directory.
2158 <parameter>ondisk</parameter>
2159 argument evaluates false,
2160 the search for matches on disk is disabled,
2161 and only matches from
2162 already-configured File or Dir Nodes are returned.
2163 The default is to return Nodes for
2164 matches on disk as well.
2169 <parameter>source</parameter>
2170 argument evaluates true,
2171 and the local directory is a variant directory,
2172 then &f-Glob; returnes Nodes from
2173 the corresponding source directory,
2174 rather than the local directory.
2175 <!-- XXX what about generated files that don't exist in src but will be sources? -->
2180 <parameter>strings</parameter>
2181 argument evaluates true,
2183 returns matches as strings, rather than Nodes.
2184 The returned strings will be relative to
2185 the local (SConscript) directory.
2186 (Note that while this may make it easier to perform
2187 arbitrary manipulation of file names,
2188 it loses the context &SCons; would have in the Node,
2189 so if the returned strings are
2190 passed to a different
2193 any Node translation there will be relative
2204 <parameter>exclude</parameter>
2205 argument may be set to a pattern or a list of patterns
2206 descibing files or directories
2207 to filter out of the match list.
2208 Elements matching a least one specified pattern will be excluded.
2209 These patterns use the same syntax as for
2210 <parameter>pattern</parameter>.
2218 Program("foo", Glob("*.c"))
2219 Zip("/tmp/everything", Glob(".??*") + Glob("*"))
2220 sources = Glob("*.cpp", exclude=["os_*_specific_*.cpp"]) \
2221 + Glob("os_%s_specific_*.cpp" % currentOS)
2228 <scons_function name="GlobalBuilders">
2229 <arguments signature="global">
2235 <parameter>flag</parameter>
2237 adds the names of the default builders
2238 (Program, Library, etc.)
2239 to the global name space
2240 so they can be called without an explicit construction environment.
2241 (This is the default.)
2243 <parameter>flag</parameter>
2245 the names of the default builders are removed
2246 from the global name space
2247 so that an explicit construction environment is required
2248 to call all builders.
2254 <scons_function name="Ignore">
2256 (target, dependency)
2260 Ignores <parameter>dependency</parameter>
2262 <parameter>target</parameter> needs to be rebuilt.
2263 <parameter>target</parameter> and
2264 <parameter>dependency</parameter>
2265 can each be a single filename or Node
2266 or a list of filenames or Nodes.
2270 &f-Ignore; can also be used to
2271 remove a target from the default build
2272 by specifying the directory the target will be built in as
2273 <parameter>target</parameter>
2274 and the file you want to skip selecting for building as
2275 <parameter>dependency</parameter>.
2276 Note that this only removes the target from
2277 the default target selection algorithm:
2278 if it is a dependency of another object being
2279 built &SCons; still builds it normally.
2280 See the third and forth examples below.
2288 env.Ignore('foo', 'foo.c')
2289 env.Ignore('bar', ['bar1.h', 'bar2.h'])
2290 env.Ignore('.', 'foobar.obj')
2291 env.Ignore('bar', 'bar/foobar.obj')
2296 <scons_function name="Literal">
2303 <parameter>string</parameter>
2304 will be preserved as-is
2305 and not have construction variables expanded.
2310 <scons_function name="Local">
2317 <parameter>targets</parameter>
2318 will have copies made in the local tree,
2319 even if an already up-to-date copy
2320 exists in a repository.
2321 Returns a list of the target Node or Nodes.
2327 <scons_function name="MergeShellPaths">
2328 <arguments signature="env">
2329 ( arg ", [" prepend ])
2333 Merges the elements of the specified
2334 <parameter>arg</parameter>,
2335 which must be a dictionary, to the construction
2336 environment's copy of the shell environment
2338 (This is the environment which is passed
2339 to subshells spawned by SCons.)
2341 <parameter>arg</parameter>
2342 must be a single value,
2343 so multiple strings must
2344 be passed in as a list,
2345 not as separate arguments to
2346 &f-MergeShellPaths;.
2350 New values are prepended to the environment variable by default,
2351 unless prepend=0 is specified.
2352 Duplicate values are always eliminated,
2353 since this function calls
2354 &f-link-AppendENVPath;
2356 &f-link-PrependENVPath;
2358 <parameter>prepend</parameter>
2359 argument. See those functions for more details.
2367 # Prepend a path to the shell PATH.
2368 env.MergeShellPaths({'PATH': '/usr/local/bin'})
2369 # Append two dirs to the shell INCLUDE.
2370 env.MergeShellPaths({'INCLUDE': ['c:/inc1', 'c:/inc2']}, prepend=0)
2376 <scons_function name="MergeFlags">
2377 <arguments signature="env">
2383 <parameter>arg</parameter>
2384 into &consvars; in <parameter>env</parameter>.
2385 If <parameter>arg</parameter> is a dictionary,
2386 each key-value pair represents a
2387 &consvar; name and the corresponding flags to merge.
2388 If <parameter>arg</parameter>
2389 is not a dictionary,
2390 &MergeFlags; attempts to convert it to one
2391 before the values are merged.
2392 &f-link-env-ParseFlags; is used for this,
2393 so values to be converted are subject to the
2395 &ParseFlags; has knowledge of which &consvars; certain
2396 flags should go to, but not all;
2397 and only for GCC and compatible compiler chains.
2398 <parameter>arg</parameter>
2399 must be a single object,
2400 so to pass multiple strings,
2401 enclose them in a list.
2405 If <literal>unique</literal> is true (the default),
2406 duplicate values are not retained.
2407 In case of duplication,
2408 any &consvar; names that end in
2409 <literal>PATH</literal>
2410 keep the left-most value so the
2411 path searcb order is not altered.
2412 All other &consvars; keep
2413 the right-most value.
2414 If <literal>unique</literal> is false,
2415 values are appended even if they are duplicates.
2423 # Add an optimization flag to $CCFLAGS.
2424 env.MergeFlags({'CCFLAGS': '-O3'})
2426 # Combine the flags returned from running pkg-config with an optimization
2427 # flag and merge the result into the construction variables.
2428 env.MergeFlags(['!pkg-config gtk+-2.0 --cflags', '-O3'])
2430 # Combine an optimization flag with the flags returned from running pkg-config
2431 # for two distinct packages and merge into the construction variables.
2435 '!pkg-config gtk+-2.0 --cflags --libs',
2436 '!pkg-config libpng12 --cflags --libs',
2443 <scons_function name="NoCache">
2449 Specifies a list of files which should
2450 <emphasis>not</emphasis>
2451 be cached whenever the
2453 method has been activated.
2454 The specified targets may be a list
2455 or an individual target.
2459 Multiple files should be specified
2460 either as separate arguments to the
2462 method, or as a list.
2464 will also accept the return value of any of the construction environment
2471 on directories and other non-File Node types has no effect because
2472 only File Nodes are cached.
2481 NoCache(env.Program('hello', 'hello.c'))
2486 <scons_function name="NoClean">
2492 Specifies a list of files or directories which should
2493 <emphasis>not</emphasis>
2494 be removed whenever the targets (or their dependencies)
2495 are specified with the
2497 command line option.
2498 The specified targets may be a list
2499 or an individual target.
2503 and prevent each specified target
2504 from being removed by calls to the
2510 Multiple files or directories should be specified
2511 either as separate arguments to the
2513 method, or as a list.
2515 will also accept the return value of any of the construction environment
2522 for a target overrides calling
2524 for the same target,
2525 and any targets passed to both functions will
2526 <emphasis>not</emphasis>
2538 NoClean(env.Program('hello', 'hello.c'))
2543 <scons_function name="ParseConfig">
2544 <arguments signature="env">
2545 (command, [function, unique])
2549 Updates the current &consenv; with the values extracted
2550 from the output of running external <parameter>command</parameter>,
2551 by passing it to a helper <parameter>function</parameter>.
2552 <parameter>command</parameter> may be a string
2553 or a list of strings representing the command and
2555 If <parameter>function</parameter>
2556 is omitted or <constant>None</constant>,
2557 &f-link-env-MergeFlags; is used.
2559 duplicate values are not
2560 added to any construction variables;
2562 <parameter>unique=False</parameter>
2563 to allow duplicate values to be added.
2567 <parameter>command</parameter> is executed using the
2568 SCons execution environment (that is, the &consvar;
2569 &cv-link-ENV; in the current &consenv;).
2570 If <parameter>command</parameter> needs additional information
2571 to operate properly, that needs to be set in the execution environment.
2572 For example, <command>pkg-config</command>
2573 may need a custom value set in the <envar>PKG_CONFIG_PATH</envar>
2574 environment variable.
2578 &f-env-MergeFlags; needs to understand
2579 the output produced by <parameter>command</parameter>
2580 in order to distribute it to appropriate &consvars;.
2581 &f-env-MergeFlags; uses a separate function to
2582 do that processing -
2583 see &f-link-env-ParseFlags; for the details, including a
2584 a table of options and corresponding construction variables.
2585 To provide alternative processing of the output of
2586 <parameter>command</parameter>,
2587 you can suppply a custom
2588 <parameter>function</parameter>,
2589 which must accept three arguments:
2590 the &consenv; to modify,
2591 a string argument containing the output from running
2592 <parameter>command</parameter>,
2594 <parameter>unique</parameter> flag.
2599 <scons_function name="ParseDepends">
2601 (filename, [must_exist, only_one])
2605 Parses the contents of <parameter>filename</parameter>
2606 as a list of dependencies in the style of
2609 <application>mkdep</application>,
2610 and explicitly establishes all of the listed dependencies.
2616 if <parameter>filename</parameter>
2619 <parameter>must_exist</parameter>
2620 argument may be set to <constant>True</constant>
2622 raise an exception if the file does not exist,
2623 or is otherwise inaccessible.
2628 <parameter>only_one</parameter>
2629 argument may be set to <constant>True</constant>
2630 to have &SCons; raise an exception
2631 if the file contains dependency
2632 information for more than one target.
2633 This can provide a small sanity check
2634 for files intended to be generated
2635 by, for example, the
2636 <literal>gcc -M</literal>
2638 which should typically only
2639 write dependency information for
2640 one output file into a corresponding
2641 <filename>.d</filename>
2646 <parameter>filename</parameter>
2647 and all of the files listed therein
2648 will be interpreted relative to
2649 the directory of the
2651 file which calls the
2658 <scons_function name="ParseFlags">
2659 <arguments signature="env">
2664 Parses one or more strings containing
2665 typical command-line flags for GCC-style tool chains
2666 and returns a dictionary with the flag values
2667 separated into the appropriate SCons construction variables.
2668 Intended as a companion to the
2669 &f-link-env-MergeFlags;
2670 method, but allows for the values in the returned dictionary
2671 to be modified, if necessary,
2672 before merging them into the construction environment.
2675 will call this method if its argument is not a dictionary,
2676 so it is usually not necessary to call
2678 directly unless you want to manipulate the values.)
2682 If the first character in any string is
2683 an exclamation mark (<literal>!</literal>),
2684 the rest of the string is executed as a command,
2685 and the output from the command is
2686 parsed as GCC tool chain command-line flags
2687 and added to the resulting dictionary.
2688 This can be used to call a <filename>*-config</filename>
2689 command typical of the POSIX programming environment
2691 <command>pkg-config</command>).
2692 Note that such a command is executed using the
2693 SCons execution environment;
2694 if the command needs additional information,
2695 that information needs to be explicitly provided.
2696 See &f-link-ParseConfig; for more details.
2700 Flag values are translated according to the prefix found,
2701 and added to the following construction variables:
2705 -arch CCFLAGS, LINKFLAGS
2707 -framework FRAMEWORKS
2708 -frameworkdir= FRAMEWORKPATH
2709 -fmerge-all-constants CCFLAGS, LINKFLAGS
2710 -fopenmp CCFLAGS, LINKFLAGS
2711 -fsanitize CCFLAGS, LINKFLAGS
2714 -isysroot CCFLAGS, LINKFLAGS
2721 -mno-cygwin CCFLAGS, LINKFLAGS
2723 -openmp CCFLAGS, LINKFLAGS
2724 -pthread CCFLAGS, LINKFLAGS
2727 -Wa, ASFLAGS, CCFLAGS
2734 + CCFLAGS, LINKFLAGS
2738 Any other strings not associated with options
2739 are assumed to be the names of libraries
2742 construction variable.
2746 Examples (all of which produce the same result):
2750 dict = env.ParseFlags('-O2 -Dfoo -Dbar=1')
2751 dict = env.ParseFlags('-O2', '-Dfoo', '-Dbar=1')
2752 dict = env.ParseFlags(['-O2', '-Dfoo -Dbar=1'])
2753 dict = env.ParseFlags('-O2', '!echo -Dfoo -Dbar=1')
2758 <scons_function name="Platform">
2759 <arguments signature="global">
2762 <arguments signature="env">
2767 When called as a global function,
2768 returns a callable platform object
2769 selected by <parameter>plat</parameter>
2770 (defaults to the detected platform for the
2772 that can be used to initialize
2773 a construction environment by passing it as the
2774 <parameter>platform</parameter> keyword argument to the
2775 &f-link-Environment; function.
2783 env = Environment(platform=Platform('win32'))
2787 When called as a method of an environment,
2788 calls the platform object indicated by
2789 <parameter>plat</parameter>
2790 to update that environment.
2794 env.Platform('posix')
2798 See the manpage section "Construction Environments" for more details.
2803 <scons_function name="Prepend">
2804 <arguments signature="env">
2809 Prepend values to &consvars; in the current &consenv;,
2810 Works like &f-link-env-Append; (see for details),
2811 except that values are added to the front,
2812 rather than the end, of any existing value of the &consvar;
2820 env.Prepend(CCFLAGS='-g ', FOO=['foo.yyy'])
2824 See also &f-link-env-Append;,
2825 &f-link-env-AppendUnique;
2826 and &f-link-env-PrependUnique;.
2831 <scons_function name="PrependENVPath">
2832 <arguments signature="env">
2833 (name, newpath, [envname, sep, delete_existing=True])
2837 Prepend path elements specified by <parameter>newpath</parameter>
2838 to the given search path string or list <parameter>name</parameter>
2839 in mapping <parameter>envname</parameter> in the &consenv;.
2840 Supplying <parameter>envname</parameter> is optional:
2841 the default is the execution environment &cv-link-ENV;.
2842 Optional <parameter>sep</parameter> is used as the search path separator,
2843 the default is the platform's separator (<systemitem>os.pathsep</systemitem>).
2844 A path element will only appear once.
2845 Any duplicates in <parameter>newpath</parameter> are dropped,
2846 keeping the first appearing (to preserve path order).
2847 If <parameter>delete_existing</parameter>
2848 is <constant>False</constant>
2849 any addition duplicating an existing path element is ignored;
2850 if <parameter>delete_existing</parameter>
2851 is <constant>True</constant> (the default) the existing value will
2852 be dropped and the path element will be inserted at the beginning.
2853 To help maintain uniqueness all paths are normalized (using
2854 <systemitem>os.path.normpath</systemitem>
2856 <systemitem>os.path.normcase</systemitem>).
2864 print('before:', env['ENV']['INCLUDE'])
2865 include_path = '/foo/bar:/foo'
2866 env.PrependENVPath('INCLUDE', include_path)
2867 print('after:', env['ENV']['INCLUDE'])
2870 <para>Yields:</para>
2874 after: /foo/bar:/foo:/biz
2878 See also &f-link-env-AppendENVPath;.
2884 <scons_function name="PrependUnique">
2885 <arguments signature="env">
2886 (key=val, [...], [delete_existing=False])
2890 Prepend values to &consvars; in the current &consenv;,
2891 maintaining uniqueness.
2892 Works like &f-link-env-Append;,
2893 except that values are added to the front,
2894 rather than the end, of the &consvar;,
2895 and values that would become duplicates
2897 If <parameter>delete_existing</parameter>
2898 is set to a true value, then for any duplicate,
2899 the existing instance of <parameter>val</parameter> is first removed,
2900 then <parameter>val</parameter> is inserted,
2901 having the effect of moving it to the front.
2909 env.PrependUnique(CCFLAGS='-g', FOO=['foo.yyy'])
2913 See also &f-link-env-Append;,
2914 &f-link-env-AppendUnique;
2915 and &f-link-env-Prepend;.
2920 <scons_function name="PyPackageDir">
2926 Finds the location of <parameter>modulename</parameter>,
2927 which can be a string or a sequence of strings,
2928 each representing the name of a &Python; module.
2929 Construction variables are expanded in
2930 <parameter>modulename</parameter>.
2931 Returns a Directory Node (see &f-link-Dir;),
2932 or a list of Directory Nodes if
2933 <parameter>modulename</parameter> is a sequence.
2934 <literal>None</literal> is returned for any module not found.
2938 When a Tool module which is installed as a
2939 &Python; module is used, you need
2940 to specify a <parameter>toolpath</parameter> argument to
2942 &f-link-Environment;
2944 as tools outside the standard project locations
2945 (<filename>site_scons/site_tools</filename>)
2946 will not be found otherwise.
2947 Using &f-PyPackageDir; allows this path to be
2948 discovered at runtime instead of hardcoding the path.
2957 tools=["default", "ExampleTool"],
2958 toolpath=[PyPackageDir("example_tool")]
2964 <scons_function name="Replace">
2965 <arguments signature="env">
2970 Replaces construction variables in the Environment
2971 with the specified keyword arguments.
2979 env.Replace(CCFLAGS='-g', FOO='foo.xxx')
2984 <scons_function name="Repository">
2991 <parameter>directory</parameter>
2992 is a repository to be searched for files.
2996 and each one adds to the list of
2997 repositories that will be searched.
3003 a repository is a copy of the source tree,
3004 from the top-level directory on down,
3006 both source files and derived files
3007 that can be used to build targets in
3008 the local source tree.
3009 The canonical example would be an
3010 official source tree maintained by an integrator.
3011 If the repository contains derived files,
3012 then the derived files should have been built using
3014 so that the repository contains the necessary
3015 signature information to allow
3017 to figure out when it is appropriate to
3018 use the repository copy of a derived file,
3019 instead of building one locally.
3023 Note that if an up-to-date derived file
3024 already exists in a repository,
3027 <emphasis>not</emphasis>
3028 make a copy in the local directory tree.
3029 In order to guarantee that a local copy
3038 <scons_function name="Requires">
3040 (target, prerequisite)
3044 Specifies an order-only relationship
3045 between <parameter>target</parameter>
3046 and <parameter>prerequisite</parameter>.
3048 will be (re)built, if necessary,
3049 <emphasis>before</emphasis>
3051 but the target file(s) do not actually
3052 depend on the prerequisites
3053 and will not be rebuilt simply because
3054 the prerequisite file(s) change.
3055 <parameter>target</parameter> and
3056 <parameter>prerequisite</parameter> may each
3057 be a string or Node, or a list of strings or Nodes.
3058 If there are multiple
3059 <parameter>target</parameter> values,
3060 the prerequisite(s) are added to each one.
3061 Returns a list of the affected target nodes.
3069 env.Requires('foo', 'file-that-must-be-built-before-foo')
3074 <scons_function name="Scanner">
3076 (function, [name, argument, skeys, path_function, node_class, node_factory, scan_check, recursive])
3080 Creates a Scanner object for
3082 <parameter>function</parameter>.
3083 See manpage section "Scanner Objects"
3084 for a complete explanation of the arguments and behavior.
3089 <scons_function name="SConscriptChdir">
3090 <arguments signature="global">
3097 changes its working directory
3098 to the directory in which each
3099 subsidiary SConscript file lives
3100 while reading and processing that script.
3101 This behavior may be disabled
3102 by specifying an argument which
3103 evaluates false, in which case
3105 will stay in the top-level directory
3106 while reading all SConscript files.
3107 (This may be necessary when building from repositories,
3108 when all the directories in which SConscript files may be found
3109 don't necessarily exist locally.)
3110 You may enable and disable
3111 this ability by calling
3121 SConscriptChdir(False)
3122 SConscript('foo/SConscript') # will not chdir to foo
3123 SConscriptChdir(True)
3124 SConscript('bar/SConscript') # will chdir to bar
3129 <scons_function name="SConsignFile">
3131 ([name, dbm_module])
3135 Specify where to store the &SCons; file signature database,
3136 and which database format to use.
3137 This may be useful to specify alternate
3138 database files and/or file locations for different types of builds.
3141 The optional <parameter>name</parameter> argument
3142 is the base name of the database file(s).
3143 If not an absolute path name,
3144 these are placed relative to the directory containing the
3145 top-level &SConstruct; file.
3147 <filename>.sconsign</filename>.
3148 The actual database file(s) stored on disk
3149 may have an appropriate suffix appended
3151 <parameter>dbm_module</parameter>
3154 The optional <parameter>dbm_module</parameter>
3155 argument specifies which
3156 &Python; database module to use
3157 for reading/writing the file.
3158 The module must be imported first;
3159 then the imported module name
3160 is passed as the argument.
3161 The default is a custom
3162 <systemitem>SCons.dblite</systemitem>
3163 module that uses pickled
3164 &Python; data structures,
3165 which works on all &Python; versions.
3166 See documentation of the &Python;
3167 <systemitem>dbm</systemitem> module
3168 for other available types.
3171 If called with no arguments,
3172 the database will default to
3173 <filename>.sconsign.dblite</filename>
3174 in the top directory of the project,
3175 which is also the default if
3176 if &f-SConsignFile; is not called.
3179 The setting is global, so the only difference
3180 between the global function and the environment method form
3181 is variable expansion on <parameter>name</parameter>.
3182 There should only be one active call to this
3183 function/method in a given build setup.
3187 <parameter>name</parameter>
3189 <constant>None</constant>,
3191 will store file signatures
3193 <filename>.sconsign</filename>
3194 file in each directory,
3195 not in a single combined database file.
3196 This is a backwards-compatibility meaure to support
3197 what was the default behavior
3198 prior to &SCons; 0.97 (i.e. before 2008).
3199 Use of this mode is discouraged and may be
3200 deprecated in a future &SCons; release.
3208 # Explicitly stores signatures in ".sconsign.dblite"
3209 # in the top-level SConstruct directory (the default behavior).
3212 # Stores signatures in the file "etc/scons-signatures"
3213 # relative to the top-level SConstruct directory.
3214 # SCons will add a database suffix to this name.
3215 SConsignFile("etc/scons-signatures")
3217 # Stores signatures in the specified absolute file name.
3218 # SCons will add a database suffix to this name.
3219 SConsignFile("/home/me/SCons/signatures")
3221 # Stores signatures in a separate .sconsign file
3222 # in each directory.
3225 # Stores signatures in a GNU dbm format .sconsign file
3227 SConsignFile(dbm_module=dbm.gnu)
3232 <scons_function name="SetDefault">
3233 <arguments signature="env">
3238 Sets construction variables to default values specified with the keyword
3239 arguments if (and only if) the variables are not already set.
3240 The following statements are equivalent:
3244 env.SetDefault(FOO='foo')
3245 if 'FOO' not in env:
3251 <scons_function name="SideEffect">
3253 (side_effect, target)
3258 <parameter>side_effect</parameter>
3259 as a side effect of building
3260 <parameter>target</parameter>.
3262 <parameter>side_effect</parameter>
3264 <parameter>target</parameter>
3265 can be a list, a file name, or a node.
3266 A side effect is a target file that is created or updated
3267 as a side effect of building other targets.
3268 For example, a Windows PDB
3269 file is created as a side effect of building the .obj
3270 files for a static library,
3271 and various log files are created updated
3272 as side effects of various TeX commands.
3273 If a target is a side effect of multiple build commands,
3275 will ensure that only one set of commands
3276 is executed at a time.
3277 Consequently, you only need to use this method
3278 for side-effect targets that are built as a result of
3279 multiple build commands.
3283 Because multiple build commands may update
3284 the same side effect file,
3286 <parameter>side_effect</parameter>
3288 <emphasis>not</emphasis>
3289 automatically removed
3291 <parameter>target</parameter>
3295 (Note, however, that the
3296 <parameter>side_effect</parameter>
3297 might be removed as part of
3298 cleaning the directory in which it lives.)
3299 If you want to make sure the
3300 <parameter>side_effect</parameter>
3301 is cleaned whenever a specific
3302 <parameter>target</parameter>
3304 you must specify this explicitly
3313 This function returns the list of side effect Node objects that were successfully added.
3314 If the list of side effects contained any side effects that had already been added,
3315 they are not added and included in the returned list.
3320 <scons_function name="Split">
3321 <arguments>(arg)</arguments>
3324 If <parameter>arg</parameter> is a string,
3325 splits on whitespace and returns a list of
3326 strings without whitespace.
3327 This mode is the most common case,
3328 and can be used to split a list of filenames
3329 (for example) rather than having to type them as a
3330 list of individually quoted words.
3331 If <parameter>arg</parameter> is a list or tuple
3332 returns the list or tuple unchanged.
3333 If <parameter>arg</parameter> is any other type of object,
3334 returns a list containing just the object.
3335 These non-string cases do not actually do any spliting,
3336 but allow an argument variable to be passed to
3337 &f-Split; without having to first check its type.
3345 files = Split("f1.c f2.c f3.c")
3346 files = env.Split("f4.c f5.c f6.c")
3356 <scons_function name="subst">
3357 <arguments signature="env">
3358 (input, [raw, target, source, conv])
3362 Performs &consvar; interpolation
3363 (<firstterm>substitution</firstterm>)
3364 on <parameter>input</parameter>,
3365 which can be a string or a sequence.
3366 Substitutable elements take the form
3367 <literal>${<replaceable>expression</replaceable>}</literal>,
3368 although if there is no ambiguity in recognizing the element,
3369 the braces can be omitted.
3370 A literal <emphasis role="bold">$</emphasis> can be entered by
3371 using <emphasis role="bold">$$</emphasis>.
3376 leading or trailing white space will
3377 be removed from the result,
3378 and all sequences of white space
3379 will be compressed to a single space character.
3381 <literal>$(</literal>
3383 <literal>$)</literal>
3384 character sequences will be stripped from the returned string,
3386 <parameter>raw</parameter>
3387 argument may be set to
3388 <literal>1</literal>
3389 if you want to preserve white space and
3390 <literal>$(</literal>-<literal>$)</literal>
3393 <parameter>raw</parameter>
3394 argument may be set to
3395 <literal>2</literal>
3396 if you want to additionally discard
3397 all characters between any
3398 <literal>$(</literal>
3400 <literal>$)</literal>
3402 (as is done for signature calculation).
3406 If <parameter>input</parameter> is a sequence
3408 the individual elements of
3409 the sequence will be expanded,
3410 and the results will be returned as a list.
3415 <parameter>target</parameter>
3417 <parameter>source</parameter>
3419 must be set to lists of
3420 target and source nodes, respectively,
3427 to be available for expansion.
3428 This is usually necessary if you are
3431 from within a &Python; function used
3436 Returned string values or sequence elements
3437 are converted to their string representation by default.
3439 <parameter>conv</parameter>
3441 may specify a conversion function
3442 that will be used in place of
3444 For example, if you want &Python; objects
3445 (including SCons Nodes)
3446 to be returned as &Python; objects,
3447 you can use a &Python;
3448 lambda expression to pass in an unnamed function
3449 that simply returns its unconverted argument.
3457 print(env.subst("The C compiler is: $CC"))
3459 def compile(target, source, env):
3460 sourceDir = env.subst(
3466 source_nodes = env.subst('$EXPAND_TO_NODELIST', conv=lambda x: x)
3471 <scons_function name="Tool">
3473 (name, [toolpath, **kwargs])
3478 Locates the tool specification module <parameter>name</parameter>
3479 and returns a callable tool object for that tool.
3480 When the environment method (&f-env-Tool;) form is used,
3481 the tool object is automatically called before the method returns
3482 to update <varname>env</varname>,
3483 and <parameter>name</parameter> is
3484 appended to the &cv-link-TOOLS;
3485 &consvar; in that environment.
3486 When the global function &f-Tool; form is used,
3487 the tool object is constructed but not called,
3488 as it lacks the context of an environment to update,
3489 and the returned object needs to be used to arrange for the call.
3493 The tool module is searched for in the tool search paths (see the
3494 <emphasis role="bold">Tools</emphasis> section in the manual page
3496 and in any paths specified by the optional
3497 <parameter>toolpath</parameter> parameter,
3498 which must be a list of strings.
3499 If <parameter>toolpath</parameter> is omitted,
3500 the <parameter>toolpath</parameter>
3501 supplied when the environment was created,
3506 Any remaining keyword arguments are saved in
3508 and will be passed to the tool module's
3509 <function>generate</function> function
3510 when the tool object is actually called.
3511 The <function>generate</function> function
3512 can update the &consenv; with &consvars; and arrange
3513 any other initialization
3514 needed to use the mechanisms that tool describes,
3515 and can use these extra arguments to help
3520 <emphasis>Changed in version 4.2:</emphasis>
3521 &f-env-Tool; now returns the tool object,
3522 previously it did not return (i.e. returned <constant>None</constant>).
3531 env.Tool('opengl', toolpath=['build/tools'])
3535 The returned tool object can be passed to an
3536 &f-link-Environment; or &f-link-Clone; call
3537 as part of the <parameter>tools</parameter> keyword argument,
3538 in which case the tool is applied to the environment being constructed,
3539 or it can be called directly,
3540 in which case a &consenv; to update must be
3541 passed as the argument.
3542 Either approach will also update the
3543 &cv-TOOLS; &consvar;.
3551 env = Environment(tools=[Tool('msvc')])
3554 msvctool = Tool('msvc')
3555 msvctool(env) # adds 'msvc' to the TOOLS variable
3556 gltool = Tool('opengl', toolpath = ['tools'])
3557 gltool(env) # adds 'opengl' to the TOOLS variable
3562 <scons_function name="Value">
3564 (value, [built_value], [name])
3568 Returns a Node object representing the specified &Python;
3569 <parameter>value</parameter>.
3570 Value Nodes can be used as dependencies of targets.
3571 If the string representation of the Value Node
3572 changes between &SCons; runs, it is considered
3573 out of date and any targets depending it will be rebuilt.
3574 Since Value Nodes have no filesystem representation,
3575 timestamps are not used; the timestamp deciders
3576 perform the same content-based up to date check.
3580 <parameter>built_value</parameter>
3581 argument can be specified
3582 when the Value Node is created
3583 to indicate the Node should already be considered "built."
3587 The optional <parameter>name</parameter> parameter can be provided as an
3588 alternative name for the resulting <literal>Value</literal> node;
3589 this is advised if the <parameter>value</parameter> parameter
3590 cannot be converted to a string.
3595 <methodname>write</methodname>
3596 method that can be used to "build" a Value Node
3597 by setting a new value.
3599 <methodname>read</methodname>
3600 method returns the built value of the Node.
3604 <emphasis>Changed in version 4.0:</emphasis>
3605 the <parameter>name</parameter> parameter was added.
3612 <!-- TODO fix second example or replace - still doesn't work -->
3616 def create(target, source, env):
3617 """Action function to create a file from a Value.
3619 Writes 'prefix=$SOURCE' into the file name given as $TARGET.
3621 with open(str(target[0]), 'wb') as f:
3622 f.write(b'prefix=' + source[0].get_contents() + b'\n')
3624 # Fetch the prefix= argument, if any, from the command line.
3625 # Use /usr/local as the default.
3626 prefix = ARGUMENTS.get('prefix', '/usr/local')
3628 # Attach builder named Config to the construction environment
3629 # using the 'create' action function above.
3630 env['BUILDERS']['Config'] = Builder(action=create)
3631 env.Config(target='package-config', source=Value(prefix))
3633 def build_value(target, source, env):
3634 """Action function to "build" a Value.
3636 Writes contents of $SOURCE into $TARGET, thus updating if it existed.
3638 target[0].write(source[0].get_contents())
3640 output = env.Value('before')
3641 input = env.Value('after')
3643 # Attach a builder named UpdateValue to the construction environment
3644 # using the 'build_value' action function above.
3645 env['BUILDERS']['UpdateValue'] = Builder(action=build_value)
3646 env.UpdateValue(target=Value(output), source=Value(input))
3651 <scons_function name="VariantDir">
3653 (variant_dir, src_dir, [duplicate])
3657 Sets up a mapping to define a variant build directory in
3658 <parameter>variant_dir</parameter>.
3659 <parameter>src_dir</parameter> must not be underneath
3660 <parameter>variant_dir</parameter>.
3661 A &f-VariantDir; mapping is global, even if called using the
3662 &f-env-VariantDir; form.
3664 can be called multiple times with the same
3665 <parameter>src_dir</parameter>
3666 to set up multiple variant builds with different options.
3670 Note if <parameter>variant_dir</parameter>
3671 is not under the project top directory,
3672 target selection rules will not pick targets in the
3673 variant directory unless they are explicitly specified.
3677 When files in <parameter>variant_dir</parameter> are referenced,
3678 &SCons; backfills as needed with files from <parameter>src_dir</parameter>
3679 to create a complete build directory.
3681 physically duplicates the source files, SConscript files,
3682 and directory structure as needed into the variant directory.
3683 Thus, a build performed in the variant directory is guaranteed to be identical
3684 to a build performed in the source directory even if
3685 intermediate source files are generated during the build,
3686 or if preprocessors or other scanners search for included files
3687 using paths relative to the source file,
3688 or if individual compilers or other invoked tools are hard-coded
3689 to put derived files in the same directory as source files.
3690 Only the files &SCons; calculates are needed for the build are
3691 duplicated into <parameter>variant_dir</parameter>.
3692 If possible on the platform,
3693 the duplication is performed by linking rather than copying.
3694 This behavior is affected by the
3695 <option>--duplicate</option>
3696 command-line option.
3700 Duplicating the source files may be disabled by setting the
3701 <parameter>duplicate</parameter>
3703 <constant>False</constant>.
3706 to invoke Builders using the path names of source files in
3707 <parameter>src_dir</parameter>
3708 and the path names of derived files within
3709 <parameter>variant_dir</parameter>.
3710 This is more efficient than duplicating,
3711 and is safe for most builds;
3712 revert to <literal>duplicate=True</literal>
3713 if it causes problems.
3718 works most naturally when used with a subsidiary SConscript file.
3719 The subsidiary SConscript file must be called as if it were in
3720 <parameter>variant_dir</parameter>,
3721 regardless of the value of
3722 <parameter>duplicate</parameter>.
3723 When calling an SConscript file, you can use the
3724 <parameter>exports</parameter> keyword argument
3725 to pass parameters (individually or as an appropriately set up environment)
3726 so the SConscript can pick up the right settings for that variant build.
3727 The SConscript must &f-link-Import; these to use them. Example:
3731 env1 = Environment(...settings for variant1...)
3732 env2 = Environment(...settings for variant2...)
3734 # run src/SConscript in two variant directories
3735 VariantDir('build/variant1', 'src')
3736 SConscript('build/variant1/SConscript', exports={"env": env1})
3737 VariantDir('build/variant2', 'src')
3738 SConscript('build/variant2/SConscript', exports={"env": env2})
3743 &f-link-SConscript; function
3744 for another way to specify a variant directory
3745 in conjunction with calling a subsidiary SConscript file.
3753 # use names in the build directory, not the source directory
3754 VariantDir('build', 'src', duplicate=0)
3755 Program('build/prog', 'build/source.c')
3757 # this builds both the source and docs in a separate subtree
3758 VariantDir('build', '.', duplicate=0)
3759 SConscript(dirs=['build/src','build/doc'])
3761 # same as previous example, but only uses SConscript
3762 SConscript(dirs='src', variant_dir='build/src', duplicate=0)
3763 SConscript(dirs='doc', variant_dir='build/doc', duplicate=0)
3768 <scons_function name="WhereIs">
3770 (program, [path, pathext, reject])
3774 Searches for the specified executable
3775 <parameter>program</parameter>,
3776 returning the full path to the program
3777 or <constant>None</constant>.
3780 When called as a &consenv; method,
3781 searches the paths in the
3782 <parameter>path</parameter> keyword argument,
3783 or if <constant>None</constant> (the default)
3784 the paths listed in the &consenv;
3785 (<varname>env</varname><literal>['ENV']['PATH']</literal>).
3786 The external environment's path list
3787 (<literal>os.environ['PATH']</literal>)
3788 is used as a fallback if the key
3789 <varname>env</varname><literal>['ENV']['PATH']</literal>
3793 On Windows systems, searches for executable
3794 programs with any of the file extensions listed in the
3795 <parameter>pathext</parameter> keyword argument,
3796 or if <constant>None</constant> (the default)
3797 the pathname extensions listed in the &consenv;
3798 (<varname>env</varname><literal>['ENV']['PATHEXT']</literal>).
3799 The external environment's pathname extensions list
3800 (<literal>os.environ['PATHEXT']</literal>)
3801 is used as a fallback if the key
3802 <varname>env</varname><literal>['ENV']['PATHEXT']</literal>
3806 When called as a global function, uses the external
3808 <literal>os.environ['PATH']</literal>
3810 <literal>os.environ['PATHEXT']</literal>,
3812 <parameter>path</parameter> and
3813 <parameter>pathext</parameter> are
3814 <constant>None</constant>.
3820 <parameter>reject</parameter>