fa9b16c389f2af97e5e42bda91245f93f4389ab9
[scons.git] / doc / man / scons.1
1 .\" __COPYRIGHT__
2 .\"
3 .\" Permission is hereby granted, free of charge, to any person obtaining
4 .\" a copy of this software and associated documentation files (the
5 .\" "Software"), to deal in the Software without restriction, including
6 .\" without limitation the rights to use, copy, modify, merge, publish,
7 .\" distribute, sublicense, and/or sell copies of the Software, and to
8 .\" permit persons to whom the Software is furnished to do so, subject to
9 .\" the following conditions:
10 .\"
11 .\" The above copyright notice and this permission notice shall be included
12 .\" in all copies or substantial portions of the Software.
13 .\"
14 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
15 .\" KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
16 .\" WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 .\" NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 .\" LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 .\" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 .\" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 .\"
22 .\" __FILE__ __REVISION__ __DATE__ __DEVELOPER__
23 .\"
24 .TH SCONS 1 "__MONTH_YEAR__"
25 .\" ES - Example Start - indents and turns off line fill
26 .rm ES
27 .de ES
28 .RS
29 .nf
30 ..
31 .\" EE - Example End - ends indent and turns line fill back on
32 .rm EE
33 .de EE
34 .fi
35 .RE
36 ..
37 .SH NAME
38 scons \- a software construction tool
39 .SH SYNOPSIS
40 .B scons
41 [
42 .IR options ...
43 ]
44 [
45 .IR name = val ...
46 ]
47 [
48 .IR targets ...
49 ]
50 .SH DESCRIPTION
51
52 The
53 .B scons
54 utility builds software (or other files) by determining which
55 component pieces must be rebuilt and executing the necessary commands to
56 rebuild them.
57
58 By default,
59 .B scons
60 searches for a file named
61 .IR SConstruct ,
62 .IR Sconstruct ,
63 or
64 .I sconstruct
65 (in that order) in the current directory and reads its
66 configuration from the first file found.
67 An alternate file name may be
68 specified via the
69 .B -f
70 option.
71
72 The
73 .I SConstruct
74 file can specify subsidiary
75 configuration files using the
76 .BR SConscript ()
77 function.
78 By convention,
79 these subsidiary files are named
80 .IR SConscript ,
81 although any name may be used.
82 (Because of this naming convention,
83 the term "SConscript files"
84 is sometimes used to refer
85 generically to all
86 .B scons
87 configuration files,
88 regardless of actual file name.)
89
90 The configuration files
91 specify the target files to be built, and
92 (optionally) the rules to build those targets.  Reasonable default
93 rules exist for building common software components (executable
94 programs, object files, libraries), so that for most software
95 projects, only the target and input files need be specified.
96
97 Before reading the
98 .I SConstruct
99 file,
100 .B scons
101 looks for a directory named
102 .I site_scons
103 in the directory containing the
104 .I SConstruct
105 file; if it exists,
106 .I site_scons
107 is added to sys.path,
108 the file
109 .IR site_scons/site_init.py ,
110 is evaluated if it exists,
111 and the directory
112 .I site_scons/site_tools
113 is added to the default toolpath if it exist.
114 See the
115 .I --no-site-dir
116 and
117 .I --site-dir
118 options for more details.
119
120 .B scons
121 reads and executes the SConscript files as Python scripts,
122 so you may use normal Python scripting capabilities
123 (such as flow control, data manipulation, and imported Python libraries)
124 to handle complicated build situations.
125 .BR scons ,
126 however, reads and executes all of the SConscript files
127 .I before
128 it begins building any targets.
129 To make this obvious,
130 .B scons
131 prints the following messages about what it is doing:
132
133 .ES
134 $ scons foo.out
135 scons: Reading SConscript files ...
136 scons: done reading SConscript files.
137 scons: Building targets  ...
138 cp foo.in foo.out
139 scons: done building targets.
140 $
141 .EE
142
143 The status messages
144 (everything except the line that reads "cp foo.in foo.out")
145 may be suppressed using the
146 .B -Q
147 option.
148
149 .B scons
150 does not automatically propagate
151 the external environment used to execute
152 .B scons
153 to the commands used to build target files.
154 This is so that builds will be guaranteed
155 repeatable regardless of the environment
156 variables set at the time
157 .B scons
158 is invoked.
159 This also means that if the compiler or other commands
160 that you want to use to build your target files
161 are not in standard system locations,
162 .B scons
163 will not find them unless
164 you explicitly set the PATH
165 to include those locations.
166 Whenever you create an
167 .B scons
168 construction environment,
169 you can propagate the value of PATH
170 from your external environment as follows:
171
172 .ES
173 import os
174 env = Environment(ENV = {'PATH' : os.environ['PATH']})
175 .EE
176
177 Similarly, if the commands use external environment variables
178 like $PATH, $HOME, $JAVA_HOME, $LANG, $SHELL, $TERM, etc.,
179 these variables can also be explicitly propagated:
180
181 .ES
182 import os
183 env = Environment(ENV = {'PATH' : os.environ['PATH'],
184                          'HOME' : os.environ['HOME']})
185 .EE
186
187 Or you may explicitly propagate the invoking user's
188 complete external environment:
189
190 .ES
191 import os
192 env = Environment(ENV = os.environ)
193 .EE
194
195 This comes at the expense of making your build
196 dependent on the user's environment being set correctly,
197 but it may be more convenient for many configurations.
198
199 .B scons
200 can scan known input files automatically for dependency
201 information (for example, #include statements
202 in C or C++ files) and will rebuild dependent files appropriately
203 whenever any "included" input file changes.
204 .B scons
205 supports the
206 ability to define new scanners for unknown input file types.
207
208 .B scons
209 knows how to fetch files automatically from
210 SCCS or RCS subdirectories
211 using SCCS, RCS or BitKeeper.
212
213 .B scons
214 is normally executed in a top-level directory containing a
215 .I SConstruct
216 file, optionally specifying
217 as command-line arguments
218 the target file or files to be built.
219
220 By default, the command
221
222 .ES
223 scons
224 .EE
225
226 will build all target files in or below the current directory.
227 Explicit default targets
228 (to be built when no targets are specified on the command line)
229 may be defined the SConscript file(s)
230 using the
231 .B Default()
232 function, described below.
233
234 Even when
235 .B Default()
236 targets are specified in the SConscript file(s),
237 all target files in or below the current directory
238 may be built by explicitly specifying
239 the current directory (.)
240 as a command-line target:
241
242 .ES
243 scons .
244 .EE
245
246 Building all target files,
247 including any files outside of the current directory,
248 may be specified by supplying a command-line target
249 of the root directory (on POSIX systems):
250
251 .ES
252 scons /
253 .EE
254
255 or the path name(s) of the volume(s) in which all the targets
256 should be built (on Windows systems):
257
258 .ES
259 scons C:\\ D:\\
260 .EE
261
262 To build only specific targets,
263 supply them as command-line arguments:
264
265 .ES
266 scons foo bar
267 .EE
268
269 in which case only the specified targets will be built
270 (along with any derived files on which they depend).
271
272 Specifying "cleanup" targets in SConscript files is not usually necessary.
273 The
274 .B -c
275 flag removes all files
276 necessary to build the specified target:
277
278 .ES
279 scons -c .
280 .EE
281
282 to remove all target files, or:
283
284 .ES
285 scons -c build export
286 .EE
287
288 to remove target files under build and export.
289 Additional files or directories to remove can be specified using the
290 .BR Clean()
291 function.
292 Conversely, targets that would normally be removed by the
293 .B -c
294 invocation
295 can be prevented from being removed by using the
296 .BR NoClean ()
297 function.
298
299 A subset of a hierarchical tree may be built by
300 remaining at the top-level directory (where the
301 .I SConstruct
302 file lives) and specifying the subdirectory as the target to be
303 built:
304
305 .ES
306 scons src/subdir
307 .EE
308
309 or by changing directory and invoking scons with the
310 .B -u
311 option, which traverses up the directory
312 hierarchy until it finds the
313 .I SConstruct
314 file, and then builds
315 targets relatively to the current subdirectory:
316
317 .ES
318 cd src/subdir
319 scons -u .
320 .EE
321
322 .B scons
323 supports building multiple targets in parallel via a
324 .B -j
325 option that takes, as its argument, the number
326 of simultaneous tasks that may be spawned:
327
328 .ES
329 scons -j 4
330 .EE
331
332 builds four targets in parallel, for example.
333
334 .B scons
335 can maintain a cache of target (derived) files that can
336 be shared between multiple builds.  When caching is enabled in a
337 SConscript file, any target files built by
338 .B scons
339 will be copied
340 to the cache.  If an up-to-date target file is found in the cache, it
341 will be retrieved from the cache instead of being rebuilt locally.
342 Caching behavior may be disabled and controlled in other ways by the
343 .BR --cache-force ,
344 .BR --cache-disable ,
345 and
346 .B --cache-show
347 command-line options.  The
348 .B --random
349 option is useful to prevent multiple builds
350 from trying to update the cache simultaneously.
351
352 Values of variables to be passed to the SConscript file(s)
353 may be specified on the command line:
354
355 .ES
356 scons debug=1 .
357 .EE
358
359 These variables are available in SConscript files
360 through the ARGUMENTS dictionary,
361 and can be used in the SConscript file(s) to modify
362 the build in any way:
363
364 .ES
365 if ARGUMENTS.get('debug', 0):
366     env = Environment(CCFLAGS = '-g')
367 else:
368     env = Environment()
369 .EE
370
371 The command-line variable arguments are also available
372 in the ARGLIST list,
373 indexed by their order on the command line.
374 This allows you to process them in order rather than by name,
375 if necessary.
376 ARGLIST[0] returns a tuple
377 containing (argname, argvalue).
378 A Python exception is thrown if you
379 try to access a list member that
380 does not exist.
381
382 .B scons
383 requires Python version 1.5.2 or later.
384 There should be no other dependencies or requirements to run
385 .B scons.
386
387 .\" The following paragraph reflects the default tool search orders
388 .\" currently in SCons/Tool/__init__.py.  If any of those search orders
389 .\" change, this documentation should change, too.
390 By default,
391 .B scons
392 knows how to search for available programming tools
393 on various systems.
394 On Windows systems,
395 .B scons
396 searches in order for the
397 Microsoft Visual C++ tools,
398 the MinGW tool chain,
399 the Intel compiler tools,
400 and the PharLap ETS compiler.
401 On OS/2 systems,
402 .B scons
403 searches in order for the
404 OS/2 compiler,
405 the GCC tool chain,
406 and the Microsoft Visual C++ tools,
407 On SGI IRIX, IBM AIX, Hewlett Packard HP-UX, and Sun Solaris systems,
408 .B scons
409 searches for the native compiler tools
410 (MIPSpro, Visual Age, aCC, and Forte tools respectively)
411 and the GCC tool chain.
412 On all other platforms,
413 including POSIX (Linux and UNIX) platforms,
414 .B scons
415 searches in order
416 for the GCC tool chain,
417 the Microsoft Visual C++ tools,
418 and the Intel compiler tools.
419 You may, of course, override these default values
420 by appropriate configuration of
421 Environment construction variables.
422
423 .SH OPTIONS
424 In general,
425 .B scons
426 supports the same command-line options as GNU
427 .BR make ,
428 and many of those supported by
429 .BR cons .
430
431 .TP
432 -b
433 Ignored for compatibility with non-GNU versions of
434 .BR make.
435
436 .TP
437 -c, --clean, --remove
438 Clean up by removing all target files for which a construction
439 command is specified.
440 Also remove any files or directories associated to the construction command
441 using the
442 .BR Clean ()
443 function.
444 Will not remove any targets specified by the
445 .BR NoClean ()
446 function.
447
448 .TP
449 .RI --cache-debug= file
450 Print debug information about the
451 .BR CacheDir ()
452 derived-file caching
453 to the specified
454 .IR file .
455 If
456 .I file
457 is
458 .B \-
459 (a hyphen),
460 the debug information are printed to the standard output.
461 The printed messages describe what signature file names are
462 being looked for in, retrieved from, or written to the
463 .BR CacheDir ()
464 directory tree.
465
466 .TP
467 --cache-disable, --no-cache
468 Disable the derived-file caching specified by
469 .BR CacheDir ().
470 .B scons
471 will neither retrieve files from the cache
472 nor copy files to the cache.
473
474 .TP
475 --cache-force, --cache-populate
476 When using
477 .BR CacheDir (),
478 populate a cache by copying any already-existing, up-to-date
479 derived files to the cache,
480 in addition to files built by this invocation.
481 This is useful to populate a new cache with
482 all the current derived files,
483 or to add to the cache any derived files
484 recently built with caching disabled via the
485 .B --cache-disable
486 option.
487
488 .TP
489 --cache-show
490 When using
491 .BR CacheDir ()
492 and retrieving a derived file from the cache,
493 show the command
494 that would have been executed to build the file,
495 instead of the usual report,
496 "Retrieved `file' from cache."
497 This will produce consistent output for build logs,
498 regardless of whether a target
499 file was rebuilt or retrieved from the cache.
500
501 .TP
502 .RI --config= mode
503 This specifies how the
504 .B Configure
505 call should use or generate the
506 results of configuration tests.
507 The option should be specified from
508 among the following choices:
509
510 .TP
511 --config=auto
512 scons will use its normal dependency mechanisms
513 to decide if a test must be rebuilt or not.
514 This saves time by not running the same configuration tests
515 every time you invoke scons,
516 but will overlook changes in system header files
517 or external commands (such as compilers)
518 if you don't specify those dependecies explicitly.
519 This is the default behavior.
520
521 .TP
522 --config=force
523 If this option is specified,
524 all configuration tests will be re-run
525 regardless of whether the
526 cached results are out of date.
527 This can be used to explicitly
528 force the configuration tests to be updated
529 in response to an otherwise unconfigured change
530 in a system header file or compiler.
531
532 .TP
533 --config=cache
534 If this option is specified,
535 no configuration tests will be rerun
536 and all results will be taken from cache.
537 Note that scons will still consider it an error
538 if --config=cache is specified
539 and a necessary test does not
540 yet have any results in the cache.
541
542 .TP
543 .RI "-C" " directory" ",  --directory=" directory
544 Change to the specified
545 .I directory
546 before searching for the
547 .IR SConstruct ,
548 .IR Sconstruct ,
549 or
550 .I sconstruct
551 file, or doing anything
552 else.  Multiple
553 .B -C
554 options are interpreted
555 relative to the previous one, and the right-most
556 .B -C
557 option wins. (This option is nearly
558 equivalent to
559 .BR "-f directory/SConstruct" ,
560 except that it will search for
561 .IR SConstruct ,
562 .IR Sconstruct ,
563 or
564 .I sconstruct
565 in the specified directory.)
566
567 .\" .TP
568 .\" -d
569 .\" Display dependencies while building target files.  Useful for
570 .\" figuring out why a specific file is being rebuilt, as well as
571 .\" general debugging of the build process.
572
573 .TP
574 -D
575 Works exactly the same way as the
576 .B -u
577 option except for the way default targets are handled.
578 When this option is used and no targets are specified on the command line,
579 all default targets are built, whether or not they are below the current
580 directory.
581
582 .TP
583 .RI --debug= type
584 Debug the build process.
585 .I type
586 specifies what type of debugging:
587
588 .TP
589 --debug=count
590 Print how many objects are created
591 of the various classes used internally by SCons
592 before and after reading the SConscript files
593 and before and after building targets.
594 This is not supported when run under Python versions earlier than 2.1,
595 when SCons is executed with the Python
596 .B -O
597 (optimized) option,
598 or when the SCons modules
599 have been compiled with optimization
600 (that is, when executing from
601 .B *.pyo
602 files).
603
604 .TP
605 --debug=dtree
606 A synonym for the newer
607 .B --tree=derived
608 option.
609 This will be deprecated in some future release
610 and ultimately removed.
611
612 .TP
613 --debug=explain
614 Print an explanation of precisely why
615 .B scons
616 is deciding to (re-)build any targets.
617 (Note:  this does not print anything
618 for targets that are
619 .I not
620 rebuilt.)
621
622 .TP
623 --debug=findlibs
624 Instruct the scanner that searches for libraries
625 to print a message about each potential library
626 name it is searching for,
627 and about the actual libraries it finds.
628
629 .TP
630 --debug=includes
631 Print the include tree after each top-level target is built.
632 This is generally used to find out what files are included by the sources
633 of a given derived file:
634
635 .ES
636 $ scons --debug=includes foo.o
637 .EE
638
639 .TP
640 --debug=memoizer
641 Prints a summary of hits and misses using the Memoizer,
642 an internal subsystem that counts
643 how often SCons uses cached values in memory
644 instead of recomputing them each time they're needed.
645 Only available when using Python 2.2 or later.
646
647 .TP
648 --debug=memory
649 Prints how much memory SCons uses
650 before and after reading the SConscript files
651 and before and after building targets.
652
653 .TP
654 --debug=nomemoizer
655 A deprecated option preserved for backwards compatibility.
656
657 .TP
658 --debug=objects
659 Prints a list of the various objects
660 of the various classes used internally by SCons.
661 This only works when run under Python 2.1 or later.
662
663 .TP
664 --debug=pdb
665 Re-run SCons under the control of the
666 .RI pdb
667 Python debugger.
668
669 .TP
670 --debug=presub
671 Print the raw command line used to build each target
672 before the construction environment variables are substituted.
673 Also shows which targets are being built by this command.
674 Output looks something like this:
675 .ES
676 $ scons --debug=presub
677 Building myprog.o with action(s):
678   $SHCC $SHCFLAGS $SHCCFLAGS $CPPFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES
679 \&...
680 .EE
681
682 .TP
683 --debug=stacktrace
684 Prints an internal Python stack trace
685 when encountering an otherwise unexplained error.
686
687 .TP
688 --debug=stree
689 A synonym for the newer
690 .B --tree=all,status
691 option.
692 This will be deprecated in some future release
693 and ultimately removed.
694
695 .TP
696 --debug=time
697 Prints various time profiling information:
698 the time spent executing each individual build command;
699 the total build time (time SCons ran from beginning to end);
700 the total time spent reading and executing SConscript files;
701 the total time spent SCons itself spend running
702 (that is, not counting reading and executing SConscript files);
703 and both the total time spent executing all build commands
704 and the elapsed wall-clock time spent executing those build commands.
705 (When
706 .B scons
707 is executed without the
708 .B -j
709 option,
710 the elapsed wall-clock time will typically
711 be slightly longer than the total time spent
712 executing all the build commands,
713 due to the SCons processing that takes place
714 in between executing each command.
715 When
716 .B scons
717 is executed
718 .I with
719 the
720 .B -j
721 option,
722 and your build configuration allows good parallelization,
723 the elapsed wall-clock time should
724 be significantly smaller than the
725 total time spent executing all the build commands,
726 since multiple build commands and
727 intervening SCons processing
728 should take place in parallel.)
729
730 .TP
731 --debug=tree
732 A synonym for the newer
733 .B --tree=all
734 option.
735 This will be deprecated in some future release
736 and ultimately removed.
737
738 .TP
739 .RI --diskcheck= types
740 Enable specific checks for
741 whether or not there is a file on disk
742 where the SCons configuration expects a directory
743 (or vice versa),
744 and whether or not RCS or SCCS sources exist
745 when searching for source and include files.
746 The
747 .I types
748 argument can be set to:
749 .BR all ,
750 to enable all checks explicitly
751 (the default behavior);
752 .BR none ,
753 to disable all such checks;
754 .BR match ,
755 to check that files and directories on disk
756 match SCons' expected configuration;
757 .BR rcs ,
758 to check for the existence of an RCS source
759 for any missing source or include files;
760 .BR sccs ,
761 to check for the existence of an SCCS source
762 for any missing source or include files.
763 Multiple checks can be specified separated by commas;
764 for example,
765 .B --diskcheck=sccs,rcs
766 would still check for SCCS and RCS sources,
767 but disable the check for on-disk matches of files and directories.
768 Disabling some or all of these checks
769 can provide a performance boost for large configurations,
770 or when the configuration will check for files and/or directories
771 across networked or shared file systems,
772 at the slight increased risk of an incorrect build
773 or of not handling errors gracefully
774 (if include files really should be
775 found in SCCS or RCS, for example,
776 or if a file really does exist
777 where the SCons configuration expects a directory).
778
779 .TP
780 .RI --duplicate= ORDER
781 There are three ways to duplicate files in a build tree: hard links,
782 soft (symbolic) links and copies. The default behaviour of SCons is to
783 prefer hard links to soft links to copies. You can specify different
784 behaviours with this option.
785 .IR ORDER
786 must be one of
787 .IR hard-soft-copy
788 (the default),
789 .IR soft-hard-copy ,
790 .IR hard-copy ,
791 .IR soft-copy
792 or
793 .IR copy .
794 SCons will attempt to duplicate files using
795 the mechanisms in the specified order.
796
797 .\" .TP
798 .\" -e, --environment-overrides
799 .\" Variables from the execution environment override construction
800 .\" variables from the SConscript files.
801
802 .TP
803 .RI -f " file" ", --file=" file ", --makefile=" file ", --sconstruct=" file
804 Use
805 .I file
806 as the initial SConscript file.
807 Multiple
808 .B -f
809 options may be specified,
810 in which case
811 .B scons
812 will read all of the specified files.
813
814 .TP
815 -h, --help
816 Print a local help message for this build, if one is defined in
817 the SConscript file(s), plus a line that describes the
818 .B -H
819 option for command-line option help.  If no local help message
820 is defined, prints the standard help message about command-line
821 options.  Exits after displaying the appropriate message.
822
823 .TP
824 -H, --help-options
825 Print the standard help message about command-line options and
826 exit.
827
828 .TP
829 -i, --ignore-errors
830 Ignore all errors from commands executed to rebuild files.
831
832 .TP
833 .RI -I " directory" ", --include-dir=" directory
834 Specifies a
835 .I directory
836 to search for
837 imported Python modules.  If several
838 .B -I
839 options
840 are used, the directories are searched in the order specified.
841
842 .TP
843 --implicit-cache
844 Cache implicit dependencies.
845 This causes
846 .B scons
847 to use the implicit (scanned) dependencies
848 from the last time it was run
849 instead of scanning the files for implicit dependencies.
850 This can significantly speed up SCons,
851 but with the following limitations:
852 .IP
853 .B scons
854 will not detect changes to implicit dependency search paths
855 (e.g.
856 .BR CPPPATH ", " LIBPATH )
857 that would ordinarily
858 cause different versions of same-named files to be used.
859 .IP
860 .B scons
861 will miss changes in the implicit dependencies
862 in cases where a new implicit
863 dependency is added earlier in the implicit dependency search path
864 (e.g.
865 .BR CPPPATH ", " LIBPATH )
866 than a current implicit dependency with the same name.
867
868 .TP
869 --implicit-deps-changed
870 Forces SCons to ignore the cached implicit dependencies. This causes the
871 implicit dependencies to be rescanned and recached. This implies
872 .BR --implicit-cache .
873
874 .TP
875 --implicit-deps-unchanged
876 Force SCons to ignore changes in the implicit dependencies.
877 This causes cached implicit dependencies to always be used.
878 This implies
879 .BR --implicit-cache .
880
881 .TP
882 --interactive
883 Starts SCons in interactive mode.
884 The SConscript files are read once and a
885 .B "scons>>>"
886 prompt is printed.
887 Targets may now be rebuilt by typing commands at interactive prompt
888 without having to re-read the SConscript files
889 and re-initialize the dependency graph from scratch.
890
891 SCons interactive mode supports the following commands:
892
893 .RS 10
894 .TP 6
895 .BI build "[OPTIONS] [TARGETS] ..."
896 Builds the specified
897 .I TARGETS
898 (and their dependencies)
899 with the specified
900 SCons command-line
901 .IR OPTIONS .
902 .B b
903 and
904 .B scons
905 are synonyms.
906
907 The following SCons command-line options affect the
908 .B build
909 command:
910
911 .ES
912 --cache-debug=FILE
913 --cache-disable, --no-cache
914 --cache-force, --cache-populate
915 --cache-show
916 --debug=TYPE
917 -i, --ignore-errors
918 -j N, --jobs=N
919 -k, --keep-going
920 -n, --no-exec, --just-print, --dry-run, --recon
921 -Q
922 -s, --silent, --quiet
923 --taskmastertrace=FILE
924 --tree=OPTIONS
925 .EE
926
927 .IP "" 6
928 Any other SCons command-line options that are specified
929 do not cause errors
930 but have no effect on the
931 .B build
932 command
933 (mainly because they affect how the SConscript files are read,
934 which only happens once at the beginning of interactive mode).
935
936 .TP 6
937 .BI clean "[OPTIONS] [TARGETS] ..."
938 Cleans the specified
939 .I TARGETS
940 (and their dependencies)
941 with the specified options.
942 .B c
943 is a synonym.
944 This command is itself a synonym for
945 .B "build --clean"
946
947 .TP 6
948 .BI exit
949 Exits SCons interactive mode.
950 You can also exit by terminating input
951 (CTRL+D on UNIX or Linux systems,
952 CTRL+Z on Windows systems).
953
954 .TP 6
955 .BI help "[COMMAND]"
956 Provides a help message about
957 the commands available in SCons interactive mode.
958 If
959 .I COMMAND
960 is specified,
961 .B h
962 and
963 .B ?
964 are synonyms.
965
966 .TP 6
967 .BI shell "[COMMANDLINE]"
968 Executes the specified
969 .I COMMANDLINE
970 in a subshell.
971 If no
972 .I COMMANDLINE
973 is specified,
974 executes the interactive command interpreter
975 specified in the
976 .B SHELL
977 environment variable
978 (on UNIX and Linux systems)
979 or the
980 .B COMSPEC
981 environment variable
982 (on Windows systems).
983 .B sh
984 and
985 .B !
986 are synonyms.
987
988 .TP 6
989 .B version
990 Prints SCons version information.
991 .RE
992
993 .IP
994 An empty line repeats the last typed command.
995 Command-line editing can be used if the
996 .B readline
997 module is available.
998
999 .ES
1000 $ scons --interactive
1001 scons: Reading SConscript files ...
1002 scons: done reading SConscript files.
1003 scons>>> build -n prog
1004 scons>>> exit
1005 .EE
1006
1007 .TP
1008 .RI -j " N" ", --jobs=" N
1009 Specifies the number of jobs (commands) to run simultaneously.
1010 If there is more than one
1011 .B -j
1012 option, the last one is effective.
1013 .\" ??? If the
1014 .\" .B -j
1015 .\" option
1016 .\" is specified without an argument,
1017 .\" .B scons
1018 .\" will not limit the number of
1019 .\" simultaneous jobs.
1020
1021 .TP
1022 -k, --keep-going
1023 Continue as much as possible after an error.  The target that
1024 failed and those that depend on it will not be remade, but other
1025 targets specified on the command line will still be processed.
1026
1027 .\" .TP
1028 .\" .RI  -l " N" ", --load-average=" N ", --max-load=" N
1029 .\" No new jobs (commands) will be started if
1030 .\" there are other jobs running and the system load
1031 .\" average is at least
1032 .\" .I N
1033 .\" (a floating-point number).
1034
1035 .\"
1036 .\" .TP
1037 .\" --list-derived
1038 .\" List derived files (targets, dependencies) that would be built,
1039 .\" but do not build them.
1040 .\" [XXX This can probably go away with the right
1041 .\" combination of other options.  Revisit this issue.]
1042 .\"
1043 .\" .TP
1044 .\" --list-actions
1045 .\" List derived files that would be built, with the actions
1046 .\" (commands) that build them.  Does not build the files.
1047 .\" [XXX This can probably go away with the right
1048 .\" combination of other options.  Revisit this issue.]
1049 .\"
1050 .\" .TP
1051 .\" --list-where
1052 .\" List derived files that would be built, plus where the file is
1053 .\" defined (file name and line number).  Does not build the files.
1054 .\" [XXX This can probably go away with the right
1055 .\" combination of other options.  Revisit this issue.]
1056
1057 .TP
1058 -m
1059 Ignored for compatibility with non-GNU versions of
1060 .BR make .
1061
1062 .TP
1063 .RI --max-drift= SECONDS
1064 Set the maximum expected drift in the modification time of files to
1065 .IR SECONDS .
1066 This value determines how long a file must be unmodified
1067 before its cached content signature
1068 will be used instead of
1069 calculating a new content signature (MD5 checksum)
1070 of the file's contents.
1071 The default value is 2 days, which means a file must have a
1072 modification time of at least two days ago in order to have its
1073 cached content signature used.
1074 A negative value means to never cache the content
1075 signature and to ignore the cached value if there already is one. A value
1076 of 0 means to always use the cached signature,
1077 no matter how old the file is.
1078
1079 .TP
1080 .RI --md5-chunksize= KILOBYTES
1081 Set the block size used to compute MD5 signatures to
1082 .IR KILOBYTES . 
1083 This value determines the size of the chunks which are read in at once when
1084 computing MD5 signatures.  Files below that size are fully stored in memory
1085 before performing the signature computation while bigger files are read in
1086 block-by-block. A huge block-size leads to high memory consumption while a very
1087 small block-size slows down the build considerably.
1088
1089 The default value is to use a chunk size of 64 kilobytes, which should
1090 be appropriate for most uses.
1091
1092 .TP
1093 -n, --just-print, --dry-run, --recon
1094 No execute.  Print the commands that would be executed to build
1095 any out-of-date target files, but do not execute the commands.
1096
1097 .TP
1098 .RI --no-site-dir
1099 Prevents the automatic addition of the standard
1100 .I site_scons
1101 dir to
1102 .IR sys.path .
1103 Also prevents loading the
1104 .I site_scons/site_init.py
1105 module if it exists, and prevents adding
1106 .I site_scons/site_tools
1107 to the toolpath.
1108
1109 .\" .TP
1110 .\" .RI -o " file" ", --old-file=" file ", --assume-old=" file
1111 .\" Do not rebuild
1112 .\" .IR file ,
1113 .\" and do
1114 .\" not rebuild anything due to changes in the contents of
1115 .\" .IR file .
1116 .\" .TP
1117 .\" .RI --override " file"
1118 .\" Read values to override specific build environment variables
1119 .\" from the specified
1120 .\" .IR file .
1121 .\" .TP
1122 .\" -p
1123 .\" Print the data base (construction environments,
1124 .\" Builder and Scanner objects) that are defined
1125 .\" after reading the SConscript files.
1126 .\" After printing, a normal build is performed
1127 .\" as usual, as specified by other command-line options.
1128 .\" This also prints version information
1129 .\" printed by the
1130 .\" .B -v
1131 .\" option.
1132 .\"
1133 .\" To print the database without performing a build do:
1134 .\"
1135 .\" .ES
1136 .\" scons -p -q
1137 .\" .EE
1138
1139 .TP
1140 .RI --profile= file
1141 Run SCons under the Python profiler
1142 and save the results in the specified
1143 .IR file .
1144 The results may be analyzed using the Python
1145 pstats module.
1146
1147 .TP
1148 -q, --question
1149 Do not run any commands, or print anything.  Just return an exit
1150 status that is zero if the specified targets are already up to
1151 date, non-zero otherwise.
1152 .TP
1153 -Q
1154 Quiets SCons status messages about
1155 reading SConscript files,
1156 building targets
1157 and entering directories.
1158 Commands that are executed
1159 to rebuild target files are still printed.
1160
1161 .\" .TP
1162 .\" -r, -R, --no-builtin-rules, --no-builtin-variables
1163 .\" Clear the default construction variables.  Construction
1164 .\" environments that are created will be completely empty.
1165
1166 .TP
1167 --random
1168 Build dependencies in a random order.  This is useful when
1169 building multiple trees simultaneously with caching enabled,
1170 to prevent multiple builds from simultaneously trying to build
1171 or retrieve the same target files.
1172
1173 .TP
1174 -s, --silent, --quiet
1175 Silent.  Do not print commands that are executed to rebuild
1176 target files.
1177 Also suppresses SCons status messages.
1178
1179 .TP
1180 -S, --no-keep-going, --stop
1181 Ignored for compatibility with GNU
1182 .BR make .
1183
1184 .TP
1185 .RI --site-dir= dir
1186 Uses the named dir as the site dir rather than the default
1187 .I site_scons
1188 dir.  This dir will get prepended to
1189 .IR sys.path ,
1190 the module
1191 .IR dir /site_init.py
1192 will get loaded if it exists, and
1193 .IR dir /site_tools
1194 will get added to the default toolpath.
1195
1196 .TP
1197 .RI --stack-size= KILOBYTES
1198 Set the size stack used to run threads to
1199 .IR KILOBYTES .
1200 This value determines the stack size of the threads used to run jobs.
1201 These are the threads that execute the actions of the builders for the
1202 nodes that are out-of-date.
1203 Note that this option has no effect unless the
1204 .B num_jobs
1205 option, which corresponds to -j and --jobs, is larger than one.  Using
1206 a stack size that is too small may cause stack overflow errors.  This
1207 usually shows up as segmentation faults that cause scons to abort
1208 before building anything.  Using a stack size that is too large will
1209 cause scons to use more memory than required and may slow down the entire
1210 build process.
1211
1212 The default value is to use a stack size of 256 kilobytes, which should
1213 be appropriate for most uses.  You should not need to increase this value
1214 unless you encounter stack overflow errors.
1215
1216 .TP
1217 -t, --touch
1218 Ignored for compatibility with GNU
1219 .BR make .
1220 (Touching a file to make it
1221 appear up-to-date is unnecessary when using
1222 .BR scons .)
1223
1224 .TP
1225 .RI --taskmastertrace= file
1226 Prints trace information to the specified
1227 .I file
1228 about how the internal Taskmaster object
1229 evaluates and controls the order in which Nodes are built.
1230 A file name of
1231 .B -
1232 may be used to specify the standard output.
1233
1234 .TP
1235 .RI -tree= options
1236 Prints a tree of the dependencies
1237 after each top-level target is built.
1238 This prints out some or all of the tree,
1239 in various formats,
1240 depending on the
1241 .I options
1242 specified:
1243
1244 .TP
1245 --tree=all
1246 Print the entire dependency tree
1247 after each top-level target is built.
1248 This prints out the complete dependency tree,
1249 including implicit dependencies and ignored dependencies.
1250
1251 .TP
1252 --tree=derived
1253 Restricts the tree output to only derived (target) files,
1254 not source files.
1255
1256 .TP
1257 --tree=status
1258 Prints status information for each displayed node.
1259
1260 .TP
1261 --tree=prune
1262 Prunes the tree to avoid repeating dependency information
1263 for nodes that have already been displayed.
1264 Any node that has already been displayed
1265 will have its name printed in
1266 .BR "[square brackets]" ,
1267 as an indication that the dependencies
1268 for that node can be found by searching
1269 for the relevant output higher up in the tree.
1270
1271 .IP
1272 Multiple options may be specified,
1273 separated by commas:
1274
1275 .ES
1276 # Prints only derived files, with status information:
1277 scons --tree=derived,status
1278
1279 # Prints all dependencies of target, with status information
1280 # and pruning dependencies of already-visited Nodes:
1281 scons --tree=all,prune,status target
1282 .EE
1283
1284 .TP
1285 -u, --up, --search-up
1286 Walks up the directory structure until an
1287 .I SConstruct ,
1288 .I Sconstruct
1289 or
1290 .I sconstruct
1291 file is found, and uses that
1292 as the top of the directory tree.
1293 If no targets are specified on the command line,
1294 only targets at or below the
1295 current directory will be built.
1296
1297 .TP
1298 -U
1299 Works exactly the same way as the
1300 .B -u
1301 option except for the way default targets are handled.
1302 When this option is used and no targets are specified on the command line,
1303 all default targets that are defined in the SConscript(s) in the current
1304 directory are built, regardless of what directory the resultant targets end
1305 up in.
1306
1307 .TP
1308 -v, --version
1309 Print the
1310 .B scons
1311 version, copyright information,
1312 list of authors, and any other relevant information.
1313 Then exit.
1314
1315 .TP
1316 -w, --print-directory
1317 Print a message containing the working directory before and
1318 after other processing.
1319
1320 .TP
1321 --no-print-directory
1322 Turn off -w, even if it was turned on implicitly.
1323
1324 .TP
1325 .RI --warn= type ", --warn=no-" type
1326 Enable or disable warnings.
1327 .I type
1328 specifies the type of warnings to be enabled or disabled:
1329
1330 .TP
1331 --warn=all, --warn=no-all
1332 Enables or disables all warnings.
1333
1334 .TP
1335 --warn=cache-write-error, --warn=no-cache-write-error
1336 Enables or disables warnings about errors trying to
1337 write a copy of a built file to a specified
1338 .BR CacheDir ().
1339 These warnings are disabled by default.
1340
1341 .TP
1342 --warn=corrupt-sconsign, --warn=no-corrupt-sconsign
1343 Enables or disables warnings about unfamiliar signature data in
1344 .B .sconsign
1345 files.
1346 These warnings are enabled by default.
1347
1348 .TP
1349 --warn=dependency, --warn=no-dependency
1350 Enables or disables warnings about dependencies.
1351 These warnings are disabled by default.
1352
1353 .TP
1354 --warn=deprecated, --warn=no-deprecated
1355 Enables or disables all warnings about use of
1356 currently deprecated features.
1357 These warnings are enabled by default.
1358 Note that the
1359 .B --warn=no-deprecated
1360 option does not disable warnings about absolutely all deprecated features.
1361 Warnings for some deprecated features that have already been through
1362 several releases with deprecation warnings
1363 may be mandatory for a release or two
1364 before they are officially no longer supported by SCons.
1365 Warnings for some specific deprecated features
1366 may be enabled or disabled individually;
1367 see below.
1368
1369 .RS
1370 .TP
1371 --warn=deprecated-copy, --warn=no-deprecated-copy
1372 Enables or disables warnings about use of the deprecated
1373 .B env.Copy()
1374 method.
1375
1376 .TP
1377 --warn=deprecated-source-signatures, --warn=no-deprecated-source-signatures
1378 Enables or disables warnings about use of the deprecated
1379 .B SourceSignatures()
1380 function or
1381 .B env.SourceSignatures()
1382 method.
1383
1384 .TP
1385 --warn=deprecated-target-signatures, --warn=no-deprecated-target-signatures
1386 Enables or disables warnings about use of the deprecated
1387 .B TargetSignatures()
1388 function or
1389 .B env.TargetSignatures()
1390 method.
1391 .RE
1392
1393 .TP
1394 --warn=duplicate-environment, --warn=no-duplicate-environment
1395 Enables or disables warnings about attempts to specify a build
1396 of a target with two different construction environments
1397 that use the same action.
1398 These warnings are enabled by default.
1399
1400 .TP
1401 --warn=fortran-cxx-mix, --warn=no-fortran-cxx-mix
1402 Enables or disables the specific warning about linking
1403 Fortran and C++ object files in a single executable,
1404 which can yield unpredictable behavior with some compilers.
1405
1406 .TP
1407 --warn=future-deprecated, --warn=no-future-deprecated
1408 Enables or disables warnings about features
1409 that will be deprecated in the future.
1410 These warnings are disabled by default.
1411 Enabling this warning is especially
1412 recommended for projects that redistribute
1413 SCons configurations for other users to build,
1414 so that the project can be warned as soon as possible
1415 about to-be-deprecated features
1416 that may require changes to the configuration.
1417
1418 .TP
1419 --warn=link, --warn=no-link
1420 Enables or disables warnings about link steps.
1421
1422 .TP
1423 --warn=misleading-keywords, --warn=no-misleading-keywords
1424 Enables or disables warnings about use of the misspelled keywords
1425 .B targets
1426 and
1427 .B sources
1428 when calling Builders.
1429 (Note the last
1430 .B s
1431 characters, the correct spellings are
1432 .B target
1433 and
1434 .B source.)
1435 These warnings are enabled by default.
1436
1437 .TP
1438 --warn=missing-sconscript, --warn=no-missing-sconscript
1439 Enables or disables warnings about missing SConscript files.
1440 These warnings are enabled by default.
1441
1442 .TP
1443 --warn=no-md5-module, --warn=no-no-md5-module
1444 Enables or disables warnings about the version of Python
1445 not having an MD5 checksum module available.
1446 These warnings are enabled by default.
1447
1448 .TP
1449 --warn=no-metaclass-support, --warn=no-no-metaclass-support
1450 Enables or disables warnings about the version of Python
1451 not supporting metaclasses when the
1452 .B --debug=memoizer
1453 option is used.
1454 These warnings are enabled by default.
1455
1456 .TP
1457 --warn=no-object-count, --warn=no-no-object-count
1458 Enables or disables warnings about the
1459 .B --debug=object
1460 feature not working when
1461 .B scons
1462 is run with the python
1463 .B \-O
1464 option or from optimized Python (.pyo) modules.
1465
1466 .TP
1467 --warn=no-parallel-support, --warn=no-no-parallel-support
1468 Enables or disables warnings about the version of Python
1469 not being able to support parallel builds when the
1470 .B -j
1471 option is used.
1472 These warnings are enabled by default.
1473
1474 .TP
1475 --warn=python-version, --warn=no-python-version
1476 Enables or disables the warning about running
1477 SCons with a deprecated version of Python.
1478 These warnings are enabled by default.
1479
1480 .TP
1481 --warn=reserved-variable, --warn=no-reserved-variable
1482 Enables or disables warnings about attempts to set the
1483 reserved construction variable names
1484 .BR CHANGED_SOURCES ,
1485 .BR CHANGED_TARGETS ,
1486 .BR TARGET ,
1487 .BR TARGETS ,
1488 .BR SOURCE ,
1489 .BR SOURCES ,
1490 .BR UNCHANGED_SOURCES
1491 or
1492 .BR UNCHANGED_TARGETS .
1493 These warnings are disabled by default.
1494
1495 .TP
1496 --warn=stack-size, --warn=no-stack-size
1497 Enables or disables warnings about requests to set the stack size
1498 that could not be honored.
1499 These warnings are enabled by default.
1500
1501 .\" .TP
1502 .\" .RI --write-filenames= file
1503 .\" Write all filenames considered into
1504 .\" .IR file .
1505 .\"
1506 .\" .TP
1507 .\" .RI -W " file" ", --what-if=" file ", --new-file=" file ", --assume-new=" file
1508 .\" Pretend that the target
1509 .\" .I file
1510 .\" has been
1511 .\" modified.  When used with the
1512 .\" .B -n
1513 .\" option, this
1514 .\" show you what would be rebuilt if you were to modify that file.
1515 .\" Without
1516 .\" .B -n
1517 .\" ... what? XXX
1518 .\"
1519 .\" .TP
1520 .\" --warn-undefined-variables
1521 .\" Warn when an undefined variable is referenced.
1522
1523 .TP
1524 .RI -Y " repository" ", --repository=" repository ", --srcdir=" repository
1525 Search the specified repository for any input and target
1526 files not found in the local directory hierarchy.  Multiple
1527 .B -Y
1528 options may be specified, in which case the
1529 repositories are searched in the order specified.
1530
1531 .SH CONFIGURATION FILE REFERENCE
1532 .\" .SS Python Basics
1533 .\" XXX Adding this in the future would be a help.
1534 .SS Construction Environments
1535 A construction environment is the basic means by which the SConscript
1536 files communicate build information to
1537 .BR scons .
1538 A new construction environment is created using the
1539 .B Environment
1540 function:
1541
1542 .ES
1543 env = Environment()
1544 .EE
1545
1546 Variables, called
1547 .I construction
1548 .IR variables ,
1549 may be set in a construction environment
1550 either by specifying them as keywords when the object is created
1551 or by assigning them a value after the object is created:
1552
1553 .ES
1554 env = Environment(FOO = 'foo')
1555 env['BAR'] = 'bar'
1556 .EE
1557
1558 As a convenience,
1559 construction variables may also be set or modified by the
1560 .I parse_flags
1561 keyword argument, which applies the
1562 .B ParseFlags
1563 method (described below) to the argument value
1564 after all other processing is completed.
1565 This is useful either if the exact content of the flags is unknown
1566 (for example, read from a control file)
1567 or if the flags are distributed to a number of construction variables.
1568
1569 .ES
1570 env = Environment(parse_flags = '-Iinclude -DEBUG -lm')
1571 .EE
1572
1573 This example adds 'include' to
1574 .BR CPPPATH ,
1575 \&'EBUG' to
1576 .BR CPPDEFINES ,
1577 and 'm' to
1578 .BR LIBS .
1579
1580 By default, a new construction environment is
1581 initialized with a set of builder methods
1582 and construction variables that are appropriate
1583 for the current platform.
1584 An optional platform keyword argument may be
1585 used to specify that an environment should
1586 be initialized for a different platform:
1587
1588 .ES
1589 env = Environment(platform = 'cygwin')
1590 env = Environment(platform = 'os2')
1591 env = Environment(platform = 'posix')
1592 env = Environment(platform = 'win32')
1593 .EE
1594
1595 Specifying a platform initializes the appropriate
1596 construction variables in the environment
1597 to use and generate file names with prefixes
1598 and suffixes appropriate for the platform.
1599
1600 Note that the
1601 .B win32
1602 platform adds the
1603 .B SystemDrive
1604 and
1605 .B SystemRoot
1606 variables from the user's external environment
1607 to the construction environment's
1608 .B ENV
1609 dictionary.
1610 This is so that any executed commands
1611 that use sockets to connect with other systems
1612 (such as fetching source files from
1613 external CVS repository specifications like
1614 .BR :pserver:anonymous@cvs.sourceforge.net:/cvsroot/scons )
1615 will work on Windows systems.
1616
1617 The platform argument may be function or callable object,
1618 in which case the Environment() method
1619 will call the specified argument to update
1620 the new construction environment:
1621
1622 .ES
1623 def my_platform(env):
1624     env['VAR'] = 'xyzzy'
1625
1626 env = Environment(platform = my_platform)
1627 .EE
1628
1629 Additionally, a specific set of tools
1630 with which to initialize the environment
1631 may be specified as an optional keyword argument:
1632
1633 .ES
1634 env = Environment(tools = ['msvc', 'lex'])
1635 .EE
1636
1637 Non-built-in tools may be specified using the toolpath argument:
1638
1639 .ES
1640 env = Environment(tools = ['default', 'foo'], toolpath = ['tools'])
1641 .EE
1642
1643 This looks for a tool specification in tools/foo.py (as well as
1644 using the ordinary default tools for the platform).  foo.py should
1645 have two functions: generate(env, **kw) and exists(env).
1646 The
1647 .B generate()
1648 function
1649 modifies the passed-in environment
1650 to set up variables so that the tool
1651 can be executed;
1652 it may use any keyword arguments
1653 that the user supplies (see below)
1654 to vary its initialization.
1655 The
1656 .B exists()
1657 function should return a true
1658 value if the tool is available.
1659 Tools in the toolpath are used before
1660 any of the built-in ones.  For example, adding gcc.py to the toolpath
1661 would override the built-in gcc tool.
1662 Also note that the toolpath is
1663 stored in the environment for use
1664 by later calls to
1665 .BR Clone ()
1666 and
1667 .BR Tool ()
1668 methods:
1669
1670 .ES
1671 base = Environment(toolpath=['custom_path'])
1672 derived = base.Clone(tools=['custom_tool'])
1673 derived.CustomBuilder()
1674 .EE
1675
1676 The elements of the tools list may also
1677 be functions or callable objects,
1678 in which case the Environment() method
1679 will call the specified elements
1680 to update the new construction environment:
1681
1682 .ES
1683 def my_tool(env):
1684     env['XYZZY'] = 'xyzzy'
1685
1686 env = Environment(tools = [my_tool])
1687 .EE
1688
1689 The individual elements of the tools list
1690 may also themselves be two-element lists of the form
1691 .RI ( toolname ", " kw_dict ).
1692 SCons searches for the
1693 .I toolname
1694 specification file as described above, and
1695 passes
1696 .IR kw_dict ,
1697 which must be a dictionary, as keyword arguments to the tool's
1698 .B generate
1699 function.
1700 The
1701 .B generate
1702 function can use the arguments to modify the tool's behavior
1703 by setting up the environment in different ways
1704 or otherwise changing its initialization.
1705
1706 .ES
1707 # in tools/my_tool.py:
1708 def generate(env, **kw):
1709   # Sets MY_TOOL to the value of keyword argument 'arg1' or 1.
1710   env['MY_TOOL'] = kw.get('arg1', '1')
1711 def exists(env):
1712   return 1
1713
1714 # in SConstruct:
1715 env = Environment(tools = ['default', ('my_tool', {'arg1': 'abc'})],
1716                   toolpath=['tools'])
1717 .EE
1718
1719 The tool definition (i.e. my_tool()) can use the PLATFORM variable from
1720 the environment it receives to customize the tool for different platforms.
1721
1722 If no tool list is specified, then SCons will auto-detect the installed
1723 tools using the PATH variable in the ENV construction variable and the
1724 platform name when the Environment is constructed. Changing the PATH
1725 variable after the Environment is constructed will not cause the tools to
1726 be redetected.
1727
1728 SCons supports the following tool specifications out of the box:
1729
1730 .ES
1731 386asm
1732 aixc++
1733 aixcc
1734 aixf77
1735 aixlink
1736 ar
1737 as
1738 bcc32
1739 c++
1740 cc
1741 cvf
1742 dmd
1743 dvipdf
1744 dvips
1745 f77
1746 f90
1747 f95
1748 fortran
1749 g++
1750 g77
1751 gas
1752 gcc
1753 gfortran
1754 gnulink
1755 gs
1756 hpc++
1757 hpcc
1758 hplink
1759 icc
1760 icl
1761 ifl
1762 ifort
1763 ilink
1764 ilink32
1765 intelc
1766 jar
1767 javac
1768 javah
1769 latex
1770 lex
1771 link
1772 linkloc
1773 m4
1774 masm
1775 midl
1776 mingw
1777 mslib
1778 mslink
1779 mssdk
1780 msvc
1781 msvs
1782 mwcc
1783 mwld
1784 nasm
1785 pdflatex
1786 pdftex
1787 qt
1788 rmic
1789 rpcgen
1790 sgiar
1791 sgic++
1792 sgicc
1793 sgilink
1794 sunar
1795 sunc++
1796 suncc
1797 sunf77
1798 sunf90
1799 sunf95
1800 sunlink
1801 swig
1802 tar
1803 tex
1804 textfile
1805 tlib
1806 yacc
1807 zip
1808 .EE
1809
1810 Additionally, there is a "tool" named
1811 .B default
1812 which configures the
1813 environment with a default set of tools for the current platform.
1814
1815 On posix and cygwin platforms
1816 the GNU tools (e.g. gcc) are preferred by SCons,
1817 on Windows the Microsoft tools (e.g. msvc)
1818 followed by MinGW are preferred by SCons,
1819 and in OS/2 the IBM tools (e.g. icc) are preferred by SCons.
1820
1821 .SS Builder Methods
1822
1823 Build rules are specified by calling a construction
1824 environment's builder methods.
1825 The arguments to the builder methods are
1826 .B target
1827 (a list of targets to be built,
1828 usually file names)
1829 and
1830 .B source
1831 (a list of sources to be built,
1832 usually file names).
1833
1834 Because long lists of file names
1835 can lead to a lot of quoting,
1836 .B scons
1837 supplies a
1838 .B Split()
1839 global function
1840 and a same-named environment method
1841 that split a single string
1842 into a list, separated on
1843 strings of white-space characters.
1844 (These are similar to the
1845 string.split() method
1846 from the standard Python library,
1847 but work even if the input isn't a string.)
1848
1849 Like all Python arguments,
1850 the target and source arguments to a builder method
1851 can be specified either with or without
1852 the "target" and "source" keywords.
1853 When the keywords are omitted,
1854 the target is first,
1855 followed by the source.
1856 The following are equivalent examples of calling the Program builder method:
1857
1858 .ES
1859 env.Program('bar', ['bar.c', 'foo.c'])
1860 env.Program('bar', Split('bar.c foo.c'))
1861 env.Program('bar', env.Split('bar.c foo.c'))
1862 env.Program(source =  ['bar.c', 'foo.c'], target = 'bar')
1863 env.Program(target = 'bar', Split('bar.c foo.c'))
1864 env.Program(target = 'bar', env.Split('bar.c foo.c'))
1865 env.Program('bar', source = string.split('bar.c foo.c'))
1866 .EE
1867
1868 Target and source file names
1869 that are not absolute path names
1870 (that is, do not begin with
1871 .B /
1872 on POSIX systems
1873 or
1874 .B \\
1875 on Windows systems,
1876 with or without
1877 an optional drive letter)
1878 are interpreted relative to the directory containing the
1879 .B SConscript
1880 file being read.
1881 An initial
1882 .B #
1883 (hash mark)
1884 on a path name means that the rest of the file name
1885 is interpreted relative to
1886 the directory containing
1887 the top-level
1888 .B SConstruct
1889 file,
1890 even if the
1891 .B #
1892 is followed by a directory separator character
1893 (slash or backslash).
1894
1895 Examples:
1896
1897 .ES
1898 # The comments describing the targets that will be built
1899 # assume these calls are in a SConscript file in the
1900 # a subdirectory named "subdir".
1901
1902 # Builds the program "subdir/foo" from "subdir/foo.c":
1903 env.Program('foo', 'foo.c')
1904
1905 # Builds the program "/tmp/bar" from "subdir/bar.c":
1906 env.Program('/tmp/bar', 'bar.c')
1907
1908 # An initial '#' or '#/' are equivalent; the following
1909 # calls build the programs "foo" and "bar" (in the
1910 # top-level SConstruct directory) from "subdir/foo.c" and
1911 # "subdir/bar.c", respectively:
1912 env.Program('#foo', 'foo.c')
1913 env.Program('#/bar', 'bar.c')
1914
1915 # Builds the program "other/foo" (relative to the top-level
1916 # SConstruct directory) from "subdir/foo.c":
1917 env.Program('#other/foo', 'foo.c')
1918 .EE
1919
1920 When the target shares the same base name
1921 as the source and only the suffix varies,
1922 and if the builder method has a suffix defined for the target file type,
1923 then the target argument may be omitted completely,
1924 and
1925 .B scons
1926 will deduce the target file name from
1927 the source file name.
1928 The following examples all build the
1929 executable program
1930 .B bar
1931 (on POSIX systems)
1932 or
1933 .B bar.exe
1934 (on Windows systems)
1935 from the bar.c source file:
1936
1937 .ES
1938 env.Program(target = 'bar', source = 'bar.c')
1939 env.Program('bar', source = 'bar.c')
1940 env.Program(source = 'bar.c')
1941 env.Program('bar.c')
1942 .EE
1943
1944 As a convenience, a
1945 .B srcdir
1946 keyword argument may be specified
1947 when calling a Builder.
1948 When specified,
1949 all source file strings that are not absolute paths
1950 will be interpreted relative to the specified
1951 .BR srcdir .
1952 The following example will build the
1953 .B build/prog
1954 (or
1955 .B build/prog.exe
1956 on Windows)
1957 program from the files
1958 .B src/f1.c
1959 and
1960 .BR src/f2.c :
1961
1962 .ES
1963 env.Program('build/prog', ['f1.c', 'f2.c'], srcdir='src')
1964 .EE
1965
1966 It is possible to override or add construction variables when calling a
1967 builder method by passing additional keyword arguments.
1968 These overridden or added
1969 variables will only be in effect when building the target, so they will not
1970 affect other parts of the build. For example, if you want to add additional
1971 libraries for just one program:
1972
1973 .ES
1974 env.Program('hello', 'hello.c', LIBS=['gl', 'glut'])
1975 .EE
1976
1977 or generate a shared library with a non-standard suffix:
1978
1979 .ES
1980 env.SharedLibrary('word', 'word.cpp',
1981                   SHLIBSUFFIX='.ocx',
1982                   LIBSUFFIXES=['.ocx'])
1983 .EE
1984
1985 (Note that both the $SHLIBSUFFIX and $LIBSUFFIXES variables must be set
1986 if you want SCons to search automatically
1987 for dependencies on the non-standard library names;
1988 see the descriptions of these variables, below, for more information.)
1989
1990 It is also possible to use the
1991 .I parse_flags
1992 keyword argument in an override:
1993
1994 .ES
1995 env = Program('hello', 'hello.c', parse_flags = '-Iinclude -DEBUG -lm')
1996 .EE
1997
1998 This example adds 'include' to
1999 .BR CPPPATH ,
2000 \&'EBUG' to
2001 .BR CPPDEFINES ,
2002 and 'm' to
2003 .BR LIBS .
2004
2005 Although the builder methods defined by
2006 .B scons
2007 are, in fact,
2008 methods of a construction environment object,
2009 they may also be called without an explicit environment:
2010
2011 .ES
2012 Program('hello', 'hello.c')
2013 SharedLibrary('word', 'word.cpp')
2014 .EE
2015
2016 In this case,
2017 the methods are called internally using a default construction
2018 environment that consists of the tools and values that
2019 .B scons
2020 has determined are appropriate for the local system.
2021
2022 Builder methods that can be called without an explicit
2023 environment may be called from custom Python modules that you
2024 import into an SConscript file by adding the following
2025 to the Python module:
2026
2027 .ES
2028 from SCons.Script import *
2029 .EE
2030
2031 All builder methods return a list-like object
2032 containing Nodes that
2033 represent the target or targets that will be built.
2034 A
2035 .I Node
2036 is an internal SCons object
2037 which represents
2038 build targets or sources.
2039
2040 The returned Node-list object
2041 can be passed to other builder methods as source(s)
2042 or passed to any SCons function or method
2043 where a filename would normally be accepted.
2044 For example, if it were necessary
2045 to add a specific
2046 .B -D
2047 flag when compiling one specific object file:
2048
2049 .ES
2050 bar_obj_list = env.StaticObject('bar.c', CPPDEFINES='-DBAR')
2051 env.Program(source = ['foo.c', bar_obj_list, 'main.c'])
2052 .EE
2053
2054 Using a Node in this way
2055 makes for a more portable build
2056 by avoiding having to specify
2057 a platform-specific object suffix
2058 when calling the Program() builder method.
2059
2060 Note that Builder calls will automatically "flatten"
2061 the source and target file lists,
2062 so it's all right to have the bar_obj list
2063 return by the StaticObject() call
2064 in the middle of the source file list.
2065 If you need to manipulate a list of lists returned by Builders
2066 directly using Python,
2067 you can either build the list by hand:
2068
2069 .ES
2070 foo = Object('foo.c')
2071 bar = Object('bar.c')
2072 objects = ['begin.o'] + foo + ['middle.o'] + bar + ['end.o']
2073 for object in objects:
2074     print str(object)
2075 .EE
2076
2077 Or you can use the
2078 .BR Flatten ()
2079 function supplied by scons
2080 to create a list containing just the Nodes,
2081 which may be more convenient:
2082
2083 .ES
2084 foo = Object('foo.c')
2085 bar = Object('bar.c')
2086 objects = Flatten(['begin.o', foo, 'middle.o', bar, 'end.o'])
2087 for object in objects:
2088     print str(object)
2089 .EE
2090
2091 Note also that because Builder calls return
2092 a list-like object, not an actual Python list,
2093 you should
2094 .I not
2095 use the Python
2096 .B +=
2097 operator to append Builder results to a Python list.
2098 Because the list and the object are different types,
2099 Python will not update the original list in place,
2100 but will instead create a new Node-list object
2101 containing the concatenation of the list
2102 elements and the Builder results.
2103 This will cause problems for any other Python variables
2104 in your SCons configuration
2105 that still hold on to a reference to the original list.
2106 Instead, use the Python
2107 .B .extend()
2108 method to make sure the list is updated in-place.
2109 Example:
2110
2111 .ES
2112 object_files = []
2113
2114 # Do NOT use += as follows:
2115 #
2116 #    object_files += Object('bar.c')
2117 #
2118 # It will not update the object_files list in place.
2119 #
2120 # Instead, use the .extend() method:
2121 object_files.extend(Object('bar.c'))
2122
2123 .EE
2124
2125 The path name for a Node's file may be used
2126 by passing the Node to the Python-builtin
2127 .B str()
2128 function:
2129
2130 .ES
2131 bar_obj_list = env.StaticObject('bar.c', CPPDEFINES='-DBAR')
2132 print "The path to bar_obj is:", str(bar_obj_list[0])
2133 .EE
2134
2135 Note again that because the Builder call returns a list,
2136 we have to access the first element in the list
2137 .B (bar_obj_list[0])
2138 to get at the Node that actually represents
2139 the object file.
2140
2141 Builder calls support a
2142 .B chdir
2143 keyword argument that
2144 specifies that the Builder's action(s)
2145 should be executed
2146 after changing directory.
2147 If the
2148 .B chdir
2149 argument is
2150 a string or a directory Node,
2151 scons will change to the specified directory.
2152 If the
2153 .B chdir
2154 is not a string or Node
2155 and is non-zero,
2156 then scons will change to the
2157 target file's directory.
2158
2159 .ES
2160 # scons will change to the "sub" subdirectory
2161 # before executing the "cp" command.
2162 env.Command('sub/dir/foo.out', 'sub/dir/foo.in',
2163             "cp dir/foo.in dir/foo.out",
2164             chdir='sub')
2165
2166 # Because chdir is not a string, scons will change to the
2167 # target's directory ("sub/dir") before executing the
2168 # "cp" command.
2169 env.Command('sub/dir/foo.out', 'sub/dir/foo.in',
2170             "cp foo.in foo.out",
2171             chdir=1)
2172 .EE
2173
2174 Note that scons will
2175 .I not
2176 automatically modify
2177 its expansion of
2178 construction variables like
2179 .B $TARGET
2180 and
2181 .B $SOURCE
2182 when using the chdir
2183 keyword argument--that is,
2184 the expanded file names
2185 will still be relative to
2186 the top-level SConstruct directory,
2187 and consequently incorrect
2188 relative to the chdir directory.
2189 If you use the chdir keyword argument,
2190 you will typically need to supply a different
2191 command line using
2192 expansions like
2193 .B ${TARGET.file}
2194 and
2195 .B ${SOURCE.file}
2196 to use just the filename portion of the
2197 targets and source.
2198
2199 .B scons
2200 provides the following builder methods:
2201
2202 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2203 '\" BEGIN GENERATED BUILDER DESCRIPTIONS
2204 '\"
2205 '\" The descriptions below of the various SCons Builders are generated
2206 '\" from the .xml files that live next to the various Python modules in
2207 '\" the build enginer library.  If you're reading this [gnt]roff file
2208 '\" with an eye towards patching this man page, you can still submit
2209 '\" a diff against this text, but it will have to be translated to a
2210 '\" diff against the underlying .xml file before the patch is actually
2211 '\" accepted.  If you do that yourself, it will make it easier to
2212 '\" integrate the patch.
2213 '\"
2214 '\" BEGIN GENERATED BUILDER DESCRIPTIONS
2215 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2216 .so builders.man
2217 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2218 '\" END GENERATED BUILDER DESCRIPTIONS
2219 '\"
2220 '\" The descriptions above of the various SCons Builders are generated
2221 '\" from the .xml files that live next to the various Python modules in
2222 '\" the build enginer library.  If you're reading this [gnt]roff file
2223 '\" with an eye towards patching this man page, you can still submit
2224 '\" a diff against this text, but it will have to be translated to a
2225 '\" diff against the underlying .xml file before the patch is actually
2226 '\" accepted.  If you do that yourself, it will make it easier to
2227 '\" integrate the patch.
2228 '\"
2229 '\" END GENERATED BUILDER DESCRIPTIONS
2230 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2231
2232 .P
2233 All
2234 targets of builder methods automatically depend on their sources.
2235 An explicit dependency can
2236 be specified using the
2237 .B Depends
2238 method of a construction environment (see below).
2239
2240 In addition,
2241 .B scons
2242 automatically scans
2243 source files for various programming languages,
2244 so the dependencies do not need to be specified explicitly.
2245 By default, SCons can
2246 C source files,
2247 C++ source files,
2248 Fortran source files with
2249 .B .F
2250 (POSIX systems only),
2251 .B .fpp,
2252 or
2253 .B .FPP
2254 file extensions,
2255 and assembly language files with
2256 .B .S
2257 (POSIX systems only),
2258 .B .spp,
2259 or
2260 .B .SPP
2261 files extensions
2262 for C preprocessor dependencies.
2263 SCons also has default support
2264 for scanning D source files,
2265 You can also write your own Scanners
2266 to add support for additional source file types.
2267 These can be added to the default
2268 Scanner object used by the
2269 .BR Object (),
2270 .BR StaticObject (),
2271 and
2272 .BR SharedObject ()
2273 Builders by adding them
2274 to the
2275 .B SourceFileScanner
2276 object as follows:
2277
2278 See the section "Scanner Objects,"
2279 below, for a more information about
2280 defining your own Scanner objects.
2281
2282 .SS Methods and Functions to Do Things
2283 In addition to Builder methods,
2284 .B scons
2285 provides a number of other construction environment methods
2286 and global functions to
2287 manipulate the build configuration.
2288
2289 Usually, a construction environment method
2290 and global function with the same name both exist
2291 so that you don't have to remember whether
2292 to a specific bit of functionality
2293 must be called with or without a construction environment.
2294 In the following list,
2295 if you call something as a global function
2296 it looks like:
2297 .ES
2298 .RI Function( arguments )
2299 .EE
2300 and if you call something through a construction
2301 environment it looks like:
2302 .ES
2303 .RI env.Function( arguments )
2304 .EE
2305 If you can call the functionality in both ways,
2306 then both forms are listed.
2307
2308 Global functions may be called from custom Python modules that you
2309 import into an SConscript file by adding the following
2310 to the Python module:
2311
2312 .ES
2313 from SCons.Script import *
2314 .EE
2315
2316 Except where otherwise noted,
2317 the same-named
2318 construction environment method
2319 and global function
2320 provide the exact same functionality.
2321 The only difference is that,
2322 where appropriate,
2323 calling the functionality through a construction environment will
2324 substitute construction variables into
2325 any supplied strings.
2326 For example:
2327
2328 .ES
2329 env = Environment(FOO = 'foo')
2330 Default('$FOO')
2331 env.Default('$FOO')
2332 .EE
2333
2334 In the above example,
2335 the first call to the global
2336 .B Default()
2337 function will actually add a target named
2338 .B $FOO
2339 to the list of default targets,
2340 while the second call to the
2341 .B env.Default()
2342 construction environment method
2343 will expand the value
2344 and add a target named
2345 .B foo
2346 to the list of default targets.
2347 For more on construction variable expansion,
2348 see the next section on
2349 construction variables.
2350
2351 Construction environment methods
2352 and global functions supported by
2353 .B scons
2354 include:
2355
2356 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2357 .TP
2358 .RI Action( action ", [" cmd/str/fun ", [" var ", ...]] [" option = value ", ...])"
2359 .TP
2360 .IR env .Action( action ", [" cmd/str/fun ", [" var ", ...]] [" option = value ", ...])"
2361 Creates an Action object for
2362 the specified
2363 .IR action .
2364 See the section "Action Objects,"
2365 below, for a complete explanation of the arguments and behavior.
2366
2367 Note that the
2368 .BR env.Action ()
2369 form of the invocation will expand
2370 construction variables in any argument strings,
2371 including the
2372 .I action
2373 argument, at the time it is called
2374 using the construction variables in the
2375 .I env
2376 construction environment through which
2377 .BR env.Action ()
2378 was called.
2379 The
2380 .BR Action ()
2381 form delays all variable expansion
2382 until the Action object is actually used.
2383
2384 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2385 .TP
2386 .RI AddMethod( object, function ", [" name ])
2387 .TP
2388 .RI env.AddMethod( function ", [" name ])
2389 When called with the
2390 .BR AddMethod ()
2391 form,
2392 adds the specified
2393 .I function
2394 to the specified
2395 .I object
2396 as the specified method
2397 .IR name .
2398 When called with the
2399 .BR env.AddMethod ()
2400 form,
2401 adds the specified
2402 .I function
2403 to the construction environment
2404 .I env
2405 as the specified method
2406 .IR name .
2407 In both cases, if
2408 .I name
2409 is omitted or
2410 .BR None ,
2411 the name of the
2412 specified
2413 .I function
2414 itself is used for the method name.
2415
2416 Examples:
2417
2418 .ES
2419 # Note that the first argument to the function to
2420 # be attached as a method must be the object through
2421 # which the method will be called; the Python
2422 # convention is to call it 'self'.
2423 def my_method(self, arg):
2424     print "my_method() got", arg
2425
2426 # Use the global AddMethod() function to add a method
2427 # to the Environment class.  This
2428 AddMethod(Environment, my_method)
2429 env = Environment()
2430 env.my_method('arg')
2431
2432 # Add the function as a method, using the function
2433 # name for the method call.
2434 env = Environment()
2435 env.AddMethod(my_method, 'other_method_name')
2436 env.other_method_name('another arg')
2437 .EE
2438
2439 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2440 .TP
2441 .RI AddOption( arguments )
2442 This function adds a new command-line option to be recognized.
2443 The specified
2444 .I arguments
2445 are the same as supported by the standard Python
2446 .BR optparse.add_option ()
2447 method (with a few additional capabilities noted below);
2448 see the documentation for
2449 .B optparse
2450 for a thorough discussion of its option-processing capabities.
2451 (Note that although the
2452 .B optparse
2453 module was not a standard module until Python 2.3,
2454 .B scons
2455 contains a compatible version of the module
2456 that is used to provide identical functionality
2457 when run by earlier Python versions.)
2458
2459 In addition to the arguments and values supported by the
2460 .B optparse.add_option ()
2461 method,
2462 the SCons
2463 .BR AddOption ()
2464 function allows you to set the
2465 .B nargs
2466 keyword value to
2467 .B '?'
2468 (a string with just the question mark)
2469 to indicate that the specified long option(s) take(s) an
2470 .I optional
2471 argument.
2472 When
2473 .B "nargs = '?'"
2474 is passed to the
2475 .BR AddOption ()
2476 function, the
2477 .B const
2478 keyword argument
2479 may be used to supply the "default"
2480 value that should be used when the
2481 option is specified on the command line
2482 without an explicit argument.
2483
2484 If no
2485 .B default=
2486 keyword argument is supplied when calling
2487 .BR AddOption (),
2488 the option will have a default value of
2489 .BR None .
2490
2491 Once a new command-line option has been added with
2492 .BR AddOption (),
2493 the option value may be accessed using
2494 .BR GetOption ()
2495 or
2496 .BR env.GetOption ().
2497 \" NOTE: in SCons 1.x or 2.0, user options will be settable, but not yet.
2498 \" Uncomment this when that works.  See tigris issue 2105.
2499 \" The value may also be set, using
2500 \" .BR SetOption ()
2501 \" or
2502 \" .BR env.SetOption (),
2503 \" if conditions in a
2504 \" .B SConscript
2505 \" require overriding any default value.
2506 \" Note, however, that a
2507 \" value specified on the command line will
2508 \" .I always
2509 \" override a value set by any SConscript file.
2510
2511 Any specified
2512 .B help=
2513 strings for the new option(s)
2514 will be displayed by the
2515 .B -H
2516 or
2517 .B -h
2518 options
2519 (the latter only if no other help text is
2520 specified in the SConscript files).
2521 The help text for the local options specified by
2522 .BR AddOption ()
2523 will appear below the SCons options themselves,
2524 under a separate
2525 .B "Local Options"
2526 heading.
2527 The options will appear in the help text
2528 in the order in which the
2529 .BR AddOption ()
2530 calls occur.
2531
2532 Example:
2533
2534 .ES
2535 AddOption('--prefix',
2536           dest='prefix',
2537           nargs=1, type='string',
2538           action='store',
2539           metavar='DIR',
2540           help='installation prefix')
2541 env = Environment(PREFIX = GetOption('prefix'))
2542 .EE
2543
2544 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2545 .TP
2546 .RI AddPostAction( target ", " action )
2547 .TP
2548 .RI env.AddPostAction( target ", " action )
2549 Arranges for the specified
2550 .I action
2551 to be performed
2552 after the specified
2553 .I target
2554 has been built.
2555 The specified action(s) may be
2556 an Action object, or anything that
2557 can be converted into an Action object
2558 (see below).
2559
2560 When multiple targets are supplied,
2561 the action may be called multiple times,
2562 once after each action that generates
2563 one or more targets in the list.
2564
2565 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2566 .TP
2567 .RI AddPreAction( target ", " action )
2568 .TP
2569 .RI env.AddPreAction( target ", " action )
2570 Arranges for the specified
2571 .I action
2572 to be performed
2573 before the specified
2574 .I target
2575 is built.
2576 The specified action(s) may be
2577 an Action object, or anything that
2578 can be converted into an Action object
2579 (see below).
2580
2581 When multiple targets are specified,
2582 the action(s) may be called multiple times,
2583 once before each action that generates
2584 one or more targets in the list.
2585
2586 Note that if any of the targets are built in multiple steps,
2587 the action will be invoked just
2588 before the "final" action that specifically
2589 generates the specified target(s).
2590 For example, when building an executable program
2591 from a specified source
2592 .B .c
2593 file via an intermediate object file:
2594
2595 .ES
2596 foo = Program('foo.c')
2597 AddPreAction(foo, 'pre_action')
2598 .EE
2599
2600 The specified
2601 .B pre_action
2602 would be executed before
2603 .B scons
2604 calls the link command that actually
2605 generates the executable program binary
2606 .BR foo ,
2607 not before compiling the
2608 .B foo.c
2609 file into an object file.
2610
2611 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2612 .TP
2613 .RI Alias( alias ", [" targets ", [" action ]])
2614 .TP
2615 .RI env.Alias( alias ", [" targets ", [" action ]])
2616 Creates one or more phony targets that
2617 expand to one or more other targets.
2618 An optional
2619 .I action
2620 (command)
2621 or list of actions
2622 can be specified that will be executed
2623 whenever the any of the alias targets are out-of-date.
2624 Returns the Node object representing the alias,
2625 which exists outside of any file system.
2626 This Node object, or the alias name,
2627 may be used as a dependency of any other target,
2628 including another alias.
2629 .B Alias
2630 can be called multiple times for the same
2631 alias to add additional targets to the alias,
2632 or additional actions to the list for this alias.
2633
2634 Examples:
2635
2636 .ES
2637 Alias('install')
2638 Alias('install', '/usr/bin')
2639 Alias(['install', 'install-lib'], '/usr/local/lib')
2640
2641 env.Alias('install', ['/usr/local/bin', '/usr/local/lib'])
2642 env.Alias('install', ['/usr/local/man'])
2643
2644 env.Alias('update', ['file1', 'file2'], "update_database $SOURCES")
2645 .EE
2646
2647 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2648 .TP
2649 .RI AllowSubstExceptions([ exception ", ...])"
2650 Specifies the exceptions that will be allowed
2651 when expanding construction variables.
2652 By default,
2653 any construction variable expansions that generate a
2654 .B NameError
2655 or
2656 .BR IndexError
2657 exception will expand to a
2658 .B ''
2659 (a null string) and not cause scons to fail.
2660 All exceptions not in the specified list
2661 will generate an error message
2662 and terminate processing.
2663
2664 If
2665 .B AllowSubstExceptions
2666 is called multiple times,
2667 each call completely overwrites the previous list
2668 of allowed exceptions.
2669
2670 Example:
2671
2672 .ES
2673 # Requires that all construction variable names exist.
2674 # (You may wish to do this if you want to enforce strictly
2675 # that all construction variables must be defined before use.)
2676 AllowSubstExceptions()
2677
2678 # Also allow a string containing a zero-division expansion
2679 # like '${1 / 0}' to evalute to ''.
2680 AllowSubstExceptions(IndexError, NameError, ZeroDivisionError)
2681 .EE
2682
2683 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2684 .TP
2685 .RI AlwaysBuild( target ", ...)"
2686 .TP
2687 .RI env.AlwaysBuild( target ", ...)"
2688 Marks each given
2689 .I target
2690 so that it is always assumed to be out of date,
2691 and will always be rebuilt if needed.
2692 Note, however, that
2693 .BR AlwaysBuild ()
2694 does not add its target(s) to the default target list,
2695 so the targets will only be built
2696 if they are specified on the command line,
2697 or are a dependent of a target specified on the command line--but
2698 they will
2699 .I always
2700 be built if so specified.
2701 Multiple targets can be passed in to a single call to
2702 .BR AlwaysBuild ().
2703
2704 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2705 .TP
2706 .RI env.Append( key = val ", [...])"
2707 Appends the specified keyword arguments
2708 to the end of construction variables in the environment.
2709 If the Environment does not have
2710 the specified construction variable,
2711 it is simply added to the environment.
2712 If the values of the construction variable
2713 and the keyword argument are the same type,
2714 then the two values will be simply added together.
2715 Otherwise, the construction variable
2716 and the value of the keyword argument
2717 are both coerced to lists,
2718 and the lists are added together.
2719 (See also the Prepend method, below.)
2720
2721 Example:
2722
2723 .ES
2724 env.Append(CCFLAGS = ' -g', FOO = ['foo.yyy'])
2725 .EE
2726
2727 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2728 .TP
2729 .RI env.AppendENVPath( name ", " newpath ", [" envname ", " sep ", " delete_existing ])
2730 This appends new path elements to the given path in the
2731 specified external environment
2732 .RB ( ENV
2733 by default).
2734 This will only add
2735 any particular path once (leaving the last one it encounters and
2736 ignoring the rest, to preserve path order),
2737 and to help assure this,
2738 will normalize all paths (using
2739 .B os.path.normpath
2740 and
2741 .BR os.path.normcase ).
2742 This can also handle the
2743 case where the given old path variable is a list instead of a
2744 string, in which case a list will be returned instead of a string.
2745
2746 If 
2747 .I delete_existing
2748 is 0, then adding a path that already exists
2749 will not move it to the end; it will stay where it is in the list.
2750
2751 Example:
2752
2753 .ES
2754 print 'before:',env['ENV']['INCLUDE']
2755 include_path = '/foo/bar:/foo'
2756 env.AppendENVPath('INCLUDE', include_path)
2757 print 'after:',env['ENV']['INCLUDE']
2758
2759 yields:
2760 before: /foo:/biz
2761 after: /biz:/foo/bar:/foo
2762 .EE
2763
2764 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2765 .TP
2766 .RI env.AppendUnique( key = val ", [...], delete_existing=0)"
2767 Appends the specified keyword arguments
2768 to the end of construction variables in the environment.
2769 If the Environment does not have
2770 the specified construction variable,
2771 it is simply added to the environment.
2772 If the construction variable being appended to is a list,
2773 then any value(s) that already exist in the
2774 construction variable will
2775 .I not
2776 be added again to the list.
2777 However, if delete_existing is 1, 
2778 existing matching values are removed first, so
2779 existing values in the arg list move to the end of the list.
2780
2781 Example:
2782
2783 .ES
2784 env.AppendUnique(CCFLAGS = '-g', FOO = ['foo.yyy'])
2785 .EE
2786
2787 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2788 .TP
2789 env.BitKeeper()
2790 A factory function that
2791 returns a Builder object
2792 to be used to fetch source files
2793 using BitKeeper.
2794 The returned Builder
2795 is intended to be passed to the
2796 .B SourceCode
2797 function.
2798
2799 Example:
2800
2801 .ES
2802 env.SourceCode('.', env.BitKeeper())
2803 .EE
2804
2805 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2806 .TP
2807 .RI BuildDir( build_dir ", " src_dir ", [" duplicate ])
2808 .TP
2809 .RI env.BuildDir( build_dir ", " src_dir ", [" duplicate ])
2810 Deprecated synonyms for
2811 .BR VariantDir ()
2812 and
2813 .BR env.VariantDir ().
2814 The
2815 .I build_dir
2816 argument becomes the
2817 .I variant_dir
2818 argument of
2819 .BR VariantDir ()
2820 or
2821 .BR env.VariantDir ().
2822
2823 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2824 .TP
2825 .RI Builder( action ", [" arguments ])
2826 .TP
2827 .RI env.Builder( action ", [" arguments ])
2828 Creates a Builder object for
2829 the specified
2830 .IR action .
2831 See the section "Builder Objects,"
2832 below, for a complete explanation of the arguments and behavior.
2833
2834 Note that the
2835 .BR env.Builder ()
2836 form of the invocation will expand
2837 construction variables in any arguments strings,
2838 including the
2839 .I action
2840 argument,
2841 at the time it is called
2842 using the construction variables in the
2843 .B env
2844 construction environment through which
2845 .BR env.Builder ()
2846 was called.
2847 The
2848 .BR Builder ()
2849 form delays all variable expansion
2850 until after the Builder object is actually called.
2851
2852 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2853 .TP
2854 .RI CacheDir( cache_dir )
2855 .TP
2856 .RI env.CacheDir( cache_dir )
2857 Specifies that
2858 .B scons
2859 will maintain a cache of derived files in
2860 .I cache_dir .
2861 The derived files in the cache will be shared
2862 among all the builds using the same
2863 .BR CacheDir ()
2864 call.
2865 Specifying a
2866 .I cache_dir
2867 of
2868 .B None
2869 disables derived file caching.
2870
2871 Calling
2872 .BR env.CacheDir ()
2873 will only affect targets built
2874 through the specified construction environment.
2875 Calling
2876 .BR CacheDir ()
2877 sets a global default
2878 that will be used by all targets built
2879 through construction environments
2880 that do
2881 .I not
2882 have an
2883 .BR env.CacheDir ()
2884 specified.
2885
2886 When a
2887 .BR CacheDir ()
2888 is being used and
2889 .B scons
2890 finds a derived file that needs to be rebuilt,
2891 it will first look in the cache to see if a
2892 derived file has already been built
2893 from identical input files and an identical build action
2894 (as incorporated into the MD5 build signature).
2895 If so,
2896 .B scons
2897 will retrieve the file from the cache.
2898 If the derived file is not present in the cache,
2899 .B scons
2900 will rebuild it and
2901 then place a copy of the built file in the cache
2902 (identified by its MD5 build signature),
2903 so that it may be retrieved by other
2904 builds that need to build the same derived file
2905 from identical inputs.
2906
2907 Use of a specified
2908 .BR CacheDir()
2909 may be disabled for any invocation
2910 by using the
2911 .B --cache-disable
2912 option.
2913
2914 If the
2915 .B --cache-force
2916 option is used,
2917 .B scons
2918 will place a copy of
2919 .I all
2920 derived files in the cache,
2921 even if they already existed
2922 and were not built by this invocation.
2923 This is useful to populate a cache
2924 the first time
2925 .BR CacheDir ()
2926 is added to a build,
2927 or after using the
2928 .B --cache-disable
2929 option.
2930
2931 When using
2932 .BR CacheDir (),
2933 .B scons
2934 will report,
2935 "Retrieved `file' from cache,"
2936 unless the
2937 .B --cache-show
2938 option is being used.
2939 When the
2940 .B --cache-show
2941 option is used,
2942 .B scons
2943 will print the action that
2944 .I would
2945 have been used to build the file,
2946 without any indication that
2947 the file was actually retrieved from the cache.
2948 This is useful to generate build logs
2949 that are equivalent regardless of whether
2950 a given derived file has been built in-place
2951 or retrieved from the cache.
2952
2953 The
2954 .BR NoCache ()
2955 method can be used to disable caching of specific files.  This can be
2956 useful if inputs and/or outputs of some tool are impossible to
2957 predict or prohibitively large.
2958
2959 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2960 .TP
2961 .RI Clean( targets ", " files_or_dirs )
2962 .TP
2963 .RI env.Clean( targets ", " files_or_dirs )
2964 This specifies a list of files or directories which should be removed
2965 whenever the targets are specified with the
2966 .B -c
2967 command line option.
2968 The specified targets may be a list
2969 or an individual target.
2970 Multiple calls to
2971 .BR Clean ()
2972 are legal,
2973 and create new targets or add files and directories to the
2974 clean list for the specified targets.
2975
2976 Multiple files or directories should be specified
2977 either as separate arguments to the
2978 .BR Clean ()
2979 method, or as a list.
2980 .BR Clean ()
2981 will also accept the return value of any of the construction environment
2982 Builder methods.
2983 Examples:
2984
2985 The related
2986 .BR NoClean ()
2987 function overrides calling
2988 .BR Clean ()
2989 for the same target,
2990 and any targets passed to both functions will
2991 .I not
2992 be removed by the
2993 .B -c
2994 option.
2995
2996 Examples:
2997
2998 .ES
2999 Clean('foo', ['bar', 'baz'])
3000 Clean('dist', env.Program('hello', 'hello.c'))
3001 Clean(['foo', 'bar'], 'something_else_to_clean')
3002 .EE
3003
3004 In this example,
3005 installing the project creates a subdirectory for the documentation.
3006 This statement causes the subdirectory to be removed
3007 if the project is deinstalled.
3008 .ES
3009 Clean(docdir, os.path.join(docdir, projectname))
3010 .EE
3011
3012 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3013 .TP
3014 .RI Command( target ", " source ", " action ", [" key = val ", ...])"
3015 .TP
3016 .RI env.Command( target ", " source ", " action ", [" key = val ", ...])"
3017 Executes a specific action
3018 (or list of actions)
3019 to build a target file or files.
3020 This is more convenient
3021 than defining a separate Builder object
3022 for a single special-case build.
3023
3024 As a special case, the
3025 .B source_scanner
3026 keyword argument can
3027 be used to specify
3028 a Scanner object
3029 that will be used to scan the sources.
3030 (The global
3031 .B DirScanner
3032 object can be used
3033 if any of the sources will be directories
3034 that must be scanned on-disk for
3035 changes to files that aren't
3036 already specified in other Builder of function calls.)
3037
3038 Any other keyword arguments specified override any
3039 same-named existing construction variables.
3040
3041 An action can be an external command,
3042 specified as a string,
3043 or a callable Python object;
3044 see "Action Objects," below,
3045 for more complete information.
3046 Also note that a string specifying an external command
3047 may be preceded by an
3048 .B @
3049 (at-sign)
3050 to suppress printing the command in question,
3051 or by a
3052 .B \-
3053 (hyphen)
3054 to ignore the exit status of the external command.
3055
3056 Examples:
3057
3058 .ES
3059 env.Command('foo.out', 'foo.in',
3060             "$FOO_BUILD < $SOURCES > $TARGET")
3061
3062 env.Command('bar.out', 'bar.in',
3063             ["rm -f $TARGET",
3064              "$BAR_BUILD < $SOURCES > $TARGET"],
3065             ENV = {'PATH' : '/usr/local/bin/'})
3066
3067 def rename(env, target, source):
3068     import os
3069     os.rename('.tmp', str(target[0]))
3070
3071 env.Command('baz.out', 'baz.in',
3072             ["$BAZ_BUILD < $SOURCES > .tmp",
3073              rename ])
3074 .EE
3075
3076 .IP
3077 Note that the
3078 .BR Command ()
3079 function will usually assume, by default,
3080 that the specified targets and/or sources are Files,
3081 if no other part of the configuration
3082 identifies what type of entry it is.
3083 If necessary, you can explicitly specify
3084 that targets or source nodes should
3085 be treated as directoriese
3086 by using the
3087 .BR Dir ()
3088 or
3089 .BR env.Dir ()
3090 functions.
3091
3092 Examples:
3093
3094 .ES
3095 env.Command('ddd.list', Dir('ddd'), 'ls -l $SOURCE > $TARGET')
3096
3097 env['DISTDIR'] = 'destination/directory'
3098 env.Command(env.Dir('$DISTDIR')), None, make_distdir)
3099 .EE
3100
3101 .IP
3102 (Also note that SCons will usually
3103 automatically create any directory necessary to hold a target file,
3104 so you normally don't need to create directories by hand.)
3105
3106 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3107 .TP
3108 .RI Configure( env ", [" custom_tests ", " conf_dir ", " log_file ", " config_h ])
3109 .TP
3110 .RI env.Configure([ custom_tests ", " conf_dir ", " log_file ", " config_h ])
3111 Creates a Configure object for integrated
3112 functionality similar to GNU autoconf.
3113 See the section "Configure Contexts,"
3114 below, for a complete explanation of the arguments and behavior.
3115
3116 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3117 .TP
3118 .RI env.Clone([ key = val ", ...])"
3119 Return a separate copy of a construction environment.
3120 If there are any keyword arguments specified,
3121 they are added to the returned copy,
3122 overwriting any existing values
3123 for the keywords.
3124
3125 Example:
3126
3127 .ES
3128 env2 = env.Clone()
3129 env3 = env.Clone(CCFLAGS = '-g')
3130 .EE
3131 .IP
3132 Additionally, a list of tools and a toolpath may be specified, as in
3133 the Environment constructor:
3134
3135 .ES
3136 def MyTool(env): env['FOO'] = 'bar'
3137 env4 = env.Clone(tools = ['msvc', MyTool])
3138 .EE
3139
3140 The
3141 .I parse_flags
3142 keyword argument is also recognized:
3143
3144 .ES
3145 # create an environment for compiling programs that use wxWidgets
3146 wx_env = env.Clone(parse_flags = '!wx-config --cflags --cxxflags')
3147 .EE
3148
3149 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3150 .TP
3151 .RI env.Copy([ key = val ", ...])"
3152 A now-deprecated synonym for
3153 .BR env.Clone() .
3154
3155 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3156 .TP
3157 .RI env.CVS( repository ", " module )
3158 A factory function that
3159 returns a Builder object
3160 to be used to fetch source files
3161 from the specified
3162 CVS
3163 .IR repository .
3164 The returned Builder
3165 is intended to be passed to the
3166 .B SourceCode
3167 function.
3168
3169 The optional specified
3170 .I module
3171 will be added to the beginning
3172 of all repository path names;
3173 this can be used, in essence,
3174 to strip initial directory names
3175 from the repository path names,
3176 so that you only have to
3177 replicate part of the repository
3178 directory hierarchy in your
3179 local build directory.
3180
3181 Examples:
3182
3183 .ES
3184 # Will fetch foo/bar/src.c
3185 # from /usr/local/CVSROOT/foo/bar/src.c.
3186 env.SourceCode('.', env.CVS('/usr/local/CVSROOT'))
3187
3188 # Will fetch bar/src.c
3189 # from /usr/local/CVSROOT/foo/bar/src.c.
3190 env.SourceCode('.', env.CVS('/usr/local/CVSROOT', 'foo'))
3191
3192 # Will fetch src.c
3193 # from /usr/local/CVSROOT/foo/bar/src.c.
3194 env.SourceCode('.', env.CVS('/usr/local/CVSROOT', 'foo/bar'))
3195 .EE
3196
3197 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3198 .TP
3199 .RI Decider( function )
3200 .TP
3201 .RI env.Decider( function )
3202 Specifies that all up-to-date decisions for
3203 targets built through this construction environment
3204 will be handled by the specified
3205 .IR function .
3206 The
3207 .I function
3208 can be one of the following strings
3209 that specify the type of decision function
3210 to be performed:
3211
3212 .RS 10
3213 .HP 6
3214 .B timestamp-newer
3215 Specifies that a target shall be considered out of date and rebuilt
3216 if the dependency's timestamp is newer than the target file's timestamp.
3217 This is the behavior of the classic Make utility,
3218 and
3219 .B make
3220 can be used a synonym for
3221 .BR timestamp-newer .
3222
3223 .HP 6
3224 .B timestamp-match
3225 Specifies that a target shall be considered out of date and rebuilt
3226 if the dependency's timestamp is different than the
3227 timestamp recorded the last time the target was built.
3228 This provides behavior very similar to the classic Make utility
3229 (in particular, files are not opened up so that their
3230 contents can be checksummed)
3231 except that the target will also be rebuilt if a
3232 dependency file has been restored to a version with an
3233 .I earlier
3234 timestamp, such as can happen when restoring files from backup archives.
3235
3236 .HP 6
3237 .B MD5
3238 Specifies that a target shall be considered out of date and rebuilt
3239 if the dependency's content has changed sine the last time
3240 the target was built,
3241 as determined be performing an MD5 checksum
3242 on the dependency's contents
3243 and comparing it to the checksum recorded the
3244 last time the target was built.
3245 .B content
3246 can be used as a synonym for
3247 .BR MD5 .
3248
3249 .HP 6
3250 .B MD5-timestamp
3251 Specifies that a target shall be considered out of date and rebuilt
3252 if the dependency's content has changed sine the last time
3253 the target was built,
3254 except that dependencies with a timestamp that matches
3255 the last time the target was rebuilt will be
3256 assumed to be up-to-date and
3257 .I not
3258 rebuilt.
3259 This provides behavior very similar
3260 to the
3261 .B MD5
3262 behavior of always checksumming file contents,
3263 with an optimization of not checking
3264 the contents of files whose timestamps haven't changed.
3265 The drawback is that SCons will
3266 .I not
3267 detect if a file's content has changed
3268 but its timestamp is the same,
3269 as might happen in an automated script
3270 that runs a build,
3271 updates a file,
3272 and runs the build again,
3273 all within a single second.
3274 .RE
3275
3276 .IP
3277 Examples:
3278
3279 .ES
3280 # Use exact timestamp matches by default.
3281 Decider('timestamp-match')
3282
3283 # Use MD5 content signatures for any targets built
3284 # with the attached construction environment.
3285 env.Decider('content')
3286 .EE
3287
3288 .IP
3289 In addition to the above already-available functions,
3290 the
3291 .I function
3292 argument may be an actual Python function
3293 that takes the following three arguments:
3294
3295 .RS 10
3296 .IP dependency
3297 The Node (file) which
3298 should cause the
3299 .I target
3300 to be rebuilt
3301 if it has "changed" since the last tme
3302 .I target was built.
3303
3304 .IP target
3305 The Node (file) being built.
3306 In the normal case,
3307 this is what should get rebuilt
3308 if the
3309 .I dependency
3310 has "changed."
3311
3312 .IP prev_ni
3313 Stored information about the state of the
3314 .I dependency
3315 the last time the
3316 .I target
3317 was built.
3318 This can be consulted to match various
3319 file characteristics
3320 such as the timestamp,
3321 size, or content signature.
3322 .RE
3323
3324 .IP
3325 The
3326 .I function
3327 should return a
3328 .B True
3329 (non-zero)
3330 value if the
3331 .I dependency
3332 has "changed" since the last time
3333 the
3334 .I target
3335 was built
3336 (indicating that the target
3337 .I should
3338 be rebuilt),
3339 and
3340 .B False
3341 (zero)
3342 otherwise
3343 (indicating that the target should
3344 .I not
3345 be rebuilt).
3346 Note that the decision can be made
3347 using whatever criteria are appopriate.
3348 Ignoring some or all of the function arguments
3349 is perfectly normal.
3350
3351 Example:
3352
3353 .ES
3354 def my_decider(dependency, target, prev_ni):
3355     return not os.path.exists(str(target))
3356
3357 env.Decider(my_decider)
3358 .EE
3359
3360 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3361 .TP
3362 .RI Default( targets )
3363 .TP
3364 .RI env.Default( targets )
3365 This specifies a list of default targets,
3366 which will be built by
3367 .B scons
3368 if no explicit targets are given on the command line.
3369 Multiple calls to
3370 .BR Default ()
3371 are legal,
3372 and add to the list of default targets.
3373
3374 Multiple targets should be specified as
3375 separate arguments to the
3376 .BR Default ()
3377 method, or as a list.
3378 .BR Default ()
3379 will also accept the Node returned by any
3380 of a construction environment's
3381 builder methods.
3382
3383 Examples:
3384
3385 .ES
3386 Default('foo', 'bar', 'baz')
3387 env.Default(['a', 'b', 'c'])
3388 hello = env.Program('hello', 'hello.c')
3389 env.Default(hello)
3390 .EE
3391 .IP
3392 An argument to
3393 .BR Default ()
3394 of
3395 .B None
3396 will clear all default targets.
3397 Later calls to
3398 .BR Default ()
3399 will add to the (now empty) default-target list
3400 like normal.
3401
3402 The current list of targets added using the
3403 .BR Default ()
3404 function or method is available in the
3405 .B DEFAULT_TARGETS
3406 list;
3407 see below.
3408
3409 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3410 .TP
3411 .RI DefaultEnvironment([ args ])
3412 Creates and returns a default construction environment object.
3413 This construction environment is used internally by SCons
3414 in order to execute many of the global functions in this list,
3415 and to fetch source files transparently
3416 from source code management systems.
3417
3418 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3419 .TP
3420 .RI Depends( target ", " dependency )
3421 .TP
3422 .RI env.Depends( target ", " dependency )
3423 Specifies an explicit dependency;
3424 the
3425 .I target
3426 will be rebuilt
3427 whenever the
3428 .I dependency
3429 has changed.
3430 Both the specified
3431 .I target
3432 and
3433 .I dependency
3434 can be a string
3435 (usually the path name of a file or directory)
3436 or Node objects,
3437 or a list of strings or Node objects
3438 (such as returned by a Builder call).
3439 This should only be necessary
3440 for cases where the dependency
3441 is not caught by a Scanner
3442 for the file.
3443
3444 Example:
3445
3446 .ES
3447 env.Depends('foo', 'other-input-file-for-foo')
3448
3449 mylib = env.Library('mylib.c')
3450 installed_lib = env.Install('lib', mylib)
3451 bar = env.Program('bar.c')
3452
3453 # Arrange for the library to be copied into the installation
3454 # directory before trying to build the "bar" program.
3455 # (Note that this is for example only.  A "real" library
3456 # dependency would normally be configured through the $LIBS
3457 # and $LIBPATH variables, not using an env.Depends() call.)
3458
3459 env.Depends(bar, installed_lib)
3460 .EE
3461
3462 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3463 .TP
3464 .RI env.Dictionary([ vars ])
3465 Returns a dictionary object
3466 containing copies of all of the
3467 construction variables in the environment.
3468 If there are any variable names specified,
3469 only the specified construction
3470 variables are returned in the dictionary.
3471
3472 Example:
3473
3474 .ES
3475 dict = env.Dictionary()
3476 cc_dict = env.Dictionary('CC', 'CCFLAGS', 'CCCOM')
3477 .EE
3478
3479 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3480 .TP
3481 .RI Dir( name ", [" directory ])
3482 .TP
3483 .RI env.Dir( name ", [" directory ])
3484 This returns a Directory Node,
3485 an object that represents the specified directory
3486 .IR name .
3487 .I name
3488 can be a relative or absolute path.
3489 .I directory
3490 is an optional directory that will be used as the parent directory.
3491 If no
3492 .I directory
3493 is specified, the current script's directory is used as the parent.
3494
3495 If
3496 .I name
3497 is a list, SCons returns a list of Dir nodes.
3498 Construction variables are expanded in
3499 .IR name .
3500
3501 Directory Nodes can be used anywhere you
3502 would supply a string as a directory name
3503 to a Builder method or function.
3504 Directory Nodes have attributes and methods
3505 that are useful in many situations;
3506 see "File and Directory Nodes," below.
3507
3508 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3509 .TP
3510 .RI env.Dump([ key ])
3511 Returns a pretty printable representation of the environment.
3512 .IR key ,
3513 if not
3514 .IR None ,
3515 should be a string containing the name of the variable of interest.
3516
3517 This SConstruct:
3518 .ES
3519 env=Environment()
3520 print env.Dump('CCCOM')
3521 .EE
3522 .IP
3523 will print:
3524 .ES
3525 \&'$CC -c -o $TARGET $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS $SOURCES'
3526 .EE
3527
3528 .ES
3529 env=Environment()
3530 print env.Dump()
3531 .EE
3532 .IP
3533 will print:
3534 .ES
3535 { 'AR': 'ar',
3536   'ARCOM': '$AR $ARFLAGS $TARGET $SOURCES\n$RANLIB $RANLIBFLAGS $TARGET',
3537   'ARFLAGS': ['r'],
3538   'AS': 'as',
3539   'ASCOM': '$AS $ASFLAGS -o $TARGET $SOURCES',
3540   'ASFLAGS': [],
3541   ...
3542 .EE
3543
3544 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3545 .TP
3546 .RI EnsurePythonVersion( major ", " minor )
3547 .TP
3548 .RI env.EnsurePythonVersion( major ", " minor )
3549 Ensure that the Python version is at least
3550 .IR major . minor .
3551 This function will
3552 print out an error message and exit SCons with a non-zero exit code if the
3553 actual Python version is not late enough.
3554
3555 Example:
3556
3557 .ES
3558 EnsurePythonVersion(2,2)
3559 .EE
3560
3561 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3562 .TP
3563 .RI EnsureSConsVersion( major ", " minor ", [" revision ])
3564 .TP
3565 .RI env.EnsureSConsVersion( major ", " minor ", [" revision ])
3566 Ensure that the SCons version is at least
3567 .IR major.minor ,
3568 or
3569 .IR major.minor.revision .
3570 if
3571 .I revision
3572 is specified.
3573 This function will
3574 print out an error message and exit SCons with a non-zero exit code if the
3575 actual SCons version is not late enough.
3576
3577 Examples:
3578
3579 .ES
3580 EnsureSConsVersion(0,14)
3581
3582 EnsureSConsVersion(0,96,90)
3583 .EE
3584
3585 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3586 .TP
3587 .RI Environment([ key = value ", ...])"
3588 .TP
3589 .RI env.Environment([ key = value ", ...])"
3590 Return a new construction environment
3591 initialized with the specified
3592 .IR key = value
3593 pairs.
3594
3595 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3596 .TP
3597 .RI Execute( action ", [" strfunction ", " varlist ])
3598 .TP
3599 .RI env.Execute( action ", [" strfunction ", " varlist ])
3600 Executes an Action object.
3601 The specified
3602 .IR action
3603 may be an Action object
3604 (see the section "Action Objects,"
3605 below, for a complete explanation of the arguments and behavior),
3606 or it may be a command-line string,
3607 list of commands,
3608 or executable Python function,
3609 each of which will be converted
3610 into an Action object
3611 and then executed.
3612 The exit value of the command
3613 or return value of the Python function
3614 will be returned.
3615
3616 Note that
3617 .B scons
3618 will print an error message if the executed
3619 .I action
3620 fails--that is,
3621 exits with or returns a non-zero value.
3622 .B scons
3623 will
3624 .I not ,
3625 however,
3626 automatically terminate the build
3627 if the specified
3628 .I action
3629 fails.
3630 If you want the build to stop in response to a failed
3631 .BR Execute ()
3632 call,
3633 you must explicitly check for a non-zero return value:
3634
3635 .ES
3636 Execute(Copy('file.out', 'file.in'))
3637
3638 if Execute("mkdir sub/dir/ectory"):
3639     # The mkdir failed, don't try to build.
3640     Exit(1)
3641 .EE
3642
3643 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3644 .TP
3645 .RI Exit([ value ])
3646 .TP
3647 .RI env.Exit([ value ])
3648 This tells
3649 .B scons
3650 to exit immediately
3651 with the specified
3652 .IR value .
3653 A default exit value of
3654 .B 0
3655 (zero)
3656 is used if no value is specified.
3657
3658 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3659 .TP
3660 .RI Export( vars )
3661 .TP
3662 .RI env.Export( vars )
3663 This tells
3664 .B scons
3665 to export a list of variables from the current
3666 SConscript file to all other SConscript files.
3667 The exported variables are kept in a global collection,
3668 so subsequent calls to
3669 .BR Export ()
3670 will over-write previous exports that have the same name.
3671 Multiple variable names can be passed to
3672 .BR Export ()
3673 as separate arguments or as a list.
3674 Keyword arguments can be used to provide names and their values.
3675 A dictionary can be used to map variables to a different name when exported.
3676 Both local variables and global variables can be exported.
3677
3678 Examples:
3679
3680 .ES
3681 env = Environment()
3682 # Make env available for all SConscript files to Import().
3683 Export("env")
3684
3685 package = 'my_name'
3686 # Make env and package available for all SConscript files:.
3687 Export("env", "package")
3688
3689 # Make env and package available for all SConscript files:
3690 Export(["env", "package"])
3691
3692 # Make env available using the name debug:
3693 Export(debug = env)
3694
3695 # Make env available using the name debug:
3696 Export({"debug":env})
3697 .EE
3698
3699 .IP
3700 Note that the
3701 .BR SConscript ()
3702 function supports an
3703 .I exports
3704 argument that makes it easier to to export a variable or
3705 set of variables to a single SConscript file.
3706 See the description of the
3707 .BR SConscript ()
3708 function, below.
3709
3710 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3711 .TP
3712 .RI File( name ", [" directory ])
3713 .TP
3714 .RI env.File( name ", [" directory ])
3715 This returns a
3716 File Node,
3717 an object that represents the specified file
3718 .IR name .
3719 .I name
3720 can be a relative or absolute path.
3721 .I directory
3722 is an optional directory that will be used as the parent directory.
3723
3724 If
3725 .I name
3726 is a list, SCons returns a list of File nodes.
3727 Construction variables are expanded in
3728 .IR name .
3729
3730 File Nodes can be used anywhere you
3731 would supply a string as a file name
3732 to a Builder method or function.
3733 File Nodes have attributes and methods
3734 that are useful in many situations;
3735 see "File and Directory Nodes," below.
3736
3737 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3738 .TP
3739 .RI FindFile( file ", " dirs )
3740 .TP
3741 .RI env.FindFile( file ", " dirs )
3742 Search for
3743 .I file
3744 in the path specified by
3745 .IR dirs .
3746 .I dirs
3747 may be a list of directory names or a single directory name.
3748 In addition to searching for files that exist in the filesytem,
3749 this function also searches for derived files
3750 that have not yet been built.
3751
3752 Example:
3753
3754 .ES
3755 foo = env.FindFile('foo', ['dir1', 'dir2'])
3756 .EE
3757
3758 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3759 .TP
3760 .RI FindInstalledFiles( )
3761 .TP
3762 .RI env.FindInstalledFiles( )
3763 Returns the list of targets set up by the
3764 .B Install()
3765 or
3766 .B InstallAs()
3767 builders.
3768
3769 This function serves as a convenient method to select the contents of
3770 a binary package.
3771
3772 Example:
3773
3774 .ES
3775 Install( '/bin', [ 'executable_a', 'executable_b' ] )
3776
3777 # will return the file node list
3778 # [ '/bin/executable_a', '/bin/executable_b' ]
3779 FindInstalledFiles()
3780
3781 Install( '/lib', [ 'some_library' ] )
3782
3783 # will return the file node list
3784 # [ '/bin/executable_a', '/bin/executable_b', '/lib/some_library' ]
3785 FindInstalledFiles()
3786 .EE
3787
3788 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3789 .TP
3790 .RI FindSourceFiles( node = '"."' )
3791 .TP
3792 .RI env.FindSourceFiles( node = '"."' )
3793
3794 Returns the list of nodes which serve as the source of the built files.
3795 It does so by inspecting the dependency tree starting at the optional
3796 argument
3797 .B node
3798 which defaults to the '"."'-node. It will then return all leaves of
3799 .B node.
3800 These are all children which have no further children.
3801
3802 This function is a convenient method to select the contents of a Source
3803 Package.
3804
3805 Example:
3806
3807 .ES
3808 Program( 'src/main_a.c' )
3809 Program( 'src/main_b.c' )
3810 Program( 'main_c.c' )
3811
3812 # returns ['main_c.c', 'src/main_a.c', 'SConstruct', 'src/main_b.c']
3813 FindSourceFiles()
3814
3815 # returns ['src/main_b.c', 'src/main_a.c' ]
3816 FindSourceFiles( 'src' )
3817 .EE
3818
3819 .IP
3820 As you can see build support files (SConstruct in the above example)
3821 will also be returned by this function.
3822
3823 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3824 .TP
3825 .RI FindPathDirs( variable )
3826 Returns a function
3827 (actually a callable Python object)
3828 intended to be used as the
3829 .B path_function
3830 of a Scanner object.
3831 The returned object will look up the specified
3832 .I variable
3833 in a construction environment
3834 and treat the construction variable's value as a list of
3835 directory paths that should be searched
3836 (like
3837 .BR CPPPATH ,
3838 .BR LIBPATH ,
3839 etc.).
3840
3841 Note that use of
3842 .BR FindPathDirs ()
3843 is generally preferable to
3844 writing your own
3845 .B path_function
3846 for the following reasons:
3847 1) The returned list will contain all appropriate directories
3848 found in source trees
3849 (when
3850 .BR VariantDir ()
3851 is used)
3852 or in code repositories
3853 (when
3854 .BR Repository ()
3855 or the
3856 .B \-Y
3857 option are used).
3858 2) scons will identify expansions of
3859 .I variable
3860 that evaluate to the same list of directories as,
3861 in fact, the same list,
3862 and avoid re-scanning the directories for files,
3863 when possible.
3864
3865 Example:
3866
3867 .ES
3868 def my_scan(node, env, path, arg):
3869     # Code to scan file contents goes here...
3870     return include_files
3871
3872 scanner = Scanner(name = 'myscanner',
3873                   function = my_scan,
3874                   path_function = FindPathDirs('MYPATH'))
3875 .EE
3876
3877 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3878 .TP
3879 .RI Flatten( sequence )
3880 .TP
3881 .RI env.Flatten( sequence )
3882 Takes a sequence (that is, a Python list or tuple)
3883 that may contain nested sequences
3884 and returns a flattened list containing
3885 all of the individual elements in any sequence.
3886 This can be helpful for collecting
3887 the lists returned by calls to Builders;
3888 other Builders will automatically
3889 flatten lists specified as input,
3890 but direct Python manipulation of
3891 these lists does not.
3892
3893 Examples:
3894
3895 .ES
3896 foo = Object('foo.c')
3897 bar = Object('bar.c')
3898
3899 # Because `foo' and `bar' are lists returned by the Object() Builder,
3900 # `objects' will be a list containing nested lists:
3901 objects = ['f1.o', foo, 'f2.o', bar, 'f3.o']
3902
3903 # Passing such a list to another Builder is all right because
3904 # the Builder will flatten the list automatically:
3905 Program(source = objects)
3906
3907 # If you need to manipulate the list directly using Python, you need to
3908 # call Flatten() yourself, or otherwise handle nested lists:
3909 for object in Flatten(objects):
3910     print str(object)
3911 .EE
3912
3913 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3914 .TP
3915 .RI GetBuildFailures()
3916 Returns a list of exceptions for the
3917 actions that failed while
3918 attempting to build targets.
3919 Each element in the returned list is a
3920 .B BuildError
3921 object
3922 with the following attributes
3923 that record various aspects
3924 of the build failure:
3925
3926 .B .node
3927 The node that was being built
3928 when the build failure occurred.
3929
3930 .B .status
3931 The numeric exit status
3932 returned by the command or Python function
3933 that failed when trying to build the
3934 specified Node.
3935
3936 .B .errstr
3937 The SCons error string
3938 describing the build failure.
3939 (This is often a generic
3940 message like "Error 2"
3941 to indicate that an executed
3942 command exited with a status of 2.)
3943
3944 .B .filename
3945 The name of the file or
3946 directory that actually caused the failure.
3947 This may be different from the
3948 .B .node
3949 attribute.
3950 For example,
3951 if an attempt to build a target named
3952 .B sub/dir/target
3953 fails because the
3954 .B sub/dir
3955 directory could not be created,
3956 then the
3957 .B .node
3958 attribute will be
3959 .B sub/dir/target
3960 but the
3961 .B .filename
3962 attribute will be
3963 .BR sub/dir .
3964
3965 .B .executor
3966 The SCons Executor object
3967 for the target Node
3968 being built.
3969 This can be used to retrieve
3970 the construction environment used
3971 for the failed action.
3972
3973 .B .action
3974 The actual SCons Action object that failed.
3975 This will be one specific action
3976 out of the possible list of
3977 actions that would have been
3978 executed to build the target.
3979
3980 .B .command
3981 The actual expanded command that was executed and failed,
3982 after expansion of
3983 .BR $TARGET ,
3984 .BR $SOURCE ,
3985 and other construction variables.
3986
3987 Note that the
3988 .BR GetBuildFailures ()
3989 function
3990 will always return an empty list
3991 until any build failure has occurred,
3992 which means that
3993 .BR GetBuildFailures ()
3994 will always return an empty list
3995 while the
3996 .B SConscript
3997 files are being read.
3998 Its primary intended use is
3999 for functions that will be
4000 executed before SCons exits
4001 by passing them to the
4002 standard Python
4003 .BR atexit.register ()
4004 function.
4005 Example:
4006
4007 .ES
4008 import atexit
4009
4010 def print_build_failures():
4011     from SCons.Script import GetBuildFailures
4012     for bf in GetBuildFailures():
4013         print "%s failed: %s" % (bf.node, bf.errstr)
4014
4015 atexit.register(print_build_failures)
4016 .EE
4017
4018 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4019 .TP
4020 .RI GetBuildPath( file ", [" ... ])
4021 .TP
4022 .RI env.GetBuildPath( file ", [" ... ])
4023 Returns the
4024 .B scons
4025 path name (or names) for the specified
4026 .I file
4027 (or files).
4028 The specified
4029 .I file
4030 or files
4031 may be
4032 .B scons
4033 Nodes or strings representing path names.
4034
4035 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4036 .TP
4037 .RI GetLaunchDir()
4038 .TP
4039 .RI env.GetLaunchDir()
4040 Returns the absolute path name of the directory from which
4041 .B scons
4042 was initially invoked.
4043 This can be useful when using the
4044 .BR \-u ,
4045 .BR \-U
4046 or
4047 .BR \-D
4048 options, which internally
4049 change to the directory in which the
4050 .B SConstruct
4051 file is found.
4052
4053 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4054 .TP
4055 .RI GetOption( name )
4056 .TP
4057 .RI env.GetOption( name )
4058 This function provides a way to query the value of
4059 SCons options set on scons command line
4060 (or set using the
4061 .IR SetOption ()
4062 function).
4063 The options supported are:
4064
4065 .RS 10
4066 .TP 6
4067 .B cache_debug
4068 which corresponds to --cache-debug;
4069 .TP 6
4070 .B cache_disable
4071 which corresponds to --cache-disable;
4072 .TP 6
4073 .B cache_force
4074 which corresponds to --cache-force;
4075 .TP 6
4076 .B cache_show
4077 which corresponds to --cache-show;
4078 .TP 6
4079 .B clean
4080 which corresponds to -c, --clean and --remove;
4081 .TP 6
4082 .B config
4083 which corresponds to --config;
4084 .TP 6
4085 .B directory
4086 which corresponds to -C and --directory;
4087 .TP 6
4088 .B diskcheck
4089 which corresponds to --diskcheck
4090 .TP 6
4091 .B duplicate
4092 which corresponds to --duplicate;
4093 .TP 6
4094 .B file
4095 which corresponds to -f, --file, --makefile and --sconstruct;
4096 .TP 6
4097 .B help
4098 which corresponds to -h and --help;
4099 .TP 6
4100 .B ignore_errors
4101 which corresponds to --ignore-errors;
4102 .TP 6
4103 .B implicit_cache
4104 which corresponds to --implicit-cache;
4105 .TP 6
4106 .B implicit_deps_changed
4107 which corresponds to --implicit-deps-changed;
4108 .TP 6
4109 .B implicit_deps_unchanged
4110 which corresponds to --implicit-deps-unchanged;
4111 .TP 6
4112 .B interactive
4113 which corresponds to --interact and --interactive;
4114 .TP 6
4115 .B keep_going
4116 which corresponds to -k and --keep-going;
4117 .TP 6
4118 .B max_drift
4119 which corresponds to --max-drift;
4120 .TP 6
4121 .B no_exec
4122 which corresponds to -n, --no-exec, --just-print, --dry-run and --recon;
4123 .TP 6
4124 .B no_site_dir
4125 which corresponds to --no-site-dir;
4126 .TP 6
4127 .B num_jobs
4128 which corresponds to -j and --jobs;
4129 .TP 6
4130 .B profile_file
4131 which corresponds to --profile;
4132 .TP 6
4133 .B question
4134 which corresponds to -q and --question;
4135 .TP 6
4136 .B random
4137 which corresponds to --random;
4138 .TP 6
4139 .B repository
4140 which corresponds to -Y, --repository and --srcdir;
4141 .TP 6
4142 .B silent
4143 which corresponds to -s, --silent and --quiet;
4144 .TP 6
4145 .B site_dir
4146 which corresponds to --site-dir;
4147 .TP 6
4148 .B stack_size
4149 which corresponds to --stack-size;
4150 .TP 6
4151 .B taskmastertrace_file
4152 which corresponds to --taskmastertrace; and
4153 .TP 6
4154 .B warn
4155 which corresponds to --warn and --warning.
4156 .RE
4157
4158 .IP
4159 See the documentation for the
4160 corresponding command line object for information about each specific
4161 option.
4162
4163 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4164 .TP
4165 .RI Glob( pattern ", [" ondisk ", " source ", " strings ])
4166 .TP
4167 .RI env.Glob( pattern ", [" ondisk ", " source ", " strings ])
4168 Returns Nodes (or strings) that match the specified
4169 .IR pattern ,
4170 relative to the directory of the current
4171 .B SConscript
4172 file.
4173 The
4174 .BR env.Glob ()
4175 form performs string substition on
4176 .I pattern
4177 and returns whatever matches
4178 the resulting expanded pattern.
4179
4180 The specified
4181 .I pattern
4182 uses Unix shell style metacharacters for matching:
4183
4184 .ES
4185   *       matches everything
4186   ?       matches any single character
4187   [seq]   matches any character in seq
4188   [!seq]  matches any char not in seq
4189 .EE
4190
4191 .IP
4192 If the first character of a filename is a dot,
4193 it must be matched explicitly.
4194 Character matches do
4195 .I not
4196 span directory separators.
4197
4198 The
4199 .BR Glob ()
4200 knows about
4201 repositories
4202 (see the
4203 .BR Repository ()
4204 function)
4205 and source directories
4206 (see the
4207 .BR VariantDir ()
4208 function)
4209 and
4210 returns a Node (or string, if so configured)
4211 in the local (SConscript) directory
4212 if matching Node is found
4213 anywhere in a corresponding
4214 repository or source directory.
4215
4216 The
4217 .B ondisk
4218 argument may be set to
4219 .B False
4220 (or any other non-true value)
4221 to disable the search for matches on disk,
4222 thereby only returning matches among
4223 already-configured File or Dir Nodes.
4224 The default behavior is to
4225 return corresponding Nodes
4226 for any on-disk matches found.
4227
4228 The
4229 .B source
4230 argument may be set to
4231 .B True
4232 (or any equivalent value)
4233 to specify that,
4234 when the local directory is a
4235 .BR VariantDir (),
4236 the returned Nodes should be from the
4237 corresponding source directory,
4238 not the local directory.
4239
4240 The
4241 .B strings
4242 argument may be set to
4243 .B True
4244 (or any equivalent value)
4245 to have the
4246 .BR Glob ()
4247 function return strings, not Nodes,
4248 that represent the matched files or directories.
4249 The returned strings will be relative to
4250 the local (SConscript) directory.
4251 (Note that This may make it easier to perform
4252 arbitrary manipulation of file names,
4253 but if the returned strings are
4254 passed to a different
4255 .B SConscript
4256 file,
4257 any Node translation will be relative
4258 to the other
4259 .B SConscript
4260 directory,
4261 not the original
4262 .B SConscript
4263 directory.)
4264
4265 Examples:
4266
4267 .ES
4268 Program('foo', Glob('*.c'))
4269 Zip('/tmp/everything', Glob('.??*') + Glob('*'))
4270 .EE
4271
4272 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4273 '\".TP
4274 '\".RI GlobalBuilders( flag )
4275 '\"When
4276 '\".B flag
4277 '\"is non-zero,
4278 '\"adds the names of the default builders
4279 '\"(Program, Library, etc.)
4280 '\"to the global name space
4281 '\"so they can be called without an explicit construction environment.
4282 '\"(This is the default.)
4283 '\"When
4284 '\".B
4285 '\"flag is zero,
4286 '\"the names of the default builders are removed
4287 '\"from the global name space
4288 '\"so that an explicit construction environment is required
4289 '\"to call all builders.
4290
4291 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4292 .TP
4293 .RI Help( text )
4294 .TP
4295 .RI env.Help( text )
4296 This specifies help text to be printed if the
4297 .B -h
4298 argument is given to
4299 .BR scons .
4300 If
4301 .BR Help
4302 is called multiple times, the text is appended together in the order
4303 that
4304 .BR Help
4305 is called.
4306
4307 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4308 .TP
4309 .RI Ignore( target ", " dependency )
4310 .TP
4311 .RI env.Ignore( target ", " dependency )
4312 The specified dependency file(s)
4313 will be ignored when deciding if
4314 the target file(s) need to be rebuilt.
4315
4316 You can also use
4317 .BR Ignore()
4318 to remove a target from the default build.
4319 In order to do this you must specify the directory the target will
4320 be built in as the target, and the file you want to skip building
4321 as the dependency.
4322
4323 Note that this will only remove the dependencies listed from 
4324 the files built by default.  It will still be built if that 
4325 dependency is needed by another object being built. 
4326 See the third and forth examples below.
4327
4328 Examples:
4329
4330 .ES
4331 env.Ignore('foo', 'foo.c')
4332 env.Ignore('bar', ['bar1.h', 'bar2.h'])
4333 env.Ignore('.','foobar.obj')
4334 env.Ignore('bar','bar/foobar.obj')
4335 .EE
4336
4337 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4338 .TP
4339 .RI Import( vars )
4340 .TP
4341 .RI env.Import( vars )
4342 This tells
4343 .B scons
4344 to import a list of variables into the current SConscript file. This
4345 will import variables that were exported with
4346 .BR Export ()
4347 or in the
4348 .I exports
4349 argument to
4350 .BR SConscript ().
4351 Variables exported by
4352 .BR SConscript ()
4353 have precedence.
4354 Multiple variable names can be passed to
4355 .BR Import ()
4356 as separate arguments or as a list. The variable "*" can be used
4357 to import all variables.
4358
4359 Examples:
4360
4361 .ES
4362 Import("env")
4363 Import("env", "variable")
4364 Import(["env", "variable"])
4365 Import("*")
4366 .EE
4367
4368 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4369 .TP
4370 .RI Literal( string )
4371 .TP
4372 .RI env.Literal( string )
4373 The specified
4374 .I string
4375 will be preserved as-is
4376 and not have construction variables expanded.
4377
4378 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4379 .TP
4380 .RI Local( targets )
4381 .TP
4382 .RI env.Local( targets )
4383 The specified
4384 .I targets
4385 will have copies made in the local tree,
4386 even if an already up-to-date copy
4387 exists in a repository.
4388 Returns a list of the target Node or Nodes.
4389
4390 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4391 \" .TP
4392 \" .RI env.MergeShellPaths( arg ", [" prepend ])
4393 \" Merges the elements of the specified
4394 \" .IR arg ,
4395 \" which must be a dictionary, to the construction
4396 \" environment's copy of the shell environment
4397 \" in env['ENV'].
4398 \" (This is the environment which is passed
4399 \" to subshells spawned by SCons.)
4400 \" Note that
4401 \" .I arg
4402 \" must be a single value,
4403 \" so multiple strings must
4404 \" be passed in as a list,
4405 \" not as separate arguments to
4406 \" .BR env.MergeShellPaths ().
4407
4408 \" New values are prepended to the environment variable by default,
4409 \" unless prepend=0 is specified.  
4410 \" Duplicate values are always eliminated, 
4411 \" since this function calls
4412 \" .B AppendENVPath
4413 \" or
4414 \" .B PrependENVPath
4415 \" depending on the
4416 \" .I prepend
4417 \" argument.  See those functions for more details.
4418
4419 \" Examples:
4420
4421 \" .ES
4422 \" # Prepend a path to the shell PATH.
4423 \" env.MergeShellPaths({'PATH':'/usr/local/bin'} )
4424 \" # Append two dirs to the shell INCLUDE.
4425 \" env.MergeShellPaths({'INCLUDE':['c:/inc1', 'c:/inc2']}, prepend=0 )
4426
4427 .EE
4428
4429 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4430 .TP
4431 .RI env.MergeFlags( arg ", [" unique ])
4432 Merges the specified
4433 .I arg
4434 values to the construction environment's construction variables.
4435 If the
4436 .I arg
4437 argument is not a dictionary,
4438 it is converted to one by calling
4439 .B env.ParseFlags()
4440 on the argument
4441 before the values are merged.
4442 Note that
4443 .I arg
4444 must be a single value,
4445 so multiple strings must
4446 be passed in as a list,
4447 not as separate arguments to
4448 .BR env.MergeFlags ().
4449
4450 By default,
4451 duplicate values are eliminated;
4452 you can, however, specify
4453 .B unique=0
4454 to allow duplicate
4455 values to be added.
4456 When eliminating duplicate values,
4457 any construction variables that end with
4458 the string
4459 .B PATH
4460 keep the left-most unique value.
4461 All other construction variables keep
4462 the right-most unique value.
4463
4464 Examples:
4465
4466 .ES
4467 # Add an optimization flag to $CCFLAGS.
4468 env.MergeFlags('-O3')
4469
4470 # Combine the flags returned from running pkg-config with an optimization
4471 # flag and merge the result into the construction variables.
4472 env.MergeFlags(['!pkg-config gtk+-2.0 --cflags', '-O3'])
4473
4474 # Combine an optimization flag with the flags returned from running pkg-config
4475 # twice and merge the result into the construction variables.
4476 env.MergeFlags(['-O3',
4477                '!pkg-config gtk+-2.0 --cflags --libs',
4478                '!pkg-config libpng12 --cflags --libs'])
4479 .EE
4480
4481 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4482 .TP
4483 .RI NoCache( target ", ...)"
4484 .TP
4485 .RI env.NoCache( target ", ...)"
4486 Specifies a list of files which should
4487 .I not
4488 be cached whenever the
4489 .BR CacheDir ()
4490 method has been activated.
4491 The specified targets may be a list
4492 or an individual target.
4493
4494 Multiple files should be specified
4495 either as separate arguments to the
4496 .BR NoCache ()
4497 method, or as a list.
4498 .BR NoCache ()
4499 will also accept the return value of any of the construction environment
4500 Builder methods.
4501
4502 Calling
4503 .BR NoCache ()
4504 on directories and other non-File Node types has no effect because
4505 only File Nodes are cached.
4506
4507 Examples:
4508
4509 .ES
4510 NoCache('foo.elf')
4511 NoCache(env.Program('hello', 'hello.c'))
4512 .EE
4513
4514 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4515 .TP
4516 .RI NoClean( target ", ...)"
4517 .TP
4518 .RI env.NoClean( target ", ...)"
4519 Specifies a list of files or directories which should
4520 .I not
4521 be removed whenever the targets (or their dependencies)
4522 are specified with the
4523 .B -c
4524 command line option.
4525 The specified targets may be a list
4526 or an individual target.
4527 Multiple calls to
4528 .BR NoClean ()
4529 are legal,
4530 and prevent each specified target
4531 from being removed by calls to the
4532 .B -c
4533 option.
4534
4535 Multiple files or directories should be specified
4536 either as separate arguments to the
4537 .BR NoClean ()
4538 method, or as a list.
4539 .BR NoClean ()
4540 will also accept the return value of any of the construction environment
4541 Builder methods.
4542
4543 Calling
4544 .BR NoClean ()
4545 for a target overrides calling
4546 .BR Clean ()
4547 for the same target,
4548 and any targets passed to both functions will
4549 .I not
4550 be removed by the
4551 .B -c
4552 option.
4553
4554 Examples:
4555
4556 .ES
4557 NoClean('foo.elf')
4558 NoClean(env.Program('hello', 'hello.c'))
4559 .EE
4560
4561 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4562 .TP
4563 .RI env.ParseConfig( command ", [" function ", " unique ])
4564 Calls the specified
4565 .I function
4566 to modify the environment as specified by the output of
4567 .I command .
4568 The default
4569 .I function
4570 is
4571 .BR env.MergeFlags (),
4572 which expects the output of a typical
4573 .I *-config command
4574 (for example,
4575 .BR gtk-config )
4576 and adds the options
4577 to the appropriate construction variables.
4578 By default,
4579 duplicate values are not
4580 added to any construction variables;
4581 you can specify
4582 .B unique=0
4583 to allow duplicate
4584 values to be added.
4585
4586 Interpreted options
4587 and the construction variables they affect
4588 are as specified for the
4589 .BR env.ParseFlags ()
4590 method (which this method calls).
4591 See that method's description, below,
4592 for a table of options and construction variables.
4593
4594 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4595 .TP
4596 .RI ParseDepends( filename ", [" must_exist ", " only_one ])
4597 .TP
4598 .RI env.ParseDepends( filename ", [" must_exist ", " only_one ])
4599 Parses the contents of the specified
4600 .I filename
4601 as a list of dependencies in the style of
4602 .BR Make
4603 or
4604 .BR mkdep ,
4605 and explicitly establishes all of the listed dependencies.
4606
4607 By default,
4608 it is not an error
4609 if the specified
4610 .I filename
4611 does not exist.
4612 The optional
4613 .I must_exist
4614 argument may be set to a non-zero
4615 value to have
4616 scons
4617 throw an exception and
4618 generate an error if the file does not exist,
4619 or is otherwise inaccessible.
4620
4621 The optional
4622 .I only_one
4623 argument may be set to a non-zero
4624 value to have
4625 scons
4626 thrown an exception and
4627 generate an error
4628 if the file contains dependency
4629 information for more than one target.
4630 This can provide a small sanity check
4631 for files intended to be generated
4632 by, for example, the
4633 .B gcc -M
4634 flag,
4635 which should typically only
4636 write dependency information for
4637 one output file into a corresponding
4638 .B .d
4639 file.
4640
4641 The
4642 .I filename
4643 and all of the files listed therein
4644 will be interpreted relative to
4645 the directory of the
4646 .I SConscript
4647 file which calls the
4648 .B ParseDepends
4649 function.
4650
4651 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4652 .TP
4653 .RI env.ParseFlags( flags ", ...)"
4654 Parses one or more strings containing
4655 typical command-line flags for GCC tool chains
4656 and returns a dictionary with the flag values
4657 separated into the appropriate SCons construction variables.
4658 This is intended as a companion to the
4659 .BR env.MergeFlags ()
4660 method, but allows for the values in the returned dictionary
4661 to be modified, if necessary,
4662 before merging them into the construction environment.
4663 (Note that
4664 .BR env.MergeFlags ()
4665 will call this method if its argument is not a dictionary,
4666 so it is usually not necessary to call
4667 .BR env.ParseFlags ()
4668 directly unless you want to manipulate the values.)
4669
4670 If the first character in any string is
4671 an exclamation mark (!),
4672 the rest of the string is executed as a command,
4673 and the output from the command is
4674 parsed as GCC tool chain command-line flags
4675 and added to the resulting dictionary.
4676
4677 Flag values are translated accordig to the prefix found,
4678 and added to the following construction variables:
4679
4680 .ES
4681 -arch               CCFLAGS, LINKFLAGS
4682 -D                  CPPDEFINES
4683 -framework          FRAMEWORKS
4684 -frameworkdir=      FRAMEWORKPATH
4685 -include            CCFLAGS
4686 -isysroot           CCFLAGS, LINKFLAGS
4687 -I                  CPPPATH
4688 -l                  LIBS
4689 -L                  LIBPATH
4690 -mno-cygwin         CCFLAGS, LINKFLAGS
4691 -mwindows           LINKFLAGS
4692 -pthread            CCFLAGS, LINKFLAGS
4693 -std=               CFLAGS
4694 -Wa,                ASFLAGS, CCFLAGS
4695 -Wl,-rpath=         RPATH
4696 -Wl,-R,             RPATH
4697 -Wl,-R              RPATH
4698 -Wl,                LINKFLAGS
4699 -Wp,                CPPFLAGS
4700 -                   CCFLAGS
4701 +                   CCFLAGS, LINKFLAGS
4702 .EE
4703
4704 .IP
4705 Any other strings not associated with options
4706 are assumed to be the names of libraries
4707 and added to the
4708 .B LIBS
4709 construction variable.
4710
4711 Examples (all of which produce the same result):
4712
4713 .ES
4714 dict = env.ParseFlags('-O2 -Dfoo -Dbar=1')
4715 dict = env.ParseFlags('-O2', '-Dfoo', '-Dbar=1')
4716 dict = env.ParseFlags(['-O2', '-Dfoo -Dbar=1'])
4717 dict = env.ParseFlags('-O2', '!echo -Dfoo -Dbar=1')
4718 .EE
4719
4720 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4721 .TP
4722 env.Perforce()
4723 A factory function that
4724 returns a Builder object
4725 to be used to fetch source files
4726 from the Perforce source code management system.
4727 The returned Builder
4728 is intended to be passed to the
4729 .B SourceCode
4730 function.
4731
4732 Example:
4733
4734 .ES
4735 env.SourceCode('.', env.Perforce())
4736 .EE
4737 .IP
4738 Perforce uses a number of external
4739 environment variables for its operation.
4740 Consequently, this function adds the
4741 following variables from the user's external environment
4742 to the construction environment's
4743 ENV dictionary:
4744 P4CHARSET,
4745 P4CLIENT,
4746 P4LANGUAGE,
4747 P4PASSWD,
4748 P4PORT,
4749 P4USER,
4750 SystemRoot,
4751 USER,
4752 and
4753 USERNAME.
4754
4755 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4756 .TP
4757 .RI Platform( string )
4758 Returns a callable object
4759 that can be used to initialize
4760 a construction environment using the
4761 platform keyword of the Environment() method.
4762
4763 Example:
4764
4765 .ES
4766 env = Environment(platform = Platform('win32'))
4767 .EE
4768 .TP
4769 .RI env.Platform( string )
4770 Applies the callable object for the specified platform
4771 .I string
4772 to the environment through which the method was called.
4773
4774 .ES
4775 env.Platform('posix')
4776 .EE
4777 .IP
4778 Note that the
4779 .B win32
4780 platform adds the
4781 .B SystemDrive
4782 and
4783 .B SystemRoot
4784 variables from the user's external environment
4785 to the construction environment's
4786 .B ENV
4787 dictionary.
4788 This is so that any executed commands
4789 that use sockets to connect with other systems
4790 (such as fetching source files from
4791 external CVS repository specifications like
4792 .BR :pserver:anonymous@cvs.sourceforge.net:/cvsroot/scons )
4793 will work on Windows systems.
4794
4795 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4796 .TP
4797 .RI Progress( callable ", [" interval ])
4798 .TP
4799 .RI Progress( string ", [" interval ", " file ", " overwrite ])
4800 .TP
4801 .RI Progress( list_of_strings ", [" interval ", " file ", " overwrite ])
4802 Allows SCons to show progress made during the build
4803 by displaying a string or calling a function while
4804 evaluating Nodes (e.g. files).
4805
4806 If the first specified argument is a Python callable
4807 (a function or an object that has a
4808 .BR __call__ ()
4809 method),
4810 the function will be called
4811 once every
4812 .I interval
4813 times a Node is evaluated.
4814 The callable will be passed the evaluated Node
4815 as its only argument.
4816 (For future compatibility,
4817 it's a good idea to also add
4818 .B *args
4819 and
4820 .B **kw
4821 as arguments to your function or method.
4822 This will prevent the code from breaking
4823 if SCons ever changes the interface
4824 to call the function with additional arguments in the future.)
4825
4826 An example of a simple custom progress function
4827 that prints a string containing the Node name
4828 every 10 Nodes:
4829
4830 .ES
4831 def my_progress_function(node, *args, **kw):
4832     print 'Evaluating node %s!' % node
4833 Progress(my_progress_function, interval=10)
4834 .EE
4835 .IP
4836 A more complicated example of a custom progress display object
4837 that prints a string containing a count
4838 every 100 evaluated Nodes.
4839 Note the use of
4840 .B \\\\r
4841 (a carriage return)
4842 at the end so that the string
4843 will overwrite itself on a display:
4844
4845 .ES
4846 import sys
4847 class ProgressCounter:
4848     count = 0
4849     def __call__(self, node, *args, **kw):
4850         self.count += 100
4851         sys.stderr.write('Evaluated %s nodes\\r' % self.count)
4852 Progress(ProgressCounter(), interval=100)
4853 .EE
4854 .IP
4855 If the first argument
4856 .BR Progress ()
4857 is a string,
4858 the string will be displayed
4859 every
4860 .I interval
4861 evaluated Nodes.
4862 The default is to print the string on standard output;
4863 an alternate output stream
4864 may be specified with the
4865 .B file=
4866 argument.
4867 The following will print a series of dots
4868 on the error output,
4869 one dot for every 100 evaluated Nodes:
4870
4871 .ES
4872 import sys
4873 Progress('.', interval=100, file=sys.stderr)
4874 .EE
4875 .IP
4876 If the string contains the verbatim substring
4877 .B $TARGET,
4878 it will be replaced with the Node.
4879 Note that, for performance reasons, this is
4880 .I not
4881 a regular SCons variable substition,
4882 so you can not use other variables
4883 or use curly braces.
4884 The following example will print the name of
4885 every evaluated Node,
4886 using a
4887 .B \\\\r
4888 (carriage return) to cause each line to overwritten by the next line,
4889 and the
4890 .B overwrite=
4891 keyword argument to make sure the previously-printed
4892 file name is overwritten with blank spaces:
4893
4894 .ES
4895 import sys
4896 Progress('$TARGET\\r', overwrite=True)
4897 .EE
4898 .IP
4899 If the first argument to
4900 .BR Progress ()
4901 is a list of strings,
4902 then each string in the list will be displayed
4903 in rotating fashion every
4904 .I interval
4905 evaluated Nodes.
4906 This can be used to implement a "spinner"
4907 on the user's screen as follows:
4908
4909 .ES
4910 Progress(['-\\r', '\\\\\\r', '|\\r', '/\\r'], interval=5)
4911 .EE
4912
4913 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4914 .TP
4915 .RI Precious( target ", ...)"
4916 .TP
4917 .RI env.Precious( target ", ...)"
4918 Marks each given
4919 .I target
4920 as precious so it is not deleted before it is rebuilt. Normally
4921 .B scons
4922 deletes a target before building it.
4923 Multiple targets can be passed in to a single call to
4924 .BR Precious ().
4925
4926 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4927 .TP
4928 .RI env.Prepend( key = val ", [...])"
4929 Appends the specified keyword arguments
4930 to the beginning of construction variables in the environment.
4931 If the Environment does not have
4932 the specified construction variable,
4933 it is simply added to the environment.
4934 If the values of the construction variable
4935 and the keyword argument are the same type,
4936 then the two values will be simply added together.
4937 Otherwise, the construction variable
4938 and the value of the keyword argument
4939 are both coerced to lists,
4940 and the lists are added together.
4941 (See also the Append method, above.)
4942
4943 Example:
4944
4945 .ES
4946 env.Prepend(CCFLAGS = '-g ', FOO = ['foo.yyy'])
4947 .EE
4948
4949 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4950 .TP
4951 .RI env.PrependENVPath( name ", " newpath ", [" envname ", " sep ", " delete_existing ])
4952 This appends new path elements to the given path in the
4953 specified external environment
4954 .RB ( ENV
4955 by default).
4956 This will only add
4957 any particular path once (leaving the first one it encounters and
4958 ignoring the rest, to preserve path order),
4959 and to help assure this,
4960 will normalize all paths (using
4961 .B os.path.normpath
4962 and
4963 .BR os.path.normcase ).
4964 This can also handle the
4965 case where the given old path variable is a list instead of a
4966 string, in which case a list will be returned instead of a string.
4967
4968 If
4969 .I delete_existing
4970 is 0, then adding a path that already exists
4971 will not move it to the beginning;
4972 it will stay where it is in the list.
4973
4974 Example:
4975
4976 .ES
4977 print 'before:',env['ENV']['INCLUDE']
4978 include_path = '/foo/bar:/foo'
4979 env.PrependENVPath('INCLUDE', include_path)
4980 print 'after:',env['ENV']['INCLUDE']
4981 .EE
4982
4983 The above exmaple will print:
4984
4985 .ES
4986 before: /biz:/foo
4987 after: /foo/bar:/foo:/biz
4988 .EE
4989
4990 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4991 .TP
4992 .RI env.PrependUnique( key = val ", delete_existing=0, [...])"
4993 Appends the specified keyword arguments
4994 to the beginning of construction variables in the environment.
4995 If the Environment does not have
4996 the specified construction variable,
4997 it is simply added to the environment.
4998 If the construction variable being appended to is a list,
4999 then any value(s) that already exist in the
5000 construction variable will
5001 .I not
5002 be added again to the list.
5003 However, if delete_existing is 1, 
5004 existing matching values are removed first, so
5005 existing values in the arg list move to the front of the list.
5006
5007 Example:
5008
5009 .ES
5010 env.PrependUnique(CCFLAGS = '-g', FOO = ['foo.yyy'])
5011 .EE
5012
5013 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5014 .TP
5015 env.RCS()
5016 A factory function that
5017 returns a Builder object
5018 to be used to fetch source files
5019 from RCS.
5020 The returned Builder
5021 is intended to be passed to the
5022 .B SourceCode
5023 function:
5024
5025 Examples:
5026
5027 .ES
5028 env.SourceCode('.', env.RCS())
5029 .EE
5030 .IP
5031 Note that
5032 .B scons
5033 will fetch source files
5034 from RCS subdirectories automatically,
5035 so configuring RCS
5036 as demonstrated in the above example
5037 should only be necessary if
5038 you are fetching from
5039 RCS,v
5040 files in the same
5041 directory as the source files,
5042 or if you need to explicitly specify RCS
5043 for a specific subdirectory.
5044
5045 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5046 .TP
5047 .RI env.Replace( key = val ", [...])"
5048 Replaces construction variables in the Environment
5049 with the specified keyword arguments.
5050
5051 Example:
5052
5053 .ES
5054 env.Replace(CCFLAGS = '-g', FOO = 'foo.xxx')
5055 .EE
5056
5057 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5058 .TP
5059 .RI Repository( directory )
5060 .TP
5061 .RI env.Repository( directory )
5062 Specifies that
5063 .I directory
5064 is a repository to be searched for files.
5065 Multiple calls to
5066 .BR Repository ()
5067 are legal,
5068 and each one adds to the list of
5069 repositories that will be searched.
5070
5071 To
5072 .BR scons ,
5073 a repository is a copy of the source tree,
5074 from the top-level directory on down,
5075 which may contain
5076 both source files and derived files
5077 that can be used to build targets in
5078 the local source tree.
5079 The canonical example would be an
5080 official source tree maintained by an integrator.
5081 If the repository contains derived files,
5082 then the derived files should have been built using
5083 .BR scons ,
5084 so that the repository contains the necessary
5085 signature information to allow
5086 .B scons
5087 to figure out when it is appropriate to
5088 use the repository copy of a derived file,
5089 instead of building one locally.
5090
5091 Note that if an up-to-date derived file
5092 already exists in a repository,
5093 .B scons
5094 will
5095 .I not
5096 make a copy in the local directory tree.
5097 In order to guarantee that a local copy
5098 will be made,
5099 use the
5100 .B Local()
5101 method.
5102
5103 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5104 .TP
5105 .RI Requires( target ", " prerequisite )
5106 .TP
5107 .RI env.Requires( target ", " prerequisite )
5108 Specifies an order-only relationship
5109 between the specified target file(s)
5110 and the specified prerequisite file(s).
5111 The prerequisite file(s)
5112 will be (re)built, if necessary,
5113 .I before
5114 the target file(s),
5115 but the target file(s) do not actually
5116 depend on the prerequisites
5117 and will not be rebuilt simply because
5118 the prerequisite file(s) change.
5119
5120 Example:
5121
5122 .ES
5123 env.Requires('foo', 'file-that-must-be-built-before-foo')
5124 .EE
5125
5126 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5127 .TP
5128 .RI Return([ vars "... , " stop= ])
5129 By default,
5130 this stops processing the current SConscript
5131 file and returns to the calling SConscript file
5132 the values of the variables named in the
5133 .I vars
5134 string arguments.
5135 Multiple strings contaning variable names may be passed to
5136 .BR Return ().
5137 Any strings that contain white space
5138
5139 The optional
5140 .B stop=
5141 keyword argument may be set to a false value
5142 to continue processing the rest of the SConscript
5143 file after the
5144 .BR Return ()
5145 call.
5146 This was the default behavior prior to SCons 0.98.
5147 However, the values returned
5148 are still the values of the variables in the named
5149 .I vars
5150 at the point
5151 .BR Return ()
5152 is called.
5153
5154 Examples:
5155
5156 .ES
5157 # Returns without returning a value.
5158 Return()
5159
5160 # Returns the value of the 'foo' Python variable.
5161 Return("foo")
5162
5163 # Returns the values of the Python variables 'foo' and 'bar'.
5164 Return("foo", "bar")
5165
5166 # Returns the values of Python variables 'val1' and 'val2'.
5167 Return('val1 val2')
5168 .EE
5169
5170 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5171 .TP
5172 .RI Scanner( function ", [" argument ", " keys ", " path_function ", " node_class ", " node_factory ", " scan_check ", " recursive ])
5173 .TP
5174 .RI env.Scanner( function ", [" argument ", " keys ", " path_function ", " node_class ", " node_factory ", " scan_check ", " recursive ])
5175 Creates a Scanner object for
5176 the specified
5177 .IR function .
5178 See the section "Scanner Objects,"
5179 below, for a complete explanation of the arguments and behavior.
5180
5181 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5182 .TP
5183 env.SCCS()
5184 A factory function that
5185 returns a Builder object
5186 to be used to fetch source files
5187 from SCCS.
5188 The returned Builder
5189 is intended to be passed to the
5190 .B SourceCode
5191 function.
5192
5193 Example:
5194
5195 .ES
5196 env.SourceCode('.', env.SCCS())
5197 .EE
5198 .IP
5199 Note that
5200 .B scons
5201 will fetch source files
5202 from SCCS subdirectories automatically,
5203 so configuring SCCS
5204 as demonstrated in the above example
5205 should only be necessary if
5206 you are fetching from
5207 .I s.SCCS
5208 files in the same
5209 directory as the source files,
5210 or if you need to explicitly specify SCCS
5211 for a specific subdirectory.
5212
5213 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5214 .TP
5215 .RI SConscript( scripts ", [" exports ", " variant_dir ", " duplicate ])
5216 '\" .RI SConscript( scripts ", [" exports ", " variant_dir ", " src_dir ", " duplicate ])
5217 .TP
5218 .RI env.SConscript( scripts ", [" exports ", " variant_dir ", " duplicate ])
5219 '\" .RI env.SConscript( scripts ", [" exports ", " variant_dir ", " src_dir ", " duplicate ])
5220 .TP
5221 .RI SConscript(dirs= subdirs ", [name=" script ", " exports ", " variant_dir ", " duplicate ])
5222 '\" .RI SConscript(dirs= subdirs ", [name=" script ", " exports ", " variant_dir ", " src_dir ", " duplicate ])
5223 .TP
5224 .RI env.SConscript(dirs= subdirs ", [name=" script ", " exports ", " variant_dir ", " duplicate ])
5225 '\" .RI env.SConscript(dirs= subdirs ", [name=" script ", " exports ", " variant_dir ", " src_dir ", " duplicate ])
5226 This tells
5227 .B scons
5228 to execute
5229 one or more subsidiary SConscript (configuration) files.
5230 Any variables returned by a called script using
5231 .BR Return ()
5232 will be returned by the call to
5233 .BR SConscript ().
5234 There are two ways to call the
5235 .BR SConscript ()
5236 function.
5237
5238 The first way you can call
5239 .BR SConscript ()
5240 is to explicitly specify one or more
5241 .I scripts
5242 as the first argument.
5243 A single script may be specified as a string;
5244 multiple scripts must be specified as a list
5245 (either explicitly or as created by
5246 a function like
5247 .BR Split ()).
5248 Examples:
5249 .ES
5250 SConscript('SConscript')      # run SConscript in the current directory
5251 SConscript('src/SConscript')  # run SConscript in the src directory
5252 SConscript(['src/SConscript', 'doc/SConscript'])
5253 config = SConscript('MyConfig.py')
5254 .EE
5255
5256 The second way you can call
5257 .BR SConscript ()
5258 is to specify a list of (sub)directory names
5259 as a
5260 .RI dirs= subdirs
5261 keyword argument.
5262 In this case,
5263 .B scons
5264 will, by default,
5265 execute a subsidiary configuration file named
5266 .B SConscript
5267 in each of the specified directories.
5268 You may specify a name other than
5269 .B SConscript
5270 by supplying an optional
5271 .RI name= script
5272 keyword argument.
5273 The first three examples below have the same effect
5274 as the first three examples above:
5275 .ES
5276 SConscript(dirs='.')      # run SConscript in the current directory
5277 SConscript(dirs='src')    # run SConscript in the src directory
5278 SConscript(dirs=['src', 'doc'])
5279 SConscript(dirs=['sub1', 'sub2'], name='MySConscript')
5280 .EE
5281
5282 The optional
5283 .I exports
5284 argument provides a list of variable names or a dictionary of
5285 named values to export to the
5286 .IR script(s) .
5287 These variables are locally exported only to the specified
5288 .IR script(s) ,
5289 and do not affect the global pool of variables used by the
5290 .BR Export ()
5291 function.
5292 '\"If multiple dirs are provided, each script gets a fresh export.
5293 The subsidiary
5294 .I script(s)
5295 must use the
5296 .BR Import ()
5297 function to import the variables.
5298 Examples:
5299 .ES
5300 foo = SConscript('sub/SConscript', exports='env')
5301 SConscript('dir/SConscript', exports=['env', 'variable'])
5302 SConscript(dirs='subdir', exports='env variable')
5303 SConscript(dirs=['one', 'two', 'three'], exports='shared_info')
5304 .EE
5305
5306 If the optional
5307 .I variant_dir
5308 argument is present, it causes an effect equivalent to the
5309 .BR VariantDir ()
5310 method described below.
5311 (If
5312 .I variant_dir
5313 is not present, the
5314 '\" .IR src_dir and
5315 .I duplicate
5316 '\" arguments are ignored.)
5317 argument is ignored.)
5318 The
5319 .I variant_dir
5320 '\" and
5321 '\" .I src_dir
5322 '\" arguments are interpreted relative to the directory of the calling
5323 argument is interpreted relative to the directory of the calling
5324 .B SConscript
5325 file.
5326 See the description of the
5327 .BR VariantDir ()
5328 function below for additional details and restrictions.
5329
5330 If
5331 .I variant_dir
5332 is present,
5333 '\" but
5334 '\" .IR src_dir " is not,"
5335 the source directory is the directory in which the
5336 .B SConscript
5337 file resides and the
5338 .B SConscript
5339 file is evaluated as if it were in the
5340 .I variant_dir
5341 directory:
5342 .ES
5343 SConscript('src/SConscript', variant_dir = 'build')
5344 .EE
5345 is equivalent to
5346 .ES
5347 VariantDir('build', 'src')
5348 SConscript('build/SConscript')
5349 .EE
5350 This later paradigm is often used when the sources are
5351 in the same directory as the
5352 .BR SConstruct:
5353 .ES
5354 SConscript('SConscript', variant_dir = 'build')
5355 .EE
5356 is equivalent to
5357 .ES
5358 VariantDir('build', '.')
5359 SConscript('build/SConscript')
5360 .EE
5361
5362 '\" If
5363 '\" .IR variant_dir " and"
5364 '\" .IR src_dir " are both present,"
5365 '\" xxxxx everything is in a state of confusion.
5366 '\" .ES
5367 '\" SConscript(dirs = 'src', variant_dir = 'build', src_dir = '.')
5368 '\" runs src/SConscript in build/src, but
5369 '\" SConscript(dirs = 'lib', variant_dir = 'build', src_dir = 'src')
5370 '\" runs lib/SConscript (in lib!).  However,
5371 '\" SConscript(dirs = 'src', variant_dir = 'build', src_dir = 'src')
5372 '\" runs src/SConscript in build.  Moreover,
5373 '\" SConscript(dirs = 'src/lib', variant_dir = 'build', src_dir = 'src')
5374 '\" runs src/lib/SConscript in build/lib.  Moreover,
5375 '\" SConscript(dirs = 'build/src/lib', variant_dir = 'build', src_dir = 'src')
5376 '\" can't find build/src/lib/SConscript, even though it ought to exist.
5377 '\" .EE
5378 '\" is equivalent to
5379 '\" .ES
5380 '\" ????????????????
5381 '\" .EE
5382 '\" and what about this alternative?
5383 '\"TODO??? SConscript('build/SConscript', src_dir='src')
5384
5385 Here are some composite examples:
5386
5387 .ES
5388 # collect the configuration information and use it to build src and doc
5389 shared_info = SConscript('MyConfig.py')
5390 SConscript('src/SConscript', exports='shared_info')
5391 SConscript('doc/SConscript', exports='shared_info')
5392 .EE
5393
5394 .ES
5395 # build debugging and production versions.  SConscript
5396 # can use Dir('.').path to determine variant.
5397 SConscript('SConscript', variant_dir='debug', duplicate=0)
5398 SConscript('SConscript', variant_dir='prod', duplicate=0)
5399 .EE
5400
5401 .ES
5402 # build debugging and production versions.  SConscript
5403 # is passed flags to use.
5404 opts = { 'CPPDEFINES' : ['DEBUG'], 'CCFLAGS' : '-pgdb' }
5405 SConscript('SConscript', variant_dir='debug', duplicate=0, exports=opts)
5406 opts = { 'CPPDEFINES' : ['NODEBUG'], 'CCFLAGS' : '-O' }
5407 SConscript('SConscript', variant_dir='prod', duplicate=0, exports=opts)
5408 .EE
5409
5410 .ES
5411 # build common documentation and compile for different architectures
5412 SConscript('doc/SConscript', variant_dir='build/doc', duplicate=0)
5413 SConscript('src/SConscript', variant_dir='build/x86', duplicate=0)
5414 SConscript('src/SConscript', variant_dir='build/ppc', duplicate=0)
5415 .EE
5416
5417 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5418 .TP
5419 .RI SConscriptChdir( value )
5420 .TP
5421 .RI env.SConscriptChdir( value )
5422 By default,
5423 .B scons
5424 changes its working directory
5425 to the directory in which each
5426 subsidiary SConscript file lives.
5427 This behavior may be disabled
5428 by specifying either:
5429
5430 .ES
5431 SConscriptChdir(0)
5432 env.SConscriptChdir(0)
5433 .EE
5434 .IP
5435 in which case
5436 .B scons
5437 will stay in the top-level directory
5438 while reading all SConscript files.
5439 (This may be necessary when building from repositories,
5440 when all the directories in which SConscript files may be found
5441 don't necessarily exist locally.)
5442 You may enable and disable
5443 this ability by calling
5444 SConscriptChdir()
5445 multiple times.
5446
5447 Example:
5448
5449 .ES
5450 env = Environment()
5451 SConscriptChdir(0)
5452 SConscript('foo/SConscript')    # will not chdir to foo
5453 env.SConscriptChdir(1)
5454 SConscript('bar/SConscript')    # will chdir to bar
5455 .EE
5456
5457 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5458 .TP
5459 .RI SConsignFile([ file , dbm_module ])
5460 .TP
5461 .RI env.SConsignFile([ file , dbm_module ])
5462 This tells
5463 .B scons
5464 to store all file signatures
5465 in the specified database
5466 .IR file .
5467 If the
5468 .I file
5469 name is omitted,
5470 .B .sconsign
5471 is used by default.
5472 (The actual file name(s) stored on disk
5473 may have an appropriated suffix appended
5474 by the
5475 .IR  dbm_module .)
5476 If
5477 .I file
5478 is not an absolute path name,
5479 the file is placed in the same directory as the top-level
5480 .B SConstruct
5481 file.
5482
5483 If
5484 .I file
5485 is
5486 .BR None ,
5487 then
5488 .B scons
5489 will store file signatures
5490 in a separate
5491 .B .sconsign
5492 file in each directory,
5493 not in one global database file.
5494 (This was the default behavior
5495 prior to SCons 0.96.91 and 0.97.)
5496
5497 The optional
5498 .I dbm_module
5499 argument can be used to specify
5500 which Python database module
5501 The default is to use a custom
5502 .B SCons.dblite
5503 module that uses pickled
5504 Python data structures,
5505 and which works on all Python versions from 1.5.2 on.
5506
5507 Examples:
5508
5509 .ES
5510 # Explicitly stores signatures in ".sconsign.dblite"
5511 # in the top-level SConstruct directory (the
5512 # default behavior).
5513 SConsignFile()
5514
5515 # Stores signatures in the file "etc/scons-signatures"
5516 # relative to the top-level SConstruct directory.
5517 SConsignFile("etc/scons-signatures")
5518
5519 # Stores signatures in the specified absolute file name.
5520 SConsignFile("/home/me/SCons/signatures")
5521
5522 # Stores signatures in a separate .sconsign file
5523 # in each directory.
5524 SConsignFile(None)
5525 .EE
5526
5527 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5528 .TP
5529 .RI env.SetDefault(key = val ", [...])"
5530 Sets construction variables to default values specified with the keyword
5531 arguments if (and only if) the variables are not already set.
5532 The following statements are equivalent:
5533
5534 .ES
5535 env.SetDefault(FOO = 'foo')
5536
5537 if not env.has_key('FOO'): env['FOO'] = 'foo'
5538 .EE
5539
5540 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5541 .TP
5542 .RI SetOption( name ", " value )
5543 .TP
5544 .RI env.SetOption( name ", " value )
5545 This function provides a way to set a select subset of the scons command
5546 line options from a SConscript file. The options supported are:
5547
5548 .RS 10
5549 .TP 6
5550 .B clean
5551 which corresponds to -c, --clean and --remove;
5552 .TP 6
5553 .B duplicate
5554 which corresponds to --duplicate;
5555 .TP 6
5556 .B help
5557 which corresponds to -h and --help;
5558 .TP 6
5559 .B implicit_cache
5560 which corresponds to --implicit-cache;
5561 .TP 6
5562 .B max_drift
5563 which corresponds to --max-drift;
5564 .TP 6
5565 .B no_exec
5566 which corresponds to -n, --no-exec, --just-print, --dry-run and --recon;
5567 .TP 6
5568 .B num_jobs
5569 which corresponds to -j and --jobs;
5570 .TP 6
5571 .B random
5572 which corresponds to --random; and
5573 .TP 6
5574 .B stack_size
5575 which corresponds to --stack-size.
5576 .RE
5577
5578 .IP
5579 See the documentation for the
5580 corresponding command line object for information about each specific
5581 option.
5582
5583 Example:
5584
5585 .ES
5586 SetOption('max_drift', 1)
5587 .EE
5588
5589 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5590 .TP
5591 .RI SideEffect( side_effect ", " target )
5592 .TP
5593 .RI env.SideEffect( side_effect ", " target )
5594 Declares
5595 .I side_effect
5596 as a side effect of building
5597 .IR target .
5598 Both
5599 .I side_effect
5600 and
5601 .I target
5602 can be a list, a file name, or a node.
5603 A side effect is a target file that is created or updated
5604 as a side effect of building other targets.
5605 For example, a Windows PDB
5606 file is created as a side effect of building the .obj
5607 files for a static library,
5608 and various log files are created updated
5609 as side effects of various TeX commands.
5610 If a target is a side effect of multiple build commands,
5611 .B scons
5612 will ensure that only one set of commands
5613 is executed at a time.
5614 Consequently, you only need to use this method
5615 for side-effect targets that are built as a result of
5616 multiple build commands.
5617
5618 Because multiple build commands may update
5619 the same side effect file,
5620 by default the
5621 .I side_effect
5622 target is
5623 .I not
5624 automatically removed
5625 when the
5626 .I target
5627 is removed by the
5628 .B -c
5629 option.
5630 (Note, however, that the
5631 .I side_effect
5632 might be removed as part of
5633 cleaning the directory in which it lives.)
5634 If you want to make sure the
5635 .I side_effect
5636 is cleaned whenever a specific
5637 .I target
5638 is cleaned,
5639 you must specify this explicitly
5640 with the
5641 .BR Clean ()
5642 or
5643 .BR env.Clean ()
5644 function.
5645
5646 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5647 .TP
5648 .RI SourceCode( entries ", " builder )
5649 .TP
5650 .RI env.SourceCode( entries ", " builder )
5651 Arrange for non-existent source files to
5652 be fetched from a source code management system
5653 using the specified
5654 .IR builder .
5655 The specified
5656 .I entries
5657 may be a Node, string or list of both,
5658 and may represent either individual
5659 source files or directories in which
5660 source files can be found.
5661
5662 For any non-existent source files,
5663 .B scons
5664 will search up the directory tree
5665 and use the first
5666 .B SourceCode
5667 builder it finds.
5668 The specified
5669 .I builder
5670 may be
5671 .BR None ,
5672 in which case
5673 .B scons
5674 will not use a builder to fetch
5675 source files for the specified
5676 .IR entries ,
5677 even if a
5678 .B SourceCode
5679 builder has been specified
5680 for a directory higher up the tree.
5681
5682 .B scons
5683 will, by default,
5684 fetch files from SCCS or RCS subdirectories
5685 without explicit configuration.
5686 This takes some extra processing time
5687 to search for the necessary
5688 source code management files on disk.
5689 You can avoid these extra searches
5690 and speed up your build a little
5691 by disabling these searches as follows:
5692
5693 .ES
5694 env.SourceCode('.', None)
5695 .EE
5696
5697 .IP
5698 Note that if the specified
5699 .I builder
5700 is one you create by hand,
5701 it must have an associated
5702 construction environment to use
5703 when fetching a source file.
5704
5705 .B scons
5706 provides a set of canned factory
5707 functions that return appropriate
5708 Builders for various popular
5709 source code management systems.
5710 Canonical examples of invocation include:
5711
5712 .ES
5713 env.SourceCode('.', env.BitKeeper('/usr/local/BKsources'))
5714 env.SourceCode('src', env.CVS('/usr/local/CVSROOT'))
5715 env.SourceCode('/', env.RCS())
5716 env.SourceCode(['f1.c', 'f2.c'], env.SCCS())
5717 env.SourceCode('no_source.c', None)
5718 .EE
5719 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion'))
5720
5721 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5722 .TP
5723 .RI env.subst( input ", [" raw ", " target ", " source ", " conv ])
5724 Performs construction variable interpolation
5725 on the specified string or sequence argument
5726 .IR input .
5727
5728 By default,
5729 leading or trailing white space will
5730 be removed from the result.
5731 and all sequences of white space
5732 will be compressed to a single space character.
5733 Additionally, any
5734 .B $(
5735 and
5736 .B $)
5737 character sequences will be stripped from the returned string,
5738 The optional
5739 .I raw
5740 argument may be set to
5741 .B 1
5742 if you want to preserve white space and
5743 .BR $( - $)
5744 sequences.
5745 The
5746 .I raw
5747 argument may be set to
5748 .B 2
5749 if you want to strip
5750 all characters between
5751 any
5752 .B $(
5753 and
5754 .B $)
5755 pairs
5756 (as is done for signature calculation).
5757
5758 If the input is a sequence
5759 (list or tuple),
5760 the individual elements of
5761 the sequence will be expanded,
5762 and the results will be returned as a list.
5763
5764 The optional
5765 .I target
5766 and
5767 .I source
5768 keyword arguments
5769 must be set to lists of
5770 target and source nodes, respectively,
5771 if you want the
5772 .BR $TARGET ,
5773 .BR $TARGETS ,
5774 .BR $SOURCE
5775 and
5776 .BR $SOURCES
5777 to be available for expansion.
5778 This is usually necessary if you are
5779 calling
5780 .BR env.subst ()
5781 from within a Python function used
5782 as an SCons action.
5783
5784 Returned string values or sequence elements
5785 are converted to their string representation by default.
5786 The optional
5787 .I conv
5788 argument
5789 may specify a conversion function
5790 that will be used in place of
5791 the default.
5792 For example, if you want Python objects
5793 (including SCons Nodes)
5794 to be returned as Python objects,
5795 you can use the Python
5796 .B lambda
5797 idiom to pass in an unnamed function
5798 that simply returns its unconverted argument.
5799
5800 Example:
5801
5802 .ES
5803 print env.subst("The C compiler is: $CC")
5804
5805 def compile(target, source, env):
5806     sourceDir = env.subst("${SOURCE.srcdir}",
5807                           target=target,
5808                           source=source)
5809
5810 source_nodes = env.subst('$EXPAND_TO_NODELIST',
5811                          conv=lambda x: x)
5812 .EE
5813
5814 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5815 '\".TP
5816 '\".RI Subversion( repository ", " module )
5817 '\"A factory function that
5818 '\"returns a Builder object
5819 '\"to be used to fetch source files
5820 '\"from the specified Subversion
5821 '\".IR repository .
5822 '\"The returned Builder
5823 '\"is intended to be passed to the
5824 '\".B SourceCode
5825 '\"function.
5826 '\"
5827 '\"The optional specified
5828 '\".I module
5829 '\"will be added to the beginning
5830 '\"of all repository path names;
5831 '\"this can be used, in essence,
5832 '\"to strip initial directory names
5833 '\"from the repository path names,
5834 '\"so that you only have to
5835 '\"replicate part of the repository
5836 '\"directory hierarchy in your
5837 '\"local build directory.
5838 '\"
5839 '\"Example:
5840 '\"
5841 '\".ES
5842 '\"# Will fetch foo/bar/src.c
5843 '\"# from /usr/local/Subversion/foo/bar/src.c.
5844 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion'))
5845 '\"
5846 '\"# Will fetch bar/src.c
5847 '\"# from /usr/local/Subversion/foo/bar/src.c.
5848 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion', 'foo'))
5849 '\"
5850 '\"# Will fetch src.c
5851 '\"# from /usr/local/Subversion/foo/bar/src.c.
5852 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion', 'foo/bar'))
5853 '\".EE
5854
5855 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5856 .TP
5857 .RI SourceSignatures( type )
5858 .TP
5859 .RI env.SourceSignatures( type )
5860 Note:  Although it is not yet officially deprecated,
5861 use of this function is discouraged.
5862 See the
5863 .BR Decider ()
5864 function for a more flexible and straightforward way
5865 to configure SCons' decision-making.
5866
5867 The
5868 .BR SourceSignatures ()
5869 function tells
5870 .B scons
5871 how to decide if a source file
5872 (a file that is not built from any other files)
5873 has changed since the last time it
5874 was used to build a particular target file.
5875 Legal values are
5876 .B "MD5"
5877 or
5878 .BR "timestamp" .
5879
5880 If the environment method is used,
5881 the specified type of source signature
5882 is only used when deciding whether targets
5883 built with that environment are up-to-date or must be rebuilt.
5884 If the global function is used,
5885 the specified type of source signature becomes the default
5886 used for all decisions
5887 about whether targets are up-to-date.
5888
5889 .B "MD5"
5890 means
5891 .B scons
5892 decides that a source file has changed
5893 if the MD5 checksum of its contents has changed since
5894 the last time it was used to rebuild a particular target file.
5895
5896 .B "timestamp"
5897 means
5898 .B scons
5899 decides that a source file has changed
5900 if its timestamp (modification time) has changed since
5901 the last time it was used to rebuild a particular target file.
5902 (Note that although this is similar to the behavior of Make,
5903 by default it will also rebuild if the dependency is
5904 .I older
5905 than the last time it was used to rebuild the target file.)
5906
5907 There is no different between the two behaviors
5908 for Python
5909 .BR Value ()
5910 node objects.
5911
5912 .B "MD5"
5913 signatures take longer to compute,
5914 but are more accurate than
5915 .B "timestamp"
5916 signatures.
5917 The default value is
5918 .BR "MD5" .
5919
5920 Note that the default
5921 .BR TargetSignatures ()
5922 setting (see below)
5923 is to use this
5924 .BR SourceSignatures ()
5925 setting for any target files that are used
5926 to build other target files.
5927 Consequently, changing the value of
5928 .BR SourceSignatures ()
5929 will, by default,
5930 affect the up-to-date decision for all files in the build
5931 (or all files built with a specific construction environment
5932 when
5933 .BR env.SourceSignatures ()
5934 is used).
5935
5936 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5937 .TP
5938 .RI Split( arg )
5939 .TP
5940 .RI env.Split( arg )
5941 Returns a list of file names or other objects.
5942 If arg is a string,
5943 it will be split on strings of white-space characters
5944 within the string,
5945 making it easier to write long lists of file names.
5946 If arg is already a list,
5947 the list will be returned untouched.
5948 If arg is any other type of object,
5949 it will be returned as a list
5950 containing just the object.
5951
5952 Example:
5953
5954 .ES
5955 files = Split("f1.c f2.c f3.c")
5956 files = env.Split("f4.c f5.c f6.c")
5957 files = Split("""
5958         f7.c
5959         f8.c
5960         f9.c
5961 """)
5962 .EE
5963
5964 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5965 .TP
5966 .RI Tag( node ", " tags )
5967 Annotates file or directory Nodes with
5968 information about how the
5969 .BR Package ()
5970 Builder should package those files or directories.
5971 All tags are optional.
5972
5973 Examples:
5974
5975 .ES
5976 # makes sure the built library will be installed with 0644 file
5977 # access mode
5978 Tag( Library( 'lib.c' ), UNIX_ATTR="0644" )
5979
5980 # marks file2.txt to be a documentation file
5981 Tag( 'file2.txt', DOC )
5982 .EE
5983
5984 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5985 .TP
5986 .RI TargetSignatures( type )
5987 .TP
5988 .RI env.TargetSignatures( type )
5989 Note:  Although it is not yet officially deprecated,
5990 use of this function is discouraged.
5991 See the
5992 .BR Decider ()
5993 function for a more flexible and straightforward way
5994 to configure SCons' decision-making.
5995
5996 The
5997 .BR TargetSignatures ()
5998 function tells
5999 .B scons
6000 how to decide if a target file
6001 (a file that
6002 .I is
6003 built from any other files)
6004 has changed since the last time it
6005 was used to build some other target file.
6006 Legal values are
6007 .BR "build" ;
6008 .BR "content"
6009 (or its synonym
6010 .BR "MD5" );
6011 .BR "timestamp" ;
6012 or
6013 .BR "source" .
6014
6015 If the environment method is used,
6016 the specified type of target signature is only used
6017 for targets built with that environment.
6018 If the global function is used,
6019 the specified type of signature becomes the default
6020 used for all target files that
6021 don't have an explicit target signature type
6022 specified for their environments.
6023
6024 .B "content"
6025 (or its synonym
6026 .BR "MD5" )
6027 means
6028 .B scons
6029 decides that a target file has changed
6030 if the MD5 checksum of its contents has changed since
6031 the last time it was used to rebuild some other target file.
6032 This means
6033 .B scons
6034 will open up
6035 MD5 sum the contents
6036 of target files after they're built,
6037 and may decide that it does not need to rebuild
6038 "downstream" target files if a file was
6039 rebuilt with exactly the same contents as the last time.
6040
6041 .B "timestamp"
6042 means
6043 .B scons
6044 decides that a target file has changed
6045 if its timestamp (modification time) has changed since
6046 the last time it was used to rebuild some other target file.
6047 (Note that although this is similar to the behavior of Make,
6048 by default it will also rebuild if the dependency is
6049 .I older
6050 than the last time it was used to rebuild the target file.)
6051
6052 .B "source"
6053 means
6054 .B scons
6055 decides that a target file has changed
6056 as specified by the corresponding
6057 .BR SourceSignatures ()
6058 setting
6059 .BR "" ( "MD5"
6060 or
6061 .BR "timestamp" ).
6062 This means that
6063 .B scons
6064 will treat all input files to a target the same way,
6065 regardless of whether they are source files
6066 or have been built from other files.
6067
6068 .B "build"
6069 means
6070 .B scons
6071 decides that a target file has changed
6072 if it has been rebuilt in this invocation
6073 or if its content or timestamp have changed
6074 as specified by the corresponding
6075 .BR SourceSignatures ()
6076 setting.
6077 This "propagates" the status of a rebuilt file
6078 so that other "downstream" target files
6079 will always be rebuilt,
6080 even if the contents or the timestamp
6081 have not changed.
6082
6083 .B "build"
6084 signatures are fastest because
6085 .B "content"
6086 (or
6087 .BR "MD5" )
6088 signatures take longer to compute,
6089 but are more accurate than
6090 .B "timestamp"
6091 signatures,
6092 and can prevent unnecessary "downstream" rebuilds
6093 when a target file is rebuilt to the exact same contents
6094 as the previous build.
6095 The
6096 .B "source"
6097 setting provides the most consistent behavior
6098 when other target files may be rebuilt from
6099 both source and target input files.
6100 The default value is
6101 .BR "source" .
6102
6103 Because the default setting is
6104 .BR "source" ,
6105 using
6106 .BR SourceSignatures ()
6107 is generally preferable to
6108 .BR TargetSignatures () ,
6109 so that the up-to-date decision
6110 will be consistent for all files
6111 (or all files built with a specific construction environment).
6112 Use of
6113 .BR TargetSignatures ()
6114 provides specific control for how built target files
6115 affect their "downstream" dependencies.
6116
6117 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6118 .TP
6119 .RI Tool( string [, toolpath ", " **kw ])
6120 Returns a callable object
6121 that can be used to initialize
6122 a construction environment using the
6123 tools keyword of the Environment() method.
6124 The object may be called with a construction
6125 environment as an argument,
6126 in which case the object will
6127 add the necessary variables
6128 to the construction environment
6129 and the name of the tool will be added to the
6130 .B $TOOLS
6131 construction variable.
6132
6133 Additional keyword arguments are passed to the tool's
6134 .B generate()
6135 method.
6136
6137 Examples:
6138
6139 .ES
6140 env = Environment(tools = [ Tool('msvc') ])
6141
6142 env = Environment()
6143 t = Tool('msvc')
6144 t(env)  # adds 'msvc' to the TOOLS variable
6145 u = Tool('opengl', toolpath = ['tools'])
6146 u(env)  # adds 'opengl' to the TOOLS variable
6147 .EE
6148 .TP
6149 .RI env.Tool( string [, toolpath ", " **kw ])
6150 Applies the callable object for the specified tool
6151 .I string
6152 to the environment through which the method was called.
6153
6154 Additional keyword arguments are passed to the tool's
6155 .B generate()
6156 method.
6157
6158 .ES
6159 env.Tool('gcc')
6160 env.Tool('opengl', toolpath = ['build/tools'])
6161 .EE
6162
6163 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6164 .TP
6165 .RI Value( value ", [" built_value ])
6166 .TP
6167 .RI env.Value( value ", [" built_value ])
6168 Returns a Node object representing the specified Python value.  Value
6169 Nodes can be used as dependencies of targets.  If the result of
6170 calling
6171 .BR str( value )
6172 changes between SCons runs, any targets depending on
6173 .BR Value( value )
6174 will be rebuilt.
6175 (This is true even when using timestamps to decide if
6176 files are up-to-date.)
6177 When using timestamp source signatures, Value Nodes'
6178 timestamps are equal to the system time when the Node is created.
6179
6180 The returned Value Node object has a
6181 .BR write ()
6182 method that can be used to "build" a Value Node
6183 by setting a new value.
6184 The optional
6185 .I built_value
6186 argument can be specified
6187 when the Value Node is created
6188 to indicate the Node should already be considered
6189 "built."
6190 There is a corresponding
6191 .BR read ()
6192 method that will return the built value of the Node.
6193
6194 Examples:
6195
6196 .ES
6197 env = Environment()
6198
6199 def create(target, source, env):
6200     # A function that will write a 'prefix=$SOURCE'
6201     # string into the file name specified as the
6202     # $TARGET.
6203     f = open(str(target[0]), 'wb')
6204     f.write('prefix=' + source[0].get_contents())
6205
6206 # Fetch the prefix= argument, if any, from the command
6207 # line, and use /usr/local as the default.
6208 prefix = ARGUMENTS.get('prefix', '/usr/local')
6209
6210 # Attach a .Config() builder for the above function action
6211 # to the construction environment.
6212 env['BUILDERS']['Config'] = Builder(action = create)
6213 env.Config(target = 'package-config', source = Value(prefix))
6214
6215 def build_value(target, source, env):
6216     # A function that "builds" a Python Value by updating
6217     # the the Python value with the contents of the file
6218     # specified as the source of the Builder call ($SOURCE).
6219     target[0].write(source[0].get_contents())
6220
6221 output = env.Value('before')
6222 input = env.Value('after')
6223
6224 # Attach a .UpdateValue() builder for the above function
6225 # action to the construction environment.
6226 env['BUILDERS']['UpdateValue'] = Builder(action = build_value)
6227 env.UpdateValue(target = Value(output), source = Value(input))
6228 .EE
6229
6230 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6231 .TP
6232 .RI VariantDir( variant_dir ", " src_dir ", [" duplicate ])
6233 .TP
6234 .RI env.VariantDir( variant_dir ", " src_dir ", [" duplicate ])
6235 Use the
6236 .BR VariantDir ()
6237 function to create a copy of your sources in another location:
6238 if a name under
6239 .IR variant_dir
6240 is not found but exists under
6241 .IR src_dir ,
6242 the file or directory is copied to
6243 .IR variant_dir .
6244 Target files can be built in a different directory
6245 than the original sources by simply refering to the sources (and targets)
6246 within the variant tree.
6247
6248 .BR VariantDir ()
6249 can be called multiple times with the same
6250 .I  src_dir
6251 to set up multiple builds with different options
6252 .RI ( variants ).
6253 The
6254 .I src_dir
6255 location must be in or underneath the SConstruct file's directory, and
6256 .I variant_dir
6257 may not be underneath
6258 .IR src_dir .
6259 '\"TODO: Can the above restrictions be clarified or relaxed?
6260 '\"TODO: The latter restriction is clearly not completely right;
6261 '\"TODO: src_dir = '.' works fine with a build dir under it.
6262
6263 The default behavior is for
6264 .B scons
6265 to physically duplicate the source files in the variant tree.
6266 Thus, a build performed in the variant tree is guaranteed to be identical
6267 to a build performed in the source tree even if
6268 intermediate source files are generated during the build,
6269 or preprocessors or other scanners search for included files
6270 relative to the source file,
6271 or individual compilers or other invoked tools are hard-coded
6272 to put derived files in the same directory as source files.
6273
6274 If possible on the platform,
6275 the duplication is performed by linking rather than copying;
6276 see also the
6277 .IR --duplicate
6278 command-line option.
6279 Moreover, only the files needed for the build are duplicated;
6280 files and directories that are not used are not present in
6281 .IR variant_dir .
6282
6283 Duplicating the source tree may be disabled by setting the
6284 .I duplicate
6285 argument to 0 (zero).
6286 This will cause
6287 .B scons
6288 to invoke Builders using the path names of source files in
6289 .I src_dir
6290 and the path names of derived files within
6291 .IR variant_dir .
6292 This is always more efficient than
6293 .IR duplicate =1,
6294 and is usually safe for most builds
6295 (but see above for cases that may cause problems).
6296
6297 Note that
6298 .BR VariantDir ()
6299 works most naturally with a subsidiary SConscript file.
6300 However, you would then call the subsidiary SConscript file
6301 not in the source directory, but in the
6302 .I variant_dir ,
6303 regardless of the value of
6304 .IR duplicate .
6305 This is how you tell
6306 .B scons
6307 which variant of a source tree to build:
6308
6309 .ES
6310 # run src/SConscript in two variant directories
6311 VariantDir('build/variant1', 'src')
6312 SConscript('build/variant1/SConscript')
6313 VariantDir('build/variant2', 'src')
6314 SConscript('build/variant2/SConscript')
6315 .EE
6316
6317 .IP
6318 See also the
6319 .BR SConscript ()
6320 function, described above,
6321 for another way to specify a variant directory
6322 in conjunction with calling a subsidiary SConscript file.
6323
6324 Examples:
6325
6326 .ES
6327 # use names in the build directory, not the source directory
6328 VariantDir('build', 'src', duplicate=0)
6329 Program('build/prog', 'build/source.c')
6330 .EE
6331
6332 .ES
6333 # this builds both the source and docs in a separate subtree
6334 VariantDir('build', '.', duplicate=0)
6335 SConscript(dirs=['build/src','build/doc'])
6336 .EE
6337
6338 .ES
6339 # same as previous example, but only uses SConscript
6340 SConscript(dirs='src', variant_dir='build/src', duplicate=0)
6341 SConscript(dirs='doc', variant_dir='build/doc', duplicate=0)
6342 .EE
6343
6344 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6345 .TP
6346 .RI WhereIs( program ", [" path  ", " pathext ", " reject ])
6347 .TP
6348 .RI env.WhereIs( program ", [" path  ", " pathext ", " reject ])
6349
6350 Searches for the specified executable
6351 .I program,
6352 returning the full path name to the program
6353 if it is found,
6354 and returning None if not.
6355 Searches the specified
6356 .I path,
6357 the value of the calling environment's PATH
6358 (env['ENV']['PATH']),
6359 or the user's current external PATH
6360 (os.environ['PATH'])
6361 by default.
6362 On Windows systems, searches for executable
6363 programs with any of the file extensions
6364 listed in the specified
6365 .I pathext,
6366 the calling environment's PATHEXT
6367 (env['ENV']['PATHEXT'])
6368 or the user's current PATHEXT
6369 (os.environ['PATHEXT'])
6370 by default.
6371 Will not select any
6372 path name or names
6373 in the specified
6374 .I reject
6375 list, if any.
6376
6377 .SS SConscript Variables
6378 In addition to the global functions and methods,
6379 .B scons
6380 supports a number of Python variables
6381 that can be used in SConscript files
6382 to affect how you want the build to be performed.
6383 These variables may be accessed from custom Python modules that you
6384 import into an SConscript file by adding the following
6385 to the Python module:
6386
6387 .ES
6388 from SCons.Script import *
6389 .EE
6390
6391 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6392 .TP
6393 ARGLIST
6394 A list
6395 .IR keyword = value
6396 arguments specified on the command line.
6397 Each element in the list is a tuple
6398 containing the
6399 .RI ( keyword , value )
6400 of the argument.
6401 The separate
6402 .I keyword
6403 and
6404 .I value
6405 elements of the tuple
6406 can be accessed by
6407 subscripting for element
6408 .B [0]
6409 and
6410 .B [1]
6411 of the tuple, respectively.
6412
6413 Example:
6414
6415 .ES
6416 print "first keyword, value =", ARGLIST[0][0], ARGLIST[0][1]
6417 print "second keyword, value =", ARGLIST[1][0], ARGLIST[1][1]
6418 third_tuple = ARGLIST[2]
6419 print "third keyword, value =", third_tuple[0], third_tuple[1]
6420 for key, value in ARGLIST:
6421     # process key and value
6422 .EE
6423
6424 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6425 .TP
6426 ARGUMENTS
6427 A dictionary of all the
6428 .IR keyword = value
6429 arguments specified on the command line.
6430 The dictionary is not in order,
6431 and if a given keyword has
6432 more than one value assigned to it
6433 on the command line,
6434 the last (right-most) value is
6435 the one in the
6436 .B ARGUMENTS
6437 dictionary.
6438
6439 Example:
6440
6441 .ES
6442 if ARGUMENTS.get('debug', 0):
6443     env = Environment(CCFLAGS = '-g')
6444 else:
6445     env = Environment()
6446 .EE
6447
6448 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6449 .TP
6450 BUILD_TARGETS
6451 A list of the targets which
6452 .B scons
6453 will actually try to build,
6454 regardless of whether they were specified on
6455 the command line or via the
6456 .BR Default ()
6457 function or method.
6458 The elements of this list may be strings
6459 .I or
6460 nodes, so you should run the list through the Python
6461 .B str
6462 function to make sure any Node path names
6463 are converted to strings.
6464
6465 Because this list may be taken from the
6466 list of targets specified using the
6467 .BR Default ()
6468 function or method,
6469 the contents of the list may change
6470 on each successive call to
6471 .BR Default ().
6472 See the
6473 .B DEFAULT_TARGETS
6474 list, below,
6475 for additional information.
6476
6477 Example:
6478
6479 .ES
6480 if 'foo' in BUILD_TARGETS:
6481     print "Don't forget to test the `foo' program!"
6482 if 'special/program' in BUILD_TARGETS:
6483     SConscript('special')
6484 .EE
6485 .IP
6486 Note that the
6487 .B BUILD_TARGETS
6488 list only contains targets expected listed
6489 on the command line or via calls to the
6490 .BR Default ()
6491 function or method.
6492 It does
6493 .I not
6494 contain all dependent targets that will be built as
6495 a result of making the sure the explicitly-specified
6496 targets are up to date.
6497
6498 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6499 .TP
6500 COMMAND_LINE_TARGETS
6501 A list of the targets explicitly specified on
6502 the command line.
6503 If there are no targets specified on the command line,
6504 the list is empty.
6505 This can be used, for example,
6506 to take specific actions only
6507 when a certain target or targets
6508 is explicitly being built.
6509
6510 Example:
6511
6512 .ES
6513 if 'foo' in COMMAND_LINE_TARGETS:
6514     print "Don't forget to test the `foo' program!"
6515 if 'special/program' in COMMAND_LINE_TARGETS:
6516     SConscript('special')
6517 .EE
6518
6519 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6520 .TP
6521 DEFAULT_TARGETS
6522 A list of the target
6523 .I nodes
6524 that have been specified using the
6525 .BR Default ()
6526 function or method.
6527 The elements of the list are nodes,
6528 so you need to run them through the Python
6529 .B str
6530 function to get at the path name for each Node.
6531
6532 Example:
6533
6534 .ES
6535 print str(DEFAULT_TARGETS[0])
6536 if 'foo' in map(str, DEFAULT_TARGETS):
6537     print "Don't forget to test the `foo' program!"
6538 .EE
6539 .IP
6540 The contents of the
6541 .B DEFAULT_TARGETS
6542 list change on on each successive call to the
6543 .BR Default ()
6544 function:
6545
6546 .ES
6547 print map(str, DEFAULT_TARGETS)   # originally []
6548 Default('foo')
6549 print map(str, DEFAULT_TARGETS)   # now a node ['foo']
6550 Default('bar')
6551 print map(str, DEFAULT_TARGETS)   # now a node ['foo', 'bar']
6552 Default(None)
6553 print map(str, DEFAULT_TARGETS)   # back to []
6554 .EE
6555 .IP
6556 Consequently, be sure to use
6557 .B DEFAULT_TARGETS
6558 only after you've made all of your
6559 .BR Default ()
6560 calls,
6561 or else simply be careful of the order
6562 of these statements in your SConscript files
6563 so that you don't look for a specific
6564 default target before it's actually been added to the list.
6565
6566 .SS Construction Variables
6567 .\" XXX From Gary Ruben, 23 April 2002:
6568 .\" I think it would be good to have an example with each construction
6569 .\" variable description in the documentation.
6570 .\" eg.
6571 .\" CC     The C compiler
6572 .\"    Example: env["CC"] = "c68x"
6573 .\"    Default: env["CC"] = "cc"
6574 .\"
6575 .\" CCCOM  The command line ...
6576 .\"    Example:
6577 .\"        To generate the compiler line c68x -ps -qq -mr -o $TARGET $SOURCES
6578 .\"        env["CC"] = "c68x"
6579 .\"        env["CFLAGS"] = "-ps -qq -mr"
6580 .\"        env["CCCOM"] = "$CC $CFLAGS -o $TARGET $SOURCES
6581 .\"    Default:
6582 .\"        (I dunno what this is ;-)
6583 A construction environment has an associated dictionary of
6584 .I construction variables
6585 that are used by built-in or user-supplied build rules.
6586 Construction variables must follow the same rules for
6587 Python identifiers:
6588 the initial character must be an underscore or letter,
6589 followed by any number of underscores, letters, or digits.
6590
6591 A number of useful construction variables are automatically defined by
6592 scons for each supported platform, and additional construction variables
6593 can be defined by the user. The following is a list of the automatically
6594 defined construction variables:
6595
6596 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6597 '\" BEGIN GENERATED CONSTRUCTION VARIABLE DESCRIPTIONS
6598 '\"
6599 '\" The descriptions below of the various SCons construction variables
6600 '\" are generated from the .xml files that live next to the various
6601 '\" Python modules in the build enginer library.  If you're reading
6602 '\" this [gnt]roff file with an eye towards patching this man page,
6603 '\" you can still submit a diff against this text, but it will have to
6604 '\" be translated to a diff against the underlying .xml file before the
6605 '\" patch is actually accepted.  If you do that yourself, it will make
6606 '\" it easier to integrate the patch.
6607 '\"
6608 '\" BEGIN GENERATED CONSTRUCTION VARIABLE DESCRIPTIONS
6609 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6610 .so variables.man
6611 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6612 '\" END GENERATED CONSTRUCTION VARIABLE DESCRIPTIONS
6613 '\"
6614 '\" The descriptions above of the various SCons construction variables
6615 '\" are generated from the .xml files that live next to the various
6616 '\" Python modules in the build enginer library.  If you're reading
6617 '\" this [gnt]roff file with an eye towards patching this man page,
6618 '\" you can still submit a diff against this text, but it will have to
6619 '\" be translated to a diff against the underlying .xml file before the
6620 '\" patch is actually accepted.  If you do that yourself, it will make
6621 '\" it easier to integrate the patch.
6622 '\"
6623 '\" END GENERATED CONSTRUCTION VARIABLE DESCRIPTIONS
6624 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6625
6626 .LP
6627 Construction variables can be retrieved and set using the
6628 .B Dictionary
6629 method of the construction environment:
6630
6631 .ES
6632 dict = env.Dictionary()
6633 dict["CC"] = "cc"
6634 .EE
6635
6636 or using the [] operator:
6637
6638 .ES
6639 env["CC"] = "cc"
6640 .EE
6641
6642 Construction variables can also be passed to the construction environment
6643 constructor:
6644
6645 .ES
6646 env = Environment(CC="cc")
6647 .EE
6648
6649 or when copying a construction environment using the
6650 .B Clone
6651 method:
6652
6653 .ES
6654 env2 = env.Clone(CC="cl.exe")
6655 .EE
6656
6657 .SS Configure Contexts
6658
6659 .B scons
6660 supports
6661 .I configure contexts,
6662 an integrated mechanism similar to the
6663 various AC_CHECK macros in GNU autoconf
6664 for testing for the existence of C header
6665 files, libraries, etc.
6666 In contrast to autoconf,
6667 .B scons
6668 does not maintain an explicit cache of the tested values,
6669 but uses its normal dependency tracking to keep the checked values
6670 up to date. However, users may override this behaviour with the
6671 .B --config
6672 command line option.
6673
6674 The following methods can be used to perform checks:
6675
6676 .TP
6677 .RI Configure( env ", [" custom_tests ", " conf_dir ", " log_file ", " config_h ", " clean ", " help])
6678 .TP
6679 .RI env.Configure([ custom_tests ", " conf_dir ", " log_file ", " config_h ", " clean ", " help])
6680 This creates a configure context, which can be used to perform checks.
6681 .I env
6682 specifies the environment for building the tests.
6683 This environment may be modified when performing checks.
6684 .I custom_tests
6685 is a dictionary containing custom tests.
6686 See also the section about custom tests below.
6687 By default, no custom tests are added to the configure context.
6688 .I conf_dir
6689 specifies a directory where the test cases are built.
6690 Note that this directory is not used for building
6691 normal targets.
6692 The default value is the directory
6693 #/.sconf_temp.
6694 .I log_file
6695 specifies a file which collects the output from commands
6696 that are executed to check for the existence of header files, libraries, etc.
6697 The default is the file #/config.log.
6698 If you are using the
6699 .BR VariantDir ()
6700 method,
6701 you may want to specify a subdirectory under your variant directory.
6702 .I config_h
6703 specifies a C header file where the results of tests
6704 will be written, e.g. #define HAVE_STDIO_H, #define HAVE_LIBM, etc.
6705 The default is to not write a
6706 .B config.h
6707 file.
6708 You can specify the same
6709 .B config.h
6710 file in multiple calls to Configure,
6711 in which case
6712 .B scons
6713 will concatenate all results in the specified file.
6714 Note that SCons
6715 uses its normal dependency checking
6716 to decide if it's necessary to rebuild
6717 the specified
6718 .I config_h
6719 file.
6720 This means that the file is not necessarily re-built each
6721 time scons is run,
6722 but is only rebuilt if its contents will have changed
6723 and some target that depends on the
6724 .I config_h
6725 file is being built.
6726
6727 The optional
6728 .B clean
6729 and
6730 .B help
6731 arguments can be used to suppress execution of the configuration
6732 tests when the
6733 .B -c/--clean
6734 or
6735 .B -H/-h/--help
6736 options are used, respectively.
6737 The default behavior is always to execute
6738 configure context tests,
6739 since the results of the tests may
6740 affect the list of targets to be cleaned
6741 or the help text.
6742 If the configure tests do not affect these,
6743 then you may add the
6744 .B clean=False
6745 or
6746 .B help=False
6747 arguments
6748 (or both)
6749 to avoid unnecessary test execution.
6750
6751 .EE
6752 A created
6753 .B Configure
6754 instance has the following associated methods:
6755
6756 .TP
6757 .RI SConf.Finish( context )
6758 .TP
6759 .IR sconf .Finish()
6760 This method should be called after configuration is done.
6761 It returns the environment as modified
6762 by the configuration checks performed.
6763 After this method is called, no further checks can be performed
6764 with this configuration context.
6765 However, you can create a new
6766 .RI Configure
6767 context to perform additional checks.
6768 Only one context should be active at a time.
6769
6770 The following Checks are predefined.
6771 (This list will likely grow larger as time
6772 goes by and developers contribute new useful tests.)
6773
6774 .TP
6775 .RI SConf.CheckHeader( context ", " header ", [" include_quotes ", " language ])
6776 .TP
6777 .IR sconf .CheckHeader( header ", [" include_quotes ", " language ])
6778 Checks if
6779 .I header
6780 is usable in the specified language.
6781 .I header
6782 may be a list,
6783 in which case the last item in the list
6784 is the header file to be checked,
6785 and the previous list items are
6786 header files whose
6787 .B #include
6788 lines should precede the
6789 header line being checked for.
6790 The optional argument
6791 .I include_quotes
6792 must be
6793 a two character string, where the first character denotes the opening
6794 quote and the second character denotes the closing quote.
6795 By default, both characters  are " (double quote).
6796 The optional argument
6797 .I language
6798 should be either
6799 .B C
6800 or
6801 .B C++
6802 and selects the compiler to be used for the check.
6803 Returns 1 on success and 0 on failure.
6804
6805 .TP
6806 .RI SConf.CheckCHeader( context ", " header ", [" include_quotes ])
6807 .TP
6808 .IR sconf .CheckCHeader( header ", [" include_quotes ])
6809 This is a wrapper around
6810 .B SConf.CheckHeader
6811 which checks if
6812 .I header
6813 is usable in the C language.
6814 .I header
6815 may be a list,
6816 in which case the last item in the list
6817 is the header file to be checked,
6818 and the previous list items are
6819 header files whose
6820 .B #include
6821 lines should precede the
6822 header line being checked for.
6823 The optional argument
6824 .I include_quotes
6825 must be
6826 a two character string, where the first character denotes the opening
6827 quote and the second character denotes the closing quote (both default
6828 to \N'34').
6829 Returns 1 on success and 0 on failure.
6830
6831 .TP
6832 .RI SConf.CheckCXXHeader( context ", " header ", [" include_quotes ])
6833 .TP
6834 .IR sconf .CheckCXXHeader( header ", [" include_quotes ])
6835 This is a wrapper around
6836 .B SConf.CheckHeader
6837 which checks if
6838 .I header
6839 is usable in the C++ language.
6840 .I header
6841 may be a list,
6842 in which case the last item in the list
6843 is the header file to be checked,
6844 and the previous list items are
6845 header files whose
6846 .B #include
6847 lines should precede the
6848 header line being checked for.
6849 The optional argument
6850 .I include_quotes
6851 must be
6852 a two character string, where the first character denotes the opening
6853 quote and the second character denotes the closing quote (both default
6854 to \N'34').
6855 Returns 1 on success and 0 on failure.
6856
6857 .TP
6858 .RI SConf.CheckFunc( context, ", " function_name ", [" header ", " language ])
6859 .TP
6860 .IR sconf .CheckFunc( function_name ", [" header ", " language ])
6861 Checks if the specified
6862 C or C++ function is available.
6863 .I function_name
6864 is the name of the function to check for.
6865 The optional
6866 .I header
6867 argument is a string
6868 that will be
6869 placed at the top
6870 of the test file
6871 that will be compiled
6872 to check if the function exists;
6873 the default is:
6874 .ES
6875 #ifdef __cplusplus
6876 extern "C"
6877 #endif
6878 char function_name();
6879 .EE
6880 The optional
6881 .I language
6882 argument should be
6883 .B C
6884 or
6885 .B C++
6886 and selects the compiler to be used for the check;
6887 the default is "C".
6888
6889 .TP
6890 .RI SConf.CheckLib( context ", [" library ", " symbol ", " header ", " language ", " autoadd=1 ])
6891 .TP
6892 .IR sconf .CheckLib([ library ", " symbol ", " header ", " language ", " autoadd=1 ])
6893 Checks if
6894 .I library
6895 provides
6896 .IR symbol .
6897 If the value of
6898 .I autoadd
6899 is 1 and the library provides the specified
6900 .IR symbol ,
6901 appends the library to the LIBS construction environment variable.
6902 .I library
6903 may also be None (the default),
6904 in which case
6905 .I symbol
6906 is checked with the current LIBS variable,
6907 or a list of library names,
6908 in which case each library in the list
6909 will be checked for
6910 .IR symbol .
6911 If
6912 .I symbol
6913 is not set or is
6914 .BR None ,
6915 then
6916 .BR SConf.CheckLib ()
6917 just checks if
6918 you can link against the specified
6919 .IR library .
6920 The optional
6921 .I language
6922 argument should be
6923 .B C
6924 or
6925 .B C++
6926 and selects the compiler to be used for the check;
6927 the default is "C".
6928 The default value for
6929 .I autoadd
6930 is 1.
6931 This method returns 1 on success and 0 on error.
6932
6933 .TP
6934 .RI SConf.CheckLibWithHeader( context ", " library ", " header ", " language ", [" call ", " autoadd ])
6935 .TP
6936 .IR sconf .CheckLibWithHeader( library ", " header ", " language ", [" call ", " autoadd ])
6937
6938 In contrast to the
6939 .RI SConf.CheckLib
6940 call, this call provides a more sophisticated way to check against libraries.
6941 Again,
6942 .I library
6943 specifies the library or a list of libraries to check.
6944 .I header
6945 specifies a header to check for.
6946 .I header
6947 may be a list,
6948 in which case the last item in the list
6949 is the header file to be checked,
6950 and the previous list items are
6951 header files whose
6952 .B #include
6953 lines should precede the
6954 header line being checked for.
6955 .I language
6956 may be one of 'C','c','CXX','cxx','C++' and 'c++'.
6957 .I call
6958 can be any valid expression (with a trailing ';').
6959 If
6960 .I call
6961 is not set,
6962 the default simply checks that you
6963 can link against the specified
6964 .IR library .
6965 .I autoadd
6966 specifies whether to add the library to the environment (only if the check
6967 succeeds). This method returns 1 on success and 0 on error.
6968
6969 .TP
6970 .RI SConf.CheckType( context ", " type_name ", [" includes ", " language ])
6971 .TP
6972 .IR sconf .CheckType( type_name ", [" includes ", " language ])
6973 Checks for the existence of a type defined by
6974 .BR typedef .
6975 .I type_name
6976 specifies the typedef name to check for.
6977 .I includes
6978 is a string containing one or more
6979 .B #include
6980 lines that will be inserted into the program
6981 that will be run to test for the existence of the type.
6982 The optional
6983 .I language
6984 argument should be
6985 .B C
6986 or
6987 .B C++
6988 and selects the compiler to be used for the check;
6989 the default is "C".
6990 Example:
6991 .ES
6992 sconf.CheckType('foo_type', '#include "my_types.h"', 'C++')
6993 .EE
6994
6995 .TP
6996 .RI Configure.CheckCC( self )
6997 Checks whether the C compiler (as defined by the CC construction variable) works
6998 by trying to compile a small source file.
6999
7000 By default, SCons only detects if there is a program with the correct name, not
7001 if it is a functioning compiler.
7002
7003 This uses the exact same command than the one used by the object builder for C
7004 source file, so it can be used to detect if a particular compiler flag works or
7005 not.
7006
7007 .TP
7008 .RI Configure.CheckCXX( self )
7009 Checks whether the C++ compiler (as defined by the CXX construction variable)
7010 works by trying to compile a small source file. By default, SCons only detects
7011 if there is a program with the correct name, not if it is a functioning compiler.
7012
7013 This uses the exact same command than the one used by the object builder for
7014 CXX source files, so it can be used to detect if a particular compiler flag
7015 works or not.
7016
7017 .TP
7018 .RI Configure.CheckSHCC( self )
7019 Checks whether the C compiler (as defined by the SHCC construction variable) works
7020 by trying to compile a small source file. By default, SCons only detects if
7021 there is a program with the correct name, not if it is a functioning compiler.
7022
7023 This uses the exact same command than the one used by the object builder for C
7024 source file, so it can be used to detect if a particular compiler flag works or
7025 not. This does not check whether the object code can be used to build a shared
7026 library, only that the compilation (not link) succeeds.
7027
7028 .TP
7029 .RI Configure.CheckSHCXX( self )
7030 Checks whether the C++ compiler (as defined by the SHCXX construction variable)
7031 works by trying to compile a small source file. By default, SCons only detects
7032 if there is a program with the correct name, not if it is a functioning compiler.
7033
7034 This uses the exact same command than the one used by the object builder for
7035 CXX source files, so it can be used to detect if a particular compiler flag
7036 works or not. This does not check whether the object code can be used to build
7037 a shared library, only that the compilation (not link) succeeds.
7038
7039 .EE
7040 Example of a typical Configure usage:
7041
7042 .ES
7043 env = Environment()
7044 conf = Configure( env )
7045 if not conf.CheckCHeader( 'math.h' ):
7046     print 'We really need math.h!'
7047     Exit(1)
7048 if conf.CheckLibWithHeader( 'qt', 'qapp.h', 'c++',
7049         'QApplication qapp(0,0);' ):
7050     # do stuff for qt - usage, e.g.
7051     conf.env.Append( CPPFLAGS = '-DWITH_QT' )
7052 env = conf.Finish()
7053 .EE
7054
7055 .TP
7056 .RI SConf.CheckTypeSize( context ", " type_name ", [" header ", " language ", " expect ])
7057 .TP
7058 .IR sconf .CheckTypeSize( type_name ", [" header ", " language ", " expect ])
7059 Checks for the size of a type defined by
7060 .BR typedef .
7061 .I type_name
7062 specifies the typedef name to check for.
7063 The optional
7064 .I header
7065 argument is a string
7066 that will be
7067 placed at the top
7068 of the test file
7069 that will be compiled
7070 to check if the function exists;
7071 the default is empty.
7072 The optional
7073 .I language
7074 argument should be
7075 .B C
7076 or
7077 .B C++
7078 and selects the compiler to be used for the check;
7079 the default is "C".
7080 The optional
7081 .I expect
7082 argument should be an integer.
7083 If this argument is used,
7084 the function will only check whether the type
7085 given in type_name has the expected size (in bytes).
7086 For example,
7087 .B "CheckTypeSize('short', expect = 2)"
7088 will return success only if short is two bytes.
7089
7090 .ES
7091 .EE
7092
7093 .TP
7094 .RI SConf.CheckDeclaration( context ", " symbol ", [" includes ", " language ])
7095 .TP
7096 .IR sconf .CheckDeclaration( symbol ", [" includes ", " language ])
7097 Checks if the specified
7098 .I symbol
7099 is declared.
7100 .I includes
7101 is a string containing one or more
7102 .B #include
7103 lines that will be inserted into the program
7104 that will be run to test for the existence of the type.
7105 The optional
7106 .I language
7107 argument should be
7108 .B C
7109 or
7110 .B C++
7111 and selects the compiler to be used for the check;
7112 the default is "C".
7113
7114 .TP
7115 .RI SConf.Define( context ", " symbol ", [" value ", " comment ])
7116 .TP
7117 .IR sconf .Define( symbol ", [" value ", " comment ])
7118 This function does not check for anything, but defines a
7119 preprocessor symbol that will be added to the configuration header file.
7120 It is the equivalent of AC_DEFINE,
7121 and defines the symbol
7122 .I name
7123 with the optional
7124 .B value
7125 and the optional comment
7126 .BR comment .
7127
7128 .IP
7129 Examples:
7130
7131 .ES
7132 env = Environment()
7133 conf = Configure( env )
7134
7135 # Puts the following line in the config header file:
7136 #    #define A_SYMBOL
7137 conf.Define('A_SYMBOL')
7138
7139 # Puts the following line in the config header file:
7140 #    #define A_SYMBOL 1
7141 conf.Define('A_SYMBOL', 1)
7142 .EE
7143
7144 .IP
7145 Be careful about quoting string values, though:
7146
7147 .ES
7148 env = Environment()
7149 conf = Configure( env )
7150
7151 # Puts the following line in the config header file:
7152 #    #define A_SYMBOL YA
7153 conf.Define('A_SYMBOL', "YA")
7154
7155 # Puts the following line in the config header file:
7156 #    #define A_SYMBOL "YA"
7157 conf.Define('A_SYMBOL', '"YA"')
7158 .EE
7159
7160 .IP
7161 For comment:
7162
7163 .ES
7164 env = Environment()
7165 conf = Configure( env )
7166
7167 # Puts the following lines in the config header file:
7168 #    /* Set to 1 if you have a symbol */
7169 #    #define A_SYMBOL 1
7170 conf.Define('A_SYMBOL', 1, 'Set to 1 if you have a symbol')
7171 .EE
7172
7173 .EE
7174 You can define your own custom checks.
7175 in addition to the predefined checks.
7176 These are passed in a dictionary to the Configure function.
7177 This dictionary maps the names of the checks
7178 to user defined Python callables
7179 (either Python functions or class instances implementing the
7180 .I __call__
7181 method).
7182 The first argument of the call is always a
7183 .I CheckContext
7184 instance followed by the arguments,
7185 which must be supplied by the user of the check.
7186 These CheckContext instances define the following methods:
7187
7188 .TP
7189 .RI CheckContext.Message( self ", " text )
7190
7191 Usually called before the check is started.
7192 .I text
7193 will be displayed to the user, e.g. 'Checking for library X...'
7194
7195 .TP
7196 .RI CheckContext.Result( self, ", " res )
7197
7198 Usually called after the check is done.
7199 .I res
7200 can be either an integer or a string. In the former case, 'yes' (res != 0)
7201 or 'no' (res == 0) is displayed to the user, in the latter case the
7202 given string is displayed.
7203
7204 .TP
7205 .RI CheckContext.TryCompile( self ", " text ", " extension )
7206 Checks if a file with the specified
7207 .I extension
7208 (e.g. '.c') containing
7209 .I text
7210 can be compiled using the environment's
7211 .B Object
7212 builder. Returns 1 on success and 0 on failure.
7213
7214 .TP
7215 .RI CheckContext.TryLink( self ", " text ", " extension )
7216 Checks, if a file with the specified
7217 .I extension
7218 (e.g. '.c') containing
7219 .I text
7220 can be compiled using the environment's
7221 .B Program
7222 builder. Returns 1 on success and 0 on failure.
7223
7224 .TP
7225 .RI CheckContext.TryRun( self ", " text ", " extension )
7226 Checks, if a file with the specified
7227 .I extension
7228 (e.g. '.c') containing
7229 .I text
7230 can be compiled using the environment's
7231 .B Program
7232 builder. On success, the program is run. If the program
7233 executes successfully
7234 (that is, its return status is 0),
7235 a tuple
7236 .I (1, outputStr)
7237 is returned, where
7238 .I outputStr
7239 is the standard output of the
7240 program.
7241 If the program fails execution
7242 (its return status is non-zero),
7243 then (0, '') is returned.
7244
7245 .TP
7246 .RI CheckContext.TryAction( self ", " action ", [" text ", " extension ])
7247 Checks if the specified
7248 .I action
7249 with an optional source file (contents
7250 .I text
7251 , extension
7252 .I extension
7253 = ''
7254 ) can be executed.
7255 .I action
7256 may be anything which can be converted to a
7257 .B scons
7258 .RI Action.
7259 On success,
7260 .I (1, outputStr)
7261 is returned, where
7262 .I outputStr
7263 is the content of the target file.
7264 On failure
7265 .I (0, '')
7266 is returned.
7267
7268 .TP
7269 .RI CheckContext.TryBuild( self ", " builder ", [" text ", " extension ])
7270 Low level implementation for testing specific builds;
7271 the methods above are based on this method.
7272 Given the Builder instance
7273 .I builder
7274 and the optional
7275 .I text
7276 of a source file with optional
7277 .IR extension ,
7278 this method returns 1 on success and 0 on failure. In addition,
7279 .I self.lastTarget
7280 is set to the build target node, if the build was successful.
7281
7282 .EE
7283 Example for implementing and using custom tests:
7284
7285 .ES
7286 def CheckQt(context, qtdir):
7287     context.Message( 'Checking for qt ...' )
7288     lastLIBS = context.env['LIBS']
7289     lastLIBPATH = context.env['LIBPATH']
7290     lastCPPPATH= context.env['CPPPATH']
7291     context.env.Append(LIBS = 'qt', LIBPATH = qtdir + '/lib', CPPPATH = qtdir + '/include' )
7292     ret = context.TryLink("""
7293 #include <qapp.h>
7294 int main(int argc, char **argv) {
7295   QApplication qapp(argc, argv);
7296   return 0;
7297 }
7298 """)
7299     if not ret:
7300         context.env.Replace(LIBS = lastLIBS, LIBPATH=lastLIBPATH, CPPPATH=lastCPPPATH)
7301     context.Result( ret )
7302     return ret
7303
7304 env = Environment()
7305 conf = Configure( env, custom_tests = { 'CheckQt' : CheckQt } )
7306 if not conf.CheckQt('/usr/lib/qt'):
7307     print 'We really need qt!'
7308     Exit(1)
7309 env = conf.Finish()
7310 .EE
7311
7312 .SS Command-Line Construction Variables
7313
7314 Often when building software,
7315 some variables must be specified at build time.
7316 For example, libraries needed for the build may be in non-standard
7317 locations, or site-specific compiler options may need to be passed to the
7318 compiler.
7319 .B scons
7320 provides a
7321 .B Variables
7322 object to support overriding construction variables
7323 on the command line:
7324 .ES
7325 $ scons VARIABLE=foo
7326 .EE
7327 The variable values can also be specified in a text-based SConscript file.
7328 To create a Variables object, call the Variables() function:
7329
7330 .TP
7331 .RI Variables([ files "], [" args ])
7332 This creates a Variables object that will read construction variables from
7333 the file or list of filenames specified in
7334 .IR files .
7335 If no files are specified,
7336 or the
7337 .I files
7338 argument is
7339 .BR None ,
7340 then no files will be read.
7341 The optional argument
7342 .I args
7343 is a dictionary of
7344 values that will override anything read from the specified files;
7345 it is primarily intended to be passed the
7346 .B ARGUMENTS
7347 dictionary that holds variables
7348 specified on the command line.
7349 Example:
7350
7351 .ES
7352 vars = Variables('custom.py')
7353 vars = Variables('overrides.py', ARGUMENTS)
7354 vars = Variables(None, {FOO:'expansion', BAR:7})
7355 .EE
7356
7357 Variables objects have the following methods:
7358
7359 .TP
7360 .RI Add( key ", [" help ", " default ", " validator ", " converter ])
7361 This adds a customizable construction variable to the Variables object.
7362 .I key
7363 is the name of the variable.
7364 .I help
7365 is the help text for the variable.
7366 .I default
7367 is the default value of the variable;
7368 if the default value is
7369 .B None
7370 and there is no explicit value specified,
7371 the construction variable will
7372 .I not
7373 be added to the construction environment.
7374 .I validator
7375 is called to validate the value of the variable, and should take three
7376 arguments: key, value, and environment.
7377 The recommended way to handle an invalid value is
7378 to raise an exception (see example below).
7379 .I converter
7380 is called to convert the value before putting it in the environment, and
7381 should take either a value, or the value and environment, as parameters.
7382 The
7383 .I converter
7384 must return a value,
7385 which will be converted into a string
7386 before being validated by the
7387 .I validator
7388 (if any)
7389 and then added to the environment.
7390
7391 Examples:
7392
7393 .ES
7394 vars.Add('CC', 'The C compiler')
7395
7396 def validate_color(key, val, env):
7397     if not val in ['red', 'blue', 'yellow']:
7398         raise "Invalid color value '%s'" % val
7399 vars.Add('COLOR', validator=valid_color)
7400 .EE
7401
7402 .TP
7403 .RI AddVariables( list )
7404 A wrapper script that adds
7405 multiple customizable construction variables
7406 to a Variables object.
7407 .I list
7408 is a list of tuple or list objects
7409 that contain the arguments
7410 for an individual call to the
7411 .B Add
7412 method.
7413
7414 .ES
7415 opt.AddVariables(
7416        ('debug', '', 0),
7417        ('CC', 'The C compiler'),
7418        ('VALIDATE', 'An option for testing validation',
7419         'notset', validator, None),
7420     )
7421 .EE
7422
7423 .TP
7424 .RI Update( env ", [" args ])
7425 This updates a construction environment
7426 .I env
7427 with the customized construction variables.
7428 Any specified variables that are
7429 .I not
7430 configured for the Variables object
7431 will be saved and may be
7432 retrieved with the
7433 .BR UnknownVariables ()
7434 method, below.
7435
7436 Normally this method is not called directly,
7437 but is called indirectly by passing the Variables object to
7438 the Environment() function:
7439
7440 .ES
7441 env = Environment(variables=vars)
7442 .EE
7443
7444 .IP
7445 The text file(s) that were specified
7446 when the Variables object was created
7447 are executed as Python scripts,
7448 and the values of (global) Python variables set in the file
7449 are added to the construction environment.
7450
7451 Example:
7452
7453 .ES
7454 CC = 'my_cc'
7455 .EE
7456
7457 .TP
7458 .RI UnknownVariables( )
7459 Returns a dictionary containing any
7460 variables that were specified
7461 either in the files or the dictionary
7462 with which the Variables object was initialized,
7463 but for which the Variables object was
7464 not configured.
7465
7466 .ES
7467 env = Environment(variables=vars)
7468 for key, value in vars.UnknownVariables():
7469     print "unknown variable:  %s=%s" % (key, value)
7470 .EE
7471
7472 .TP
7473 .RI Save( filename ", " env )
7474 This saves the currently set variables into a script file named
7475 .I filename
7476 that can be used on the next invocation to automatically load the current
7477 settings.  This method combined with the Variables method can be used to
7478 support caching of variables between runs.
7479
7480 .ES
7481 env = Environment()
7482 vars = Variables(['variables.cache', 'custom.py'])
7483 vars.Add(...)
7484 vars.Update(env)
7485 vars.Save('variables.cache', env)
7486 .EE
7487
7488 .TP
7489 .RI GenerateHelpText( env ", [" sort ])
7490 This generates help text documenting the customizable construction
7491 variables suitable to passing in to the Help() function.
7492 .I env
7493 is the construction environment that will be used to get the actual values
7494 of customizable variables. Calling with
7495 an optional
7496 .I sort
7497 function
7498 will cause the output to be sorted
7499 by the specified argument.
7500 The specific
7501 .I sort
7502 function
7503 should take two arguments
7504 and return
7505 -1, 0 or 1
7506 (like the standard Python
7507 .I cmp
7508 function).
7509
7510 .ES
7511 Help(vars.GenerateHelpText(env))
7512 Help(vars.GenerateHelpText(env, sort=cmp))
7513 .EE
7514
7515 .TP
7516 .RI FormatVariableHelpText( env ", " opt ", " help ", " default ", " actual )
7517 This method returns a formatted string
7518 containing the printable help text
7519 for one option.
7520 It is normally not called directly,
7521 but is called by the
7522 .IR GenerateHelpText ()
7523 method to create the returned help text.
7524 It may be overridden with your own
7525 function that takes the arguments specified above
7526 and returns a string of help text formatted to your liking.
7527 Note that the
7528 .IR GenerateHelpText ()
7529 will not put any blank lines or extra
7530 characters in between the entries,
7531 so you must add those characters to the returned
7532 string if you want the entries separated.
7533
7534 .ES
7535 def my_format(env, opt, help, default, actual):
7536     fmt = "\n%s: default=%s actual=%s (%s)\n"
7537     return fmt % (opt, default. actual, help)
7538 vars.FormatVariableHelpText = my_format
7539 .EE
7540
7541 To make it more convenient to work with customizable Variables,
7542 .B scons
7543 provides a number of functions
7544 that make it easy to set up
7545 various types of Variables:
7546
7547 .TP
7548 .RI BoolVariable( key ", " help ", " default )
7549 Return a tuple of arguments
7550 to set up a Boolean option.
7551 The option will use
7552 the specified name
7553 .IR key ,
7554 have a default value of
7555 .IR default ,
7556 and display the specified
7557 .I help
7558 text.
7559 The option will interpret the values
7560 .BR y ,
7561 .BR yes ,
7562 .BR t ,
7563 .BR true ,
7564 .BR 1 ,
7565 .B on
7566 and
7567 .B all
7568 as true,
7569 and the values
7570 .BR n ,
7571 .BR no ,
7572 .BR f ,
7573 .BR false ,
7574 .BR 0 ,
7575 .B off
7576 and
7577 .B none
7578 as false.
7579
7580 .TP
7581 .RI EnumVariable( key ", " help ", " default ", " allowed_values ", [" map ", " ignorecase ])
7582 Return a tuple of arguments
7583 to set up an option
7584 whose value may be one
7585 of a specified list of legal enumerated values.
7586 The option will use
7587 the specified name
7588 .IR key ,
7589 have a default value of
7590 .IR default ,
7591 and display the specified
7592 .I help
7593 text.
7594 The option will only support those
7595 values in the
7596 .I allowed_values
7597 list.
7598 The optional
7599 .I map
7600 argument is a dictionary
7601 that can be used to convert
7602 input values into specific legal values
7603 in the
7604 .I allowed_values
7605 list.
7606 If the value of
7607 .I ignore_case
7608 is
7609 .B 0
7610 (the default),
7611 then the values are case-sensitive.
7612 If the value of
7613 .I ignore_case
7614 is
7615 .BR 1 ,
7616 then values will be matched
7617 case-insensitive.
7618 If the value of
7619 .I ignore_case
7620 is
7621 .BR 1 ,
7622 then values will be matched
7623 case-insensitive,
7624 and all input values will be
7625 converted to lower case.
7626
7627 .TP
7628 .RI ListVariable( key ", " help ", " default ", " names ", [", map ])
7629 Return a tuple of arguments
7630 to set up an option
7631 whose value may be one or more
7632 of a specified list of legal enumerated values.
7633 The option will use
7634 the specified name
7635 .IR key ,
7636 have a default value of
7637 .IR default ,
7638 and display the specified
7639 .I help
7640 text.
7641 The option will only support the values
7642 .BR all ,
7643 .BR none ,
7644 or the values in the
7645 .I names
7646 list.
7647 More than one value may be specified,
7648 with all values separated by commas.
7649 The default may be a string of
7650 comma-separated default values,
7651 or a list of the default values.
7652 The optional
7653 .I map
7654 argument is a dictionary
7655 that can be used to convert
7656 input values into specific legal values
7657 in the
7658 .I names
7659 list.
7660
7661 .TP
7662 .RI PackageVariable( key ", " help ", " default )
7663 Return a tuple of arguments
7664 to set up an option
7665 whose value is a path name
7666 of a package that may be
7667 enabled, disabled or
7668 given an explicit path name.
7669 The option will use
7670 the specified name
7671 .IR key ,
7672 have a default value of
7673 .IR default ,
7674 and display the specified
7675 .I help
7676 text.
7677 The option will support the values
7678 .BR yes ,
7679 .BR true ,
7680 .BR on ,
7681 .BR enable
7682 or
7683 .BR search ,
7684 in which case the specified
7685 .I default
7686 will be used,
7687 or the option may be set to an
7688 arbitrary string
7689 (typically the path name to a package
7690 that is being enabled).
7691 The option will also support the values
7692 .BR no ,
7693 .BR false ,
7694 .BR off
7695 or
7696 .BR disable
7697 to disable use of the specified option.
7698
7699 .TP
7700 .RI PathVariable( key ", " help ", " default ", [" validator ])
7701 Return a tuple of arguments
7702 to set up an option
7703 whose value is expected to be a path name.
7704 The option will use
7705 the specified name
7706 .IR key ,
7707 have a default value of
7708 .IR default ,
7709 and display the specified
7710 .I help
7711 text.
7712 An additional
7713 .I validator
7714 may be specified
7715 that will be called to
7716 verify that the specified path
7717 is acceptable.
7718 SCons supplies the
7719 following ready-made validators:
7720 .BR PathVariable.PathExists
7721 (the default),
7722 which verifies that the specified path exists;
7723 .BR PathVariable.PathIsFile ,
7724 which verifies that the specified path is an existing file;
7725 .BR PathVariable.PathIsDir ,
7726 which verifies that the specified path is an existing directory;
7727 .BR PathVariable.PathIsDirCreate ,
7728 which verifies that the specified path is a directory
7729 and will create the specified directory if the path does not exist;
7730 and
7731 .BR PathVariable.PathAccept ,
7732 which simply accepts the specific path name argument without validation,
7733 and which is suitable if you want your users
7734 to be able to specify a directory path that will be
7735 created as part of the build process, for example.
7736 You may supply your own
7737 .I validator
7738 function,
7739 which must take three arguments
7740 .RI ( key ,
7741 the name of the variable to be set;
7742 .IR val ,
7743 the specified value being checked;
7744 and
7745 .IR env ,
7746 the construction environment)
7747 and should raise an exception
7748 if the specified value is not acceptable.
7749
7750 .RE
7751 These functions make it
7752 convenient to create a number
7753 of variables with consistent behavior
7754 in a single call to the
7755 .B AddVariables
7756 method:
7757
7758 .ES
7759 vars.AddVariables(
7760     BoolVariable('warnings', 'compilation with -Wall and similiar', 1),
7761     EnumVariable('debug', 'debug output and symbols', 'no'
7762                allowed_values=('yes', 'no', 'full'),
7763                map={}, ignorecase=0),  # case sensitive
7764     ListVariable('shared',
7765                'libraries to build as shared libraries',
7766                'all',
7767                names = list_of_libs),
7768     PackageVariable('x11',
7769                   'use X11 installed here (yes = search some places)',
7770                   'yes'),
7771     PathVariable('qtdir', 'where the root of Qt is installed', qtdir),
7772     PathVariable('foopath', 'where the foo library is installed', foopath,
7773                PathVariable.PathIsDir),
7774
7775 )
7776 .EE
7777
7778 .SS File and Directory Nodes
7779
7780 The
7781 .IR File ()
7782 and
7783 .IR Dir ()
7784 functions return
7785 .I File
7786 and
7787 .I Dir
7788 Nodes, respectively.
7789 python objects, respectively.
7790 Those objects have several user-visible attributes
7791 and methods that are often useful:
7792
7793 .IP path
7794 The build path
7795 of the given
7796 file or directory.
7797 This path is relative to the top-level directory
7798 (where the
7799 .B SConstruct
7800 file is found).
7801 The build path is the same as the source path if
7802 .I variant_dir
7803 is not being used.
7804
7805 .IP abspath
7806 The absolute build path of the given file or directory.
7807
7808 .IP srcnode()
7809 The
7810 .IR srcnode ()
7811 method
7812 returns another
7813 .I File
7814 or
7815 .I Dir
7816 object representing the
7817 .I source
7818 path of the given
7819 .I File
7820 or
7821 .IR Dir .
7822 The
7823
7824 .ES
7825 # Get the current build dir's path, relative to top.
7826 Dir('.').path
7827 # Current dir's absolute path
7828 Dir('.').abspath
7829 # Next line is always '.', because it is the top dir's path relative to itself.
7830 Dir('#.').path
7831 File('foo.c').srcnode().path   # source path of the given source file.
7832
7833 # Builders also return File objects:
7834 foo = env.Program('foo.c')
7835 print "foo will be built in %s"%foo.path
7836 .EE
7837
7838 A
7839 .I Dir
7840 Node or
7841 .I File
7842 Node can also be used to create
7843 file and subdirectory Nodes relative to the generating Node.
7844 A
7845 .I Dir
7846 Node will place the new Nodes within the directory it represents.
7847 A
7848 .I File
7849 node will place the new Nodes within its parent directory
7850 (that is, "beside" the file in question).
7851 If
7852 .I d
7853 is a
7854 .I Dir
7855 (directory) Node and
7856 .I f
7857 is a
7858 .I File
7859 (file) Node,
7860 then these methods are available:
7861
7862 .TP
7863 .IR d .Dir( name )
7864 Returns a directory Node for a subdirectory of
7865 .I d
7866 named
7867 .IR name .
7868
7869 .TP
7870 .IR d .File( name )
7871 Returns a file Node for a file within
7872 .I d
7873 named
7874 .IR name .
7875
7876 .TP
7877 .IR d .Entry( name )
7878 Returns an unresolved Node within
7879 .I d
7880 named
7881 .IR name .
7882
7883 .TP
7884 .IR f .Dir( name )
7885 Returns a directory named
7886 .I name
7887 within the parent directory of
7888 .IR f .
7889
7890 .TP
7891 .IR f .File( name )
7892 Returns a file named
7893 .I name
7894 within the parent directory of
7895 .IR f .
7896
7897 .TP
7898 .IR f .Entry( name )
7899 Returns an unresolved Node named
7900 .I name
7901 within the parent directory of
7902 .IR f .
7903
7904 .RE
7905 For example:
7906
7907 .ES
7908 # Get a Node for a file within a directory
7909 incl = Dir('include')
7910 f = incl.File('header.h')
7911
7912 # Get a Node for a subdirectory within a directory
7913 dist = Dir('project-3.2.1)
7914 src = dist.Dir('src')
7915
7916 # Get a Node for a file in the same directory
7917 cfile = File('sample.c')
7918 hfile = cfile.File('sample.h')
7919
7920 # Combined example
7921 docs = Dir('docs')
7922 html = docs.Dir('html')
7923 index = html.File('index.html')
7924 css = index.File('app.css')
7925 .EE
7926
7927 .SH EXTENDING SCONS
7928 .SS Builder Objects
7929 .B scons
7930 can be extended to build different types of targets
7931 by adding new Builder objects
7932 to a construction environment.
7933 .IR "In general" ,
7934 you should only need to add a new Builder object
7935 when you want to build a new type of file or other external target.
7936 If you just want to invoke a different compiler or other tool
7937 to build a Program, Object, Library, or any other
7938 type of output file for which
7939 .B scons
7940 already has an existing Builder,
7941 it is generally much easier to
7942 use those existing Builders
7943 in a construction environment
7944 that sets the appropriate construction variables
7945 (CC, LINK, etc.).
7946
7947 Builder objects are created
7948 using the
7949 .B Builder
7950 function.
7951 The
7952 .B Builder
7953 function accepts the following arguments:
7954
7955 .IP action
7956 The command line string used to build the target from the source.
7957 .B action
7958 can also be:
7959 a list of strings representing the command
7960 to be executed and its arguments
7961 (suitable for enclosing white space in an argument),
7962 a dictionary
7963 mapping source file name suffixes to
7964 any combination of command line strings
7965 (if the builder should accept multiple source file extensions),
7966 a Python function;
7967 an Action object
7968 (see the next section);
7969 or a list of any of the above.
7970
7971 An action function
7972 takes three arguments:
7973 .I source
7974 - a list of source nodes,
7975 .I target
7976 - a list of target nodes,
7977 .I env
7978 - the construction environment.
7979
7980 .IP prefix
7981 The prefix that will be prepended to the target file name.
7982 This may be specified as a:
7983
7984 .RS 10
7985 .HP 6
7986 *
7987 .IR string ,
7988
7989 .HP 6
7990 *
7991 .I callable object
7992 - a function or other callable that takes
7993 two arguments (a construction environment and a list of sources)
7994 and returns a prefix,
7995
7996 .HP 6
7997 *
7998 .I dictionary
7999 - specifies a mapping from a specific source suffix (of the first
8000 source specified) to a corresponding target prefix.  Both the source
8001 suffix and target prefix specifications may use environment variable
8002 substitution, and the target prefix (the 'value' entries in the
8003 dictionary) may also be a callable object.  The default target prefix
8004 may be indicated by a dictionary entry with a key value of None.
8005 .RE
8006 .P
8007
8008 .ES
8009 b = Builder("build_it < $SOURCE > $TARGET"
8010             prefix = "file-")
8011
8012 def gen_prefix(env, sources):
8013     return "file-" + env['PLATFORM'] + '-'
8014 b = Builder("build_it < $SOURCE > $TARGET",
8015             prefix = gen_prefix)
8016
8017 b = Builder("build_it < $SOURCE > $TARGET",
8018             suffix = { None: "file-",
8019                        "$SRC_SFX_A": gen_prefix })
8020 .EE
8021
8022 .IP suffix
8023 The suffix that will be appended to the target file name.
8024 This may be specified in the same manner as the prefix above.
8025 If the suffix is a string, then
8026 .B scons
8027 will append a '.' to the beginning of the suffix if it's not already
8028 there.  The string returned by callable object (or obtained from the
8029 dictionary) is untouched and must append its own '.'  to the beginning
8030 if one is desired.
8031
8032 .ES
8033 b = Builder("build_it < $SOURCE > $TARGET"
8034             suffix = "-file")
8035
8036 def gen_suffix(env, sources):
8037     return "." + env['PLATFORM'] + "-file"
8038 b = Builder("build_it < $SOURCE > $TARGET",
8039             suffix = gen_suffix)
8040
8041 b = Builder("build_it < $SOURCE > $TARGET",
8042             suffix = { None: ".sfx1",
8043                        "$SRC_SFX_A": gen_suffix })
8044 .EE
8045
8046 .IP ensure_suffix
8047 When set to any true value, causes
8048 .B scons
8049 to add the target suffix specified by the
8050 .I suffix
8051 keyword to any target strings
8052 that have a different suffix.
8053 (The default behavior is to leave untouched
8054 any target file name that looks like it already has any suffix.)
8055
8056 .ES
8057 b1 = Builder("build_it < $SOURCE > $TARGET"
8058              suffix = ".out")
8059 b2 = Builder("build_it < $SOURCE > $TARGET"
8060              suffix = ".out",
8061              ensure_suffix)
8062 env = Environment()
8063 env['BUILDERS']['B1'] = b1
8064 env['BUILDERS']['B2'] = b2
8065
8066 # Builds "foo.txt" because ensure_suffix is not set.
8067 env.B1('foo.txt', 'foo.in')
8068
8069 # Builds "bar.txt.out" because ensure_suffix is set.
8070 env.B2('bar.txt', 'bar.in')
8071 .EE
8072
8073 .IP src_suffix
8074 The expected source file name suffix.  This may be a string or a list
8075 of strings.
8076
8077 .IP target_scanner
8078 A Scanner object that
8079 will be invoked to find
8080 implicit dependencies for this target file.
8081 This keyword argument should be used
8082 for Scanner objects that find
8083 implicit dependencies
8084 based only on the target file
8085 and the construction environment,
8086 .I not
8087 for implicit
8088 (See the section "Scanner Objects," below,
8089 for information about creating Scanner objects.)
8090
8091 .IP source_scanner
8092 A Scanner object that
8093 will be invoked to
8094 find implicit dependences in
8095 any source files
8096 used to build this target file.
8097 This is where you would
8098 specify a scanner to
8099 find things like
8100 .B #include
8101 lines in source files.
8102 The pre-built
8103 .B DirScanner
8104 Scanner object may be used to
8105 indicate that this Builder
8106 should scan directory trees
8107 for on-disk changes to files
8108 that
8109 .B scons
8110 does not know about from other Builder or function calls.
8111 (See the section "Scanner Objects," below,
8112 for information about creating your own Scanner objects.)
8113
8114 .IP target_factory
8115 A factory function that the Builder will use
8116 to turn any targets specified as strings into SCons Nodes.
8117 By default,
8118 SCons assumes that all targets are files.
8119 Other useful target_factory
8120 values include
8121 .BR Dir ,
8122 for when a Builder creates a directory target,
8123 and
8124 .BR Entry ,
8125 for when a Builder can create either a file
8126 or directory target.
8127
8128 Example:
8129
8130 .ES
8131 MakeDirectoryBuilder = Builder(action=my_mkdir, target_factory=Dir)
8132 env = Environment()
8133 env.Append(BUILDERS = {'MakeDirectory':MakeDirectoryBuilder})
8134 env.MakeDirectory('new_directory', [])
8135 .EE
8136
8137 .IP
8138 Note that the call to the MakeDirectory Builder
8139 needs to specify an empty source list
8140 to make the string represent the builder's target;
8141 without that, it would assume the argument is the source,
8142 and would try to deduce the target name from it,
8143 which in the absence of an automatically-added prefix or suffix
8144 would lead to a matching target and source name
8145 and a circular dependency.
8146
8147 .IP source_factory
8148 A factory function that the Builder will use
8149 to turn any sources specified as strings into SCons Nodes.
8150 By default,
8151 SCons assumes that all source are files.
8152 Other useful source_factory
8153 values include
8154 .BR Dir ,
8155 for when a Builder uses a directory as a source,
8156 and
8157 .BR Entry ,
8158 for when a Builder can use files
8159 or directories (or both) as sources.
8160
8161 Example:
8162
8163 .ES
8164 CollectBuilder = Builder(action=my_mkdir, source_factory=Entry)
8165 env = Environment()
8166 env.Append(BUILDERS = {'Collect':CollectBuilder})
8167 env.Collect('archive', ['directory_name', 'file_name'])
8168 .EE
8169
8170 .IP emitter
8171 A function or list of functions to manipulate the target and source
8172 lists before dependencies are established
8173 and the target(s) are actually built.
8174 .B emitter
8175 can also be a string containing a construction variable to expand
8176 to an emitter function or list of functions,
8177 or a dictionary mapping source file suffixes
8178 to emitter functions.
8179 (Only the suffix of the first source file
8180 is used to select the actual emitter function
8181 from an emitter dictionary.)
8182
8183 An emitter function
8184 takes three arguments:
8185 .I source
8186 - a list of source nodes,
8187 .I target
8188 - a list of target nodes,
8189 .I env
8190 - the construction environment.
8191 An emitter must return a tuple containing two lists,
8192 the list of targets to be built by this builder,
8193 and the list of sources for this builder.
8194
8195 Example:
8196
8197 .ES
8198 def e(target, source, env):
8199     return (target + ['foo.foo'], source + ['foo.src'])
8200
8201 # Simple association of an emitter function with a Builder.
8202 b = Builder("my_build < $TARGET > $SOURCE",
8203             emitter = e)
8204
8205 def e2(target, source, env):
8206     return (target + ['bar.foo'], source + ['bar.src'])
8207
8208 # Simple association of a list of emitter functions with a Builder.
8209 b = Builder("my_build < $TARGET > $SOURCE",
8210             emitter = [e, e2])
8211
8212 # Calling an emitter function through a construction variable.
8213 env = Environment(MY_EMITTER = e)
8214 b = Builder("my_build < $TARGET > $SOURCE",
8215             emitter = '$MY_EMITTER')
8216
8217 # Calling a list of emitter functions through a construction variable.
8218 env = Environment(EMITTER_LIST = [e, e2])
8219 b = Builder("my_build < $TARGET > $SOURCE",
8220             emitter = '$EMITTER_LIST')
8221
8222 # Associating multiple emitters with different file
8223 # suffixes using a dictionary.
8224 def e_suf1(target, source, env):
8225     return (target + ['another_target_file'], source)
8226 def e_suf2(target, source, env):
8227     return (target, source + ['another_source_file'])
8228 b = Builder("my_build < $TARGET > $SOURCE",
8229             emitter = {'.suf1' : e_suf1,
8230                        '.suf2' : e_suf2})
8231 .EE
8232
8233 .IP multi
8234 Specifies whether this builder is allowed to be called multiple times for
8235 the same target file(s). The default is 0, which means the builder
8236 can not be called multiple times for the same target file(s). Calling a
8237 builder multiple times for the same target simply adds additional source
8238 files to the target; it is not allowed to change the environment associated
8239 with the target, specify addition environment overrides, or associate a different
8240 builder with the target.
8241
8242 .IP env
8243 A construction environment that can be used
8244 to fetch source code using this Builder.
8245 (Note that this environment is
8246 .I not
8247 used for normal builds of normal target files,
8248 which use the environment that was
8249 used to call the Builder for the target file.)
8250
8251 .IP generator
8252 A function that returns a list of actions that will be executed to build
8253 the target(s) from the source(s).
8254 The returned action(s) may be
8255 an Action object, or anything that
8256 can be converted into an Action object
8257 (see the next section).
8258
8259 The generator function
8260 takes four arguments:
8261 .I source
8262 - a list of source nodes,
8263 .I target
8264 - a list of target nodes,
8265 .I env
8266 - the construction environment,
8267 .I for_signature
8268 - a Boolean value that specifies
8269 whether the generator is being called
8270 for generating a build signature
8271 (as opposed to actually executing the command).
8272 Example:
8273
8274 .ES
8275 def g(source, target, env, for_signature):
8276     return [["gcc", "-c", "-o"] + target + source]
8277
8278 b = Builder(generator=g)
8279 .EE
8280
8281 .IP
8282 The
8283 .I generator
8284 and
8285 .I action
8286 arguments must not both be used for the same Builder.
8287
8288 .IP src_builder
8289 Specifies a builder to use when a source file name suffix does not match
8290 any of the suffixes of the builder. Using this argument produces a
8291 multi-stage builder.
8292
8293 .IP single_source
8294 Specifies that this builder expects exactly one source file per call. Giving
8295 more than one source file without target files results in implicitely calling
8296 the builder multiple times (once for each source given). Giving multiple
8297 source files together with target files results in a UserError exception.
8298
8299 .RE
8300 .IP
8301 The
8302 .I generator
8303 and
8304 .I action
8305 arguments must not both be used for the same Builder.
8306
8307 .IP source_ext_match
8308 When the specified
8309 .I action
8310 argument is a dictionary,
8311 the default behavior when a builder is passed
8312 multiple source files is to make sure that the
8313 extensions of all the source files match.
8314 If it is legal for this builder to be
8315 called with a list of source files with different extensions,
8316 this check can be suppressed by setting
8317 .B source_ext_match
8318 to
8319 .B None
8320 or some other non-true value.
8321 When
8322 .B source_ext_match
8323 is disable,
8324 .B scons
8325 will use the suffix of the first specified
8326 source file to select the appropriate action from the
8327 .I action
8328 dictionary.
8329
8330 In the following example,
8331 the setting of
8332 .B source_ext_match
8333 prevents
8334 .B scons
8335 from exiting with an error
8336 due to the mismatched suffixes of
8337 .B foo.in
8338 and
8339 .BR foo.extra .
8340
8341 .ES
8342 b = Builder(action={'.in' : 'build $SOURCES > $TARGET'},
8343             source_ext_match = None)
8344
8345 env = Environment(BUILDERS = {'MyBuild':b})
8346 env.MyBuild('foo.out', ['foo.in', 'foo.extra'])
8347 .EE
8348
8349 .IP env
8350 A construction environment that can be used
8351 to fetch source code using this Builder.
8352 (Note that this environment is
8353 .I not
8354 used for normal builds of normal target files,
8355 which use the environment that was
8356 used to call the Builder for the target file.)
8357
8358 .ES
8359 b = Builder(action="build < $SOURCE > $TARGET")
8360 env = Environment(BUILDERS = {'MyBuild' : b})
8361 env.MyBuild('foo.out', 'foo.in', my_arg = 'xyzzy')
8362 .EE
8363
8364 .IP chdir
8365 A directory from which scons
8366 will execute the
8367 action(s) specified
8368 for this Builder.
8369 If the
8370 .B chdir
8371 argument is
8372 a string or a directory Node,
8373 scons will change to the specified directory.
8374 If the
8375 .B chdir
8376 is not a string or Node
8377 and is non-zero,
8378 then scons will change to the
8379 target file's directory.
8380
8381 Note that scons will
8382 .I not
8383 automatically modify
8384 its expansion of
8385 construction variables like
8386 .B $TARGET
8387 and
8388 .B $SOURCE
8389 when using the chdir
8390 keyword argument--that is,
8391 the expanded file names
8392 will still be relative to
8393 the top-level SConstruct directory,
8394 and consequently incorrect
8395 relative to the chdir directory.
8396 Builders created using chdir keyword argument,
8397 will need to use construction variable
8398 expansions like
8399 .B ${TARGET.file}
8400 and
8401 .B ${SOURCE.file}
8402 to use just the filename portion of the
8403 targets and source.
8404
8405 .ES
8406 b = Builder(action="build < ${SOURCE.file} > ${TARGET.file}",
8407             chdir=1)
8408 env = Environment(BUILDERS = {'MyBuild' : b})
8409 env.MyBuild('sub/dir/foo.out', 'sub/dir/foo.in')
8410 .EE
8411
8412 .B WARNING:
8413 Python only keeps one current directory
8414 location for all of the threads.
8415 This means that use of the
8416 .B chdir
8417 argument
8418 will
8419 .I not
8420 work with the SCons
8421 .B -j
8422 option,
8423 because individual worker threads spawned
8424 by SCons interfere with each other
8425 when they start changing directory.
8426
8427 .RE
8428 Any additional keyword arguments supplied
8429 when a Builder object is created
8430 (that is, when the Builder() function is called)
8431 will be set in the executing construction
8432 environment when the Builder object is called.
8433 The canonical example here would be
8434 to set a construction variable to
8435 the repository of a source code system.
8436
8437 Any additional keyword arguments supplied
8438 when a Builder
8439 .I object
8440 is called
8441 will only be associated with the target
8442 created by that particular Builder call
8443 (and any other files built as a
8444 result of the call).
8445
8446 These extra keyword arguments are passed to the
8447 following functions:
8448 command generator functions,
8449 function Actions,
8450 and emitter functions.
8451
8452 .SS Action Objects
8453
8454 The
8455 .BR Builder ()
8456 function will turn its
8457 .B action
8458 keyword argument into an appropriate
8459 internal Action object.
8460 You can also explicity create Action objects
8461 using the
8462 .BR Action ()
8463 global function,
8464 which can then be passed to the
8465 .BR Builder ()
8466 function.
8467 This can be used to configure
8468 an Action object more flexibly,
8469 or it may simply be more efficient
8470 than letting each separate Builder object
8471 create a separate Action
8472 when multiple
8473 Builder objects need to do the same thing.
8474
8475 The
8476 .BR Action ()
8477 global function
8478 returns an appropriate object for the action
8479 represented by the type of the first argument:
8480
8481 .IP Action
8482 If the first argument is already an Action object,
8483 the object is simply returned.
8484
8485 .IP String
8486 If the first argument is a string,
8487 a command-line Action is returned.
8488 Note that the command-line string
8489 may be preceded by an
8490 .B @
8491 (at-sign)
8492 to suppress printing of the specified command line,
8493 or by a
8494 .B \-
8495 (hyphen)
8496 to ignore the exit status from the specified command:
8497
8498 .ES
8499 Action('$CC -c -o $TARGET $SOURCES')
8500
8501 # Doesn't print the line being executed.
8502 Action('@build $TARGET $SOURCES')
8503
8504 # Ignores return value
8505 Action('-build $TARGET $SOURCES')
8506 .EE
8507 .\" XXX From Gary Ruben, 23 April 2002:
8508 .\" What would be useful is a discussion of how you execute command
8509 .\" shell commands ie. what is the process used to spawn the shell, pass
8510 .\" environment variables to it etc., whether there is one shell per
8511 .\" environment or one per command etc.  It might help to look at the Gnu
8512 .\" make documentation to see what they think is important to discuss about
8513 .\" a build system. I'm sure you can do a better job of organising the
8514 .\" documentation than they have :-)
8515
8516 .IP List
8517 If the first argument is a list,
8518 then a list of Action objects is returned.
8519 An Action object is created as necessary
8520 for each element in the list.
8521 If an element
8522 .I within
8523 the list is itself a list,
8524 the internal list is the
8525 command and arguments to be executed via
8526 the command line.
8527 This allows white space to be enclosed
8528 in an argument by defining
8529 a command in a list within a list:
8530
8531 .ES
8532 Action([['cc', '-c', '-DWHITE SPACE', '-o', '$TARGET', '$SOURCES']])
8533 .EE
8534
8535 .IP Function
8536 If the first argument is a Python function,
8537 a function Action is returned.
8538 The Python function must take three keyword arguments,
8539 .B target
8540 (a Node object representing the target file),
8541 .B source
8542 (a Node object representing the source file)
8543 and
8544 .B env
8545 (the construction environment
8546 used for building the target file).
8547 The
8548 .B target
8549 and
8550 .B source
8551 arguments may be lists of Node objects if there is
8552 more than one target file or source file.
8553 The actual target and source file name(s) may
8554 be retrieved from their Node objects
8555 via the built-in Python str() function:
8556
8557 .ES
8558 target_file_name = str(target)
8559 source_file_names = map(lambda x: str(x), source)
8560 .EE
8561 .IP
8562 The function should return
8563 .B 0
8564 or
8565 .B None
8566 to indicate a successful build of the target file(s).
8567 The function may raise an exception
8568 or return a non-zero exit status
8569 to indicate an unsuccessful build.
8570
8571 .ES
8572 def build_it(target = None, source = None, env = None):
8573     # build the target from the source
8574     return 0
8575
8576 a = Action(build_it)
8577 .EE
8578
8579 If the action argument is not one of the above,
8580 None is returned.
8581 .PP
8582
8583 The second argument is optional and is used to define the output
8584 which is printed when the Action is actually performed.
8585 In the absence of this parameter,
8586 or if it's an empty string,
8587 a default output depending on the type of the action is used.
8588 For example, a command-line action will print the executed command.
8589 The argument must be either a Python function or a string.
8590
8591 In the first case,
8592 it's a function that returns a string to be printed
8593 to describe the action being executed.
8594 The function may also be specified by the
8595 .IR strfunction =
8596 keyword argument.
8597 Like a function to build a file,
8598 this function must take three keyword arguments:
8599 .B target
8600 (a Node object representing the target file),
8601 .B source
8602 (a Node object representing the source file)
8603 and
8604 .BR env
8605 (a construction environment).
8606 The
8607 .B target
8608 and
8609 .B source
8610 arguments may be lists of Node objects if there is
8611 more than one target file or source file.
8612
8613 In the second case, you provide the string itself.
8614 The string may also be specified by the
8615 .IR cmdstr =
8616 keyword argument.
8617 The string typically contains variables, notably
8618 $TARGET(S) and $SOURCE(S), or consists of just a single
8619 variable, which is optionally defined somewhere else.
8620 SCons itself heavily uses the latter variant.
8621
8622 Examples:
8623
8624 .ES
8625 def build_it(target, source, env):
8626     # build the target from the source
8627     return 0
8628
8629 def string_it(target, source, env):
8630     return "building '%s' from '%s'" % (target[0], source[0])
8631
8632 # Use a positional argument.
8633 f = Action(build_it, string_it)
8634 s = Action(build_it, "building '$TARGET' from '$SOURCE'")
8635
8636 # Alternatively, use a keyword argument.
8637 f = Action(build_it, strfunction=string_it)
8638 s = Action(build_it, cmdstr="building '$TARGET' from '$SOURCE'")
8639
8640 # You can provide a configurable variable.
8641 l = Action(build_it, '$STRINGIT')
8642 .EE
8643
8644 The third and succeeding arguments, if present,
8645 may either be a construction variable or a list of construction variables
8646 whose values will be included in the signature of the Action
8647 when deciding whether a target should be rebuilt because the action changed.
8648 The variables may also be specified by a
8649 .IR varlist =
8650 keyword parameter;
8651 if both are present, they are combined.
8652 This is necessary whenever you want a target to be rebuilt
8653 when a specific construction variable changes.
8654 This is not often needed for a string action,
8655 as the expanded variables will normally be part of the command line,
8656 but may be needed if a Python function action uses
8657 the value of a construction variable when generating the command line.
8658
8659 .ES
8660 def build_it(target, source, env):
8661     # build the target from the 'XXX' construction variable
8662     open(target[0], 'w').write(env['XXX'])
8663     return 0
8664
8665 # Use positional arguments.
8666 a = Action(build_it, '$STRINGIT', ['XXX'])
8667
8668 # Alternatively, use a keyword argument.
8669 a = Action(build_it, varlist=['XXX'])
8670 .EE
8671
8672 The
8673 .BR Action ()
8674 global function
8675 can be passed the following
8676 optional keyword arguments
8677 to modify the Action object's behavior:
8678
8679 .IP
8680 .B chdir
8681 The
8682 .B chdir
8683 keyword argument specifies that
8684 scons will execute the action
8685 after changing to the specified directory.
8686 If the
8687 .B chdir
8688 argument is
8689 a string or a directory Node,
8690 scons will change to the specified directory.
8691 If the
8692 .B chdir
8693 argument
8694 is not a string or Node
8695 and is non-zero,
8696 then scons will change to the
8697 target file's directory.
8698
8699 Note that scons will
8700 .I not
8701 automatically modify
8702 its expansion of
8703 construction variables like
8704 .B $TARGET
8705 and
8706 .B $SOURCE
8707 when using the chdir
8708 keyword argument--that is,
8709 the expanded file names
8710 will still be relative to
8711 the top-level SConstruct directory,
8712 and consequently incorrect
8713 relative to the chdir directory.
8714 Builders created using chdir keyword argument,
8715 will need to use construction variable
8716 expansions like
8717 .B ${TARGET.file}
8718 and
8719 .B ${SOURCE.file}
8720 to use just the filename portion of the
8721 targets and source.
8722
8723 .ES
8724 a = Action("build < ${SOURCE.file} > ${TARGET.file}",
8725            chdir=1)
8726 .EE
8727
8728 .IP
8729 .B exitstatfunc
8730 The
8731 .BR Action ()
8732 global function
8733 also takes an
8734 .B exitstatfunc
8735 keyword argument
8736 which specifies a function
8737 that is passed the exit status
8738 (or return value)
8739 from the specified action
8740 and can return an arbitrary
8741 or modified value.
8742 This can be used, for example,
8743 to specify that an Action object's
8744 return value should be ignored
8745 under special conditions
8746 and SCons should, therefore,
8747 consider that the action always suceeds:
8748
8749 .ES
8750 def always_succeed(s):
8751     # Always return 0, which indicates success.
8752     return 0
8753 a = Action("build < ${SOURCE.file} > ${TARGET.file}",
8754            exitstatfunc=always_succeed)
8755 .EE
8756
8757 .IP
8758 .B batch_key
8759 The
8760 .B batch_key
8761 keyword argument can be used
8762 to specify that the Action can create multiple target files
8763 by processing multiple independent source files simultaneously.
8764 (The canonical example is "batch compilation"
8765 of multiple object files
8766 by passing multiple source files
8767 to a single invocation of a compiler
8768 such as Microsoft's Visual C / C++ compiler.)
8769 If the
8770 .B batch_key
8771 argument is any non-False, non-callable Python value,
8772 the configured Action object will cause
8773 .B scons
8774 to collect all targets built with the Action object
8775 and configured with the same construction environment
8776 into single invocations of the Action object's
8777 command line or function.
8778 Command lines will typically want to use the
8779 .BR CHANGED_SOURCES
8780 construction variable
8781 (and possibly
8782 .BR CHANGED_TARGETS
8783 as well)
8784 to only pass to the command line those sources that
8785 have actually changed since their targets were built.
8786
8787 Example:
8788
8789 .ES
8790 a = Action('build $CHANGED_SOURCES', batch_key=True)
8791 .EE
8792
8793 The
8794 .B batch_key
8795 argument may also be
8796 a callable function
8797 that returns a key that
8798 will be used to identify different
8799 "batches" of target files to be collected
8800 for batch building.
8801 A
8802 .B batch_key
8803 function must take the following arguments:
8804
8805 .IP action
8806 The action object.
8807
8808 .IP env
8809 The construction environment
8810 configured for the target.
8811
8812 .IP target
8813 The list of targets for a particular configured action.
8814
8815 .IP source
8816 The list of source for a particular configured action.
8817
8818 The returned key should typically
8819 be a tuple of values derived from the arguments,
8820 using any appropriate logic to decide
8821 how multiple invocations should be batched.
8822 For example, a
8823 .B batch_key
8824 function may decide to return
8825 the value of a specific construction
8826 variable from the
8827 .B env
8828 argument
8829 which will cause
8830 .B scons
8831 to batch-build targets
8832 with matching values of that variable,
8833 or perhaps return the
8834 .BR id ()
8835 of the entire construction environment,
8836 in which case
8837 .B scons
8838 will batch-build
8839 all targets configured with the same construction environment.
8840 Returning
8841 .B None
8842 indicates that
8843 the particular target should
8844 .I not
8845 be part of any batched build,
8846 but instead will be built
8847 by a separate invocation of action's
8848 command or function.
8849 Example:
8850
8851 .ES
8852 def batch_key(action, env, target, source):
8853     tdir = target[0].dir
8854     if tdir.name == 'special':
8855         # Don't batch-build any target
8856         # in the special/ subdirectory.
8857         return None
8858     return (id(action), id(env), tdir)
8859 a = Action('build $CHANGED_SOURCES', batch_key=batch_key)
8860 .EE
8861
8862 .SS Miscellaneous Action Functions
8863
8864 .B scons
8865 supplies a number of functions
8866 that arrange for various common
8867 file and directory manipulations
8868 to be performed.
8869 These are similar in concept to "tasks" in the
8870 Ant build tool,
8871 although the implementation is slightly different.
8872 These functions do not actually
8873 perform the specified action
8874 at the time the function is called,
8875 but instead return an Action object
8876 that can be executed at the
8877 appropriate time.
8878 (In Object-Oriented terminology,
8879 these are actually
8880 Action
8881 .I Factory
8882 functions
8883 that return Action objects.)
8884
8885 In practice,
8886 there are two natural ways
8887 that these
8888 Action Functions
8889 are intended to be used.
8890
8891 First,
8892 if you need
8893 to perform the action
8894 at the time the SConscript
8895 file is being read,
8896 you can use the
8897 .B Execute
8898 global function to do so:
8899 .ES
8900 Execute(Touch('file'))
8901 .EE
8902
8903 Second,
8904 you can use these functions
8905 to supply Actions in a list
8906 for use by the
8907 .B Command
8908 method.
8909 This can allow you to
8910 perform more complicated
8911 sequences of file manipulation
8912 without relying
8913 on platform-specific
8914 external commands:
8915 that
8916 .ES
8917 env = Environment(TMPBUILD = '/tmp/builddir')
8918 env.Command('foo.out', 'foo.in',
8919             [Mkdir('$TMPBUILD'),
8920              Copy('$TMPBUILD', '${SOURCE.dir}'),
8921              "cd $TMPBUILD && make",
8922              Delete('$TMPBUILD')])
8923 .EE
8924
8925 .TP
8926 .RI Chmod( dest ", " mode )
8927 Returns an Action object that
8928 changes the permissions on the specified
8929 .I dest
8930 file or directory to the specified
8931 .IR mode .
8932 Examples:
8933
8934 .ES
8935 Execute(Chmod('file', 0755))
8936
8937 env.Command('foo.out', 'foo.in',
8938             [Copy('$TARGET', '$SOURCE'),
8939              Chmod('$TARGET', 0755)])
8940 .EE
8941
8942 .TP
8943 .RI Copy( dest ", " src )
8944 Returns an Action object
8945 that will copy the
8946 .I src
8947 source file or directory to the
8948 .I dest
8949 destination file or directory.
8950 Examples:
8951
8952 .ES
8953 Execute(Copy('foo.output', 'foo.input'))
8954
8955 env.Command('bar.out', 'bar.in',
8956             Copy('$TARGET', '$SOURCE'))
8957 .EE
8958
8959 .TP
8960 .RI Delete( entry ", [" must_exist ])
8961 Returns an Action that
8962 deletes the specified
8963 .IR entry ,
8964 which may be a file or a directory tree.
8965 If a directory is specified,
8966 the entire directory tree
8967 will be removed.
8968 If the
8969 .I must_exist
8970 flag is set,
8971 then a Python error will be thrown
8972 if the specified entry does not exist;
8973 the default is
8974 .BR must_exist=0 ,
8975 that is, the Action will silently do nothing
8976 if the entry does not exist.
8977 Examples:
8978
8979 .ES
8980 Execute(Delete('/tmp/buildroot'))
8981
8982 env.Command('foo.out', 'foo.in',
8983             [Delete('${TARGET.dir}'),
8984              MyBuildAction])
8985
8986 Execute(Delete('file_that_must_exist', must_exist=1))
8987 .EE
8988
8989 .TP
8990 .RI Mkdir( dir )
8991 Returns an Action
8992 that creates the specified
8993 directory
8994 .I dir .
8995 Examples:
8996
8997 .ES
8998 Execute(Mkdir('/tmp/outputdir'))
8999
9000 env.Command('foo.out', 'foo.in',
9001             [Mkdir('/tmp/builddir'),
9002              Copy('/tmp/builddir/foo.in', '$SOURCE'),
9003              "cd /tmp/builddir && make",
9004              Copy('$TARGET', '/tmp/builddir/foo.out')])
9005 .EE
9006
9007 .TP
9008 .RI Move( dest ", " src )
9009 Returns an Action
9010 that moves the specified
9011 .I src
9012 file or directory to
9013 the specified
9014 .I dest
9015 file or directory.
9016 Examples:
9017
9018 .ES
9019 Execute(Move('file.destination', 'file.source'))
9020
9021 env.Command('output_file', 'input_file',
9022             [MyBuildAction,
9023              Move('$TARGET', 'file_created_by_MyBuildAction')])
9024 .EE
9025
9026 .TP
9027 .RI Touch( file )
9028 Returns an Action
9029 that updates the modification time
9030 on the specified
9031 .IR file .
9032 Examples:
9033
9034 .ES
9035 Execute(Touch('file_to_be_touched'))
9036
9037 env.Command('marker', 'input_file',
9038             [MyBuildAction,
9039              Touch('$TARGET')])
9040 .EE
9041
9042 .SS Variable Substitution
9043
9044 Before executing a command,
9045 .B scons
9046 performs construction variable interpolation on the strings that make up
9047 the command line of builders.
9048 Variables are introduced by a
9049 .B $
9050 prefix.
9051 Besides construction variables, scons provides the following
9052 variables for each command execution:
9053
9054 .IP CHANGED_SOURCES
9055 The file names of all sources of the build command
9056 that have changed since the target was last built.
9057
9058 .IP CHANGED_TARGETS
9059 The file names of all targets that would be built
9060 from sources that have changed since the target was last built.
9061
9062 .IP SOURCE
9063 The file name of the source of the build command,
9064 or the file name of the first source
9065 if multiple sources are being built.
9066
9067 .IP SOURCES
9068 The file names of the sources of the build command.
9069
9070 .IP TARGET
9071 The file name of the target being built,
9072 or the file name of the first target
9073 if multiple targets are being built.
9074
9075 .IP TARGETS
9076 The file names of all targets being built.
9077
9078 .IP UNCHANGED_SOURCES
9079 The file names of all sources of the build command
9080 that have
9081 .I not
9082 changed since the target was last built.
9083
9084 .IP UNCHANGED_TARGETS
9085 The file names of all targets that would be built
9086 from sources that have
9087 .I not
9088 changed since the target was last built.
9089
9090 (Note that the above variables are reserved
9091 and may not be set in a construction environment.)
9092
9093 .LP
9094 For example, given the construction variable CC='cc', targets=['foo'], and
9095 sources=['foo.c', 'bar.c']:
9096
9097 .ES
9098 action='$CC -c -o $TARGET $SOURCES'
9099 .EE
9100
9101 would produce the command line:
9102
9103 .ES
9104 cc -c -o foo foo.c bar.c
9105 .EE
9106
9107 Variable names may be surrounded by curly braces ({})
9108 to separate the name from the trailing characters.
9109 Within the curly braces, a variable name may have
9110 a Python slice subscript appended to select one
9111 or more items from a list.
9112 In the previous example, the string:
9113
9114 .ES
9115 ${SOURCES[1]}
9116 .EE
9117
9118 would produce:
9119
9120 .ES
9121 bar.c
9122 .EE
9123
9124 Additionally, a variable name may
9125 have the following special
9126 modifiers appended within the enclosing curly braces
9127 to modify the interpolated string:
9128
9129 .IP base
9130 The base path of the file name,
9131 including the directory path
9132 but excluding any suffix.
9133
9134 .IP dir
9135 The name of the directory in which the file exists.
9136
9137 .IP file
9138 The file name,
9139 minus any directory portion.
9140
9141 .IP filebase
9142 Just the basename of the file,
9143 minus any suffix
9144 and minus the directory.
9145
9146 .IP suffix
9147 Just the file suffix.
9148
9149 .IP abspath
9150 The absolute path name of the file.
9151
9152 .IP posix
9153 The POSIX form of the path,
9154 with directories separated by
9155 .B /
9156 (forward slashes)
9157 not backslashes.
9158 This is sometimes necessary on Windows systems
9159 when a path references a file on other (POSIX) systems.
9160
9161 .IP srcpath
9162 The directory and file name to the source file linked to this file through
9163 .BR VariantDir ().
9164 If this file isn't linked,
9165 it just returns the directory and filename unchanged.
9166
9167 .IP srcdir
9168 The directory containing the source file linked to this file through
9169 .BR VariantDir ().
9170 If this file isn't linked,
9171 it just returns the directory part of the filename.
9172
9173 .IP rsrcpath
9174 The directory and file name to the source file linked to this file through
9175 .BR VariantDir ().
9176 If the file does not exist locally but exists in a Repository,
9177 the path in the Repository is returned.
9178 If this file isn't linked, it just returns the
9179 directory and filename unchanged.
9180
9181 .IP rsrcdir
9182 The Repository directory containing the source file linked to this file through
9183 .BR VariantDir ().
9184 If this file isn't linked,
9185 it just returns the directory part of the filename.
9186
9187 .LP
9188 For example, the specified target will
9189 expand as follows for the corresponding modifiers:
9190
9191 .ES
9192 $TARGET              => sub/dir/file.x
9193 ${TARGET.base}       => sub/dir/file
9194 ${TARGET.dir}        => sub/dir
9195 ${TARGET.file}       => file.x
9196 ${TARGET.filebase}   => file
9197 ${TARGET.suffix}     => .x
9198 ${TARGET.abspath}    => /top/dir/sub/dir/file.x
9199
9200 SConscript('src/SConscript', variant_dir='sub/dir')
9201 $SOURCE              => sub/dir/file.x
9202 ${SOURCE.srcpath}    => src/file.x
9203 ${SOURCE.srcdir}     => src
9204
9205 Repository('/usr/repository')
9206 $SOURCE              => sub/dir/file.x
9207 ${SOURCE.rsrcpath}   => /usr/repository/src/file.x
9208 ${SOURCE.rsrcdir}    => /usr/repository/src
9209 .EE
9210
9211 Note that curly braces braces may also be used
9212 to enclose arbitrary Python code to be evaluated.
9213 (In fact, this is how the above modifiers are substituted,
9214 they are simply attributes of the Python objects
9215 that represent TARGET, SOURCES, etc.)
9216 See the section "Python Code Substitution," below,
9217 for more thorough examples of
9218 how this can be used.
9219
9220 Lastly, a variable name
9221 may be a callable Python function
9222 associated with a
9223 construction variable in the environment.
9224 The function should
9225 take four arguments:
9226 .I target
9227 - a list of target nodes,
9228 .I source
9229 - a list of source nodes,
9230 .I env
9231 - the construction environment,
9232 .I for_signature
9233 - a Boolean value that specifies
9234 whether the function is being called
9235 for generating a build signature.
9236 SCons will insert whatever
9237 the called function returns
9238 into the expanded string:
9239
9240 .ES
9241 def foo(target, source, env, for_signature):
9242     return "bar"
9243
9244 # Will expand $BAR to "bar baz"
9245 env=Environment(FOO=foo, BAR="$FOO baz")
9246 .EE
9247
9248 You can use this feature to pass arguments to a
9249 Python function by creating a callable class
9250 that stores one or more arguments in an object,
9251 and then uses them when the
9252 .B __call__()
9253 method is called.
9254 Note that in this case,
9255 the entire variable expansion must
9256 be enclosed by curly braces
9257 so that the arguments will
9258 be associated with the
9259 instantiation of the class:
9260
9261 .ES
9262 class foo:
9263     def __init__(self, arg):
9264         self.arg = arg
9265
9266     def __call__(self, target, source, env, for_signature):
9267         return self.arg + " bar"
9268
9269 # Will expand $BAR to "my argument bar baz"
9270 env=Environment(FOO=foo, BAR="${FOO('my argument')} baz")
9271 .EE
9272
9273 .LP
9274 The special pseudo-variables
9275 .B "$("
9276 and
9277 .B "$)"
9278 may be used to surround parts of a command line
9279 that may change
9280 .I without
9281 causing a rebuild--that is,
9282 which are not included in the signature
9283 of target files built with this command.
9284 All text between
9285 .B "$("
9286 and
9287 .B "$)"
9288 will be removed from the command line
9289 before it is added to file signatures,
9290 and the
9291 .B "$("
9292 and
9293 .B "$)"
9294 will be removed before the command is executed.
9295 For example, the command line:
9296
9297 .ES
9298 echo Last build occurred $( $TODAY $). > $TARGET
9299 .EE
9300
9301 .LP
9302 would execute the command:
9303
9304 .ES
9305 echo Last build occurred $TODAY. > $TARGET
9306 .EE
9307
9308 .LP
9309 but the command signature added to any target files would be:
9310
9311 .ES
9312 echo Last build occurred  . > $TARGET
9313 .EE
9314
9315 .SS Python Code Substitution
9316
9317 Any python code within
9318 .BR "${" - "}"
9319 pairs gets evaluated by python 'eval', with the python globals set to
9320 the current environment's set of construction variables.
9321 So in the following case:
9322 .ES
9323 env['COND'] = 0
9324 env.Command('foo.out', 'foo.in',
9325    '''echo ${COND==1 and 'FOO' or 'BAR'} > $TARGET''')
9326 .EE
9327 the command executed will be either
9328 .ES
9329 echo FOO > foo.out
9330 .EE
9331 or
9332 .ES
9333 echo BAR > foo.out
9334 .EE
9335 according to the current value of env['COND'] when the command is
9336 executed.  The evaluation occurs when the target is being
9337 built, not when the SConscript is being read.  So if env['COND'] is changed
9338 later in the SConscript, the final value will be used.
9339
9340 Here's a more interesting example.  Note that all of COND, FOO, and
9341 BAR are environment variables, and their values are substituted into
9342 the final command.  FOO is a list, so its elements are interpolated
9343 separated by spaces.
9344
9345 .ES
9346 env=Environment()
9347 env['COND'] = 0
9348 env['FOO'] = ['foo1', 'foo2']
9349 env['BAR'] = 'barbar'
9350 env.Command('foo.out', 'foo.in',
9351     'echo ${COND==1 and FOO or BAR} > $TARGET')
9352
9353 # Will execute this:
9354 #  echo foo1 foo2 > foo.out
9355 .EE
9356
9357 SCons uses the following rules when converting construction variables into
9358 command lines:
9359
9360 .IP String
9361 When the value is a string it is interpreted as a space delimited list of
9362 command line arguments.
9363
9364 .IP List
9365 When the value is a list it is interpreted as a list of command line
9366 arguments. Each element of the list is converted to a string.
9367
9368 .IP Other
9369 Anything that is not a list or string is converted to a string and
9370 interpreted as a single command line argument.
9371
9372 .IP Newline
9373 Newline characters (\\n) delimit lines. The newline parsing is done after
9374 all other parsing, so it is not possible for arguments (e.g. file names) to
9375 contain embedded newline characters. This limitation will likely go away in
9376 a future version of SCons.
9377
9378 .SS Scanner Objects
9379
9380 You can use the
9381 .B Scanner
9382 function to define
9383 objects to scan
9384 new file types for implicit dependencies.
9385 Scanner accepts the following arguments:
9386
9387 .IP function
9388 This can be either:
9389 1) a Python function that will process
9390 the Node (file)
9391 and return a list of strings (file names)
9392 representing the implicit
9393 dependencies found in the contents;
9394 or:
9395 2) a dictionary that maps keys
9396 (typically the file suffix, but see below for more discussion)
9397 to other Scanners that should be called.
9398
9399 If the argument is actually a Python function,
9400 the function must take three or four arguments:
9401
9402     def scanner_function(node, env, path):
9403
9404     def scanner_function(node, env, path, arg=None):
9405
9406 The
9407 .B node
9408 argument is the internal
9409 SCons node representing the file.
9410 Use
9411 .B str(node)
9412 to fetch the name of the file, and
9413 .B node.get_contents()
9414 to fetch contents of the file.
9415 Note that the file is
9416 .I not
9417 guaranteed to exist before the scanner is called,
9418 so the scanner function should check that
9419 if there's any chance that the scanned file
9420 might not exist
9421 (for example, if it's built from other files).
9422
9423 The
9424 .B env
9425 argument is the construction environment for the scan.
9426 Fetch values from it using the
9427 .B env.Dictionary()
9428 method.
9429
9430 The
9431 .B path
9432 argument is a tuple (or list)
9433 of directories that can be searched
9434 for files.
9435 This will usually be the tuple returned by the
9436 .B path_function
9437 argument (see below).
9438
9439 The
9440 .B arg
9441 argument is the argument supplied
9442 when the scanner was created, if any.
9443
9444 .IP name
9445 The name of the Scanner.
9446 This is mainly used
9447 to identify the Scanner internally.
9448
9449 .IP argument
9450 An optional argument that, if specified,
9451 will be passed to the scanner function
9452 (described above)
9453 and the path function
9454 (specified below).
9455
9456 .IP skeys
9457 An optional list that can be used to
9458 determine which scanner should be used for
9459 a given Node.
9460 In the usual case of scanning for file names,
9461 this argument will be a list of suffixes
9462 for the different file types that this
9463 Scanner knows how to scan.
9464 If the argument is a string,
9465 then it will be expanded
9466 into a list by the current environment.
9467
9468 .IP path_function
9469 A Python function that takes four or five arguments:
9470 a construction environment,
9471 a Node for the directory containing
9472 the SConscript file in which
9473 the first target was defined,
9474 a list of target nodes,
9475 a list of source nodes,
9476 and an optional argument supplied
9477 when the scanner was created.
9478 The
9479 .B path_function
9480 returns a tuple of directories
9481 that can be searched for files to be returned
9482 by this Scanner object.
9483 (Note that the
9484 .BR FindPathDirs ()
9485 function can be used to return a ready-made
9486 .B path_function
9487 for a given construction variable name,
9488 instead of having to write your own function from scratch.)
9489
9490 .IP node_class
9491 The class of Node that should be returned
9492 by this Scanner object.
9493 Any strings or other objects returned
9494 by the scanner function
9495 that are not of this class
9496 will be run through the
9497 .B node_factory
9498 function.
9499
9500 .IP node_factory
9501 A Python function that will take a string
9502 or other object
9503 and turn it into the appropriate class of Node
9504 to be returned by this Scanner object.
9505
9506 .IP scan_check
9507 An optional Python function that takes two arguments,
9508 a Node (file) and a construction environment,
9509 and returns whether the
9510 Node should, in fact,
9511 be scanned for dependencies.
9512 This check can be used to eliminate unnecessary
9513 calls to the scanner function when,
9514 for example, the underlying file
9515 represented by a Node does not yet exist.
9516
9517 .IP recursive
9518 An optional flag that
9519 specifies whether this scanner should be re-invoked
9520 on the dependency files returned by the scanner.
9521 When this flag is not set,
9522 the Node subsystem will
9523 only invoke the scanner on the file being scanned,
9524 and not (for example) also on the files
9525 specified by the #include lines
9526 in the file being scanned.
9527 .I recursive
9528 may be a callable function,
9529 in which case it will be called with a list of
9530 Nodes found and
9531 should return a list of Nodes
9532 that should be scanned recursively;
9533 this can be used to select a specific subset of
9534 Nodes for additional scanning.
9535
9536 Note that
9537 .B scons
9538 has a global
9539 .B SourceFileScanner
9540 object that is used by
9541 the
9542 .BR Object (),
9543 .BR SharedObject (),
9544 and
9545 .BR StaticObject ()
9546 builders to decide
9547 which scanner should be used
9548 for different file extensions.
9549 You can using the
9550 .BR SourceFileScanner.add_scanner ()
9551 method to add your own Scanner object
9552 to the
9553 .B scons
9554 infrastructure
9555 that builds target programs or
9556 libraries from a list of
9557 source files of different types:
9558
9559 .ES
9560 def xyz_scan(node, env, path):
9561     contents = node.get_text_contents()
9562     # Scan the contents and return the included files.
9563
9564 XYZScanner = Scanner(xyz_scan)
9565
9566 SourceFileScanner.add_scanner('.xyx', XYZScanner)
9567
9568 env.Program('my_prog', ['file1.c', 'file2.f', 'file3.xyz'])
9569 .EE
9570
9571 .SH SYSTEM-SPECIFIC BEHAVIOR
9572 SCons and its configuration files are very portable,
9573 due largely to its implementation in Python.
9574 There are, however, a few portability
9575 issues waiting to trap the unwary.
9576 .SS .C file suffix
9577 SCons handles the upper-case
9578 .B .C
9579 file suffix differently,
9580 depending on the capabilities of
9581 the underlying system.
9582 On a case-sensitive system
9583 such as Linux or UNIX,
9584 SCons treats a file with a
9585 .B .C
9586 suffix as a C++ source file.
9587 On a case-insensitive system
9588 such as Windows,
9589 SCons treats a file with a
9590 .B .C
9591 suffix as a C source file.
9592 .SS .F file suffix
9593 SCons handles the upper-case
9594 .B .F
9595 file suffix differently,
9596 depending on the capabilities of
9597 the underlying system.
9598 On a case-sensitive system
9599 such as Linux or UNIX,
9600 SCons treats a file with a
9601 .B .F
9602 suffix as a Fortran source file
9603 that is to be first run through
9604 the standard C preprocessor.
9605 On a case-insensitive system
9606 such as Windows,
9607 SCons treats a file with a
9608 .B .F
9609 suffix as a Fortran source file that should
9610 .I not
9611 be run through the C preprocessor.
9612 .SS Windows:  Cygwin Tools and Cygwin Python vs. Windows Pythons
9613 Cygwin supplies a set of tools and utilities
9614 that let users work on a
9615 Windows system using a more POSIX-like environment.
9616 The Cygwin tools, including Cygwin Python,
9617 do this, in part,
9618 by sharing an ability to interpret UNIX-like path names.
9619 For example, the Cygwin tools
9620 will internally translate a Cygwin path name
9621 like /cygdrive/c/mydir
9622 to an equivalent Windows pathname
9623 of C:/mydir (equivalent to C:\\mydir).
9624
9625 Versions of Python
9626 that are built for native Windows execution,
9627 such as the python.org and ActiveState versions,
9628 do not have the Cygwin path name semantics.
9629 This means that using a native Windows version of Python
9630 to build compiled programs using Cygwin tools
9631 (such as gcc, bison, and flex)
9632 may yield unpredictable results.
9633 "Mixing and matching" in this way
9634 can be made to work,
9635 but it requires careful attention to the use of path names
9636 in your SConscript files.
9637
9638 In practice, users can sidestep
9639 the issue by adopting the following rules:
9640 When using gcc,
9641 use the Cygwin-supplied Python interpreter
9642 to run SCons;
9643 when using Microsoft Visual C/C++
9644 (or some other Windows compiler)
9645 use the python.org or ActiveState version of Python
9646 to run SCons.
9647 .SS Windows:  scons.bat file
9648 On Windows systems,
9649 SCons is executed via a wrapper
9650 .B scons.bat
9651 file.
9652 This has (at least) two ramifications:
9653
9654 First, Windows command-line users
9655 that want to use variable assignment
9656 on the command line
9657 may have to put double quotes
9658 around the assignments:
9659
9660 .ES
9661 scons "FOO=BAR" "BAZ=BLEH"
9662 .EE
9663
9664 Second, the Cygwin shell does not
9665 recognize this file as being the same
9666 as an
9667 .B scons
9668 command issued at the command-line prompt.
9669 You can work around this either by
9670 executing
9671 .B scons.bat
9672 from the Cygwin command line,
9673 or by creating a wrapper shell
9674 script named
9675 .B scons .
9676
9677 .SS MinGW
9678
9679 The MinGW bin directory must be in your PATH environment variable or the
9680 PATH variable under the ENV construction variable for SCons
9681 to detect and use the MinGW tools. When running under the native Windows
9682 Python interpreter, SCons will prefer the MinGW tools over the Cygwin
9683 tools, if they are both installed, regardless of the order of the bin
9684 directories in the PATH variable. If you have both MSVC and MinGW
9685 installed and you want to use MinGW instead of MSVC,
9686 then you must explictly tell SCons to use MinGW by passing
9687
9688 .ES
9689 tools=['mingw']
9690 .EE
9691
9692 to the Environment() function, because SCons will prefer the MSVC tools
9693 over the MinGW tools.
9694
9695 .SH EXAMPLES
9696
9697 To help you get started using SCons,
9698 this section contains a brief overview of some common tasks.
9699
9700 .SS Basic Compilation From a Single Source File
9701
9702 .ES
9703 env = Environment()
9704 env.Program(target = 'foo', source = 'foo.c')
9705 .EE
9706
9707 Note:  Build the file by specifying
9708 the target as an argument
9709 ("scons foo" or "scons foo.exe").
9710 or by specifying a dot ("scons .").
9711
9712 .SS Basic Compilation From Multiple Source Files
9713
9714 .ES
9715 env = Environment()
9716 env.Program(target = 'foo', source = Split('f1.c f2.c f3.c'))
9717 .EE
9718
9719 .SS Setting a Compilation Flag
9720
9721 .ES
9722 env = Environment(CCFLAGS = '-g')
9723 env.Program(target = 'foo', source = 'foo.c')
9724 .EE
9725
9726 .SS Search The Local Directory For .h Files
9727
9728 Note:  You do
9729 .I not
9730 need to set CCFLAGS to specify -I options by hand.
9731 SCons will construct the right -I options from CPPPATH.
9732
9733 .ES
9734 env = Environment(CPPPATH = ['.'])
9735 env.Program(target = 'foo', source = 'foo.c')
9736 .EE
9737
9738 .SS Search Multiple Directories For .h Files
9739
9740 .ES
9741 env = Environment(CPPPATH = ['include1', 'include2'])
9742 env.Program(target = 'foo', source = 'foo.c')
9743 .EE
9744
9745 .SS Building a Static Library
9746
9747 .ES
9748 env = Environment()
9749 env.StaticLibrary(target = 'foo', source = Split('l1.c l2.c'))
9750 env.StaticLibrary(target = 'bar', source = ['l3.c', 'l4.c'])
9751 .EE
9752
9753 .SS Building a Shared Library
9754
9755 .ES
9756 env = Environment()
9757 env.SharedLibrary(target = 'foo', source = ['l5.c', 'l6.c'])
9758 env.SharedLibrary(target = 'bar', source = Split('l7.c l8.c'))
9759 .EE
9760
9761 .SS Linking a Local Library Into a Program
9762
9763 .ES
9764 env = Environment(LIBS = 'mylib', LIBPATH = ['.'])
9765 env.Library(target = 'mylib', source = Split('l1.c l2.c'))
9766 env.Program(target = 'prog', source = ['p1.c', 'p2.c'])
9767 .EE
9768
9769 .SS Defining Your Own Builder Object
9770
9771 Notice that when you invoke the Builder,
9772 you can leave off the target file suffix,
9773 and SCons will add it automatically.
9774
9775 .ES
9776 bld = Builder(action = 'pdftex < $SOURCES > $TARGET'
9777               suffix = '.pdf',
9778               src_suffix = '.tex')
9779 env = Environment(BUILDERS = {'PDFBuilder' : bld})
9780 env.PDFBuilder(target = 'foo.pdf', source = 'foo.tex')
9781
9782 # The following creates "bar.pdf" from "bar.tex"
9783 env.PDFBuilder(target = 'bar', source = 'bar')
9784 .EE
9785
9786 Note also that the above initialization
9787 overwrites the default Builder objects,
9788 so the Environment created above
9789 can not be used call Builders like env.Program(),
9790 env.Object(), env.StaticLibrary(), etc.
9791
9792 .SS Adding Your Own Builder Object to an Environment
9793
9794 .ES
9795 bld = Builder(action = 'pdftex < $SOURCES > $TARGET'
9796               suffix = '.pdf',
9797               src_suffix = '.tex')
9798 env = Environment()
9799 env.Append(BUILDERS = {'PDFBuilder' : bld})
9800 env.PDFBuilder(target = 'foo.pdf', source = 'foo.tex')
9801 env.Program(target = 'bar', source = 'bar.c')
9802 .EE
9803
9804 You also can use other Pythonic techniques to add
9805 to the BUILDERS construction variable, such as:
9806
9807 .ES
9808 env = Environment()
9809 env['BUILDERS]['PDFBuilder'] = bld
9810 .EE
9811
9812 .SS Defining Your Own Scanner Object
9813
9814 The following example shows an extremely simple scanner (the
9815 .BR kfile_scan ()
9816 function)
9817 that doesn't use a search path at all
9818 and simply returns the
9819 file names present on any
9820 .B include
9821 lines in the scanned file.
9822 This would implicitly assume that all included
9823 files live in the top-level directory:
9824
9825 .ES
9826 import re
9827
9828 '\" Note:  the \\ in the following are for the benefit of nroff/troff,
9829 '\" not inappropriate doubled escape characters within the r'' raw string.
9830 include_re = re.compile(r'^include\\s+(\\S+)$', re.M)
9831
9832 def kfile_scan(node, env, path, arg):
9833     contents = node.get_text_contents()
9834     includes = include_re.findall(contents)
9835     return includes
9836
9837 kscan = Scanner(name = 'kfile',
9838                 function = kfile_scan,
9839                 argument = None,
9840                 skeys = ['.k'])
9841 scanners = Environment().Dictionary('SCANNERS')
9842 env = Environment(SCANNERS = scanners + [kscan])
9843
9844 env.Command('foo', 'foo.k', 'kprocess < $SOURCES > $TARGET')
9845
9846 bar_in = File('bar.in')
9847 env.Command('bar', bar_in, 'kprocess $SOURCES > $TARGET')
9848 bar_in.target_scanner = kscan
9849 .EE
9850
9851 Here is a similar but more complete example that searches
9852 a path of directories
9853 (specified as the
9854 .B MYPATH
9855 construction variable)
9856 for files that actually exist:
9857
9858 .ES
9859 include_re = re.compile(r'^include\\s+(\\S+)$', re.M)
9860
9861 def my_scan(node, env, path, arg):
9862    contents = node.get_text_contents()
9863    includes = include_re.findall(contents)
9864    if includes == []:
9865         return []
9866     results = []
9867     for inc in includes:
9868         for dir in path:
9869             file = dir + os.sep + inc
9870             if os.path.exists(file):
9871                 results.append(file)
9872                 break
9873     return results
9874
9875 scanner = Scanner(name = 'myscanner',
9876                  function = my_scan,
9877                  argument = None,
9878                  skeys = ['.x'],
9879                  path_function = FindPathDirs('MYPATH'),
9880                  )
9881 scanners = Environment().Dictionary('SCANNERS')
9882 env = Environment(SCANNERS = scanners + [scanner])
9883 .EE
9884
9885 The
9886 .BR FindPathDirs ()
9887 function used in the previous example returns a function
9888 (actually a callable Python object)
9889 that will return a list of directories
9890 specified in the
9891 .B $MYPATH
9892 construction variable.
9893 If you need to customize how the search path is derived,
9894 you would provide your own
9895 .B path_function
9896 argument when creating the Scanner object,
9897 as follows:
9898
9899 .ES
9900 # MYPATH is a list of directories to search for files in
9901 def pf(env, dir, target, source, arg):
9902     top_dir = Dir('#').abspath
9903     results = []
9904     if env.has_key('MYPATH'):
9905         for p in env['MYPATH']:
9906             results.append(top_dir + os.sep + p)
9907     return results
9908
9909 scanner = Scanner(name = 'myscanner',
9910                  function = my_scan,
9911                  argument = None,
9912                  skeys = ['.x'],
9913                  path_function = pf,
9914                  )
9915 .EE
9916
9917 .SS Creating a Hierarchical Build
9918
9919 Notice that the file names specified in a subdirectory's
9920 SConscript
9921 file are relative to that subdirectory.
9922
9923 .ES
9924 SConstruct:
9925
9926     env = Environment()
9927     env.Program(target = 'foo', source = 'foo.c')
9928
9929     SConscript('sub/SConscript')
9930
9931 sub/SConscript:
9932
9933     env = Environment()
9934     # Builds sub/foo from sub/foo.c
9935     env.Program(target = 'foo', source = 'foo.c')
9936
9937     SConscript('dir/SConscript')
9938
9939 sub/dir/SConscript:
9940
9941     env = Environment()
9942     # Builds sub/dir/foo from sub/dir/foo.c
9943     env.Program(target = 'foo', source = 'foo.c')
9944 .EE
9945
9946 .SS Sharing Variables Between SConscript Files
9947
9948 You must explicitly Export() and Import() variables that
9949 you want to share between SConscript files.
9950
9951 .ES
9952 SConstruct:
9953
9954     env = Environment()
9955     env.Program(target = 'foo', source = 'foo.c')
9956
9957     Export("env")
9958     SConscript('subdirectory/SConscript')
9959
9960 subdirectory/SConscript:
9961
9962     Import("env")
9963     env.Program(target = 'foo', source = 'foo.c')
9964 .EE
9965
9966 .SS Building Multiple Variants From the Same Source
9967
9968 Use the variant_dir keyword argument to
9969 the SConscript function to establish
9970 one or more separate variant build directory trees
9971 for a given source directory:
9972
9973 .ES
9974 SConstruct:
9975
9976     cppdefines = ['FOO']
9977     Export("cppdefines")
9978     SConscript('src/SConscript', variant_dir='foo')
9979
9980     cppdefines = ['BAR']
9981     Export("cppdefines")
9982     SConscript('src/SConscript', variant_dir='bar')
9983
9984 src/SConscript:
9985
9986     Import("cppdefines")
9987     env = Environment(CPPDEFINES = cppdefines)
9988     env.Program(target = 'src', source = 'src.c')
9989 .EE
9990
9991 Note the use of the Export() method
9992 to set the "cppdefines" variable to a different
9993 value each time we call the SConscript function.
9994
9995 .SS Hierarchical Build of Two Libraries Linked With a Program
9996
9997 .ES
9998 SConstruct:
9999
10000     env = Environment(LIBPATH = ['#libA', '#libB'])
10001     Export('env')
10002     SConscript('libA/SConscript')
10003     SConscript('libB/SConscript')
10004     SConscript('Main/SConscript')
10005
10006 libA/SConscript:
10007
10008     Import('env')
10009     env.Library('a', Split('a1.c a2.c a3.c'))
10010
10011 libB/SConscript:
10012
10013     Import('env')
10014     env.Library('b', Split('b1.c b2.c b3.c'))
10015
10016 Main/SConscript:
10017
10018     Import('env')
10019     e = env.Copy(LIBS = ['a', 'b'])
10020     e.Program('foo', Split('m1.c m2.c m3.c'))
10021 .EE
10022
10023 The '#' in the LIBPATH directories specify that they're relative to the
10024 top-level directory, so they don't turn into "Main/libA" when they're
10025 used in Main/SConscript.
10026
10027 Specifying only 'a' and 'b' for the library names
10028 allows SCons to append the appropriate library
10029 prefix and suffix for the current platform
10030 (for example, 'liba.a' on POSIX systems,
10031 \&'a.lib' on Windows).
10032
10033 .SS Customizing construction variables from the command line.
10034
10035 The following would allow the C compiler to be specified on the command
10036 line or in the file custom.py.
10037
10038 .ES
10039 vars = Variables('custom.py')
10040 vars.Add('CC', 'The C compiler.')
10041 env = Environment(variables=vars)
10042 Help(vars.GenerateHelpText(env))
10043 .EE
10044
10045 The user could specify the C compiler on the command line:
10046
10047 .ES
10048 scons "CC=my_cc"
10049 .EE
10050
10051 or in the custom.py file:
10052
10053 .ES
10054 CC = 'my_cc'
10055 .EE
10056
10057 or get documentation on the options:
10058
10059 .ES
10060 $ scons -h
10061
10062 CC: The C compiler.
10063     default: None
10064     actual: cc
10065
10066 .EE
10067
10068 .SS Using Microsoft Visual C++ precompiled headers
10069
10070 Since windows.h includes everything and the kitchen sink, it can take quite
10071 some time to compile it over and over again for a bunch of object files, so
10072 Microsoft provides a mechanism to compile a set of headers once and then
10073 include the previously compiled headers in any object file. This
10074 technology is called precompiled headers. The general recipe is to create a
10075 file named "StdAfx.cpp" that includes a single header named "StdAfx.h", and
10076 then include every header you want to precompile in "StdAfx.h", and finally
10077 include "StdAfx.h" as the first header in all the source files you are
10078 compiling to object files. For example:
10079
10080 StdAfx.h:
10081 .ES
10082 #include <windows.h>
10083 #include <my_big_header.h>
10084 .EE
10085
10086 StdAfx.cpp:
10087 .ES
10088 #include <StdAfx.h>
10089 .EE
10090
10091 Foo.cpp:
10092 .ES
10093 #include <StdAfx.h>
10094
10095 /* do some stuff */
10096 .EE
10097
10098 Bar.cpp:
10099 .ES
10100 #include <StdAfx.h>
10101
10102 /* do some other stuff */
10103 .EE
10104
10105 SConstruct:
10106 .ES
10107 env=Environment()
10108 env['PCHSTOP'] = 'StdAfx.h'
10109 env['PCH'] = env.PCH('StdAfx.cpp')[0]
10110 env.Program('MyApp', ['Foo.cpp', 'Bar.cpp'])
10111 .EE
10112
10113 For more information see the document for the PCH builder, and the PCH and
10114 PCHSTOP construction variables. To learn about the details of precompiled
10115 headers consult the MSDN documention for /Yc, /Yu, and /Yp.
10116
10117 .SS Using Microsoft Visual C++ external debugging information
10118
10119 Since including debugging information in programs and shared libraries can
10120 cause their size to increase significantly, Microsoft provides a mechanism
10121 for including the debugging information in an external file called a PDB
10122 file. SCons supports PDB files through the PDB construction
10123 variable.
10124
10125 SConstruct:
10126 .ES
10127 env=Environment()
10128 env['PDB'] = 'MyApp.pdb'
10129 env.Program('MyApp', ['Foo.cpp', 'Bar.cpp'])
10130 .EE
10131
10132 For more information see the document for the PDB construction variable.
10133
10134 .SH ENVIRONMENT
10135
10136 .IP SCONS_LIB_DIR
10137 Specifies the directory that contains the SCons Python module directory
10138 (e.g. /home/aroach/scons-src-0.01/src/engine).
10139
10140 .IP SCONSFLAGS
10141 A string of options that will be used by scons in addition to those passed
10142 on the command line.
10143
10144 .SH "SEE ALSO"
10145 .B scons
10146 User Manual,
10147 .B scons
10148 Design Document,
10149 .B scons
10150 source code.
10151
10152 .SH AUTHORS
10153 Steven Knight <knight@baldmt.com>
10154 .br
10155 Anthony Roach <aroach@electriceyeball.com>
10156