Merged revisions 1441-1539 via svnmerge from
[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 .\" ES - Example Start - indents and turns off line fill
25 .de ES
26 .RS
27 .nf
28 ..
29 .\" EE - Example End - ends indent and turns line fill back on
30 .de EE
31 .fi
32 .RE
33 ..
34 .TH SCONS 1 "December 2005"
35 .SH NAME
36 scons \- a software construction tool
37 .SH SYNOPSIS
38 .B scons
39 [
40 .IR options ...
41 ]
42 [
43 .IR name = val ...
44 ]
45 [
46 .IR targets ...
47 ]
48 .SH DESCRIPTION
49
50 The 
51 .B scons 
52 utility builds software (or other files) by determining which
53 component pieces must be rebuilt and executing the necessary commands to
54 rebuild them.
55
56 By default, 
57 .B scons 
58 searches for a file named 
59 .IR SConstruct ,
60 .IR Sconstruct ,
61 or
62 .I sconstruct
63 (in that order) in the current directory and reads its
64 configuration from the first file found.
65 An alternate file name may be
66 specified via the 
67 .B -f
68 option.
69
70 The
71 .I SConstruct
72 file can specify subsidiary
73 configuration files using the
74 .B SConscript()
75 function.
76 By convention,
77 these subsidiary files are named
78 .IR SConscript ,
79 although any name may be used.
80 (Because of this naming convention,
81 the term "SConscript files"
82 is sometimes used to refer
83 generically to all
84 .B scons
85 configuration files,
86 regardless of actual file name.)
87
88 The configuration files
89 specify the target files to be built, and
90 (optionally) the rules to build those targets.  Reasonable default
91 rules exist for building common software components (executable
92 programs, object files, libraries), so that for most software
93 projects, only the target and input files need be specified.
94
95 .B scons
96 reads and executes the SConscript files as Python scripts,
97 so you may use normal Python scripting capabilities
98 (such as flow control, data manipulation, and imported Python libraries)
99 to handle complicated build situations.
100 .BR scons ,
101 however, reads and executes all of the SConscript files
102 .I before
103 it begins building any targets.
104 To make this obvious,
105 .B scons
106 prints the following messages about what it is doing:
107
108 .ES
109 $ scons foo.out
110 scons: Reading SConscript files ...
111 scons: done reading SConscript files.
112 scons: Building targets  ...
113 cp foo.in foo.out
114 scons: done building targets.
115 $
116 .EE
117
118 The status messages
119 (everything except the line that reads "cp foo.in foo.out")
120 may be suppressed using the
121 .B -Q
122 option.
123
124 .B scons
125 does not automatically propagate
126 the external environment used to execute
127 .B scons
128 to the commands used to build target files.
129 This is so that builds will be guaranteed
130 repeatable regardless of the environment
131 variables set at the time
132 .B scons
133 is invoked.
134 This also means that if the compiler or other commands
135 that you want to use to build your target files
136 are not in standard system locations,
137 .B scons
138 will not find them unless
139 you explicitly set the PATH
140 to include those locations.
141 Whenever you create an
142 .B scons
143 construction environment,
144 you can propagate the value of PATH
145 from your external environment as follows:
146
147 .ES
148 import os
149 env = Environment(ENV = {'PATH' : os.environ['PATH']})
150 .EE
151
152 Similarly, if the commands use external environment variables
153 like $PATH, $HOME, $JAVA_HOME, $LANG, $SHELL, $TERM, etc.,
154 these variables can also be explicitly propagated:
155
156 .ES
157 import os
158 env = Environment(ENV = {'PATH' : os.environ['PATH'],
159                          'HOME' : os.environ['HOME']})
160 .EE
161
162 Or you may explicitly propagate the invoking user's
163 complete external environment:
164
165 .ES
166 import os
167 env = Environment(ENV = os.environ['PATH'])
168 .EE
169
170 This comes at the expense of making your build
171 dependent on the user's environment being set correctly,
172 but it may be more convenient for many configurations.
173
174 .B scons
175 can scan known input files automatically for dependency
176 information (for example, #include statements
177 in C or C++ files) and will rebuild dependent files appropriately
178 whenever any "included" input file changes. 
179 .B scons
180 supports the
181 ability to define new scanners for unknown input file types.
182
183 .B scons
184 knows how to fetch files automatically from
185 SCCS or RCS subdirectories
186 using SCCS, RCS or BitKeeper.
187
188 .B scons
189 is normally executed in a top-level directory containing a
190 .I SConstruct
191 file, optionally specifying
192 as command-line arguments
193 the target file or files to be built.
194
195 By default, the command
196
197 .ES
198 scons
199 .EE
200
201 will build all target files in or below the current directory.
202 Explicit default targets
203 (to be built when no targets are specified on the command line)
204 may be defined the SConscript file(s)
205 using the
206 .B Default()
207 function, described below.
208
209 Even when
210 .B Default()
211 targets are specified in the SConscript file(s),
212 all target files in or below the current directory
213 may be built by explicitly specifying
214 the current directory (.)
215 as a command-line target:
216
217 .ES
218 scons .
219 .EE
220
221 Building all target files,
222 including any files outside of the current directory,
223 may be specified by supplying a command-line target
224 of the root directory (on POSIX systems):
225
226 .ES
227 scons /
228 .EE
229
230 or the path name(s) of the volume(s) in which all the targets
231 should be built (on Windows systems):
232
233 .ES
234 scons C:\\ D:\\
235 .EE
236
237 To build only specific targets,
238 supply them as command-line arguments:
239
240 .ES
241 scons foo bar
242 .EE
243
244 in which case only the specified targets will be built
245 (along with any derived files on which they depend).
246
247 Specifying "cleanup" targets in SConscript files is not
248 necessary.  The 
249 .B -c
250 flag removes all files
251 necessary to build the specified target:
252
253 .ES
254 scons -c .
255 .EE
256
257 to remove all target files, or:
258
259 .ES
260 scons -c build export
261 .EE
262
263 to remove target files under build and export.
264 Additional files or directories to remove can be specified using the
265 .BR Clean()
266 function.
267 Conversely, targets that would normally be removed by the
268 .B -c
269 invocation
270 can be prevented from being removed by using the
271 .BR NoClean ()
272 function.
273
274 A subset of a hierarchical tree may be built by
275 remaining at the top-level directory (where the 
276 .I SConstruct
277 file lives) and specifying the subdirectory as the target to be
278 built:
279
280 .ES
281 scons src/subdir
282 .EE
283
284 or by changing directory and invoking scons with the
285 .B -u
286 option, which traverses up the directory
287 hierarchy until it finds the 
288 .I SConstruct
289 file, and then builds
290 targets relatively to the current subdirectory:
291
292 .ES
293 cd src/subdir
294 scons -u .
295 .EE
296
297 .B scons
298 supports building multiple targets in parallel via a
299 .B -j
300 option that takes, as its argument, the number
301 of simultaneous tasks that may be spawned:
302
303 .ES
304 scons -j 4
305 .EE
306
307 builds four targets in parallel, for example.
308
309 .B scons
310 can maintain a cache of target (derived) files that can
311 be shared between multiple builds.  When caching is enabled in a
312 SConscript file, any target files built by 
313 .B scons
314 will be copied
315 to the cache.  If an up-to-date target file is found in the cache, it
316 will be retrieved from the cache instead of being rebuilt locally.
317 Caching behavior may be disabled and controlled in other ways by the
318 .BR --cache-force , 
319 .BR --cache-disable ,
320 and
321 .B --cache-show
322 command-line options.  The
323 .B --random
324 option is useful to prevent multiple builds
325 from trying to update the cache simultaneously.
326
327 Values of variables to be passed to the SConscript file(s)
328 may be specified on the command line:
329
330 .ES
331 scons debug=1 .
332 .EE
333
334 These variables are available in SConscript files
335 through the ARGUMENTS dictionary,
336 and can be used in the SConscript file(s) to modify
337 the build in any way:
338
339 .ES
340 if ARGUMENTS.get('debug', 0):
341     env = Environment(CCFLAGS = '-g')
342 else:
343     env = Environment()
344 .EE
345
346 The command-line variable arguments are also available
347 in the ARGLIST list,
348 indexed by their order on the command line.
349 This allows you to process them in order rather than by name,
350 if necessary.
351 ARGLIST[0] returns a tuple
352 containing (argname, argvalue).
353 A Python exception is thrown if you
354 try to access a list member that
355 does not exist.
356
357 .B scons
358 requires Python version 1.5.2 or later.
359 There should be no other dependencies or requirements to run
360 .B scons.
361
362 .\" The following paragraph reflects the default tool search orders
363 .\" currently in SCons/Tool/__init__.py.  If any of those search orders
364 .\" change, this documentation should change, too.
365 By default,
366 .B scons
367 knows how to search for available programming tools
368 on various systems.
369 On Windows systems,
370 .B scons
371 searches in order for the
372 Microsoft Visual C++ tools,
373 the MinGW tool chain,
374 the Intel compiler tools,
375 and the PharLap ETS compiler.
376 On OS/2 systems,
377 .B scons
378 searches in order for the 
379 OS/2 compiler,
380 the GCC tool chain,
381 and the Microsoft Visual C++ tools,
382 On SGI IRIX, IBM AIX, Hewlett Packard HP-UX, and Sun Solaris systems,
383 .B scons
384 searches for the native compiler tools
385 (MIPSpro, Visual Age, aCC, and Forte tools respectively)
386 and the GCC tool chain.
387 On all other platforms,
388 including POSIX (Linux and UNIX) platforms,
389 .B scons
390 searches in order
391 for the GCC tool chain,
392 the Microsoft Visual C++ tools,
393 and the Intel compiler tools.
394 You may, of course, override these default values
395 by appropriate configuration of
396 Environment construction variables.
397
398 .SH OPTIONS
399 In general, 
400 .B scons 
401 supports the same command-line options as GNU
402 .BR make , 
403 and many of those supported by 
404 .BR cons .
405
406 .TP
407 -b
408 Ignored for compatibility with non-GNU versions of
409 .BR make.
410
411 .TP
412 -c, --clean, --remove
413 Clean up by removing all target files for which a construction
414 command is specified.
415 Also remove any files or directories associated to the construction command
416 using the
417 .BR Clean ()
418 function.
419 Will not remove any targets specified by the
420 .BR NoClean ()
421 function.
422
423 .TP
424 --cache-disable, --no-cache
425 Disable the derived-file caching specified by
426 .BR CacheDir ().
427 .B scons
428 will neither retrieve files from the cache
429 nor copy files to the cache.
430
431 .TP
432 --cache-force, --cache-populate
433 When using
434 .BR CacheDir (),
435 populate a cache by copying any already-existing, up-to-date
436 derived files to the cache,
437 in addition to files built by this invocation.
438 This is useful to populate a new cache with
439 all the current derived files,
440 or to add to the cache any derived files
441 recently built with caching disabled via the
442 .B --cache-disable
443 option.
444
445 .TP
446 --cache-show
447 When using
448 .BR CacheDir ()
449 and retrieving a derived file from the cache,
450 show the command
451 that would have been executed to build the file,
452 instead of the usual report,
453 "Retrieved `file' from cache."
454 This will produce consistent output for build logs,
455 regardless of whether a target
456 file was rebuilt or retrieved from the cache.
457
458 .TP
459 .RI --config= mode
460 This specifies how the
461 .B Configure
462 call should use or generate the
463 results of configuration tests.
464 The option should be specified from
465 among the following choices:
466
467 .TP
468 --config=auto
469 scons will use its normal dependency mechanisms
470 to decide if a test must be rebuilt or not.
471 This saves time by not running the same configuration tests
472 every time you invoke scons,
473 but will overlook changes in system header files
474 or external commands (such as compilers)
475 if you don't specify those dependecies explicitly.
476 This is the default behavior.
477
478 .TP
479 --config=force
480 If this option is specified,
481 all configuration tests will be re-run
482 regardless of whether the
483 cached results are out of date.
484 This can be used to explicitly
485 force the configuration tests to be updated
486 in response to an otherwise unconfigured change
487 in a system header file or compiler.
488
489 .TP
490 --config=cache
491 If this option is specified,
492 no configuration tests will be rerun
493 and all results will be taken from cache.
494 Note that scons will still consider it an error
495 if --config=cache is specified
496 and a necessary test does not
497 yet have any results in the cache.
498
499 .TP 
500 .RI "-C" " directory" ",  --directory=" directory
501 Change to the specified 
502 .I directory
503 before searching for the 
504 .IR SConstruct ,
505 .IR Sconstruct ,
506 or
507 .I sconstruct
508 file, or doing anything
509 else.  Multiple 
510 .B -C
511 options are interpreted
512 relative to the previous one, and the right-most
513 .B -C
514 option wins. (This option is nearly
515 equivalent to 
516 .BR "-f directory/SConstruct" ,
517 except that it will search for
518 .IR SConstruct ,
519 .IR Sconstruct , 
520 or
521 .I sconstruct
522 in the specified directory.)
523
524 .\" .TP
525 .\" -d
526 .\" Display dependencies while building target files.  Useful for
527 .\" figuring out why a specific file is being rebuilt, as well as
528 .\" general debugging of the build process.
529
530 .TP
531 -D
532 Works exactly the same way as the
533 .B -u
534 option except for the way default targets are handled.
535 When this option is used and no targets are specified on the command line,
536 all default targets are built, whether or not they are below the current
537 directory.
538
539 .TP
540 .RI --debug= type
541 Debug the build process.
542 .I type
543 specifies what type of debugging:
544
545 .TP
546 --debug=count
547 Print how many objects are created
548 of the various classes used internally by SCons
549 before and after reading the SConscript files
550 and before and after building targets.
551 This only works when run under Python 2.1 or later.
552
553 .TP
554 --debug=dtree
555 Print the dependency tree
556 after each top-level target is built. This prints out only derived files.
557
558 .TP
559 --debug=explain
560 Print an explanation of precisely why
561 .B scons
562 is deciding to (re-)build any targets.
563 (Note:  this does not print anything
564 for targets that are
565 .I not
566 rebuilt.)
567
568 .TP
569 --debug=findlibs
570 Instruct the scanner that searches for libraries
571 to print a message about each potential library
572 name it is searching for,
573 and about the actual libraries it finds.
574
575 .TP
576 --debug=includes
577 Print the include tree after each top-level target is built. 
578 This is generally used to find out what files are included by the sources
579 of a given derived file:
580
581 .ES
582 $ scons --debug=includes foo.o
583 .EE
584
585 .TP
586 --debug=memoizer
587 Prints a summary of hits and misses in the Memoizer,
588 the internal SCons subsystem for caching
589 various values in memory instead of
590 recomputing them each time they're needed.
591
592 .TP
593 --debug=memory
594 Prints how much memory SCons uses
595 before and after reading the SConscript files
596 and before and after building targets.
597
598 .TP
599 --debug=nomemoizer
600 Disables use of the Memoizer,
601 the internal SCons subsystem for caching
602 various values in memory instead of
603 recomputing them each time they're needed.
604 This provides more accurate counts of the
605 underlying function calls in the 
606 Python profiler output when using the
607 .RI --profile=
608 option.
609 (When the Memoizer is used,
610 the profiler counts all
611 memoized functions as being executed
612 by the Memoizer's wrapper calls.)
613
614 .TP
615 --debug=objects
616 Prints a list of the various objects
617 of the various classes used internally by SCons.
618 This only works when run under Python 2.1 or later.
619
620 .TP
621 --debug=pdb
622 Re-run SCons under the control of the
623 .RI pdb
624 Python debugger.
625
626 .TP
627 --debug=presub
628 Print the raw command line used to build each target
629 before the construction environment variables are substituted.
630 Also shows which targets are being built by this command.
631 Output looks something like this:
632 .ES
633 $ scons --debug=presub
634 Building myprog.o with action(s):
635   $SHCC $SHCCFLAGS $CPPFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES
636 ...
637 .EE
638
639 .TP
640 --debug=stacktrace
641 Prints an internal Python stack trace
642 when encountering an otherwise unexplained error.
643
644 .TP
645 --debug=stree
646 Print the dependency tree along with status information.  This is the
647 same as the debug=tree option, but additional status information is
648 provided for each node in the tree.
649
650 .TP
651 --debug=time
652 Prints various time profiling information: the time spent
653 executing each build command, the total build time, the total time spent
654 executing build commands, the total time spent executing SConstruct and
655 SConscript files, and the total time spent executing SCons itself.
656
657 .TP
658 --debug=tree
659 Print the dependency tree
660 after each top-level target is built. This prints out the complete
661 dependency tree including implicit dependencies and ignored
662 dependencies.
663
664 .TP
665 .RI --diskcheck= types
666 Enable specific checks for
667 whether or not there is a file on disk
668 where the SCons configuration expects a directory
669 (or vice versa),
670 and whether or not RCS or SCCS sources exist
671 when searching for source and include files.
672 The
673 .I types
674 argument can be set to:
675 .BR all ,
676 to enable all checks explicitly
677 (the default behavior);
678 .BR none ,
679 to disable all such checks;
680 .BR match ,
681 to check that files and directories on disk
682 match SCons' expected configuration;
683 .BR rcs ,
684 to check for the existence of an RCS source
685 for any missing source or include files;
686 .BR sccs ,
687 to check for the existence of an SCCS source
688 for any missing source or include files.
689 Multiple checks can be specified separated by commas;
690 for example,
691 .B --diskcheck=sccs,rcs
692 would still check for SCCS and RCS sources,
693 but disable the check for on-disk matches of files and directories.
694 Disabling some or all of these checks
695 can provide a performance boost for large configurations,
696 or when the configuration will check for files and/or directories
697 across networked or shared file systems,
698 at the slight increased risk of an incorrect build
699 or of not handling errors gracefully
700 (if include files really should be
701 found in SCCS or RCS, for example,
702 or if a file really does exist
703 where the SCons configuration expects a directory).
704
705 .\" .TP
706 .\" -e, --environment-overrides
707 .\" Variables from the execution environment override construction
708 .\" variables from the SConscript files.
709
710 .TP
711 .RI -f " file" ", --file=" file ", --makefile=" file ", --sconstruct=" file
712 Use 
713 .I file 
714 as the initial SConscript file.
715
716 .TP 
717 -h, --help
718 Print a local help message for this build, if one is defined in
719 the SConscript file(s), plus a line that describes the 
720 .B -H
721 option for command-line option help.  If no local help message
722 is defined, prints the standard help message about command-line
723 options.  Exits after displaying the appropriate message.
724
725 .TP
726 -H, --help-options
727 Print the standard help message about command-line options and
728 exit.
729
730 .TP
731 -i, --ignore-errors
732 Ignore all errors from commands executed to rebuild files.
733
734 .TP 
735 .RI -I " directory" ", --include-dir=" directory
736 Specifies a 
737 .I directory
738 to search for
739 imported Python modules.  If several 
740 .B -I
741 options
742 are used, the directories are searched in the order specified.
743
744 .TP
745 --implicit-cache
746 Cache implicit dependencies. This can cause 
747 .B scons
748 to miss changes in the implicit dependencies in cases where a new implicit
749 dependency is added earlier in the implicit dependency search path
750 (e.g. CPPPATH) than a current implicit dependency with the same name.
751
752 .TP
753 --implicit-deps-changed
754 Force SCons to ignore the cached implicit dependencies. This causes the
755 implicit dependencies to be rescanned and recached. This implies
756 .BR --implicit-cache .
757
758 .TP
759 --implicit-deps-unchanged
760 Force SCons to ignore changes in the implicit dependencies.
761 This causes cached implicit dependencies to always be used.
762 This implies 
763 .BR --implicit-cache .
764
765 .TP
766 .RI -j " N" ", --jobs=" N
767 Specifies the number of jobs (commands) to run simultaneously.
768 If there is more than one 
769 .B -j 
770 option, the last one is effective.
771 .\" ??? If the 
772 .\" .B -j 
773 .\" option
774 .\" is specified without an argument,
775 .\" .B scons 
776 .\" will not limit the number of
777 .\" simultaneous jobs.
778
779 .TP
780 -k, --keep-going
781 Continue as much as possible after an error.  The target that
782 failed and those that depend on it will not be remade, but other
783 targets specified on the command line will still be processed.
784
785 .\" .TP
786 .\" .RI  -l " N" ", --load-average=" N ", --max-load=" N
787 .\" No new jobs (commands) will be started if
788 .\" there are other jobs running and the system load
789 .\" average is at least 
790 .\" .I N
791 .\" (a floating-point number).
792
793 .TP
794 .RI --duplicate= ORDER
795 There are three ways to duplicate files in a build tree: hard links,
796 soft (symbolic) links and copies. The default behaviour of SCons is to 
797 prefer hard links to soft links to copies. You can specify different
798 behaviours with this option.
799 .IR ORDER 
800 must be one of 
801 .IR hard-soft-copy
802 (the default),
803 .IR soft-hard-copy ,
804 .IR hard-copy ,
805 .IR soft-copy
806 or
807 .IR copy .
808 SCons will attempt to duplicate files using
809 the mechanisms in the specified order.
810
811 .\"
812 .\" .TP
813 .\" --list-derived
814 .\" List derived files (targets, dependencies) that would be built,
815 .\" but do not build them.
816 .\" [XXX This can probably go away with the right
817 .\" combination of other options.  Revisit this issue.]
818 .\"
819 .\" .TP
820 .\" --list-actions
821 .\" List derived files that would be built, with the actions
822 .\" (commands) that build them.  Does not build the files.
823 .\" [XXX This can probably go away with the right
824 .\" combination of other options.  Revisit this issue.]
825 .\"
826 .\" .TP
827 .\" --list-where
828 .\" List derived files that would be built, plus where the file is
829 .\" defined (file name and line number).  Does not build the files.
830 .\" [XXX This can probably go away with the right
831 .\" combination of other options.  Revisit this issue.]
832
833 .TP
834 -m
835 Ignored for compatibility with non-GNU versions of
836 .BR make .
837
838 .TP
839 .RI --max-drift= SECONDS
840 Set the maximum expected drift in the modification time of files to 
841 .IR SECONDS .
842 This value determines how long a file must be unmodified
843 before its cached content signature
844 will be used instead of
845 calculating a new content signature (MD5 checksum)
846 of the file's contents.
847 The default value is 2 days, which means a file must have a
848 modification time of at least two days ago in order to have its
849 cached content signature used.
850 A negative value means to never cache the content
851 signature and to ignore the cached value if there already is one. A value
852 of 0 means to always use the cached signature,
853 no matter how old the file is.
854
855 .TP
856 -n, --just-print, --dry-run, --recon
857 No execute.  Print the commands that would be executed to build
858 any out-of-date target files, but do not execute the commands.
859
860 .\" .TP
861 .\" .RI -o " file" ", --old-file=" file ", --assume-old=" file
862 .\" Do not rebuild 
863 .\" .IR file ,
864 .\" and do
865 .\" not rebuild anything due to changes in the contents of
866 .\" .IR file .
867 .\" .TP 
868 .\" .RI --override " file"
869 .\" Read values to override specific build environment variables
870 .\" from the specified 
871 .\" .IR file .
872 .\" .TP
873 .\" -p
874 .\" Print the data base (construction environments,
875 .\" Builder and Scanner objects) that are defined
876 .\" after reading the SConscript files.
877 .\" After printing, a normal build is performed
878 .\" as usual, as specified by other command-line options.
879 .\" This also prints version information
880 .\" printed by the 
881 .\" .B -v
882 .\" option.
883 .\"
884 .\" To print the database without performing a build do:
885 .\"
886 .\" .ES
887 .\" scons -p -q
888 .\" .EE
889
890 .TP
891 .RI --profile= file
892 Run SCons under the Python profiler
893 and save the results in the specified
894 .IR file .
895 The results may be analyzed using the Python
896 pstats module.
897
898 .TP
899 -q, --question
900 Do not run any commands, or print anything.  Just return an exit
901 status that is zero if the specified targets are already up to
902 date, non-zero otherwise.
903 .TP
904 -Q
905 Quiets SCons status messages about
906 reading SConscript files,
907 building targets
908 and entering directories.
909 Commands that are executed
910 to rebuild target files are still printed.
911
912 .\" .TP
913 .\" -r, -R, --no-builtin-rules, --no-builtin-variables
914 .\" Clear the default construction variables.  Construction
915 .\" environments that are created will be completely empty.
916
917 .TP
918 --random
919 Build dependencies in a random order.  This is useful when
920 building multiple trees simultaneously with caching enabled,
921 to prevent multiple builds from simultaneously trying to build
922 or retrieve the same target files.
923
924 .TP
925 -s, --silent, --quiet
926 Silent.  Do not print commands that are executed to rebuild
927 target files.
928 Also suppresses SCons status messages.
929
930 .TP
931 -S, --no-keep-going, --stop
932 Ignored for compatibility with GNU 
933 .BR make .
934
935 .TP
936 -t, --touch
937 Ignored for compatibility with GNU
938 .BR make .  
939 (Touching a file to make it
940 appear up-to-date is unnecessary when using 
941 .BR scons .)
942
943 .TP
944 .RI --taskmastertrace= file
945 Prints trace information to the specified
946 .I file
947 about how the internal Taskmaster object
948 evaluates and controls the order in which Nodes are built.
949 A file name of
950 .B -
951 may be used to specify the standard output.
952
953 .TP
954 -u, --up, --search-up
955 Walks up the directory structure until an 
956 .I SConstruct ,
957 .I Sconstruct
958 or 
959 .I sconstruct
960 file is found, and uses that
961 as the top of the directory tree.
962 If no targets are specified on the command line,
963 only targets at or below the
964 current directory will be built.
965
966 .TP
967 -U
968 Works exactly the same way as the
969 .B -u
970 option except for the way default targets are handled.
971 When this option is used and no targets are specified on the command line,
972 all default targets that are defined in the SConscript(s) in the current
973 directory are built, regardless of what directory the resultant targets end
974 up in.
975
976 .TP
977 -v, --version
978 Print the 
979 .B scons
980 version, copyright information,
981 list of authors, and any other relevant information.
982 Then exit.
983
984 .TP
985 -w, --print-directory
986 Print a message containing the working directory before and
987 after other processing.
988
989 .TP
990 .RI --warn= type ", --warn=no-" type
991 Enable or disable warnings.
992 .I type
993 specifies the type of warnings to be enabled or disabled:
994
995 .TP
996 --warn=all, --warn=no-all
997 Enables or disables all warnings.
998
999 .TP
1000 --warn=dependency, --warn=no-dependency
1001 Enables or disables warnings about dependencies.
1002 These warnings are disabled by default.
1003
1004 .TP
1005 --warn=deprecated, --warn=no-deprecated
1006 Enables or disables warnings about use of deprecated features.
1007 These warnings are enabled by default.
1008
1009 .TP
1010 --warn=missing-sconscript, --warn=no-missing-sconscript
1011 Enables or disables warnings about missing SConscript files.
1012 These warnings are enabled by default.
1013
1014 .TP
1015 --no-print-directory
1016 Turn off -w, even if it was turned on implicitly.
1017
1018 .\" .TP
1019 .\" .RI --write-filenames= file
1020 .\" Write all filenames considered into
1021 .\" .IR file .
1022 .\"
1023 .\" .TP
1024 .\" .RI -W " file" ", --what-if=" file ", --new-file=" file ", --assume-new=" file
1025 .\" Pretend that the target 
1026 .\" .I file 
1027 .\" has been
1028 .\" modified.  When used with the 
1029 .\" .B -n
1030 .\" option, this
1031 .\" show you what would be rebuilt if you were to modify that file.
1032 .\" Without 
1033 .\" .B -n
1034 .\" ... what? XXX
1035 .\"
1036 .\" .TP
1037 .\" --warn-undefined-variables
1038 .\" Warn when an undefined variable is referenced.
1039
1040 .TP 
1041 .RI -Y " repository" ", --repository=" repository
1042 Search the specified repository for any input and target
1043 files not found in the local directory hierarchy.  Multiple
1044 .B -Y
1045 options may specified, in which case the
1046 repositories are searched in the order specified.
1047
1048 .SH CONFIGURATION FILE REFERENCE
1049 .\" .SS Python Basics
1050 .\" XXX Adding this in the future would be a help.
1051 .SS Construction Environments
1052 A construction environment is the basic means by which the SConscript
1053 files communicate build information to 
1054 .BR scons .
1055 A new construction environment is created using the 
1056 .B Environment 
1057 function:
1058
1059 .ES
1060 env = Environment()
1061 .EE
1062
1063 By default, a new construction environment is
1064 initialized with a set of builder methods
1065 and construction variables that are appropriate
1066 for the current platform.
1067 An optional platform keyword argument may be
1068 used to specify that an environment should
1069 be initialized for a different platform:
1070
1071 .ES
1072 env = Environment(platform = 'cygwin')
1073 env = Environment(platform = 'os2')
1074 env = Environment(platform = 'posix')
1075 env = Environment(platform = 'win32')
1076 .EE
1077
1078 Specifying a platform initializes the appropriate
1079 construction variables in the environment
1080 to use and generate file names with prefixes
1081 and suffixes appropriate for the platform.
1082
1083 Note that the
1084 .B win32
1085 platform adds the
1086 .B SYSTEMDRIVE
1087 and
1088 .B SYSTEMROOT
1089 variables from the user's external environment
1090 to the construction environment's
1091 .B ENV
1092 dictionary.
1093 This is so that any executed commands
1094 that use sockets to connect with other systems
1095 (such as fetching source files from
1096 external CVS repository specifications like 
1097 .BR :pserver:anonymous@cvs.sourceforge.net:/cvsroot/scons )
1098 will work on Windows systems.
1099
1100 The platform argument may be function or callable object,
1101 in which case the Environment() method
1102 will call the specified argument to update
1103 the new construction environment:
1104
1105 .ES
1106 def my_platform(env):
1107     env['VAR'] = 'xyzzy'
1108
1109 env = Environment(platform = my_platform)
1110 .EE
1111
1112 Additionally, a specific set of tools
1113 with which to initialize the environment
1114 may specified as an optional keyword argument:
1115
1116 .ES
1117 env = Environment(tools = ['msvc', 'lex'])
1118 .EE
1119
1120 Non-built-in tools may be specified using the toolpath argument:
1121
1122 .ES
1123 env = Environment(tools = ['default', 'foo'], toolpath = ['tools'])
1124 .EE
1125
1126 This looks for a tool specification in tools/foo.py (as well as
1127 using the ordinary default tools for the platform).  foo.py should
1128 have two functions: generate(env, **kw) and exists(env).
1129 The
1130 .B generate()
1131 function
1132 modifies the passed-in environment
1133 to set up variables so that the tool
1134 can be executed;
1135 it may use any keyword arguments
1136 that the user supplies (see below)
1137 to vary its initialization.
1138 The
1139 .B exists()
1140 function should return a true
1141 value if the tool is available.
1142 Tools in the toolpath are used before
1143 any of the built-in ones.  For example, adding gcc.py to the toolpath
1144 would override the built-in gcc tool.
1145 Also note that the toolpath is
1146 stored in the environment for use
1147 by later calls to
1148 .BR Copy ()
1149 and
1150 .BR Tool ()
1151 methods:
1152
1153 .ES
1154 base = Environment(toolpath=['custom_path'])
1155 derived = base.Copy(tools=['custom_tool'])
1156 derived.CustomBuilder()
1157 .EE
1158
1159 The elements of the tools list may also
1160 be functions or callable objects,
1161 in which case the Environment() method
1162 will call the specified elements
1163 to update the new construction environment:
1164
1165 .ES
1166 def my_tool(env):
1167     env['XYZZY'] = 'xyzzy'
1168
1169 env = Environment(tools = [my_tool])
1170 .EE
1171
1172 The individual elements of the tools list
1173 may also themselves be two-element lists of the form
1174 .RI ( toolname ", " kw_dict ).
1175 SCons searches for the
1176 .I toolname
1177 specification file as described above, and
1178 passes
1179 .IR kw_dict ,
1180 which must be a dictionary, as keyword arguments to the tool's
1181 .B generate
1182 function.
1183 The
1184 .B generate
1185 function can use the arguments to modify the tool's behavior
1186 by setting up the environment in different ways
1187 or otherwise changing its initialization.
1188
1189 .ES
1190 # in tools/my_tool.py:
1191 def generate(env, **kw):
1192   # Sets MY_TOOL to the value of keyword argument 'arg1' or 1.
1193   env['MY_TOOL'] = kw.get('arg1', '1')
1194 def exists(env):
1195   return 1
1196
1197 # in SConstruct:
1198 env = Environment(tools = ['default', ('my_tool', {'arg1': 'abc'})],
1199                   toolpath=['tools'])
1200 .EE
1201
1202 The tool definition (i.e. my_tool()) can use the PLATFORM variable from
1203 the environment it receives to customize the tool for different platforms.
1204
1205 If no tool list is specified, then SCons will auto-detect the installed
1206 tools using the PATH variable in the ENV construction variable and the
1207 platform name when the Environment is constructed. Changing the PATH
1208 variable after the Environment is constructed will not cause the tools to
1209 be redetected.
1210
1211 SCons supports the following tool specifications out of the box:
1212
1213 .ES
1214 386asm
1215 aixc++
1216 aixcc
1217 aixf77
1218 aixlink
1219 ar
1220 as
1221 bcc32
1222 c++
1223 cc
1224 cvf
1225 dmd
1226 dvipdf
1227 dvips
1228 f77
1229 f90
1230 f95
1231 fortran
1232 g++
1233 g77
1234 gas
1235 gcc
1236 gnulink
1237 gs
1238 hpc++
1239 hpcc
1240 hplink
1241 icc
1242 icl
1243 ifl
1244 ifort
1245 ilink
1246 ilink32
1247 intelc
1248 jar
1249 javac
1250 javah
1251 latex
1252 lex
1253 link
1254 linkloc
1255 m4
1256 masm
1257 midl
1258 mingw
1259 mslib
1260 mslink
1261 msvc
1262 msvs
1263 mwcc
1264 mwld
1265 nasm
1266 pdflatex
1267 pdftex
1268 qt
1269 rmic
1270 rpcgen
1271 sgiar
1272 sgic++
1273 sgicc
1274 sgilink
1275 sunar
1276 sunc++
1277 suncc
1278 sunlink
1279 swig
1280 tar
1281 tex
1282 tlib
1283 yacc
1284 zip
1285 .EE
1286
1287 Additionally, there is a "tool" named
1288 .B default
1289 which configures the
1290 environment with a default set of tools for the current platform.
1291
1292 On posix and cygwin platforms
1293 the GNU tools (e.g. gcc) are preferred by SCons,
1294 on Windows the Microsoft tools (e.g. msvc)
1295 followed by MinGW are preferred by SCons,
1296 and in OS/2 the IBM tools (e.g. icc) are preferred by SCons.
1297
1298 .SS Builder Methods
1299
1300 Build rules are specified by calling a construction
1301 environment's builder methods.
1302 The arguments to the builder methods are
1303 .B target
1304 (a list of target files)
1305 and
1306 .B source
1307 (a list of source files).
1308
1309 Because long lists of file names
1310 can lead to a lot of quoting,
1311 .B scons
1312 supplies a
1313 .B Split()
1314 global function
1315 and a same-named environment method
1316 that split a single string
1317 into a list, separated on
1318 strings of white-space characters.
1319 (These are similar to the
1320 string.split() method
1321 from the standard Python library,
1322 but work even if the input isn't a string.)
1323
1324 Like all Python arguments,
1325 the target and source arguments to a builder method
1326 can be specified either with or without
1327 the "target" and "source" keywords.
1328 When the keywords are omitted,
1329 the target is first,
1330 followed by the source.
1331 The following are equivalent examples of calling the Program builder method:
1332
1333 .ES
1334 env.Program('bar', ['bar.c', 'foo.c'])
1335 env.Program('bar', Split('bar.c foo.c'))
1336 env.Program('bar', env.Split('bar.c foo.c'))
1337 env.Program(source =  ['bar.c', 'foo.c'], target = 'bar')
1338 env.Program(target = 'bar', Split('bar.c foo.c'))
1339 env.Program(target = 'bar', env.Split('bar.c foo.c'))
1340 env.Program('bar', source = string.split('bar.c foo.c'))
1341 .EE
1342
1343 When the target shares the same base name
1344 as the source and only the suffix varies,
1345 and if the builder method has a suffix defined for the target file type,
1346 then the target argument may be omitted completely,
1347 and
1348 .B scons
1349 will deduce the target file name from
1350 the source file name.
1351 The following examples all build the
1352 executable program
1353 .B bar
1354 (on POSIX systems)
1355 or 
1356 .B bar.exe
1357 (on Windows systems)
1358 from the bar.c source file:
1359
1360 .ES
1361 env.Program(target = 'bar', source = 'bar.c')
1362 env.Program('bar', source = 'bar.c')
1363 env.Program(source = 'bar.c')
1364 env.Program('bar.c')
1365 .EE
1366
1367 It is possible to override or add construction variables when calling a
1368 builder method by passing additional keyword arguments.
1369 These overridden or added
1370 variables will only be in effect when building the target, so they will not
1371 affect other parts of the build. For example, if you want to add additional
1372 libraries for just one program:
1373
1374 .ES
1375 env.Program('hello', 'hello.c', LIBS=['gl', 'glut'])
1376 .EE
1377
1378 or generate a shared library with a non-standard suffix:
1379
1380 .ES
1381 env.SharedLibrary('word', 'word.cpp',
1382                   SHLIBSUFFIX='.ocx',
1383                   LIBSUFFIXES=['.ocx'])
1384 .EE
1385
1386 (Note that both the $SHLIBSUFFIX and $LIBSUFFIXES variables must be set
1387 if you want SCons to search automatically
1388 for dependencies on the non-standard library names;
1389 see the descriptions of these variables, below, for more information.)
1390
1391 Although the builder methods defined by
1392 .B scons
1393 are, in fact,
1394 methods of a construction environment object,
1395 they may also be called without an explicit environment:
1396
1397 .ES
1398 Program('hello', 'hello.c')
1399 SharedLibrary('word', 'word.cpp')
1400 .EE
1401
1402 In this case,
1403 the methods are called internally using a default construction
1404 environment that consists of the tools and values that
1405 .B scons
1406 has determined are appropriate for the local system.
1407
1408 Builder methods that can be called without an explicit
1409 environment may be called from custom Python modules that you
1410 import into an SConscript file by adding the following
1411 to the Python module:
1412
1413 .ES
1414 from SCons.Script import *
1415 .EE
1416
1417 All builder methods return a list of Nodes
1418 that represent the target or targets that will be built.
1419 A
1420 .I Node
1421 is an internal SCons object
1422 which represents
1423 build targets or sources.
1424
1425 The returned Node(s)
1426 can be passed to other builder methods as source(s)
1427 or passed to any SCons function or method
1428 where a filename would normally be accepted.
1429 For example, if it were necessary
1430 to add a specific
1431 .B -D
1432 flag when compiling one specific object file:
1433
1434 .ES
1435 bar_obj_list = env.StaticObject('bar.c', CPPDEFINES='-DBAR')
1436 env.Program(source = ['foo.c', bar_obj_list, 'main.c'])
1437 .EE
1438
1439 Using a Node in this way
1440 makes for a more portable build
1441 by avoiding having to specify
1442 a platform-specific object suffix
1443 when calling the Program() builder method.
1444
1445 Note that Builder calls will automatically "flatten"
1446 the source and target file lists,
1447 so it's all right to have the bar_obj list
1448 return by the StaticObject() call
1449 in the middle of the source file list.
1450 If you need to manipulate a list of lists returned by Builders
1451 directly using Python,
1452 you can either build the list by hand:
1453
1454 .ES
1455 foo = Object('foo.c')
1456 bar = Object('bar.c')
1457 objects = ['begin.o'] + foo + ['middle.o'] + bar + ['end.o']
1458 for object in objects:
1459     print str(object)
1460 .EE
1461
1462 Or you can use the
1463 .BR Flatten ()
1464 supplied by scons
1465 to create a list containing just the Nodes,
1466 which may be more convenient:
1467
1468 .ES
1469 foo = Object('foo.c')
1470 bar = Object('bar.c')
1471 objects = Flatten(['begin.o', foo, 'middle.o', bar, 'end.o'])
1472 for object in objects:
1473     print str(object)
1474 .EE
1475
1476 The path name for a Node's file may be used
1477 by passing the Node to the Python-builtin
1478 .B str()
1479 function:
1480
1481 .ES
1482 bar_obj_list = env.StaticObject('bar.c', CPPDEFINES='-DBAR')
1483 print "The path to bar_obj is:", str(bar_obj_list[0])
1484 .EE
1485
1486 Note again that because the Builder call returns a list,
1487 we have to access the first element in the list
1488 .B (bar_obj_list[0])
1489 to get at the Node that actually represents
1490 the object file.
1491
1492 Builder calls support a
1493 .B chdir
1494 keyword argument that
1495 specifies that the Builder's action(s)
1496 should be executed
1497 after changing directory.
1498 If the
1499 .B chdir
1500 argument is
1501 a string or a directory Node,
1502 scons will change to the specified directory.
1503 If the
1504 .B chdir
1505 is not a string or Node
1506 and is non-zero,
1507 then scons will change to the
1508 target file's directory.
1509
1510 .ES
1511 # scons will change to the "sub" subdirectory
1512 # before executing the "cp" command.
1513 env.Command('sub/dir/foo.out', 'sub/dir/foo.in',
1514             "cp dir/foo.in dir/foo.out",
1515             chdir='sub')
1516
1517 # Because chdir is not a string, scons will change to the
1518 # target's directory ("sub/dir") before executing the
1519 # "cp" command.
1520 env.Command('sub/dir/foo.out', 'sub/dir/foo.in',
1521             "cp foo.in foo.out",
1522             chdir=1)
1523 .EE
1524
1525 Note that scons will
1526 .I not
1527 automatically modify
1528 its expansion of
1529 construction variables like
1530 .B $TARGET
1531 and
1532 .B $SOURCE
1533 when using the chdir
1534 keyword argument--that is,
1535 the expanded file names
1536 will still be relative to
1537 the top-level SConstruct directory,
1538 and consequently incorrect
1539 relative to the chdir directory.
1540 If you use the chdir keyword argument,
1541 you will typically need to supply a different
1542 command line using
1543 expansions like
1544 .B ${TARGET.file}
1545 and
1546 .B ${SOURCE.file}
1547 to use just the filename portion of the
1548 targets and source.
1549
1550 .B scons
1551 provides the following builder methods:
1552
1553 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1554 '\" BEGIN GENERATED BUILDER DESCRIPTIONS
1555 '\"
1556 '\" The descriptions below of the various SCons Builders are generated
1557 '\" from the .xml files that live next to the various Python modules in
1558 '\" the build enginer library.  If you're reading this [gnt]roff file
1559 '\" with an eye towards patching this man page, you can still submit
1560 '\" a diff against this text, but it will have to be translated to a
1561 '\" diff against the underlying .xml file before the patch is actually
1562 '\" accepted.  If you do that yourself, it will make it easier to
1563 '\" integrate the patch.
1564 '\"
1565 '\" BEGIN GENERATED BUILDER DESCRIPTIONS
1566 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1567 .so builders.man
1568 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1569 '\" END GENERATED BUILDER DESCRIPTIONS
1570 '\"
1571 '\" The descriptions above of the various SCons Builders are generated
1572 '\" from the .xml files that live next to the various Python modules in
1573 '\" the build enginer library.  If you're reading this [gnt]roff file
1574 '\" with an eye towards patching this man page, you can still submit
1575 '\" a diff against this text, but it will have to be translated to a
1576 '\" diff against the underlying .xml file before the patch is actually
1577 '\" accepted.  If you do that yourself, it will make it easier to
1578 '\" integrate the patch.
1579 '\"
1580 '\" END GENERATED BUILDER DESCRIPTIONS
1581 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1582
1583 All
1584 targets of builder methods automatically depend on their sources.
1585 An explicit dependency can
1586 be specified using the 
1587 .B Depends 
1588 method of a construction environment (see below).
1589
1590 In addition,
1591 .B scons
1592 automatically scans
1593 source files for various programming languages,
1594 so the dependencies do not need to be specified explicitly.
1595 By default, SCons can
1596 C source files,
1597 C++ source files,
1598 Fortran source files with
1599 .B .F
1600 (POSIX systems only),
1601 .B .fpp,
1602 or
1603 .B .FPP
1604 file extensions,
1605 and assembly language files with
1606 .B .S
1607 (POSIX systems only),
1608 .B .spp,
1609 or
1610 .B .SPP
1611 files extensions
1612 for C preprocessor dependencies.
1613 SCons also has default support
1614 for scanning D source files,
1615 You can also write your own Scanners
1616 to add support for additional source file types.
1617 These can be added to the default
1618 Scanner object used by
1619 the
1620 .BR Object ()
1621 .BR StaticObject ()
1622 and
1623 .BR SharedObject ()
1624 Builders by adding them
1625 to the
1626 .B SourceFileScanner
1627 object as follows:
1628
1629 See the section "Scanner Objects,"
1630 below, for a more information about
1631 defining your own Scanner objects.
1632
1633 .SS Methods and Functions to Do Things
1634 In addition to Builder methods,
1635 .B scons
1636 provides a number of other construction environment methods
1637 and global functions to
1638 manipulate the build configuration.
1639
1640 Usually, a construction environment method
1641 and global function with the same name both exist
1642 so that you don't have to remember whether
1643 to a specific bit of functionality
1644 must be called with or without a construction environment.
1645 In the following list,
1646 if you call something as a global function
1647 it looks like:
1648 .ES
1649 .RI Function( arguments )
1650 .EE
1651 and if you call something through a construction
1652 environment it looks like:
1653 .ES
1654 .RI env.Function( arguments )
1655 .EE
1656 If you can call the functionality in both ways,
1657 then both forms are listed.
1658
1659 Global functions may be called from custom Python modules that you
1660 import into an SConscript file by adding the following
1661 to the Python module:
1662
1663 .ES
1664 from SCons.Script import *
1665 .EE
1666
1667 Except where otherwise noted,
1668 the same-named
1669 construction environment method
1670 and global function 
1671 provide the exact same functionality.
1672 The only difference is that,
1673 where appropriate,
1674 calling the functionality through a construction environment will
1675 substitute construction variables into
1676 any supplied strings.
1677 For example:
1678 .ES
1679 env = Environment(FOO = 'foo')
1680 Default('$FOO')
1681 env.Default('$FOO')
1682 .EE
1683 the first call to the global
1684 .B Default()
1685 function will actually add a target named
1686 .B $FOO
1687 to the list of default targets,
1688 while the second call to the
1689 .B env.Default()
1690 construction environment method
1691 will expand the value
1692 and add a target named
1693 .B foo
1694 to the list of default targets.
1695 For more on construction variable expansion,
1696 see the next section on
1697 construction variables.
1698
1699 Construction environment methods
1700 and global functions supported by
1701 .B scons
1702 include:
1703
1704 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1705 .TP 
1706 .RI Action( action ", [" strfunction ", " varlist ])
1707 .TP
1708 .RI env.Action( action ", [" strfunction ", " varlist ])
1709 Creates an Action object for
1710 the specified
1711 .IR action .
1712 See the section "Action Objects,"
1713 below, for a complete explanation of the arguments and behavior.
1714
1715 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1716 .TP 
1717 .RI AddPostAction( target ", " action )
1718 .TP
1719 .RI env.AddPostAction( target ", " action )
1720 Arranges for the specified
1721 .I action
1722 to be performed
1723 after the specified
1724 .I target
1725 has been built.
1726 The specified action(s) may be
1727 an Action object, or anything that
1728 can be converted into an Action object
1729 (see below).
1730
1731 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1732 .TP 
1733 .RI AddPreAction( target ", " action )
1734 .TP
1735 .RI env.AddPreAction( target ", " action )
1736 Arranges for the specified
1737 .I action
1738 to be performed
1739 before the specified
1740 .I target
1741 is built.
1742 The specified action(s) may be
1743 an Action object, or anything that
1744 can be converted into an Action object
1745 (see below).
1746
1747 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1748 .TP
1749 .RI Alias( alias ", [" targets ", [" action ]])
1750 .TP
1751 .RI env.Alias( alias ", [" targets ", [" action ]])
1752 Creates one or more phony targets that
1753 expand to one or more other targets.
1754 An optional
1755 .I action
1756 (command)
1757 or list of actions
1758 can be specified that will be executed
1759 whenever the any of the alias targets are out-of-date.
1760 Returns the Node object representing the alias,
1761 which exists outside of any file system.
1762 This Node object, or the alias name,
1763 may be used as a dependency of any other target,
1764 including another alias.
1765 .B Alias
1766 can be called multiple times for the same
1767 alias to add additional targets to the alias,
1768 or additional actions to the list for this alias.
1769
1770 .ES
1771 Alias('install')
1772 Alias('install', '/usr/bin')
1773 Alias(['install', 'install-lib'], '/usr/local/lib')
1774
1775 env.Alias('install', ['/usr/local/bin', '/usr/local/lib'])
1776 env.Alias('install', ['/usr/local/man'])
1777
1778 env.Alias('update', ['file1', 'file2'], "update_database $SOURCES")
1779 .EE
1780
1781 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1782 .TP
1783 .RI AlwaysBuild( target ", ...)"
1784 .TP
1785 .RI env.AlwaysBuild( target ", ...)"
1786 Marks each given
1787 .I target
1788 so that it is always assumed to be out of date,
1789 and will always be rebuilt if needed.
1790 Note, however, that
1791 .BR AlwaysBuild ()
1792 does not add its target(s) to the default target list,
1793 so the targets will only be built
1794 if they are specified on the command line,
1795 or are a dependent of a target specified on the command line--but
1796 they will
1797 .I always
1798 be built if so specified.
1799 Multiple targets can be passed in to a single call to
1800 .BR AlwaysBuild ().
1801
1802 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1803 .TP
1804 .RI env.Append( key = val ", [...])"
1805 Appends the specified keyword arguments
1806 to the end of construction variables in the environment.
1807 If the Environment does not have
1808 the specified construction variable,
1809 it is simply added to the environment.
1810 If the values of the construction variable
1811 and the keyword argument are the same type,
1812 then the two values will be simply added together.
1813 Otherwise, the construction variable
1814 and the value of the keyword argument
1815 are both coerced to lists,
1816 and the lists are added together.
1817 (See also the Prepend method, below.)
1818
1819 .ES
1820 env.Append(CCFLAGS = ' -g', FOO = ['foo.yyy'])
1821 .EE
1822
1823 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1824 .TP
1825 .RI env.AppendENVPath( name ", " newpath ", [" envname ", " sep ])
1826 This appends new path elements to the given path in the
1827 specified external environment
1828 .RB ( ENV
1829 by default).
1830 This will only add
1831 any particular path once (leaving the last one it encounters and
1832 ignoring the rest, to preserve path order),
1833 and to help assure this,
1834 will normalize all paths (using
1835 .B os.path.normpath
1836 and
1837 .BR os.path.normcase ).
1838 This can also handle the
1839 case where the given old path variable is a list instead of a
1840 string, in which case a list will be returned instead of a string.
1841 Example:
1842
1843 .ES
1844 print 'before:',env['ENV']['INCLUDE']
1845 include_path = '/foo/bar:/foo'
1846 env.AppendENVPath('INCLUDE', include_path)
1847 print 'after:',env['ENV']['INCLUDE']
1848
1849 yields:
1850 before: /foo:/biz
1851 after: /biz:/foo/bar:/foo
1852 .EE
1853
1854 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1855 .TP
1856 .RI env.AppendUnique( key = val ", [...])"
1857 Appends the specified keyword arguments
1858 to the end of construction variables in the environment.
1859 If the Environment does not have
1860 the specified construction variable,
1861 it is simply added to the environment.
1862 If the construction variable being appended to is a list,
1863 then any value(s) that already exist in the
1864 construction variable will
1865 .I not
1866 be added again to the list.
1867
1868 .ES
1869 env.AppendUnique(CCFLAGS = '-g', FOO = ['foo.yyy'])
1870 .EE
1871
1872 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1873 .TP
1874 env.BitKeeper()
1875 A factory function that
1876 returns a Builder object
1877 to be used to fetch source files
1878 using BitKeeper.
1879 The returned Builder
1880 is intended to be passed to the
1881 .B SourceCode
1882 function.
1883
1884 .ES
1885 env.SourceCode('.', env.BitKeeper())
1886 .EE
1887
1888 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1889 .TP
1890 .RI BuildDir( build_dir ", " src_dir ", [" duplicate ])
1891 .TP
1892 .RI env.BuildDir( build_dir ", " src_dir ", [" duplicate ])
1893 This specifies a build directory
1894 .I build_dir
1895 in which to build all derived files
1896 that would normally be built under
1897 .IR src_dir .
1898 Multiple build directories can be set up for multiple build variants, for
1899 example. 
1900 .I src_dir
1901 must be underneath the SConstruct file's directory,
1902 and
1903 .I build_dir
1904 may not be underneath the
1905 .I src_dir .
1906
1907 The default behavior is for
1908 .B scons
1909 to duplicate all of the files in the tree underneath
1910 .I src_dir
1911 into
1912 .IR build_dir ,
1913 and then build the derived files within the copied tree.
1914 (The duplication is performed by
1915 linking or copying,
1916 depending on the platform; see also the
1917 .IR --duplicate
1918 option.)
1919 This guarantees correct builds
1920 regardless of whether intermediate source files
1921 are generated during the build,
1922 where preprocessors or other scanners search
1923 for included files,
1924 or whether individual compilers or other invoked tools
1925 are hard-coded to put derived files in the same directory as source files.
1926
1927 This behavior of making a complete copy of the source tree
1928 may be disabled by setting
1929 .I duplicate
1930 to 0.
1931 This will cause
1932 .B scons
1933 to invoke Builders using the
1934 path names of source files in
1935 .I src_dir
1936 and the path names of derived files within
1937 .IR build_dir .
1938 This is always more efficient than
1939 .IR duplicate =1,
1940 and is usually safe for most builds.
1941 Specifying
1942 .IR duplicate =0,
1943 however,
1944 may cause build problems
1945 if source files are generated during the build,
1946 if any invoked tools are hard-coded to
1947 put derived files in the same directory as the source files.
1948
1949 Note that specifying a
1950 .B BuildDir
1951 works most naturally
1952 with a subsidiary SConscript file
1953 in the source directory.
1954 However,
1955 you would then call the subsidiary SConscript file
1956 not in the source directory,
1957 but in the
1958 .I build_dir ,
1959 as if
1960 .B scons
1961 had made a virtual copy of the source tree
1962 regardless of the value of 
1963 .IR duplicate .
1964 This is how you tell
1965 .B scons
1966 which variant of a source tree to build.
1967 For example:
1968
1969 .ES
1970 BuildDir('build-variant1', 'src')
1971 SConscript('build-variant1/SConscript')
1972 BuildDir('build-variant2', 'src')
1973 SConscript('build-variant2/SConscript')
1974 .EE
1975
1976 .IP
1977 See also the
1978 .BR SConscript ()
1979 function, described below,
1980 for another way to 
1981 specify a build directory
1982 in conjunction with calling a subsidiary
1983 SConscript file.)
1984
1985 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1986 .TP 
1987 .RI Builder( action ", [" arguments ])
1988 .TP 
1989 .RI env.Builder( action ", [" arguments ])
1990 Creates a Builder object for
1991 the specified
1992 .IR action .
1993 See the section "Builder Objects,"
1994 below, for a complete explanation of the arguments and behavior.
1995
1996 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1997 .TP 
1998 .RI CacheDir( cache_dir )
1999 .TP 
2000 .RI env.CacheDir( cache_dir )
2001 Specifies that
2002 .B scons
2003 will maintain a cache of derived files in
2004 .I cache_dir .
2005 The derived files in the cache will be shared
2006 among all the builds using the same
2007 .BR CacheDir ()
2008 call.
2009
2010 When a
2011 .BR CacheDir ()
2012 is being used and
2013 .B scons
2014 finds a derived file that needs to be rebuilt,
2015 it will first look in the cache to see if a
2016 derived file has already been built
2017 from identical input files and an identical build action
2018 (as incorporated into the MD5 build signature).
2019 If so,
2020 .B scons
2021 will retrieve the file from the cache.
2022 If the derived file is not present in the cache,
2023 .B scons
2024 will rebuild it and
2025 then place a copy of the built file in the cache
2026 (identified by its MD5 build signature),
2027 so that it may be retrieved by other
2028 builds that need to build the same derived file
2029 from identical inputs.
2030
2031 Use of a specified
2032 .BR CacheDir()
2033 may be disabled for any invocation
2034 by using the
2035 .B --cache-disable
2036 option.
2037
2038 If the
2039 .B --cache-force
2040 option is used,
2041 .B scons
2042 will place a copy of
2043 .I all
2044 derived files in the cache,
2045 even if they already existed
2046 and were not built by this invocation.
2047 This is useful to populate a cache
2048 the first time
2049 .BR CacheDir ()
2050 is added to a build,
2051 or after using the
2052 .B --cache-disable
2053 option.
2054
2055 When using
2056 .BR CacheDir (),
2057 .B scons
2058 will report,
2059 "Retrieved `file' from cache,"
2060 unless the
2061 .B --cache-show
2062 option is being used.
2063 When the
2064 .B --cache-show
2065 option is used,
2066 .B scons
2067 will print the action that
2068 .I would
2069 have been used to build the file,
2070 without any indication that
2071 the file was actually retrieved from the cache.
2072 This is useful to generate build logs
2073 that are equivalent regardless of whether
2074 a given derived file has been built in-place
2075 or retrieved from the cache.
2076
2077 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2078 .TP 
2079 .RI Clean( targets ", " files_or_dirs )
2080 .TP 
2081 .RI env.Clean( targets ", " files_or_dirs )
2082 This specifies a list of files or directories which should be removed
2083 whenever the targets are specified with the
2084 .B -c
2085 command line option.
2086 The specified targets may be a list
2087 or an individual target.
2088 Multiple calls to
2089 .BR Clean ()
2090 are legal,
2091 and create new targets or add files and directories to the
2092 clean list for the specified targets.
2093
2094 Multiple files or directories should be specified
2095 either as separate arguments to the
2096 .BR Clean ()
2097 method, or as a list.
2098 .BR Clean ()
2099 will also accept the return value of any of the construction environment
2100 Builder methods.
2101 Examples:
2102
2103 The related
2104 .BR NoClean () 
2105 function overrides calling
2106 .BR Clean ()
2107 for the same target,
2108 and any targets passed to both functions will
2109 .I not
2110 be removed by the
2111 .B -c
2112 option.
2113
2114 Examples:
2115
2116 .ES
2117 Clean('foo', ['bar', 'baz'])
2118 Clean('dist', env.Program('hello', 'hello.c'))
2119 Clean(['foo', 'bar'], 'something_else_to_clean')
2120 .EE
2121
2122 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2123 .TP
2124 .RI Command( target ", " source ", " action ", [" key = val ", ...])"
2125 .TP
2126 .RI env.Command( target ", " source ", " action ", [" key = val ", ...])"
2127 Executes a specific action
2128 (or list of actions)
2129 to build a target file or files.
2130 This is more convenient
2131 than defining a separate Builder object
2132 for a single special-case build.
2133
2134 As a special case, the
2135 .B source_scanner
2136 keyword argument can
2137 be used to specify
2138 a Scanner object
2139 that will be used to scan the sources.
2140 (The global
2141 .B DirScanner
2142 object can be used
2143 if any of the sources will be directories
2144 that must be scanned on-disk for
2145 changes to files that aren't
2146 already specified in other Builder of function calls.)
2147
2148 Any other keyword arguments specified override any
2149 same-named existing construction variables.
2150
2151 An action can be an external command,
2152 specified as a string,
2153 or a callable Python object;
2154 see "Action Objects," below,
2155 for more complete information.
2156 Also note that a string specifying an external command
2157 may be preceded by an
2158 .B @
2159 (at-sign)
2160 to suppress printing the command in question,
2161 or by a
2162 .B \-
2163 (hyphen)
2164 to ignore the exit status of the external command.
2165 Examples:
2166
2167 .ES
2168 env.Command('foo.out', 'foo.in',
2169             "$FOO_BUILD < $SOURCES > $TARGET")
2170
2171 env.Command('bar.out', 'bar.in',
2172             ["rm -f $TARGET",
2173              "$BAR_BUILD < $SOURCES > $TARGET"],
2174             ENV = {'PATH' : '/usr/local/bin/'})
2175
2176 def rename(env, target, source):
2177     import os
2178     os.rename('.tmp', str(target[0]))
2179
2180 env.Command('baz.out', 'baz.in',
2181             ["$BAZ_BUILD < $SOURCES > .tmp",
2182              rename ])
2183 .EE
2184
2185 Note that the
2186 .BR Command ()
2187 function will usually assume, by default,
2188 that the specified targets and/or sources are Files,
2189 if no other part of the configuration
2190 identifies what type of entry it is.
2191 If necessary, you can explicitly specify
2192 that targets or source nodes should
2193 be treated as directoriese
2194 by using the
2195 .BR Dir ()
2196 or
2197 .BR env.Dir ()
2198 functions:
2199
2200 .ES
2201 env.Command('ddd.list', Dir('ddd'), 'ls -l $SOURCE > $TARGET')
2202
2203 env['DISTDIR'] = 'destination/directory'
2204 env.Command(env.Dir('$DISTDIR')), None, make_distdir)
2205 .EE
2206
2207 (Also note that SCons will usually
2208 automatically create any directory necessary to hold a target file,
2209 so you normally don't need to create directories by hand.)
2210
2211 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2212 .TP
2213 .RI Configure( env ", [" custom_tests ", " conf_dir ", " log_file ", " config_h ])
2214 .TP
2215 .RI env.Configure([ custom_tests ", " conf_dir ", " log_file ", " config_h ])
2216 Creates a Configure object for integrated
2217 functionality similar to GNU autoconf.
2218 See the section "Configure Contexts,"
2219 below, for a complete explanation of the arguments and behavior.
2220
2221 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2222 .TP
2223 .RI env.Copy([ key = val ", ...])"
2224 Return a separate copy of a construction environment.
2225 If there are any keyword arguments specified,
2226 they are added to the returned copy,
2227 overwriting any existing values
2228 for the keywords.
2229
2230 .ES
2231 env2 = env.Copy()
2232 env3 = env.Copy(CCFLAGS = '-g')
2233 .EE
2234 .IP
2235 Additionally, a list of tools and a toolpath may be specified, as in
2236 the Environment constructor:
2237
2238 .ES
2239 def MyTool(env): env['FOO'] = 'bar'
2240 env4 = env.Copy(tools = ['msvc', MyTool])
2241 .EE
2242
2243 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2244 .TP
2245 .RI env.CVS( repository ", " module )
2246 A factory function that
2247 returns a Builder object
2248 to be used to fetch source files
2249 from the specified
2250 CVS
2251 .IR repository .
2252 The returned Builder
2253 is intended to be passed to the
2254 .B SourceCode
2255 function.
2256
2257 The optional specified
2258 .I module
2259 will be added to the beginning
2260 of all repository path names;
2261 this can be used, in essence,
2262 to strip initial directory names
2263 from the repository path names,
2264 so that you only have to
2265 replicate part of the repository
2266 directory hierarchy in your
2267 local build directory:
2268
2269 .ES
2270 # Will fetch foo/bar/src.c
2271 # from /usr/local/CVSROOT/foo/bar/src.c.
2272 env.SourceCode('.', env.CVS('/usr/local/CVSROOT'))
2273
2274 # Will fetch bar/src.c
2275 # from /usr/local/CVSROOT/foo/bar/src.c.
2276 env.SourceCode('.', env.CVS('/usr/local/CVSROOT', 'foo'))
2277
2278 # Will fetch src.c
2279 # from /usr/local/CVSROOT/foo/bar/src.c.
2280 env.SourceCode('.', env.CVS('/usr/local/CVSROOT', 'foo/bar'))
2281 .EE
2282
2283 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2284 .TP 
2285 .RI Default( targets )
2286 .TP
2287 .RI env.Default( targets )
2288 This specifies a list of default targets,
2289 which will be built by
2290 .B scons
2291 if no explicit targets are given on the command line.
2292 Multiple calls to
2293 .BR Default ()
2294 are legal,
2295 and add to the list of default targets.
2296
2297 Multiple targets should be specified as
2298 separate arguments to the
2299 .BR Default ()
2300 method, or as a list.
2301 .BR Default ()
2302 will also accept the Node returned by any
2303 of a construction environment's
2304 builder methods.
2305 Examples:
2306
2307 .ES
2308 Default('foo', 'bar', 'baz')
2309 env.Default(['a', 'b', 'c'])
2310 hello = env.Program('hello', 'hello.c')
2311 env.Default(hello)
2312 .EE
2313 .IP
2314 An argument to
2315 .BR Default ()
2316 of
2317 .B None
2318 will clear all default targets.
2319 Later calls to
2320 .BR Default ()
2321 will add to the (now empty) default-target list
2322 like normal.
2323
2324 The current list of targets added using the
2325 .BR Default ()
2326 function or method is available in the
2327 .B DEFAULT_TARGETS
2328 list;
2329 see below.
2330
2331 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2332 .TP
2333 .RI DefaultEnvironment([ args ])
2334 Creates and returns a default construction environment object.
2335 This construction environment is used internally by SCons
2336 in order to execute many of the global functions in this list,
2337 and to fetch source files transparently
2338 from source code management systems.
2339
2340 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2341 .TP
2342 .RI Depends( target ", " dependency )
2343 .TP
2344 .RI env.Depends( target ", " dependency )
2345 Specifies an explicit dependency;
2346 the target file(s) will be rebuilt
2347 whenever the dependency file(s) has changed.
2348 This should only be necessary
2349 for cases where the dependency
2350 is not caught by a Scanner
2351 for the file.
2352
2353 .ES
2354 env.Depends('foo', 'other-input-file-for-foo')
2355 .EE
2356
2357 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2358 .TP
2359 .RI env.Dictionary([ vars ])
2360 Returns a dictionary object
2361 containing copies of all of the
2362 construction variables in the environment.
2363 If there are any variable names specified,
2364 only the specified construction
2365 variables are returned in the dictionary.
2366
2367 .ES
2368 dict = env.Dictionary()
2369 cc_dict = env.Dictionary('CC', 'CCFLAGS', 'CCCOM')
2370 .EE
2371
2372 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2373 .TP
2374 .RI Dir( name ", [" directory ])
2375 .TP
2376 .RI env.Dir( name ", [" directory ])
2377 This returns a Directory Node,
2378 an object that represents the specified directory
2379 .IR name . 
2380 .I name
2381 can be a relative or absolute path. 
2382 .I directory
2383 is an optional directory that will be used as the parent directory. 
2384 If no
2385 .I directory
2386 is specified, the current script's directory is used as the parent.
2387
2388 Directory Nodes can be used anywhere you
2389 would supply a string as a directory name
2390 to a Builder method or function.
2391 Directory Nodes have attributes and methods
2392 that are useful in many situations;
2393 see "File and Directory Nodes," below.
2394
2395 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2396 .TP
2397 .RI env.Dump([ key ])
2398 Returns a pretty printable representation of the environment.
2399 .IR key ,
2400 if not
2401 .IR None ,
2402 should be a string containing the name of the variable of interest.
2403
2404 This SConstruct:
2405 .ES
2406 env=Environment()
2407 print env.Dump('CCCOM')
2408 .EE
2409 will print:
2410 .ES
2411 '$CC $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES'
2412 .EE
2413
2414 .ES
2415 env=Environment()
2416 print env.Dump()
2417 .EE
2418 will print:
2419 .ES
2420 { 'AR': 'ar',
2421   'ARCOM': '$AR $ARFLAGS $TARGET $SOURCES\n$RANLIB $RANLIBFLAGS $TARGET',
2422   'ARFLAGS': ['r'],
2423   'AS': 'as',
2424   'ASCOM': '$AS $ASFLAGS -o $TARGET $SOURCES',
2425   'ASFLAGS': [],
2426   ...
2427 .EE
2428
2429 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2430 .TP
2431 .RI EnsurePythonVersion( major ", " minor )
2432 .TP
2433 .RI env.EnsurePythonVersion( major ", " minor )
2434 Ensure that the Python version is at least 
2435 .IR major . minor . 
2436 This function will
2437 print out an error message and exit SCons with a non-zero exit code if the
2438 actual Python version is not late enough.
2439
2440 .ES
2441 EnsurePythonVersion(2,2)
2442 .EE
2443
2444 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2445 .TP
2446 .RI EnsureSConsVersion( major ", " minor ", [" revision ])
2447 .TP
2448 .RI env.EnsureSConsVersion( major ", " minor ", [" revision ])
2449 Ensure that the SCons version is at least 
2450 .IR major.minor ,
2451 or
2452 .IR major.minor.revision . 
2453 if
2454 .I revision
2455 is specified.
2456 This function will
2457 print out an error message and exit SCons with a non-zero exit code if the
2458 actual SCons version is not late enough.
2459
2460 .ES
2461 EnsureSConsVersion(0,14)
2462
2463 EnsureSConsVersion(0,96,90)
2464 .EE
2465
2466 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2467 .TP
2468 .RI Environment([ key = value ", ...])"
2469 .TP
2470 .RI env.Environment([ key = value ", ...])"
2471 Return a new construction environment
2472 initialized with the specified
2473 .IR key = value
2474 pairs.
2475
2476 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2477 .TP 
2478 .RI Execute( action ", [" strfunction ", " varlist ])
2479 .TP
2480 .RI env.Execute( action ", [" strfunction ", " varlist ])
2481 Executes an Action object.
2482 The specified
2483 .IR action
2484 may be an Action object
2485 (see the section "Action Objects,"
2486 below, for a complete explanation of the arguments and behavior),
2487 or it may be a command-line string,
2488 list of commands,
2489 or executable Python function,
2490 each of which will be converted
2491 into an Action object
2492 and then executed.
2493 The exit value of the command
2494 or return value of the Python function
2495 will be returned.
2496
2497 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2498 .TP
2499 .RI Exit([ value ])
2500 .TP
2501 .RI env.Exit([ value ])
2502 This tells
2503 .B scons
2504 to exit immediately
2505 with the specified
2506 .IR value .
2507 A default exit value of
2508 .B 0
2509 (zero)
2510 is used if no value is specified.
2511
2512 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2513 .TP
2514 .RI Export( vars )
2515 .TP
2516 .RI env.Export( vars )
2517 This tells 
2518 .B scons
2519 to export a list of variables from the current
2520 SConscript file to all other SConscript files.
2521 The exported variables are kept in a global collection,
2522 so subsequent calls to
2523 .BR Export ()
2524 will over-write previous exports that have the same name. 
2525 Multiple variable names can be passed to
2526 .BR Export ()
2527 as separate arguments or as a list. A dictionary can be used to map
2528 variables to a different name when exported. Both local variables and
2529 global variables can be exported.
2530 Examples:
2531
2532 .ES
2533 env = Environment()
2534 # Make env available for all SConscript files to Import().
2535 Export("env")
2536
2537 package = 'my_name'
2538 # Make env and package available for all SConscript files:.
2539 Export("env", "package")
2540
2541 # Make env and package available for all SConscript files:
2542 Export(["env", "package"])
2543
2544 # Make env available using the name debug:.
2545 Export({"debug":env})
2546 .EE
2547
2548 .IP
2549 Note that the
2550 .BR SConscript ()
2551 function supports an
2552 .I exports
2553 argument that makes it easier to to export a variable or
2554 set of variables to a single SConscript file.
2555 See the description of the
2556 .BR SConscript ()
2557 function, below.
2558
2559 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2560 .TP 
2561 .RI File( name ", [" directory ])
2562 .TP 
2563 .RI env.File( name ", [" directory ])
2564 This returns a
2565 File Node,
2566 an object that represents the specified file
2567 .IR name . 
2568 .I name
2569 can be a relative or absolute path. 
2570 .I directory
2571 is an optional directory that will be used as the parent directory. 
2572
2573 File Nodes can be used anywhere you
2574 would supply a string as a file name
2575 to a Builder method or function.
2576 File Nodes have attributes and methods
2577 that are useful in many situations;
2578 see "File and Directory Nodes," below.
2579
2580 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2581 .TP
2582 .RI FindFile( file ", " dirs )
2583 .TP
2584 .RI env.FindFile( file ", " dirs )
2585 Search for 
2586 .I file 
2587 in the path specified by 
2588 .IR dirs .
2589 .I file
2590 may be a list of file names or a single file name. In addition to searching
2591 for files that exist in the filesytem, this function also searches for
2592 derived files that have not yet been built.
2593
2594 .ES
2595 foo = env.FindFile('foo', ['dir1', 'dir2'])
2596 .EE
2597
2598 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2599 .TP
2600 .RI Flatten( sequence )
2601 .TP
2602 .RI env.Flatten( sequence )
2603 Takes a sequence (that is, a Python list or tuple)
2604 that may contain nested sequences
2605 and returns a flattened list containing
2606 all of the individual elements in any sequence.
2607 This can be helpful for collecting
2608 the lists returned by calls to Builders;
2609 other Builders will automatically
2610 flatten lists specified as input,
2611 but direct Python manipulation of
2612 these lists does not:
2613
2614 .ES
2615 foo = Object('foo.c')
2616 bar = Object('bar.c')
2617
2618 # Because `foo' and `bar' are lists returned by the Object() Builder,
2619 # `objects' will be a list containing nested lists:
2620 objects = ['f1.o', foo, 'f2.o', bar, 'f3.o']
2621
2622 # Passing such a list to another Builder is all right because
2623 # the Builder will flatten the list automatically:
2624 Program(source = objects)
2625
2626 # If you need to manipulate the list directly using Python, you need to
2627 # call Flatten() yourself, or otherwise handle nested lists:
2628 for object in Flatten(objects):
2629     print str(object)
2630 .EE
2631
2632 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2633 .TP
2634 .RI GetBuildPath( file ", [" ... ])
2635 .TP
2636 .RI env.GetBuildPath( file ", [" ... ])
2637 Returns the
2638 .B scons
2639 path name (or names) for the specified
2640 .I file
2641 (or files).
2642 The specified
2643 .I file
2644 or files
2645 may be
2646 .B scons
2647 Nodes or strings representing path names.
2648
2649 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2650 .TP
2651 .RI GetLaunchDir()
2652 .TP
2653 .RI env.GetLaunchDir()
2654 Returns the absolute path name of the directory from which
2655 .B
2656 scons
2657 was initially invoked.
2658 This can be useful when using the
2659 .BR \-u ,
2660 .BR \-U
2661 or
2662 .BR \-D
2663 options, which internally
2664 change to the directory in which the
2665 .B SConstruct
2666 file is found.
2667
2668 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2669 .TP
2670 .RI GetOption( name )
2671 .TP
2672 .RI env.GetOption( name )
2673 This function provides a way to query a select subset of the scons command line
2674 options from a SConscript file. See 
2675 .IR SetOption () 
2676 for a description of the options available.
2677
2678 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2679 '\".TP
2680 '\".RI GlobalBuilders( flag )
2681 '\"When
2682 '\".B flag
2683 '\"is non-zero,
2684 '\"adds the names of the default builders
2685 '\"(Program, Library, etc.)
2686 '\"to the global name space
2687 '\"so they can be called without an explicit construction environment.
2688 '\"(This is the default.)
2689 '\"When
2690 '\".B
2691 '\"flag is zero,
2692 '\"the names of the default builders are removed
2693 '\"from the global name space
2694 '\"so that an explicit construction environment is required
2695 '\"to call all builders.
2696
2697 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2698 .TP
2699 .RI Help( text )
2700 .TP
2701 .RI env.Help( text )
2702 This specifies help text to be printed if the 
2703 .B -h 
2704 argument is given to
2705 .BR scons .
2706 If
2707 .BR Help
2708 is called multiple times, the text is appended together in the order
2709 that
2710 .BR Help
2711 is called.
2712
2713 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2714 .TP
2715 .RI Ignore( target ", " dependency )
2716 .TP
2717 .RI env.Ignore( target ", " dependency )
2718 The specified dependency file(s)
2719 will be ignored when deciding if
2720 the target file(s) need to be rebuilt.
2721
2722 .ES
2723 env.Ignore('foo', 'foo.c')
2724 env.Ignore('bar', ['bar1.h', 'bar2.h'])
2725 .EE
2726
2727 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2728 .TP 
2729 .RI Import( vars )
2730 .TP 
2731 .RI env.Import( vars )
2732 This tells 
2733 .B scons
2734 to import a list of variables into the current SConscript file. This
2735 will import variables that were exported with
2736 .BR Export ()
2737 or in the 
2738 .I exports
2739 argument to 
2740 .BR SConscript ().
2741 Variables exported by 
2742 .BR SConscript ()
2743 have precedence.
2744 Multiple variable names can be passed to 
2745 .BR Import ()
2746 as separate arguments or as a list. The variable "*" can be used
2747 to import all variables.
2748 Examples:
2749
2750 .ES
2751 Import("env")
2752 Import("env", "variable")
2753 Import(["env", "variable"])
2754 Import("*")
2755 .EE
2756
2757 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2758 .TP
2759 .RI Install( dir ", " source )
2760 .TP
2761 .RI env.Install( dir ", " source )
2762 Installs one or more files in a destination directory.
2763 The file names remain the same.
2764
2765 .ES
2766 env.Install(dir = '/usr/local/bin', source = ['foo', 'bar'])
2767 .EE
2768
2769 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2770 .TP
2771 .RI InstallAs( target ", " source )
2772 .TP
2773 .RI env.InstallAs( target ", " source )
2774 Installs one or more files as specific file names,
2775 allowing changing a file name as part of the
2776 installation.
2777 It is an error if the target and source
2778 list different numbers of files.
2779
2780 .ES
2781 env.InstallAs(target = '/usr/local/bin/foo',
2782               source = 'foo_debug')
2783 env.InstallAs(target = ['../lib/libfoo.a', '../lib/libbar.a'],
2784               source = ['libFOO.a', 'libBAR.a'])
2785 .EE
2786
2787 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2788 .TP
2789 .RI Literal( string )
2790 .TP
2791 .RI env.Literal( string )
2792 The specified
2793 .I string
2794 will be preserved as-is
2795 and not have construction variables expanded.
2796
2797 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2798 .TP
2799 .RI Local( targets )
2800 .TP
2801 .RI env.Local( targets )
2802 The specified
2803 .I targets
2804 will have copies made in the local tree,
2805 even if an already up-to-date copy
2806 exists in a repository.
2807 Returns a list of the target Node or Nodes.
2808
2809 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2810 .TP
2811 .RI env.MergeFlags( arg ", [" unique ])
2812 Merges the specified
2813 .I arg
2814 values to the construction envrionment's construction variables.
2815 If the
2816 .I arg
2817 argument is not a dictionary,
2818 it is converted to one by calling
2819 .B env.ParseFlags()
2820 on the argument
2821 before the values are merged.
2822 Note that
2823 .I arg
2824 must be a single value,
2825 so multiple strings must
2826 be passed in as a list,
2827 not as separate arguments to
2828 .BR env.MergeFlags ().
2829
2830 By default, 
2831 duplicate values are eliminated;
2832 you can, however, specify
2833 .B unique=0
2834 to allow duplicate
2835 values to be added.
2836 When eliminating duplicate values,
2837 any construction variables that end with
2838 the string
2839 .B PATH
2840 keep the left-most unique value.
2841 All other construction variables keep
2842 the right-most unique value.
2843
2844 Examples:
2845
2846 .ES
2847 # Add an optimization flag to $CCFLAGS.
2848 env.MergeFlags('-O3')
2849
2850 # Combine the flags returned from running pkg-config with an optimization
2851 # flag and merge the result into the construction variables.
2852 env.MergeFlags(['!pkg-config gtk+-2.0 --cflags', '-O3'])
2853
2854 env.MergeFlags(['-O3',
2855                '!pkg-config gtk+-2.0 --cflags --libs',
2856                '!pkg-config libpng12 --cflags --libs'])
2857 .EE
2858
2859 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2860 .TP
2861 .RI NoClean( target ", ...)"
2862 .TP
2863 .RI env.NoClean( target ", ...)"
2864 Specifies a list of files or directories which should
2865 .I not
2866 be removed whenever the targets (or their dependencies)
2867 are specified with the
2868 .B -c
2869 command line option.
2870 The specified targets may be a list
2871 or an individual target.
2872 Multiple calls to
2873 .BR NoClean ()
2874 are legal,
2875 and prevent each specified target
2876 from being removed by calls to the
2877 .B -c
2878 option.
2879
2880 Multiple files or directories should be specified
2881 either as separate arguments to the
2882 .BR NoClean ()
2883 method, or as a list.
2884 .BR NoClean ()
2885 will also accept the return value of any of the construction environment
2886 Builder methods.
2887
2888 Calling
2889 .BR NoClean () 
2890 for a target overrides calling
2891 .BR Clean ()
2892 for the same target,
2893 and any targets passed to both functions will
2894 .I not
2895 be removed by the
2896 .B -c
2897 option.
2898
2899 Examples:
2900
2901 .ES
2902 NoClean('foo.elf')
2903 NoClean(env.Program('hello', 'hello.c'))
2904 .EE
2905
2906 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2907 .TP
2908 .RI env.ParseConfig( command ", [" function ", " unique ])
2909 Calls the specified
2910 .I function
2911 to modify the environment as specified by the output of
2912 .I command .
2913 The default
2914 .I function
2915 is
2916 .BR env.MergeFlags (),
2917 which expects the output of a typical
2918 .I *-config command
2919 (for example,
2920 .BR gtk-config )
2921 and adds the options
2922 to the appropriate construction variables.
2923 By default, 
2924 duplicate values are not
2925 added to any construction variables;
2926 you can specify
2927 .B unique=0
2928 to allow duplicate
2929 values to be added.
2930
2931 Interpreted options
2932 and the construction variables they affect
2933 are as specified for the
2934 .BR env.ParseFlags ()
2935 method (which thie method calls).
2936 See that method's description, below,
2937 for a table of options and construction variables.
2938
2939 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2940 .TP
2941 .RI ParseDepends( filename ", [" must_exist ])
2942 .TP
2943 .RI env.ParseDepends( filename ", [" must_exist " " only_one ])
2944 Parses the contents of the specified
2945 .I filename
2946 as a list of dependencies in the style of
2947 .BR Make
2948 or
2949 .BR mkdep ,
2950 and explicitly establishes all of the listed dependencies.
2951
2952 By default,
2953 it is not an error
2954 if the specified
2955 .I filename
2956 does not exist.
2957 The optional
2958 .I must_exit
2959 argument may be set to a non-zero
2960 value to have
2961 scons
2962 throw an exception and
2963 generate an error if the file does not exist,
2964 or is otherwise inaccessible.
2965
2966 The optional
2967 .I only_one
2968 argument may be set to a non-zero
2969 value to have
2970 scons
2971 thrown an exception and
2972 generate an error
2973 if the file contains dependency
2974 information for more than one target.
2975 This can provide a small sanity check
2976 for files intended to be generated
2977 by, for example, the
2978 .B gcc -M
2979 flag,
2980 which should typically only
2981 write dependency information for
2982 one output file into a corresponding
2983 .B .d
2984 file.
2985
2986 The
2987 .I filename
2988 and all of the files listed therein
2989 will be interpreted relative to
2990 the directory of the
2991 .I SConscript
2992 file which calls the
2993 .B ParseDepends
2994 function.
2995
2996 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2997 .TP
2998 .RI env.ParseFlags( flags ", ...)"
2999 Parses one or more strings containing
3000 typical command-line flags for GCC tool chains
3001 and returns a dictionary with the flag values
3002 separated into the appropriate SCons construction variables.
3003 This is intended as a companion to the
3004 .BR env.MergeFlags ()
3005 method, but allows for the values in the returned dictionary
3006 to be modified, if necessary,
3007 before merging them into the construction environment.
3008 (Note that
3009 .BR env.MergeFlags ()
3010 will call this method if its argument is not a dictionary,
3011 so it is usually not necessary to call
3012 .BR env.ParseFlags ()
3013 directly unless you want to manipulate the values.)
3014
3015 If the first character in any string is
3016 an exclamation mark (!),
3017 the rest of the string is executed as a command,
3018 and the output from the command is
3019 parsed as GCC tool chain command-line flags
3020 and added to the resulting dictionary.
3021
3022 Flag values are translated accordig to the prefix found,
3023 and added to the following construction variables:
3024
3025 .ES
3026 -arch               CCFLAGS, LINKFLAGS
3027 -D                  CPPDEFINES
3028 -framework          FRAMEWORKS
3029 -frameworkdir=      FRAMEWORKPATH
3030 -include            CCFLAGS
3031 -isysroot           CCFLAGS, LINKFLAGS
3032 -I                  CPPPATH
3033 -l                  LIBS
3034 -L                  LIBPATH
3035 -mno-cygwin         CCFLAGS, LINKFLAGS
3036 -mwindows           LINKFLAGS
3037 -pthread            CCFLAGS, LINKFLAGS
3038 -Wa,                ASFLAGS, CCFLAGS
3039 -Wl,-rpath=         RPATH
3040 -Wl,-R,             RPATH
3041 -Wl,-R              RPATH
3042 -Wl,                LINKFLAGS
3043 -Wp,                CPPFLAGS
3044 -                   CCFLAGS
3045 +                   CCFLAGS, LINKFLAGS
3046 .EE
3047
3048 Any other strings not associated with options
3049 are assumed to be the names of libraries
3050 and added to the
3051 .B LIBS 
3052 construction variable.
3053
3054 Examples (all of which produce the same result):
3055
3056 .ES
3057 dict = env.ParseFlags('-O2 -Dfoo -Dbar=1')
3058 dict = env.ParseFlags('-O2', '-Dfoo', '-Dbar=1')
3059 dict = env.ParseFlags(['-O2', '-Dfoo -Dbar=1'])
3060 dict = env.ParseFlags('-O2', '!echo -Dfoo -Dbar=1')
3061 .EE
3062
3063 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3064 .TP
3065 env.Perforce()
3066 A factory function that
3067 returns a Builder object
3068 to be used to fetch source files
3069 from the Perforce source code management system.
3070 The returned Builder
3071 is intended to be passed to the
3072 .B SourceCode
3073 function:
3074
3075 .ES
3076 env.SourceCode('.', env.Perforce())
3077 .EE
3078 .IP
3079 Perforce uses a number of external
3080 environment variables for its operation.
3081 Consequently, this function adds the
3082 following variables from the user's external environment
3083 to the construction environment's
3084 ENV dictionary:
3085 P4CHARSET,
3086 P4CLIENT,
3087 P4LANGUAGE,
3088 P4PASSWD,
3089 P4PORT,
3090 P4USER,
3091 SYSTEMROOT,
3092 USER,
3093 and
3094 USERNAME.
3095
3096 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3097 .TP
3098 .RI Platform( string )
3099 Returns a callable object
3100 that can be used to initialize
3101 a construction environment using the
3102 platform keyword of the Environment() method:
3103
3104 .ES
3105 env = Environment(platform = Platform('win32'))
3106 .EE
3107 .TP
3108 .RI env.Platform( string )
3109 Applies the callable object for the specified platform
3110 .I string
3111 to the environment through which the method was called.
3112
3113 .ES
3114 env.Platform('posix')
3115 .EE
3116 .IP
3117 Note that the
3118 .B win32
3119 platform adds the
3120 .B SYSTEMDRIVE
3121 and
3122 .B SYSTEMROOT
3123 variables from the user's external environment
3124 to the construction environment's
3125 .B ENV
3126 dictionary.
3127 This is so that any executed commands
3128 that use sockets to connect with other systems
3129 (such as fetching source files from
3130 external CVS repository specifications like 
3131 .BR :pserver:anonymous@cvs.sourceforge.net:/cvsroot/scons )
3132 will work on Windows systems.
3133
3134 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3135 .TP
3136 .RI Precious( target ", ...)"
3137 .TP
3138 .RI env.Precious( target ", ...)"
3139 Marks each given
3140 .I target
3141 as precious so it is not deleted before it is rebuilt. Normally
3142 .B scons
3143 deletes a target before building it.
3144 Multiple targets can be passed in to a single call to
3145 .BR Precious ().
3146
3147 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3148 .TP
3149 .RI env.Prepend( key = val ", [...])"
3150 Appends the specified keyword arguments
3151 to the beginning of construction variables in the environment.
3152 If the Environment does not have
3153 the specified construction variable,
3154 it is simply added to the environment.
3155 If the values of the construction variable
3156 and the keyword argument are the same type,
3157 then the two values will be simply added together.
3158 Otherwise, the construction variable
3159 and the value of the keyword argument
3160 are both coerced to lists,
3161 and the lists are added together.
3162 (See also the Append method, above.)
3163
3164 .ES
3165 env.Prepend(CCFLAGS = '-g ', FOO = ['foo.yyy'])
3166 .EE
3167
3168 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3169 .TP
3170 .RI env.PrependENVPath( name ", " newpath ", [" envname ", " sep ])
3171 This appends new path elements to the given path in the
3172 specified external environment
3173 .RB ( ENV
3174 by default).
3175 This will only add
3176 any particular path once (leaving the first one it encounters and
3177 ignoring the rest, to preserve path order),
3178 and to help assure this,
3179 will normalize all paths (using
3180 .B os.path.normpath
3181 and
3182 .BR os.path.normcase ).
3183 This can also handle the
3184 case where the given old path variable is a list instead of a
3185 string, in which case a list will be returned instead of a string.
3186 Example:
3187
3188 .ES
3189 print 'before:',env['ENV']['INCLUDE']
3190 include_path = '/foo/bar:/foo'
3191 env.PrependENVPath('INCLUDE', include_path)
3192 print 'after:',env['ENV']['INCLUDE']
3193
3194 yields:
3195 before: /biz:/foo
3196 after: /foo/bar:/foo:/biz
3197 .EE
3198
3199 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3200 .TP
3201 .RI env.PrependUnique( key = val ", [...])"
3202 Appends the specified keyword arguments
3203 to the beginning of construction variables in the environment.
3204 If the Environment does not have
3205 the specified construction variable,
3206 it is simply added to the environment.
3207 If the construction variable being appended to is a list,
3208 then any value(s) that already exist in the
3209 construction variable will
3210 .I not
3211 be added again to the list.
3212
3213 .ES
3214 env.PrependUnique(CCFLAGS = '-g', FOO = ['foo.yyy'])
3215 .EE
3216
3217 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3218 .TP
3219 env.RCS()
3220 A factory function that
3221 returns a Builder object
3222 to be used to fetch source files
3223 from RCS.
3224 The returned Builder
3225 is intended to be passed to the
3226 .B SourceCode
3227 function:
3228
3229 .ES
3230 env.SourceCode('.', env.RCS())
3231 .EE
3232 .IP
3233 Note that
3234 .B scons
3235 will fetch source files
3236 from RCS subdirectories automatically,
3237 so configuring RCS
3238 as demonstrated in the above example
3239 should only be necessary if
3240 you are fetching from
3241 RCS,v
3242 files in the same
3243 directory as the source files,
3244 or if you need to explicitly specify RCS
3245 for a specific subdirectory.
3246
3247 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3248 .TP
3249 .RI env.Replace( key = val ", [...])"
3250 Replaces construction variables in the Environment
3251 with the specified keyword arguments.
3252
3253 .ES
3254 env.Replace(CCFLAGS = '-g', FOO = 'foo.xxx')
3255 .EE
3256
3257 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3258 .TP
3259 .RI Repository( directory )
3260 .TP
3261 .RI env.Repository( directory )
3262 Specifies that
3263 .I directory
3264 is a repository to be searched for files.
3265 Multiple calls to
3266 .BR Repository ()
3267 are legal,
3268 and each one adds to the list of
3269 repositories that will be searched.
3270
3271 To
3272 .BR scons ,
3273 a repository is a copy of the source tree,
3274 from the top-level directory on down,
3275 which may contain
3276 both source files and derived files
3277 that can be used to build targets in
3278 the local source tree.
3279 The canonical example would be an
3280 official source tree maintained by an integrator.
3281 If the repository contains derived files,
3282 then the derived files should have been built using
3283 .BR scons ,
3284 so that the repository contains the necessary
3285 signature information to allow
3286 .B scons
3287 to figure out when it is appropriate to
3288 use the repository copy of a derived file,
3289 instead of building one locally.
3290
3291 Note that if an up-to-date derived file
3292 already exists in a repository,
3293 .B scons
3294 will
3295 .I not
3296 make a copy in the local directory tree.
3297 In order to guarantee that a local copy
3298 will be made,
3299 use the
3300 .B Local()
3301 method.
3302
3303 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3304 .TP
3305 .RI Return( vars )
3306 This tells
3307 .B scons
3308 what variable(s) to use as the return value(s) of the current SConscript
3309 file. These variables will be returned to the "calling" SConscript file
3310 as the return value(s) of 
3311 .BR SConscript ().
3312 Multiple variable names should be passed to 
3313 .BR Return ()
3314 as a list. Example:
3315
3316 .ES
3317 Return("foo")
3318 Return(["foo", "bar"])
3319 .EE
3320
3321 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3322 .TP 
3323 .RI Scanner( function ", [" argument ", " keys ", " path_function ", " node_class ", " node_factory ", " scan_check ", " recursive ])
3324 .TP 
3325 .RI env.Scanner( function ", [" argument ", " keys ", " path_function ", " node_class ", " node_factory ", " scan_check ", " recursive ])
3326 Creates a Scanner object for
3327 the specified
3328 .IR function .
3329 See the section "Scanner Objects,"
3330 below, for a complete explanation of the arguments and behavior.
3331
3332 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3333 .TP
3334 env.SCCS()
3335 A factory function that
3336 returns a Builder object
3337 to be used to fetch source files
3338 from SCCS.
3339 The returned Builder
3340 is intended to be passed to the
3341 .B SourceCode
3342 function:
3343
3344 .ES
3345 env.SourceCode('.', env.SCCS())
3346 .EE
3347 .IP
3348 Note that
3349 .B scons
3350 will fetch source files
3351 from SCCS subdirectories automatically,
3352 so configuring SCCS
3353 as demonstrated in the above example
3354 should only be necessary if
3355 you are fetching from
3356 .I s.SCCS
3357 files in the same
3358 directory as the source files,
3359 or if you need to explicitly specify SCCS
3360 for a specific subdirectory.
3361
3362 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3363 .TP
3364 .RI SConscript( scripts ", [" exports ", " build_dir ", " src_dir ", " duplicate ])
3365 .TP
3366 .RI env.SConscript( scripts ", [" exports ", " build_dir ", " src_dir ", " duplicate ])
3367 .TP
3368 .RI SConscript(dirs= subdirs ", [name=" script ", " exports ", " build_dir ", " src_dir ", " duplicate ])
3369 .TP
3370 .RI env.SConscript(dirs= subdirs ", [name=" script ", " exports ", " build_dir ", " src_dir ", " duplicate ])
3371 This tells
3372 .B scons
3373 to execute
3374 one or more subsidiary SConscript (configuration) files.
3375 There are two ways to call the
3376 .BR SConscript ()
3377 function.
3378
3379 The first way you can call
3380 .BR SConscript ()
3381 is to explicitly specify one or more
3382 .I scripts
3383 as the first argument.
3384 A single script may be specified as a string;
3385 multiple scripts must be specified as a list
3386 (either explicitly or as created by
3387 a function like
3388 .BR Split ()).
3389
3390 The second way you can call
3391 .BR SConscript ()
3392 is to specify a list of (sub)directory names
3393 as a
3394 .RI dirs= subdirs
3395 keyword argument.
3396 In this case,
3397 .B scons
3398 will, by default,
3399 execute a subsidiary configuration file named
3400 .B SConscript
3401 in each of the specified directories.
3402 You may specify a name other than
3403 .B SConscript
3404 by supplying an optional
3405 .RI name= script
3406 keyword argument.
3407
3408 The optional 
3409 .I exports
3410 argument provides a list of variable names or a dictionary of
3411 named values to export to the
3412 .IR script(s) ". "
3413 These variables are locally exported only to the specified
3414 .IR script(s) ,
3415 and do not affect the
3416 global pool of variables used by
3417 the
3418 .BR Export ()
3419 function.
3420 '\"If multiple dirs are provided,
3421 '\"each script gets a fresh export.
3422 The subsidiary
3423 .I script(s)
3424 must use the
3425 .BR Import ()
3426 function to import the variables.
3427
3428 The optional
3429 .I build_dir
3430 argument specifies that all of the target files
3431 (for example, object files and executables)
3432 that would normally be built in the subdirectory in which
3433 .I script
3434 resides should actually
3435 be built in
3436 .IR build_dir .
3437 .I build_dir
3438 is interpreted relative to the directory
3439 of the calling SConscript file.
3440
3441 The optional
3442 .I src_dir
3443 argument specifies that the
3444 source files from which
3445 the target files should be built
3446 can be found in
3447 .IR src_dir .
3448 .I src_dir
3449 is interpreted relative to the directory
3450 of the calling SConscript file.
3451
3452 By default,
3453 .B scons
3454 will link or copy (depending on the platform)
3455 all the source files into the build directory.
3456 This behavior may be disabled by
3457 setting the optional
3458 .I duplicate
3459 argument to 0
3460 (it is set to 1 by default),
3461 in which case
3462 .B scons
3463 will refer directly to
3464 the source files in their source directory
3465 when building target files.
3466 (Setting
3467 .IR duplicate =0
3468 is usually safe, and always more efficient
3469 than the default of
3470 .IR duplicate =1,
3471 but it may cause build problems in certain end-cases,
3472 such as compiling from source files that
3473 are generated by the build.)
3474
3475 Any variables returned by 
3476 .I script 
3477 using 
3478 .BR Return ()
3479 will be returned by the call to
3480 .BR SConscript (). 
3481
3482 Examples:
3483
3484 .ES
3485 SConscript('subdir/SConscript')
3486 foo = SConscript('sub/SConscript', exports='env')
3487 SConscript('dir/SConscript', exports=['env', 'variable'])
3488 SConscript('src/SConscript', build_dir='build', duplicate=0)
3489 SConscript('bld/SConscript', src_dir='src', exports='env variable')
3490 SConscript(dirs=['sub1', 'sub2'])
3491 SConscript(dirs=['sub3', 'sub4'], name='MySConscript')
3492 .EE
3493
3494 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3495 .TP
3496 .RI SConscriptChdir( value )
3497 .TP
3498 .RI env.SConscriptChdir( value )
3499 By default,
3500 .B scons
3501 changes its working directory
3502 to the directory in which each
3503 subsidiary SConscript file lives.
3504 This behavior may be disabled
3505 by specifying either:
3506
3507 .ES
3508 SConscriptChdir(0)
3509 env.SConscriptChdir(0)
3510 .EE
3511 .IP
3512 in which case
3513 .B scons
3514 will stay in the top-level directory
3515 while reading all SConscript files.
3516 (This may be necessary when building from repositories,
3517 when all the directories in which SConscript files may be found
3518 don't necessarily exist locally.)
3519
3520 You may enable and disable
3521 this ability by calling
3522 SConscriptChdir()
3523 multiple times:
3524
3525 .ES
3526 env = Environment()
3527 SConscriptChdir(0)
3528 SConscript('foo/SConscript')    # will not chdir to foo
3529 env.SConscriptChdir(1)
3530 SConscript('bar/SConscript')    # will chdir to bar
3531 .EE
3532
3533 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3534 .TP
3535 .RI SConsignFile([ file , dbm_module ])
3536 .TP
3537 .RI env.SConsignFile([ file , dbm_module ])
3538 This tells
3539 .B scons
3540 to store all file signatures
3541 in the specified database
3542 .IR file .
3543 If the
3544 .I file
3545 name is omitted,
3546 .B .sconsign
3547 is used by default.
3548 (The actual file name(s) stored on disk
3549 may have an appropriated suffix appended
3550 by the
3551 .IR  dbm_module .)
3552 If
3553 .I file
3554 is not an absolute path name,
3555 the file is placed in the same directory as the top-level
3556 .B SConstruct
3557 file.
3558
3559 If
3560 .I file
3561 is
3562 .BR None ,
3563 then
3564 .B scons
3565 will store file signatures
3566 in a separate
3567 .B .sconsign
3568 file in each directory,
3569 not in one global database file.
3570 (This was the default behavior
3571 prior to SCons 0.96.91 and 0.97.)
3572
3573 The optional
3574 .I dbm_module
3575 argument can be used to specify
3576 which Python database module
3577 The default is to use a custom
3578 .B SCons.dblite
3579 module that uses pickled
3580 Python data structures,
3581 and which works on all Python versions from 1.5.2 on.
3582
3583 Examples:
3584
3585 .ES
3586 # Explicitly stores signatures in ".sconsign.dblite"
3587 # in the top-level SConstruct directory (the
3588 # default behavior).
3589 SConsignFile()
3590
3591 # Stores signatures in the file "etc/scons-signatures"
3592 # relative to the top-level SConstruct directory.
3593 SConsignFile("etc/scons-signatures")
3594
3595 # Stores signatures in the specified absolute file name.
3596 SConsignFile("/home/me/SCons/signatures")
3597
3598 # Stores signatures in a separate .sconsign file
3599 # in each directory.
3600 SConsignFile(None)
3601 .EE
3602
3603 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3604 .TP
3605 .RI env.SetDefault(key = val ", [...])"
3606 Sets construction variables to default values specified with the keyword
3607 arguments if (and only if) the variables are not already set.
3608 The following statements are equivalent:
3609
3610 .ES
3611 env.SetDefault(FOO = 'foo')
3612
3613 if not env.has_key('FOO'): env['FOO'] = 'foo'
3614 .EE
3615
3616 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3617 .TP
3618 .RI SetOption( name ", " value )
3619 .TP
3620 .RI env.SetOption( name ", " value )
3621 This function provides a way to set a select subset of the scons command
3622 line options from a SConscript file. The options supported are:
3623 .B clean
3624 which corresponds to -c, --clean, and --remove;
3625 .B duplicate
3626 which 
3627 corresponds to --duplicate;
3628 .B implicit_cache
3629 which corresponds to --implicit-cache;
3630 .B max_drift
3631 which corresponds to --max-drift;
3632 .B num_jobs
3633 which corresponds to -j and --jobs.
3634 See the documentation for the
3635 corresponding command line object for information about each specific
3636 option. Example:
3637
3638 .ES
3639 SetOption('max_drift', 1)
3640 .EE
3641
3642 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3643 .TP
3644 .RI SideEffect( side_effect ", " target )
3645 .TP
3646 .RI env.SideEffect( side_effect ", " target )
3647 Declares
3648 .I side_effect
3649 as a side effect of building
3650 .IR target . 
3651 Both 
3652 .I side_effect 
3653 and
3654 .I target
3655 can be a list, a file name, or a node.
3656 A side effect is a target that is created
3657 as a side effect of building other targets.
3658 For example, a Windows PDB
3659 file is created as a side effect of building the .obj
3660 files for a static library.
3661 If a target is a side effect of multiple build commands,
3662 .B scons
3663 will ensure that only one set of commands
3664 is executed at a time.
3665 Consequently, you only need to use this method
3666 for side-effect targets that are built as a result of
3667 multiple build commands.
3668
3669 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3670 .TP
3671 .RI SourceCode( entries ", " builder )
3672 .TP
3673 .RI env.SourceCode( entries ", " builder )
3674 Arrange for non-existent source files to
3675 be fetched from a source code management system
3676 using the specified
3677 .IR builder .
3678 The specified
3679 .I entries
3680 may be a Node, string or list of both,
3681 and may represent either individual
3682 source files or directories in which
3683 source files can be found.
3684
3685 For any non-existent source files,
3686 .B scons
3687 will search up the directory tree
3688 and use the first
3689 .B SourceCode
3690 builder it finds.
3691 The specified
3692 .I builder
3693 may be
3694 .BR None ,
3695 in which case
3696 .B scons
3697 will not use a builder to fetch
3698 source files for the specified
3699 .IR entries ,
3700 even if a
3701 .B SourceCode
3702 builder has been specified
3703 for a directory higher up the tree.
3704
3705 .B scons
3706 will, by default,
3707 fetch files from SCCS or RCS subdirectories
3708 without explicit configuration.
3709 This takes some extra processing time
3710 to search for the necessary
3711 source code management files on disk.
3712 You can avoid these extra searches
3713 and speed up your build a little
3714 by disabling these searches as follows:
3715
3716 .ES
3717 env.SourceCode('.', None)
3718 .EE
3719
3720 .IP
3721 Note that if the specified
3722 .I builder
3723 is one you create by hand,
3724 it must have an associated
3725 construction environment to use
3726 when fetching a source file.
3727
3728 .B scons
3729 provides a set of canned factory
3730 functions that return appropriate
3731 Builders for various popular
3732 source code management systems.
3733 Canonical examples of invocation include:
3734
3735 .ES
3736 env.SourceCode('.', env.BitKeeper('/usr/local/BKsources'))
3737 env.SourceCode('src', env.CVS('/usr/local/CVSROOT'))
3738 env.SourceCode('/', env.RCS())
3739 env.SourceCode(['f1.c', 'f2.c'], env.SCCS())
3740 env.SourceCode('no_source.c', None)
3741 .EE
3742 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion'))
3743
3744 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3745 .TP
3746 .RI env.subst( string ", [" raw ", " target ", " source ", " conv ])
3747 Performs construction variable interpolation
3748 on the specified string argument.
3749
3750 By default,
3751 leading or trailing white space will
3752 be removed from the result.
3753 and all sequences of white space
3754 will be compressed to a single space character.
3755 Additionally, any
3756 .B $(
3757 and
3758 .B $)
3759 character sequences will be stripped from the returned string,
3760 The optional
3761 .I raw
3762 argument may be set to
3763 .B 1
3764 if you want to preserve white space and
3765 .BR $( - $)
3766 sequences.
3767 The
3768 .I raw
3769 argument may be set to
3770 .B 2
3771 if you want to strip
3772 all characters between
3773 any
3774 .B $(
3775 and
3776 .B $)
3777 pairs
3778 (as is done for signature calculation).
3779
3780 The optional
3781 .I target
3782 and
3783 .I source
3784 keyword arguments
3785 must be set to lists of
3786 target and source nodes, respectively,
3787 if you want the
3788 .BR $TARGET ,
3789 .BR $TARGETS ,
3790 .BR $SOURCE
3791 and
3792 .BR $SOURCES
3793 to be available for expansion.
3794 This is usually necessary if you are
3795 calling
3796 .BR env.subst ()
3797 from within a Python function used
3798 as an SCons action.
3799
3800 By default,
3801 all returned values are converted
3802 to their string representation.
3803 The optional
3804 .I conv
3805 argument
3806 may specify a conversion function
3807 that will be used in place of
3808 the default.
3809 For example, if you want Python objects
3810 (including SCons Nodes)
3811 to be returned as Python objects,
3812 you can use the Python
3813 .B lambda
3814 idiom to pass in an unnamed function
3815 that simply returns its unconverted argument.
3816
3817 .ES
3818 print env.subst("The C compiler is: $CC")
3819
3820 def compile(target, source, env):
3821     sourceDir = env.subst("${SOURCE.srcdir}",
3822                           target=target,
3823                           source=source)
3824
3825 source_nodes = env.subst('$EXPAND_TO_NODELIST',
3826                          conv=lambda x: x)
3827 .EE
3828
3829 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3830 '\".TP
3831 '\".RI Subversion( repository ", " module )
3832 '\"A factory function that
3833 '\"returns a Builder object
3834 '\"to be used to fetch source files
3835 '\"from the specified Subversion
3836 '\".IR repository .
3837 '\"The returned Builder
3838 '\"is intended to be passed to the
3839 '\".B SourceCode
3840 '\"function.
3841 '\"
3842 '\"The optional specified
3843 '\".I module
3844 '\"will be added to the beginning
3845 '\"of all repository path names;
3846 '\"this can be used, in essence,
3847 '\"to strip initial directory names
3848 '\"from the repository path names,
3849 '\"so that you only have to
3850 '\"replicate part of the repository
3851 '\"directory hierarchy in your
3852 '\"local build directory:
3853 '\"
3854 '\".ES
3855 '\"# Will fetch foo/bar/src.c
3856 '\"# from /usr/local/Subversion/foo/bar/src.c.
3857 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion'))
3858 '\"
3859 '\"# Will fetch bar/src.c
3860 '\"# from /usr/local/Subversion/foo/bar/src.c.
3861 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion', 'foo'))
3862 '\"
3863 '\"# Will fetch src.c
3864 '\"# from /usr/local/Subversion/foo/bar/src.c.
3865 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion', 'foo/bar'))
3866 '\".EE
3867
3868 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3869 .TP
3870 .RI SourceSignatures( type )
3871 .TP
3872 .RI env.SourceSignatures( type )
3873 This function tells SCons what type of signature to use for source files:
3874 .B "MD5"
3875 or
3876 .BR "timestamp" .
3877 If the environment method is used,
3878 the specified type of source signature
3879 is only used when deciding whether targets
3880 built with that environment are up-to-date or must be rebuilt.
3881 If the global function is used,
3882 the specified type of source signature becomes the default
3883 used for all decisions
3884 about whether targets are up-to-date.
3885
3886 "MD5" means the signature of a source file
3887 is the MD5 checksum of its contents.
3888 "timestamp" means the signature of a source file
3889 is its timestamp (modification time).
3890 There is no different between the two behaviors
3891 for Python
3892 .BR Value ()
3893 node objects.
3894 "MD5" signatures take longer to compute,
3895 but are more accurate than "timestamp" signatures.
3896 The default is "MD5".
3897
3898 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3899 .TP
3900 .RI Split( arg )
3901 .TP
3902 .RI env.Split( arg )
3903 Returns a list of file names or other objects.
3904 If arg is a string,
3905 it will be split on strings of white-space characters
3906 within the string,
3907 making it easier to write long lists of file names.
3908 If arg is already a list,
3909 the list will be returned untouched.
3910 If arg is any other type of object,
3911 it will be returned as a list
3912 containing just the object.
3913
3914 .ES
3915 files = Split("f1.c f2.c f3.c")
3916 files = env.Split("f4.c f5.c f6.c")
3917 files = Split("""
3918         f7.c
3919         f8.c
3920         f9.c
3921 """)
3922 .EE
3923
3924 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3925 .TP
3926 .RI TargetSignatures( type )
3927 .TP
3928 .RI env.TargetSignatures( type )
3929 This function tells SCons what type of signatures to use
3930 for target files:
3931 .B "build"
3932 or
3933 .BR "content" .
3934 If the environment method is used,
3935 the specified type of signature is only used
3936 for targets built with that environment.
3937 If the global function is used,
3938 the specified type of signature becomes the default
3939 used for all target files that
3940 don't have an explicit target signature type
3941 specified for their environments.
3942
3943 "build" means the signature of a target file
3944 is made by concatenating all of the
3945 signatures of all its source files.
3946 "content" means the signature of a target
3947 file is an MD5 checksum of its contents.
3948 "build" signatures are usually faster to compute,
3949 but "content" signatures can prevent unnecessary rebuilds
3950 when a target file is rebuilt to the exact same contents
3951 as the previous build.
3952 The default is "build".
3953
3954 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3955 .TP
3956 .RI Tool( string [, toolpath ", " **kw ])
3957 Returns a callable object
3958 that can be used to initialize
3959 a construction environment using the
3960 tools keyword of the Environment() method.
3961 The object may be called with a construction
3962 environment as an argument,
3963 in which case the object will
3964 add the necessary variables
3965 to the construction environment
3966 and the name of the tool will be added to the
3967 .B $TOOLS
3968 construction variable.
3969
3970 Additional keyword arguments are passed to the tool's
3971 .B generate()
3972 method.
3973
3974 .ES
3975 env = Environment(tools = [ Tool('msvc') ])
3976
3977 env = Environment()
3978 t = Tool('msvc')
3979 t(env)  # adds 'msvc' to the TOOLS variable
3980 u = Tool('opengl', toolpath = ['tools'])
3981 u(env)  # adds 'opengl' to the TOOLS variable
3982 .EE
3983 .TP
3984 .RI env.Tool( string [, toolpath ", " **kw ])
3985 Applies the callable object for the specified tool
3986 .I string
3987 to the environment through which the method was called.
3988
3989 Additional keyword arguments are passed to the tool's
3990 .B generate()
3991 method.
3992
3993 .ES
3994 env.Tool('gcc')
3995 env.Tool('opengl', toolpath = ['build/tools'])
3996 .EE
3997
3998 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3999 .TP
4000 .RI Value( value )
4001 .TP
4002 .RI env.Value( value )
4003 Returns a Node object representing the specified Python value.  Value
4004 nodes can be used as dependencies of targets.  If the result of
4005 calling
4006 .BR str( value )
4007 changes between SCons runs, any targets depending on
4008 .BR Value( value )
4009 will be rebuilt.  When using timestamp source signatures, Value nodes'
4010 timestamps are equal to the system time when the node is created.
4011
4012 .ES
4013 def create(target, source, env):
4014     f = open(str(target[0]), 'wb')
4015     f.write('prefix=' + source[0].get_contents())
4016     
4017 prefix = ARGUMENTS.get('prefix', '/usr/local')
4018 env = Environment()
4019 env['BUILDERS']['Config'] = Builder(action = create)
4020 env.Config(target = 'package-config', source = Value(prefix))
4021 .EE
4022
4023 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4024 .TP
4025 .RI WhereIs( program ", [" path  ", " pathext ", " reject ])
4026 .TP
4027 .RI env.WhereIs( program ", [" path  ", " pathext ", " reject ])
4028
4029 Searches for the specified executable
4030 .I program,
4031 returning the full path name to the program
4032 if it is found,
4033 and returning None if not.
4034 Searches the specified
4035 .I path,
4036 the value of the calling environment's PATH
4037 (env['ENV']['PATH']),
4038 or the user's current external PATH
4039 (os.environ['PATH'])
4040 by default.
4041 On Windows systems, searches for executable
4042 programs with any of the file extensions
4043 listed in the specified
4044 .I pathext,
4045 the calling environment's PATHEXT
4046 (env['ENV']['PATHEXT'])
4047 or the user's current PATHEXT
4048 (os.environ['PATHEXT'])
4049 by default.
4050 Will not select any
4051 path name or names
4052 in the specified
4053 .I reject
4054 list, if any.
4055
4056 .SS SConscript Variables
4057 In addition to the global functions and methods,
4058 .B scons
4059 supports a number of Python variables
4060 that can be used in SConscript files
4061 to affect how you want the build to be performed.
4062 These variables may be accessed from custom Python modules that you
4063 import into an SConscript file by adding the following
4064 to the Python module:
4065
4066 .ES
4067 from SCons.Script import *
4068 .EE
4069
4070 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4071 .TP
4072 ARGLIST
4073 A list
4074 .IR keyword = value
4075 arguments specified on the command line.
4076 Each element in the list is a tuple
4077 containing the
4078 .RI ( keyword , value )
4079 of the argument.
4080 The separate
4081 .I keyword
4082 and
4083 .I value
4084 elements of the tuple
4085 can be accessed by
4086 subscripting for element
4087 .B [0]
4088 and
4089 .B [1]
4090 of the tuple, respectively.
4091
4092 .ES
4093 print "first keyword, value =", ARGLIST[0][0], ARGLIST[0][1]
4094 print "second keyword, value =", ARGLIST[1][0], ARGLIST[1][1]
4095 third_tuple = ARGLIST[2]
4096 print "third keyword, value =", third_tuple[0], third_tuple[1]
4097 for key, value in ARGLIST:
4098     # process key and value
4099 .EE
4100
4101 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4102 .TP
4103 ARGUMENTS
4104 A dictionary of all the
4105 .IR keyword = value
4106 arguments specified on the command line.
4107 The dictionary is not in order,
4108 and if a given keyword has
4109 more than one value assigned to it
4110 on the command line,
4111 the last (right-most) value is
4112 the one in the
4113 .B ARGUMENTS
4114 dictionary.
4115
4116 .ES
4117 if ARGUMENTS.get('debug', 0):
4118     env = Environment(CCFLAGS = '-g')
4119 else:
4120     env = Environment()
4121 .EE
4122
4123 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4124 .TP
4125 BUILD_TARGETS
4126 A list of the targets which
4127 .B scons
4128 will actually try to build,
4129 regardless of whether they were specified on
4130 the command line or via the
4131 .BR Default ()
4132 function or method.
4133 The elements of this list may be strings
4134 .I or
4135 nodes, so you should run the list through the Python
4136 .B str
4137 function to make sure any Node path names
4138 are converted to strings.
4139
4140 Because this list may be taken from the
4141 list of targets specified using the
4142 .BR Default ()
4143 function or method,
4144 the contents of the list may change
4145 on each successive call to
4146 .BR Default ().
4147 See the
4148 .B DEFAULT_TARGETS
4149 list, below,
4150 for additional information.
4151
4152 .ES
4153 if 'foo' in BUILD_TARGETS:
4154     print "Don't forget to test the `foo' program!"
4155 if 'special/program' in BUILD_TARGETS:
4156     SConscript('special')
4157 .EE
4158 .IP
4159 Note that the
4160 .B BUILD_TARGETS
4161 list only contains targets expected listed
4162 on the command line or via calls to the
4163 .BR Default ()
4164 function or method.
4165 It does
4166 .I not
4167 contain all dependent targets that will be built as
4168 a result of making the sure the explicitly-specified
4169 targets are up to date.
4170
4171 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4172 .TP
4173 COMMAND_LINE_TARGETS
4174 A list of the targets explicitly specified on
4175 the command line.
4176 If there are no targets specified on the command line,
4177 the list is empty.
4178 This can be used, for example,
4179 to take specific actions only
4180 when a certain target or targets
4181 is explicitly being built:
4182
4183 .ES
4184 if 'foo' in COMMAND_LINE_TARGETS:
4185     print "Don't forget to test the `foo' program!"
4186 if 'special/program' in COMMAND_LINE_TARGETS:
4187     SConscript('special')
4188 .EE
4189
4190 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4191 .TP
4192 DEFAULT_TARGETS
4193 A list of the target
4194 .I nodes
4195 that have been specified using the
4196 .BR Default ()
4197 function or method.
4198 The elements of the list are nodes,
4199 so you need to run them through the Python
4200 .B str
4201 function to get at the path name for each Node.
4202
4203 .ES
4204 print str(DEFAULT_TARGETS[0])
4205 if 'foo' in map(str, DEFAULT_TARGETS):
4206     print "Don't forget to test the `foo' program!"
4207 .EE
4208 .IP
4209 The contents of the
4210 .B DEFAULT_TARGETS
4211 list change on on each successive call to the
4212 .BR Default ()
4213 function:
4214
4215 .ES
4216 print map(str, DEFAULT_TARGETS)   # originally []
4217 Default('foo')
4218 print map(str, DEFAULT_TARGETS)   # now a node ['foo']
4219 Default('bar')
4220 print map(str, DEFAULT_TARGETS)   # now a node ['foo', 'bar']
4221 Default(None)
4222 print map(str, DEFAULT_TARGETS)   # back to []
4223 .EE
4224 .IP
4225 Consequently, be sure to use
4226 .B DEFAULT_TARGETS
4227 only after you've made all of your
4228 .BR Default ()
4229 calls,
4230 or else simply be careful of the order
4231 of these statements in your SConscript files
4232 so that you don't look for a specific
4233 default target before it's actually been added to the list.
4234
4235 .SS Construction Variables
4236 .\" XXX From Gary Ruben, 23 April 2002:
4237 .\" I think it would be good to have an example with each construction
4238 .\" variable description in the documentation.
4239 .\" eg.
4240 .\" CC     The C compiler
4241 .\"    Example: env["CC"] = "c68x"
4242 .\"    Default: env["CC"] = "cc"
4243 .\" 
4244 .\" CCCOM  The command line ...
4245 .\"    Example:
4246 .\"        To generate the compiler line c68x -ps -qq -mr -o $TARGET $SOURCES
4247 .\"        env["CC"] = "c68x"
4248 .\"        env["CFLAGS"] = "-ps -qq -mr"
4249 .\"        env["CCCOM"] = "$CC $CFLAGS -o $TARGET $SOURCES
4250 .\"    Default:
4251 .\"        (I dunno what this is ;-)
4252 A construction environment has an associated dictionary of
4253 .I construction variables
4254 that are used by built-in or user-supplied build rules.
4255 Construction variables must follow the same rules for
4256 Python identifiers:
4257 the initial character must be an underscore or letter,
4258 followed by any number of underscores, letters, or digits.
4259
4260 A number of useful construction variables are automatically defined by
4261 scons for each supported platform, and additional construction variables
4262 can be defined by the user. The following is a list of the automatically
4263 defined construction variables:
4264
4265 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4266 '\" BEGIN GENERATED CONSTRUCTION VARIABLE DESCRIPTIONS
4267 '\"
4268 '\" The descriptions below of the various SCons contruction variables
4269 '\" are generated from the .xml files that live next to the various
4270 '\" Python modules in the build enginer library.  If you're reading
4271 '\" this [gnt]roff file with an eye towards patching this man page,
4272 '\" you can still submit a diff against this text, but it will have to
4273 '\" be translated to a diff against the underlying .xml file before the
4274 '\" patch is actually accepted.  If you do that yourself, it will make
4275 '\" it easier to integrate the patch.
4276 '\"
4277 '\" BEGIN GENERATED CONSTRUCTION VARIABLE DESCRIPTIONS
4278 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4279 .so variables.man
4280 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4281 '\" END GENERATED CONSTRUCTION VARIABLE DESCRIPTIONS
4282 '\"
4283 '\" The descriptions above of the various SCons contruction variables
4284 '\" are generated from the .xml files that live next to the various
4285 '\" Python modules in the build enginer library.  If you're reading
4286 '\" this [gnt]roff file with an eye towards patching this man page,
4287 '\" you can still submit a diff against this text, but it will have to
4288 '\" be translated to a diff against the underlying .xml file before the
4289 '\" patch is actually accepted.  If you do that yourself, it will make
4290 '\" it easier to integrate the patch.
4291 '\"
4292 '\" END GENERATED CONSTRUCTION VARIABLE DESCRIPTIONS
4293 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4294
4295 .LP
4296 Construction variables can be retrieved and set using the 
4297 .B Dictionary 
4298 method of the construction environment:
4299
4300 .ES
4301 dict = env.Dictionary()
4302 dict["CC"] = "cc"
4303 .EE
4304
4305 or using the [] operator:
4306
4307 .ES
4308 env["CC"] = "cc"
4309 .EE
4310
4311 Construction variables can also be passed to the construction environment
4312 constructor:
4313
4314 .ES
4315 env = Environment(CC="cc")
4316 .EE
4317
4318 or when copying a construction environment using the 
4319 .B Copy 
4320 method:
4321
4322 .ES
4323 env2 = env.Copy(CC="cl.exe")
4324 .EE
4325
4326 .SS Configure Contexts
4327
4328 .B scons
4329 supports
4330 .I configure contexts,
4331 an integrated mechanism similar to the
4332 various AC_CHECK macros in GNU autoconf
4333 for testing for the existence of C header
4334 files, libraries, etc.
4335 In contrast to autoconf,
4336 .B scons
4337 does not maintain an explicit cache of the tested values,
4338 but uses its normal dependency tracking to keep the checked values
4339 up to date. However, users may override this behaviour with the 
4340 .B --config
4341 command line option.
4342
4343 The following methods can be used to perform checks:
4344
4345 .TP
4346 .RI Configure( env ", [" custom_tests ", " conf_dir ", " log_file ", " config_h ])
4347 .TP
4348 .RI env.Configure([ custom_tests ", " conf_dir ", " log_file ", " config_h ])
4349 This creates a configure context, which can be used to perform checks.
4350 .I env
4351 specifies the environment for building the tests.
4352 This environment may be modified when performing checks.
4353 .I custom_tests
4354 is a dictionary containing custom tests.
4355 See also the section about custom tests below. 
4356 By default, no custom tests are added to the configure context.
4357 .I conf_dir
4358 specifies a directory where the test cases are built.
4359 Note that this directory is not used for building
4360 normal targets.
4361 The default value is the directory
4362 #/.sconf_temp.
4363 .I log_file
4364 specifies a file which collects the output from commands
4365 that are executed to check for the existence of header files, libraries, etc.
4366 The default is the file #/config.log.
4367 If you are using the
4368 .B BuildDir
4369 method,
4370 you may want to specify a subdirectory under your build directory.
4371 .I config_h
4372 specifies a C header file where the results of tests 
4373 will be written, e.g. #define HAVE_STDIO_H, #define HAVE_LIBM, etc. 
4374 The default is to not write a
4375 .B config.h
4376 file.
4377 You can specify the same
4378 .B config.h
4379 file in multiple calls to Configure,
4380 in which case
4381 .B scons
4382 will concatenate all results in the specified file.
4383 Note that SCons
4384 uses its normal dependency checking
4385 to decide if it's necessary to rebuild
4386 the specified
4387 .I config_h
4388 file.
4389 This means that the file is not necessarily re-built each
4390 time scons is run,
4391 but is only rebuilt if its contents will have changed
4392 and some target that depends on the
4393 .I config_h
4394 file is being built.
4395
4396 .EE
4397 A created
4398 .B Configure
4399 instance has the following associated methods:
4400
4401 .TP 
4402 .RI Configure.Finish( self )
4403 This method should be called after configuration is done.
4404 It returns the environment as modified
4405 by the configuration checks performed.
4406 After this method is called, no further checks can be performed
4407 with this configuration context.
4408 However, you can create a new 
4409 .RI Configure 
4410 context to perform additional checks.
4411 Only one context should be active at a time.
4412
4413 The following Checks are predefined.
4414 (This list will likely grow larger as time
4415 goes by and developers contribute new useful tests.)
4416
4417 .TP
4418 .RI Configure.CheckHeader( self ", " header ", [" include_quotes ", " language ])
4419 Checks if 
4420 .I header
4421 is usable in the specified language.
4422 .I header
4423 may be a list,
4424 in which case the last item in the list
4425 is the header file to be checked,
4426 and the previous list items are
4427 header files whose
4428 .B #include
4429 lines should precede the
4430 header line being checked for.
4431 The optional argument 
4432 .I include_quotes 
4433 must be
4434 a two character string, where the first character denotes the opening
4435 quote and the second character denotes the closing quote.
4436 By default, both characters  are " (double quote).
4437 The optional argument
4438 .I language
4439 should be either
4440 .B C
4441 or
4442 .B C++
4443 and selects the compiler to be used for the check.
4444 Returns 1 on success and 0 on failure.
4445
4446 .TP
4447 .RI Configure.CheckCHeader( self ", " header ", [" include_quotes ])
4448 This is a wrapper around
4449 .B Configure.CheckHeader
4450 which checks if 
4451 .I header
4452 is usable in the C language.
4453 .I header
4454 may be a list,
4455 in which case the last item in the list
4456 is the header file to be checked,
4457 and the previous list items are
4458 header files whose
4459 .B #include
4460 lines should precede the
4461 header line being checked for.
4462 The optional argument 
4463 .I include_quotes 
4464 must be
4465 a two character string, where the first character denotes the opening
4466 quote and the second character denotes the closing quote (both default
4467 to \N'34').
4468 Returns 1 on success and 0 on failure.
4469
4470 .TP
4471 .RI Configure.CheckCXXHeader( self ", " header ", [" include_quotes ])
4472 This is a wrapper around
4473 .B Configure.CheckHeader
4474 which checks if 
4475 .I header
4476 is usable in the C++ language.
4477 .I header
4478 may be a list,
4479 in which case the last item in the list
4480 is the header file to be checked,
4481 and the previous list items are
4482 header files whose
4483 .B #include
4484 lines should precede the
4485 header line being checked for.
4486 The optional argument 
4487 .I include_quotes 
4488 must be
4489 a two character string, where the first character denotes the opening
4490 quote and the second character denotes the closing quote (both default
4491 to \N'34').
4492 Returns 1 on success and 0 on failure. 
4493
4494 .TP
4495 .RI Configure.CheckFunc( self ", " function_name ", [" header ", " language ])
4496 Checks if the specified
4497 C or C++ function is available.
4498 .I function_name
4499 is the name of the function to check for.
4500 The optional
4501 .I header
4502 argument is a string
4503 that will be
4504 placed at the top
4505 of the test file
4506 that will be compiled
4507 to check if the function exists;
4508 the default is:
4509 .ES
4510 #ifdef __cplusplus
4511 extern "C"
4512 #endif
4513 char function_name();
4514 .EE
4515 The optional
4516 .I language
4517 argument should be
4518 .B C
4519 or
4520 .B C++
4521 and selects the compiler to be used for the check;
4522 the default is "C".
4523
4524 .TP 
4525 .RI Configure.CheckLib( self ", [" library ", " symbol ", " header ", " language ", " autoadd=1 ])
4526 Checks if 
4527 .I library 
4528 provides 
4529 .IR symbol .
4530 If the value of
4531 .I autoadd
4532 is 1 and the library provides the specified
4533 .IR symbol ,
4534 appends the library to the LIBS construction environment variable.
4535 .I library 
4536 may also be None (the default),
4537 in which case 
4538 .I symbol 
4539 is checked with the current LIBS variable,
4540 or a list of library names,
4541 in which case each library in the list
4542 will be checked for
4543 .IR symbol .
4544 If 
4545 .I symbol
4546 is not set or is
4547 .BR None ,
4548 then
4549 .BR Configure.CheckLib ()
4550 just checks if
4551 you can link against the specified
4552 .IR library .
4553 The optional
4554 .I language
4555 argument should be
4556 .B C
4557 or
4558 .B C++
4559 and selects the compiler to be used for the check;
4560 the default is "C".
4561 The default value for
4562 .I autoadd
4563 is 1.
4564 This method returns 1 on success and 0 on error.
4565
4566 .TP 
4567 .RI Configure.CheckLibWithHeader( self ", " library ", " header ", " language ", [" call ", " autoadd ])
4568
4569 In contrast to the 
4570 .RI Configure.CheckLib 
4571 call, this call provides a more sophisticated way to check against libraries.
4572 Again, 
4573 .I library
4574 specifies the library or a list of libraries to check. 
4575 .I header
4576 specifies a header to check for.
4577 .I header
4578 may be a list,
4579 in which case the last item in the list
4580 is the header file to be checked,
4581 and the previous list items are
4582 header files whose
4583 .B #include
4584 lines should precede the
4585 header line being checked for.
4586 .I language
4587 may be one of 'C','c','CXX','cxx','C++' and 'c++'.
4588 .I call
4589 can be any valid expression (with a trailing ';').
4590 If
4591 .I call
4592 is not set,
4593 the default simply checks that you
4594 can link against the specified
4595 .IR library .
4596 .I autoadd
4597 specifies whether to add the library to the environment (only if the check 
4598 succeeds). This method returns 1 on success and 0 on error.
4599
4600 .TP
4601 .RI Configure.CheckType( self ", " type_name ", [" includes ", " language ])
4602 Checks for the existence of a type defined by
4603 .BR typedef .
4604 .I type_name
4605 specifies the typedef name to check for.
4606 .I includes
4607 is a string containing one or more
4608 .B #include
4609 lines that will be inserted into the program
4610 that will be run to test for the existence of the type.
4611 The optional
4612 .I language
4613 argument should be
4614 .B C
4615 or
4616 .B C++
4617 and selects the compiler to be used for the check;
4618 the default is "C".
4619
4620 .EE
4621 Example of a typical Configure usage:
4622
4623 .ES
4624 env = Environment()
4625 conf = Configure( env )
4626 if not conf.CheckCHeader( 'math.h' ):
4627     print 'We really need math.h!'
4628     Exit(1)
4629 if conf.CheckLibWithHeader( 'qt', 'qapp.h', 'c++', 'QApplication qapp(0,0);' ):
4630     # do stuff for qt - usage, e.g.
4631     conf.env.Append( CPPFLAGS = '-DWITH_QT' )
4632 env = conf.Finish() 
4633 .EE
4634
4635 .EE
4636 You can define your own custom checks. 
4637 in addition to the predefined checks.
4638 These are passed in a dictionary to the Configure function.
4639 This dictionary maps the names of the checks
4640 to user defined Python callables 
4641 (either Python functions or class instances implementing the
4642 .I __call__
4643 method).
4644 The first argument of the call is always a 
4645 .I CheckContext
4646 instance followed by the arguments,
4647 which must be supplied by the user of the check.
4648 These CheckContext instances define the following methods:
4649
4650 .TP 
4651 .RI CheckContext.Message( self ", " text )
4652
4653 Usually called before the check is started. 
4654 .I text
4655 will be displayed to the user, e.g. 'Checking for library X...'
4656
4657 .TP
4658 .RI CheckContext.Result( self, ", " res )
4659
4660 Usually called after the check is done. 
4661 .I res
4662 can be either an integer or a string. In the former case, 'ok' (res != 0) 
4663 or 'failed' (res == 0) is displayed to the user, in the latter case the 
4664 given string is displayed.
4665
4666 .TP
4667 .RI CheckContext.TryCompile( self ", " text ", " extension )
4668 Checks if a file with the specified 
4669 .I extension
4670 (e.g. '.c') containing 
4671 .I text 
4672 can be compiled using the environment's
4673 .B Object 
4674 builder. Returns 1 on success and 0 on failure.
4675
4676 .TP 
4677 .RI CheckContext.TryLink( self ", " text ", " extension )
4678 Checks, if a file with the specified
4679 .I extension
4680 (e.g. '.c') containing 
4681 .I text 
4682 can be compiled using the environment's
4683 .B Program
4684 builder. Returns 1 on success and 0 on failure.
4685
4686 .TP
4687 .RI CheckContext.TryRun( self ", " text ", " extension )
4688 Checks, if a file with the specified
4689 .I extension
4690 (e.g. '.c') containing 
4691 .I text 
4692 can be compiled using the environment's
4693 .B Program
4694 builder. On success, the program is run. If the program
4695 executes successfully
4696 (that is, its return status is 0),
4697 a tuple
4698 .I (1, outputStr)
4699 is returned, where
4700 .I outputStr
4701 is the standard output of the
4702 program.
4703 If the program fails execution
4704 (its return status is non-zero),
4705 then (0, '') is returned.
4706
4707 .TP
4708 .RI CheckContext.TryAction( self ", " action ", [" text ", " extension ])
4709 Checks if the specified
4710 .I action 
4711 with an optional source file (contents
4712 .I text
4713 , extension 
4714 .I extension
4715 = ''
4716 ) can be executed. 
4717 .I action 
4718 may be anything which can be converted to a 
4719 .B scons
4720 .RI Action.
4721 On success,
4722 .I (1, outputStr)
4723 is returned, where
4724 .I outputStr
4725 is the content of the target file.
4726 On failure
4727 .I (0, '')
4728 is returned.
4729
4730 .TP
4731 .RI CheckContext.TryBuild( self ", " builder ", [" text ", " extension ])
4732 Low level implementation for testing specific builds;
4733 the methods above are based on this method.
4734 Given the Builder instance
4735 .I builder
4736 and the optional 
4737 .I text
4738 of a source file with optional
4739 .IR extension ,
4740 this method returns 1 on success and 0 on failure. In addition, 
4741 .I self.lastTarget 
4742 is set to the build target node, if the build was successful.
4743
4744 .EE
4745 Example for implementing and using custom tests:
4746
4747 .ES
4748 def CheckQt(context, qtdir):
4749     context.Message( 'Checking for qt ...' )
4750     lastLIBS = context.env['LIBS']
4751     lastLIBPATH = context.env['LIBPATH']
4752     lastCPPPATH= context.env['CPPPATH']
4753     context.env.Append(LIBS = 'qt', LIBPATH = qtdir + '/lib', CPPPATH = qtdir + '/include' )
4754     ret = context.TryLink("""
4755 #include <qapp.h>
4756 int main(int argc, char **argv) { 
4757   QApplication qapp(argc, argv);
4758   return 0;
4759 }
4760 """)
4761     if not ret:
4762         context.env.Replace(LIBS = lastLIBS, LIBPATH=lastLIBPATH, CPPPATH=lastCPPPATH)
4763     context.Result( ret )
4764     return ret
4765
4766 env = Environment()
4767 conf = Configure( env, custom_tests = { 'CheckQt' : CheckQt } )
4768 if not conf.CheckQt('/usr/lib/qt'):
4769     print 'We really need qt!'
4770     Exit(1)
4771 env = conf.Finish() 
4772 .EE
4773
4774 .SS Construction Variable Options
4775
4776 Often when building software, various options need to be specified at build
4777 time that are not known when the SConstruct/SConscript files are
4778 written. For example, libraries needed for the build may be in non-standard
4779 locations, or site-specific compiler options may need to be passed to the
4780 compiler. 
4781 .B scons
4782 provides a mechanism for overridding construction variables from the
4783 command line or a text-based SConscript file through an Options
4784 object. To create an Options object, call the Options() function:
4785
4786 .TP
4787 .RI Options([ files "], [" args ])
4788 This creates an Options object that will read construction variables from
4789 the file or list of filenames specified in
4790 .IR files .
4791 If no files are specified,
4792 or the
4793 .I files
4794 argument is
4795 .BR None ,
4796 then no files will be read.
4797 The optional argument
4798 .I args
4799 is a dictionary of
4800 values that will override anything read from the specified files;
4801 it is primarily intended to be passed the
4802 .B ARGUMENTS
4803 dictionary that holds variables
4804 specified on the command line.
4805 Example:
4806
4807 .ES
4808 opts = Options('custom.py')
4809 opts = Options('overrides.py', ARGUMENTS)
4810 opts = Options(None, {FOO:'expansion', BAR:7})
4811 .EE
4812
4813 Options objects have the following methods:
4814
4815 .TP
4816 .RI Add( key ", [" help ", " default ", " validator ", " converter ])
4817 This adds a customizable construction variable to the Options object. 
4818 .I key
4819 is the name of the variable. 
4820 .I help 
4821 is the help text for the variable.
4822 .I default 
4823 is the default value of the variable;
4824 if the default value is
4825 .B None
4826 and there is no explicit value specified,
4827 the construction variable will
4828 .I not
4829 be added to the construction environment.
4830 .I validator
4831 is called to validate the value of the variable, and should take three
4832 arguments: key, value, and environment.
4833 The recommended way to handle an invalid value is
4834 to raise an exception (see example below).
4835 .I converter
4836 is called to convert the value before putting it in the environment, and
4837 should take a single argument: value.
4838 The
4839 .I converter
4840 must return a value,
4841 which will be converted into a string
4842 before being validated by the
4843 .I validator
4844 (if any)
4845 and then added to the environment.
4846
4847 Examples:
4848
4849 .ES
4850 opts.Add('CC', 'The C compiler')
4851
4852 def validate_color(key, val, env):
4853     if not val in ['red', 'blue', 'yellow']:
4854         raise "Invalid color value '%s'" % val
4855 opts.Add('COLOR', validator=valid_color)
4856 .EE
4857
4858 .TP
4859 .RI AddOptions( list )
4860 A wrapper script that adds
4861 multiple customizable construction variables
4862 to an Options object.
4863 .I list
4864 is a list of tuple or list objects
4865 that contain the arguments
4866 for an individual call to the
4867 .B Add
4868 method.
4869
4870 .ES
4871 opt.AddOptions(
4872        ('debug', '', 0),
4873        ('CC', 'The C compiler'),
4874        ('VALIDATE', 'An option for testing validation',
4875         'notset', validator, None),
4876     )
4877 .EE
4878
4879 .TP
4880 .RI Update( env ", [" args ])
4881 This updates a construction environment
4882 .I env
4883 with the customized construction variables. Normally this method is not
4884 called directly, but is called indirectly by passing the Options object to
4885 the Environment() function:
4886
4887 .ES
4888 env = Environment(options=opts)
4889 .EE
4890
4891 .IP
4892 The text file(s) that were specified
4893 when the Options object was created
4894 are executed as Python scripts,
4895 and the values of (global) Python variables set in the file
4896 are added to the construction environment.
4897 Example:
4898
4899 .ES
4900 CC = 'my_cc'
4901 .EE
4902
4903 .TP
4904 .RI Save( filename ", " env )
4905 This saves the currently set options into a script file named  
4906 .I filename
4907 that can be used on the next invocation to automatically load the current
4908 settings.  This method combined with the Options method can be used to
4909 support caching of options between runs.
4910
4911 .ES
4912 env = Environment()
4913 opts = Options(['options.cache', 'custom.py'])
4914 opts.Add(...)
4915 opts.Update(env)
4916 opts.Save('options.cache', env)
4917 .EE
4918
4919 .TP
4920 .RI GenerateHelpText( env ", [" sort ])
4921 This generates help text documenting the customizable construction
4922 variables suitable to passing in to the Help() function. 
4923 .I env
4924 is the construction environment that will be used to get the actual values
4925 of customizable variables. Calling with 
4926 an optional
4927 .I sort
4928 function
4929 will cause the output to be sorted
4930 by the specified argument.
4931 The specific
4932 .I sort
4933 function
4934 should take two arguments
4935 and return
4936 -1, 0 or 1
4937 (like the standard Python
4938 .I cmp
4939 function).
4940
4941 .ES
4942 Help(opts.GenerateHelpText(env))
4943 Help(opts.GenerateHelpText(env, sort=cmp))
4944 .EE
4945
4946 .TP
4947 .RI FormatOptionHelpText( env ", " opt ", " help ", " default ", " actual )
4948 This method returns a formatted string
4949 containing the printable help text
4950 for one option.
4951 It is normally not called directly,
4952 but is called by the
4953 .IR GenerateHelpText ()
4954 method to create the returned help text.
4955 It may be overridden with your own
4956 function that takes the arguments specified above
4957 and returns a string of help text formatted to your liking.
4958 Note that the
4959 .IR GenerateHelpText ()
4960 will not put any blank lines or extra
4961 characters in between the entries,
4962 so you must add those characters to the returned
4963 string if you want the entries separated.
4964
4965 .ES
4966 def my_format(env, opt, help, default, actual):
4967     fmt = "\n%s: default=%s actual=%s (%s)\n"
4968     return fmt % (opt, default. actual, help)
4969 opts.FormatOptionHelpText = my_format
4970 .EE
4971
4972 To make it more convenient to work with customizable Options,
4973 .B scons
4974 provides a number of functions
4975 that make it easy to set up
4976 various types of Options:
4977
4978 .TP
4979 .RI BoolOption( key ", " help ", " default )
4980 Return a tuple of arguments
4981 to set up a Boolean option.
4982 The option will use
4983 the specified name
4984 .IR key ,
4985 have a default value of
4986 .IR default ,
4987 and display the specified
4988 .I help
4989 text.
4990 The option will interpret the values
4991 .BR y ,
4992 .BR yes ,
4993 .BR t ,
4994 .BR true ,
4995 .BR 1 ,
4996 .B on
4997 and
4998 .B all
4999 as true,
5000 and the values
5001 .BR n ,
5002 .BR no ,
5003 .BR f ,
5004 .BR false ,
5005 .BR 0 ,
5006 .B off
5007 and
5008 .B none
5009 as false.
5010
5011 .TP
5012 .RI EnumOption( key ", " help ", " default ", " allowed_values ", [" map ", " ignorecase ])
5013 Return a tuple of arguments
5014 to set up an option
5015 whose value may be one
5016 of a specified list of legal enumerated values.
5017 The option will use
5018 the specified name
5019 .IR key ,
5020 have a default value of
5021 .IR default ,
5022 and display the specified
5023 .I help
5024 text.
5025 The option will only support those
5026 values in the
5027 .I allowed_values
5028 list.
5029 The optional
5030 .I map
5031 argument is a dictionary
5032 that can be used to convert
5033 input values into specific legal values
5034 in the
5035 .I allowed_values
5036 list.
5037 If the value of
5038 .I ignore_case
5039 is
5040 .B 0
5041 (the default),
5042 then the values are case-sensitive.
5043 If the value of
5044 .I ignore_case
5045 is
5046 .BR 1 ,
5047 then values will be matched
5048 case-insensitive.
5049 If the value of
5050 .I ignore_case
5051 is
5052 .BR 1 ,
5053 then values will be matched
5054 case-insensitive,
5055 and all input values will be
5056 converted to lower case.
5057
5058 .TP
5059 .RI ListOption( key ", " help ", " default ", " names ", [", map ])
5060 Return a tuple of arguments
5061 to set up an option
5062 whose value may be one or more
5063 of a specified list of legal enumerated values.
5064 The option will use
5065 the specified name
5066 .IR key ,
5067 have a default value of
5068 .IR default ,
5069 and display the specified
5070 .I help
5071 text.
5072 The option will only support the values
5073 .BR all ,
5074 .BR none ,
5075 or the values in the
5076 .I names
5077 list.
5078 More than one value may be specified,
5079 with all values separated by commas.
5080 The default may be a string of
5081 comma-separated default values,
5082 or a list of the default values.
5083 The optional
5084 .I map
5085 argument is a dictionary
5086 that can be used to convert
5087 input values into specific legal values
5088 in the
5089 .I names
5090 list.
5091
5092 .TP
5093 .RI PackageOption( key ", " help ", " default )
5094 Return a tuple of arguments
5095 to set up an option
5096 whose value is a path name
5097 of a package that may be
5098 enabled, disabled or 
5099 given an explicit path name.
5100 The option will use
5101 the specified name
5102 .IR key ,
5103 have a default value of
5104 .IR default ,
5105 and display the specified
5106 .I help
5107 text.
5108 The option will support the values
5109 .BR yes ,
5110 .BR true ,
5111 .BR on ,
5112 .BR enable
5113 or
5114 .BR search ,
5115 in which case the specified
5116 .I default
5117 will be used,
5118 or the option may be set to an
5119 arbitrary string
5120 (typically the path name to a package
5121 that is being enabled).
5122 The option will also support the values
5123 .BR no ,
5124 .BR false ,
5125 .BR off
5126 or
5127 .BR disable
5128 to disable use of the specified option.
5129
5130 .TP
5131 .RI PathOption( key ", " help ", " default ", [" validator ])
5132 Return a tuple of arguments
5133 to set up an option
5134 whose value is expected to be a path name.
5135 The option will use
5136 the specified name
5137 .IR key ,
5138 have a default value of
5139 .IR default ,
5140 and display the specified
5141 .I help
5142 text.
5143 An additional
5144 .I validator
5145 may be specified
5146 that will be called to
5147 verify that the specified path
5148 is acceptable.
5149 SCons supplies the
5150 following ready-made validators:
5151 .BR PathOption.PathExists
5152 (the default),
5153 which verifies that the specified path exists;
5154 .BR PathOption.PathIsFile ,
5155 which verifies that the specified path is an existing file;
5156 .BR PathOption.PathIsDir ,
5157 which verifies that the specified path is an existing directory;
5158 and
5159 .BR PathOption.PathIsDirCreate ,
5160 which verifies that the specified path is a directory,
5161 and will create the specified directory if the path does not exist.
5162 You may supply your own
5163 .I validator
5164 function,
5165 which must take three arguments
5166 .RI ( key ,
5167 the name of the options variable to be set;
5168 .IR val ,
5169 the specified value being checked;
5170 and
5171 .IR env ,
5172 the construction environment)
5173 and should raise an exception
5174 if the specified value is not acceptable.
5175
5176 .RE
5177 These functions make it
5178 convenient to create a number
5179 of options with consistent behavior
5180 in a single call to the
5181 .B AddOptions
5182 method:
5183
5184 .ES
5185 opts.AddOptions(
5186     BoolOption('warnings', 'compilation with -Wall and similiar', 1),
5187     EnumOption('debug', 'debug output and symbols', 'no'
5188                allowed_values=('yes', 'no', 'full'),
5189                map={}, ignorecase=0),  # case sensitive
5190     ListOption('shared',
5191                'libraries to build as shared libraries',
5192                'all',
5193                names = list_of_libs),
5194     PackageOption('x11',
5195                   'use X11 installed here (yes = search some places)',
5196                   'yes'),
5197     PathOption('qtdir', 'where the root of Qt is installed', qtdir),
5198     PathOption('foopath', 'where the foo library is installed', foopath,
5199                PathOption.PathIsDir),
5200
5201 )
5202 .EE
5203
5204 .SS File and Directory Nodes
5205
5206 The
5207 .IR File ()
5208 and
5209 .IR Dir ()
5210 functions return
5211 .I File
5212 and
5213 .I Dir
5214 Nodes, respectively.
5215 python objects, respectively.
5216 Those objects have several user-visible attributes
5217 and methods that are often useful:
5218
5219 .IP path
5220 The build path
5221 of the given
5222 file or directory.
5223 This path is relative to the top-level directory
5224 (where the
5225 .B SConstruct
5226 file is found).
5227 The build path is the same as the source path if
5228 .I build_dir
5229 is not being used.
5230
5231 .IP abspath
5232 The absolute build path of the given file or directory.
5233
5234 .IP srcnode()
5235 The
5236 .IR srcnode ()
5237 method
5238 returns another
5239 .I File
5240 or
5241 .I Dir
5242 object representing the
5243 .I source
5244 path of the given
5245 .I File
5246 or
5247 .IR Dir .
5248 The 
5249
5250 .ES
5251 # Get the current build dir's path, relative to top.
5252 Dir('.').path
5253 # Current dir's absolute path
5254 Dir('.').abspath
5255 # Next line is always '.', because it is the top dir's path relative to itself.
5256 Dir('#.').path
5257 File('foo.c').srcnode().path   # source path of the given source file.
5258
5259 # Builders also return File objects:
5260 foo = env.Program('foo.c')
5261 print "foo will be built in %s"%foo.path
5262 .EE
5263
5264 .SH EXTENDING SCONS
5265 .SS Builder Objects
5266 .B scons
5267 can be extended to build different types of targets
5268 by adding new Builder objects
5269 to a construction environment.
5270 .IR "In general" ,
5271 you should only need to add a new Builder object
5272 when you want to build a new type of file or other external target.
5273 If you just want to invoke a different compiler or other tool
5274 to build a Program, Object, Library, or any other
5275 type of output file for which
5276 .B scons
5277 already has an existing Builder,
5278 it is generally much easier to
5279 use those existing Builders
5280 in a construction environment
5281 that sets the appropriate construction variables
5282 (CC, LINK, etc.).
5283
5284 Builder objects are created
5285 using the
5286 .B Builder 
5287 function.
5288 The
5289 .B Builder
5290 function accepts the following arguments:
5291
5292 .IP action
5293 The command line string used to build the target from the source. 
5294 .B action
5295 can also be:
5296 a list of strings representing the command
5297 to be executed and its arguments
5298 (suitable for enclosing white space in an argument),
5299 a dictionary
5300 mapping source file name suffixes to
5301 any combination of command line strings
5302 (if the builder should accept multiple source file extensions),
5303 a Python function;
5304 an Action object
5305 (see the next section);
5306 or a list of any of the above.
5307
5308 An action function
5309 takes three arguments:
5310 .I source 
5311 - a list of source nodes, 
5312 .I target
5313 - a list of target nodes,
5314 .I env
5315 - the construction environment.
5316
5317 .IP prefix 
5318 The prefix that will be prepended to the target file name.
5319 This may be specified as a:
5320
5321 .RS 10
5322 .HP 6
5323
5324 .IR string ,
5325
5326 .HP 6
5327
5328 .I callable object
5329 - a function or other callable that takes
5330 two arguments (a construction environment and a list of sources)
5331 and returns a prefix,
5332
5333 .HP 6
5334
5335 .I dictionary
5336 - specifies a mapping from a specific source suffix (of the first 
5337 source specified) to a corresponding target prefix.  Both the source
5338 suffix and target prefix specifications may use environment variable
5339 substitution, and the target prefix (the 'value' entries in the
5340 dictionary) may also be a callable object.  The default target prefix
5341 may be indicated by a dictionary entry with a key value of None.
5342 .RE
5343 .P
5344
5345 .ES
5346 b = Builder("build_it < $SOURCE > $TARGET"
5347             prefix = "file-")
5348
5349 def gen_prefix(env, sources):
5350     return "file-" + env['PLATFORM'] + '-'
5351 b = Builder("build_it < $SOURCE > $TARGET",
5352             prefix = gen_prefix)
5353
5354 b = Builder("build_it < $SOURCE > $TARGET",
5355             suffix = { None: "file-",
5356                        "$SRC_SFX_A": gen_prefix })
5357 .EE
5358
5359 .IP suffix
5360 The suffix that will be appended to the target file name.
5361 This may be specified in the same manner as the prefix above.
5362 If the suffix is a string, then
5363 .B scons
5364 will append a '.' to the beginning of the suffix if it's not already
5365 there.  The string returned by callable object (or obtained from the
5366 dictionary) is untouched and must append its own '.'  to the beginning
5367 if one is desired.
5368
5369 .ES
5370 b = Builder("build_it < $SOURCE > $TARGET"
5371             suffix = "-file")
5372
5373 def gen_suffix(env, sources):
5374     return "." + env['PLATFORM'] + "-file"
5375 b = Builder("build_it < $SOURCE > $TARGET",
5376             suffix = gen_suffix)
5377
5378 b = Builder("build_it < $SOURCE > $TARGET",
5379             suffix = { None: ".sfx1",
5380                        "$SRC_SFX_A": gen_suffix })
5381 .EE
5382
5383 .IP src_suffix
5384 The expected source file name suffix.  This may be a string or a list
5385 of strings.
5386
5387 .IP target_scanner
5388 A Scanner object that
5389 will be invoked to find
5390 implicit dependencies for this target file.
5391 This keyword argument should be used
5392 for Scanner objects that find
5393 implicit dependencies
5394 based only on the target file
5395 and the construction environment,
5396 .I not 
5397 for implicit
5398 (See the section "Scanner Objects," below,
5399 for information about creating Scanner objects.)
5400
5401 .IP source_scanner
5402 A Scanner object that
5403 will be invoked to
5404 find implicit dependences in
5405 any source files
5406 used to build this target file.
5407 This is where you would
5408 specify a scanner to
5409 find things like
5410 .B #include
5411 lines in source files.
5412 The pre-built
5413 .B DirScanner
5414 Scanner object may be used to
5415 indicate that this Builder
5416 should scan directory trees
5417 for on-disk changes to files
5418 that
5419 .B scons
5420 does not know about from other Builder or function calls.
5421 (See the section "Scanner Objects," below,
5422 for information about creating your own Scanner objects.)
5423
5424 .IP target_factory
5425 A factory function that the Builder will use
5426 to turn any targets specified as strings into SCons Nodes.
5427 By default,
5428 SCons assumes that all targets are files.
5429 Other useful target_factory
5430 values include
5431 .BR Dir ,
5432 for when a Builder creates a directory target,
5433 and
5434 .BR Entry ,
5435 for when a Builder can create either a file
5436 or directory target.
5437
5438 Example:
5439
5440 .ES
5441 MakeDirectoryBuilder = Builder(action=my_mkdir, target_factory=Dir)
5442 env = Environment()
5443 env.Append(BUILDERS = {'MakeDirectory':MakeDirectoryBuilder})
5444 env.MakeDirectory('new_directory', [])
5445 .EE
5446
5447 Note that the call to the MakeDirectory Builder
5448 needs to specify an empty source list
5449 to make the string represent the builder's target;
5450 without that, it would assume the argument is the source,
5451 and would try to deduce the target name from it,
5452 which in the absence of an automatically-added prefix or suffix
5453 would lead to a matching target and source name
5454 and a circular dependency.
5455
5456 .IP source_factory
5457 A factory function that the Builder will use
5458 to turn any sources specified as strings into SCons Nodes.
5459 By default,
5460 SCons assumes that all source are files.
5461 Other useful source_factory
5462 values include
5463 .BR Dir ,
5464 for when a Builder uses a directory as a source,
5465 and
5466 .BR Entry ,
5467 for when a Builder can use files
5468 or directories (or both) as sources.
5469
5470 Example:
5471
5472 .ES
5473 CollectBuilder = Builder(action=my_mkdir, source_factory=Entry)
5474 env = Environment()
5475 env.Append(BUILDERS = {'Collect':CollectBuilder})
5476 env.Collect('archive', ['directory_name', 'file_name'])
5477 .EE
5478
5479 .IP emitter
5480 A function or list of functions to manipulate the target and source
5481 lists before dependencies are established
5482 and the target(s) are actually built.
5483 .B emitter
5484 can also be a string containing a construction variable to expand
5485 to an emitter function or list of functions,
5486 or a dictionary mapping source file suffixes
5487 to emitter functions.
5488 (Only the suffix of the first source file
5489 is used to select the actual emitter function
5490 from an emitter dictionary.)
5491
5492 An emitter function
5493 takes three arguments:
5494 .I source 
5495 - a list of source nodes, 
5496 .I target
5497 - a list of target nodes,
5498 .I env
5499 - the construction environment.
5500 An emitter must return a tuple containing two lists,
5501 the list of targets to be built by this builder,
5502 and the list of sources for this builder.
5503
5504 Example:
5505
5506 .ES
5507 def e(target, source, env):
5508     return (target + ['foo.foo'], source + ['foo.src'])
5509
5510 # Simple association of an emitter function with a Builder.
5511 b = Builder("my_build < $TARGET > $SOURCE",
5512             emitter = e)
5513
5514 def e2(target, source, env):
5515     return (target + ['bar.foo'], source + ['bar.src'])
5516
5517 # Simple association of a list of emitter functions with a Builder.
5518 b = Builder("my_build < $TARGET > $SOURCE",
5519             emitter = [e, e2])
5520
5521 # Calling an emitter function through a construction variable.
5522 env = Environment(MY_EMITTER = e)
5523 b = Builder("my_build < $TARGET > $SOURCE",
5524             emitter = '$MY_EMITTER')
5525
5526 # Calling a list of emitter functions through a construction variable.
5527 env = Environment(EMITTER_LIST = [e, e2])
5528 b = Builder("my_build < $TARGET > $SOURCE",
5529             emitter = '$EMITTER_LIST')
5530
5531 # Associating multiple emitters with different file
5532 # suffixes using a dictionary.
5533 def e_suf1(target, source, env):
5534     return (target + ['another_target_file'], source)
5535 def e_suf2(target, source, env):
5536     return (target, source + ['another_source_file'])
5537 b = Builder("my_build < $TARGET > $SOURCE",
5538             emitter = {'.suf1' : e_suf1,
5539                        '.suf2' : e_suf2})
5540 .EE
5541
5542 .IP multi
5543 Specifies whether this builder is allowed to be called multiple times for
5544 the same target file(s). The default is 0, which means the builder
5545 can not be called multiple times for the same target file(s). Calling a
5546 builder multiple times for the same target simply adds additional source
5547 files to the target; it is not allowed to change the environment associated
5548 with the target, specify addition environment overrides, or associate a different
5549 builder with the target. 
5550
5551 .IP env
5552 A construction environment that can be used
5553 to fetch source code using this Builder.
5554 (Note that this environment is
5555 .I not
5556 used for normal builds of normal target files,
5557 which use the environment that was
5558 used to call the Builder for the target file.)
5559
5560 .IP generator
5561 A function that returns a list of actions that will be executed to build
5562 the target(s) from the source(s).
5563 The returned action(s) may be
5564 an Action object, or anything that
5565 can be converted into an Action object
5566 (see the next section).
5567
5568 The generator function
5569 takes four arguments:
5570 .I source 
5571 - a list of source nodes, 
5572 .I target
5573 - a list of target nodes,
5574 .I env
5575 - the construction environment,
5576 .I for_signature
5577 - a Boolean value that specifies
5578 whether the generator is being called
5579 for generating a build signature
5580 (as opposed to actually executing the command).
5581 Example:
5582
5583 .ES
5584 def g(source, target, env, for_signature):
5585     return [["gcc", "-c", "-o"] + target + source] 
5586
5587 b = Builder(generator=g)
5588 .EE
5589
5590 .IP
5591 The 
5592 .I generator
5593 and
5594 .I action
5595 arguments must not both be used for the same Builder.
5596
5597 .IP src_builder
5598 Specifies a builder to use when a source file name suffix does not match
5599 any of the suffixes of the builder. Using this argument produces a
5600 multi-stage builder.
5601
5602 .IP single_source
5603 Specifies that this builder expects exactly one source file per call. Giving
5604 more than one source files without target files results in implicitely calling
5605 the builder multiple times (once for each source given). Giving multiple 
5606 source files together with target files results in a UserError exception.
5607
5608 .RE
5609 .IP
5610 The 
5611 .I generator
5612 and
5613 .I action
5614 arguments must not both be used for the same Builder.
5615
5616 .IP source_ext_match
5617 When the specified
5618 .I action
5619 argument is a dictionary,
5620 the default behavior when a builder is passed
5621 multiple source files is to make sure that the
5622 extensions of all the source files match.
5623 If it is legal for this builder to be
5624 called with a list of source files with different extensions,
5625 this check can be suppressed by setting
5626 .B source_ext_match
5627 to
5628 .B None
5629 or some other non-true value.
5630 When
5631 .B source_ext_match
5632 is disable,
5633 .B scons
5634 will use the suffix of the first specified
5635 source file to select the appropriate action from the
5636 .I action
5637 dictionary.
5638
5639 In the following example,
5640 the setting of
5641 .B source_ext_match
5642 prevents
5643 .B scons 
5644 from exiting with an error
5645 due to the mismatched suffixes of
5646 .B foo.in
5647 and
5648 .BR foo.extra .
5649
5650 .ES
5651 b = Builder(action={'.in' : 'build $SOURCES > $TARGET'},
5652             source_ext_match = None)
5653
5654 env = Environment(BUILDERS = {'MyBuild':b})
5655 env.MyBuild('foo.out', ['foo.in', 'foo.extra'])
5656 .EE
5657
5658 .IP env
5659 A construction environment that can be used
5660 to fetch source code using this Builder.
5661 (Note that this environment is
5662 .I not
5663 used for normal builds of normal target files,
5664 which use the environment that was
5665 used to call the Builder for the target file.)
5666
5667 .ES
5668 b = Builder(action="build < $SOURCE > $TARGET")
5669 env = Environment(BUILDERS = {'MyBuild' : b})
5670 env.MyBuild('foo.out', 'foo.in', my_arg = 'xyzzy')
5671 .EE
5672
5673 .IP chdir
5674 A directory from which scons
5675 will execute the
5676 action(s) specified
5677 for this Builder.
5678 If the
5679 .B chdir
5680 argument is
5681 a string or a directory Node,
5682 scons will change to the specified directory.
5683 If the
5684 .B chdir
5685 is not a string or Node
5686 and is non-zero,
5687 then scons will change to the
5688 target file's directory.
5689
5690 Note that scons will
5691 .I not
5692 automatically modify
5693 its expansion of
5694 construction variables like
5695 .B $TARGET
5696 and
5697 .B $SOURCE
5698 when using the chdir
5699 keyword argument--that is,
5700 the expanded file names
5701 will still be relative to
5702 the top-level SConstruct directory,
5703 and consequently incorrect
5704 relative to the chdir directory.
5705 Builders created using chdir keyword argument,
5706 will need to use construction variable
5707 expansions like
5708 .B ${TARGET.file}
5709 and
5710 .B ${SOURCE.file}
5711 to use just the filename portion of the
5712 targets and source.
5713
5714 .ES
5715 b = Builder(action="build < ${SOURCE.file} > ${TARGET.file}",
5716             chdir=1)
5717 env = Environment(BUILDERS = {'MyBuild' : b})
5718 env.MyBuild('sub/dir/foo.out', 'sub/dir/foo.in')
5719 .EE
5720
5721 .B WARNING:
5722 Python only keeps one current directory
5723 location for all of the threads.
5724 This means that use of the
5725 .B chdir
5726 argument
5727 will
5728 .I not
5729 work with the SCons
5730 .B -j
5731 option,
5732 because individual worker threads spawned
5733 by SCons interfere with each other
5734 when they start changing directory.
5735
5736 .RE
5737 Any additional keyword arguments supplied
5738 when a Builder object is created
5739 (that is, when the Builder() function is called)
5740 will be set in the executing construction
5741 environment when the Builder object is called.
5742 The canonical example here would be
5743 to set a construction variable to 
5744 the repository of a source code system.
5745
5746 Any additional keyword arguments supplied
5747 when a Builder
5748 .I object
5749 is called
5750 will only be associated with the target
5751 created by that particular Builder call
5752 (and any other files built as a
5753 result of the call).
5754
5755 These extra keyword arguments are passed to the
5756 following functions:
5757 command generator functions,
5758 function Actions,
5759 and emitter functions.
5760
5761 .SS Action Objects
5762
5763 The
5764 .BR Builder()
5765 function will turn its
5766 .B action
5767 keyword argument into an appropriate
5768 internal Action object.
5769 You can also explicity create Action objects
5770 using the
5771 .BR Action ()
5772 global function,
5773 which can then be passed to the
5774 .BR Builder ()
5775 function.
5776 This can be used to configure
5777 an Action object more flexibly,
5778 or it may simply be more efficient
5779 than letting each separate Builder object
5780 create a separate Action
5781 when multiple
5782 Builder objects need to do the same thing.
5783
5784 The
5785 .BR Action ()
5786 global function
5787 returns an appropriate object for the action
5788 represented by the type of the first argument:
5789
5790 .IP Action
5791 If the first argument is already an Action object,
5792 the object is simply returned.
5793
5794 .IP String
5795 If the first argument is a string,
5796 a command-line Action is returned.
5797 Note that the command line string
5798 may be preceded by an
5799 .B @
5800 (at-sign)
5801 to suppress printing of the
5802 specified command line,
5803 or by a
5804 .B \-
5805 (hyphen)
5806 to ignore the exit status from
5807 the specified command.
5808 Examples:
5809
5810 .ES
5811 Action('$CC -c -o $TARGET $SOURCES')
5812
5813 # Doesn't print the line being executed.
5814 Action('@build $TARGET $SOURCES')
5815
5816 # Ignores
5817 Action('-build $TARGET $SOURCES')
5818 .EE
5819
5820 .\" XXX From Gary Ruben, 23 April 2002:
5821 .\" What would be useful is a discussion of how you execute command
5822 .\" shell commands ie. what is the process used to spawn the shell, pass
5823 .\" environment variables to it etc., whether there is one shell per
5824 .\" environment or one per command etc.  It might help to look at the Gnu
5825 .\" make documentation to see what they think is important to discuss about
5826 .\" a build system. I'm sure you can do a better job of organising the
5827 .\" documentation than they have :-)
5828
5829
5830 .IP List
5831 If the first argument is a list,
5832 then a list of Action objects is returned.
5833 An Action object is created as necessary
5834 for each element in the list.
5835 If an element
5836 .I within
5837 the list is itself a list,
5838 the internal list is the
5839 command and arguments to be executed via
5840 the command line.
5841 This allows white space to be enclosed
5842 in an argument by defining
5843 a command in a list within a list:
5844
5845 .ES
5846 Action([['cc', '-c', '-DWHITE SPACE', '-o', '$TARGET', '$SOURCES']])
5847 .EE
5848
5849 .IP Function
5850 If the first argument is a Python function,
5851 a function Action is returned.
5852 The Python function takes three keyword arguments,
5853 .B target
5854 (a Node object representing the target file),
5855 .B source
5856 (a Node object representing the source file)
5857 and
5858 .B env
5859 (the construction environment
5860 used for building the target file).
5861 The
5862 .B target
5863 and
5864 .B source
5865 arguments may be lists of Node objects if there is
5866 more than one target file or source file.
5867 The actual target and source file name(s) may
5868 be retrieved from their Node objects
5869 via the built-in Python str() function:
5870
5871 .ES
5872 target_file_name = str(target)
5873 source_file_names = map(lambda x: str(x), source)
5874 .EE
5875 .IP
5876 The function should return
5877 .B 0
5878 or
5879 .B None
5880 to indicate a successful build of the target file(s).
5881 The function may raise an exception
5882 or return a non-zero exit status
5883 to indicate an unsuccessful build.
5884
5885 .ES
5886 def build_it(target = None, source = None, env = None):
5887     # build the target from the source
5888     return 0
5889  
5890 a = Action(build_it)
5891 .EE
5892
5893 If the action argument is not one of the above,
5894 None is returned.
5895 .PP
5896
5897 The second, optional argument
5898 is used to define the output which is printed
5899 when the Action is actually performed.
5900 In the absence of this parameter, or if it's an
5901 empty string, a default output depending on the type of the action
5902 is used. For example, a command-line action will print
5903 the executed command. The argument is either a python function
5904 or a string.
5905
5906 In the first case, it's a function that returns
5907 a string to be printed to describe the action being executed.
5908 Like a function to build a file,
5909 this function takes three arguments:
5910 .B target
5911 (a Node object representing the target file),
5912 .B source
5913 (a Node object representing the source file)
5914 and
5915 .BR env
5916 (a construction environment).
5917 The
5918 .B target
5919 and
5920 .B source
5921 arguments may be lists of Node objects if there is
5922 more than one target file or source file.
5923
5924 In the second case, you provide the string itself.
5925 The string typically contains variables, notably
5926 $TARGET(S) and $SOURCE(S), or consists of just a single
5927 variable, which is optionally defined somewhere else.
5928 SCons itself heavily uses the latter variant.
5929
5930 Examples:
5931
5932 .ES
5933 def build_it(target, source, env):
5934     # build the target from the source
5935     return 0
5936
5937 def string_it(target, source, env):
5938     return "building '%s' from '%s'" % (target[0], source[0])
5939
5940 # Use a positional argument.
5941 f = Action(build_it, string_it)
5942 s = Action(build_it, "building '$TARGET' from '$SOURCE'")
5943
5944 # Alternatively, use a keyword argument.
5945 f = Action(build_it, strfunction=string_it)
5946 s = Action(build_it, cmdstr="building '$TARGET' from '$SOURCE'")
5947
5948 # You can provide a configurable variable.
5949 l = Action(build_it, '$STRINGIT')
5950 .EE
5951
5952 The third, also optional argument
5953 is a list of construction variables
5954 whose values will be included
5955 in the signature of the Action
5956 when deciding whether a target should
5957 be rebuilt because the action changed.
5958 This is necessary whenever you want a target to
5959 be rebuilt when a specific
5960 construction variable changes,
5961 because the underlying Python code for a function
5962 will not change when the value of the construction variable does.
5963
5964 .ES
5965 def build_it(target, source, env):
5966     # build the target from the 'XXX' construction variable
5967     open(target[0], 'w').write(env['XXX'])
5968     return 0
5969
5970 # Use positional arguments.
5971 a = Action(build_it, '$STRINGIT', ['XXX'])
5972
5973 # Alternatively, use a keyword argument.
5974 a = Action(build_it, varlist=['XXX'])
5975 .EE
5976
5977 The
5978 .BR Action ()
5979 global function
5980 also takes a
5981 .B chdir
5982 keyword argument
5983 which specifies that
5984 scons will execute the action
5985 after changing to the specified directory.
5986 If the chdir argument is
5987 a string or a directory Node,
5988 scons will change to the specified directory.
5989 If the chdir argument
5990 is not a string or Node
5991 and is non-zero,
5992 then scons will change to the
5993 target file's directory.
5994
5995 Note that scons will
5996 .I not
5997 automatically modify
5998 its expansion of
5999 construction variables like
6000 .B $TARGET
6001 and
6002 .B $SOURCE
6003 when using the chdir
6004 keyword argument--that is,
6005 the expanded file names
6006 will still be relative to
6007 the top-level SConstruct directory,
6008 and consequently incorrect
6009 relative to the chdir directory.
6010 Builders created using chdir keyword argument,
6011 will need to use construction variable
6012 expansions like
6013 .B ${TARGET.file}
6014 and
6015 .B ${SOURCE.file}
6016 to use just the filename portion of the
6017 targets and source.
6018
6019 .ES
6020 a = Action("build < ${SOURCE.file} > ${TARGET.file}",
6021            chdir=1)
6022 .EE
6023
6024 The
6025 .BR Action ()
6026 global function
6027 also takes an
6028 .B exitstatfunc
6029 keyword argument
6030 which specifies a function
6031 that is passed the exit status
6032 (or return value)
6033 from the specified action
6034 and can return an arbitrary
6035 or modified value.
6036 This can be used, for example,
6037 to specify that an Action object's
6038 return value should be ignored
6039 and SCons should, therefore,
6040 consider that the action always suceeds:
6041
6042 .ES
6043 def always_succeed(s):
6044     # Always return 0, which indicates success.
6045     return 0
6046 a = Action("build < ${SOURCE.file} > ${TARGET.file}",
6047            exitstatfunc=always_succeed)
6048 .EE
6049
6050 .SS Miscellaneous Action Functions
6051
6052 .B scons
6053 supplies a number of functions
6054 that arrange for various common
6055 file and directory manipulations
6056 to be performed.
6057 These are similar in concept to "tasks" in the 
6058 Ant build tool,
6059 although the implementation is slightly different.
6060 These functions do not actually
6061 perform the specified action
6062 at the time the function is called,
6063 but instead return an Action object
6064 that can be executed at the
6065 appropriate time.
6066 (In Object-Oriented terminology,
6067 these are actually
6068 Action
6069 .I Factory
6070 functions
6071 that return Action objects.)
6072
6073 In practice,
6074 there are two natural ways
6075 that these
6076 Action Functions
6077 are intended to be used.
6078
6079 First,
6080 if you need
6081 to perform the action
6082 at the time the SConscript
6083 file is being read,
6084 you can use the
6085 .B Execute
6086 global function to do so:
6087 .ES
6088 Execute(Touch('file'))
6089 .EE
6090
6091 Second,
6092 you can use these functions
6093 to supply Actions in a list
6094 for use by the
6095 .B Command
6096 method.
6097 This can allow you to
6098 perform more complicated
6099 sequences of file manipulation
6100 without relying
6101 on platform-specific
6102 external commands:
6103 that 
6104 .ES
6105 env = Environment(TMPBUILD = '/tmp/builddir')
6106 env.Command('foo.out', 'foo.in',
6107             [Mkdir('$TMPBUILD'),
6108              Copy('$TMPBUILD', '${SOURCE.dir}'),
6109              "cd $TMPBUILD && make",
6110              Delete('$TMPBUILD')])
6111 .EE
6112
6113 .TP
6114 .RI Chmod( dest ", " mode )
6115 Returns an Action object that
6116 changes the permissions on the specified
6117 .I dest
6118 file or directory to the specified
6119 .IR mode .
6120 Examples:
6121
6122 .ES
6123 Execute(Chmod('file', 0755))
6124
6125 env.Command('foo.out', 'foo.in',
6126             [Copy('$TARGET', '$SOURCE'),
6127              Chmod('$TARGET', 0755)])
6128 .EE
6129
6130 .TP
6131 .RI Copy( dest ", " src )
6132 Returns an Action object
6133 that will copy the
6134 .I src
6135 source file or directory to the
6136 .I dest
6137 destination file or directory.
6138 Examples:
6139
6140 .ES
6141 Execute(Copy('foo.output', 'foo.input'))
6142
6143 env.Command('bar.out', 'bar.in',
6144             Copy('$TARGET', '$SOURCE'))
6145 .EE
6146
6147 .TP
6148 .RI Delete( entry ", [" must_exist ])
6149 Returns an Action that
6150 deletes the specified
6151 .IR entry ,
6152 which may be a file or a directory tree.
6153 If a directory is specified,
6154 the entire directory tree
6155 will be removed.
6156 If the
6157 .I must_exist
6158 flag is set,
6159 then a Python error will be thrown
6160 if the specified entry does not exist;
6161 the default is
6162 .BR must_exist=0 ,
6163 that is, the Action will silently do nothing
6164 if the entry does not exist.
6165 Examples:
6166
6167 .ES
6168 Execute(Delete('/tmp/buildroot'))
6169
6170 env.Command('foo.out', 'foo.in',
6171             [Delete('${TARGET.dir}'),
6172              MyBuildAction])
6173
6174 Execute(Delete('file_that_must_exist', must_exist=1))
6175 .EE
6176
6177 .TP
6178 .RI Mkdir( dir )
6179 Returns an Action
6180 that creates the specified
6181 directory
6182 .I dir .
6183 Examples:
6184
6185 .ES
6186 Execute(Mkdir('/tmp/outputdir'))
6187
6188 env.Command('foo.out', 'foo.in',
6189             [Mkdir('/tmp/builddir',
6190              Copy('$SOURCE', '/tmp/builddir')
6191              "cd /tmp/builddir && ])
6192
6193 .EE
6194
6195 .TP
6196 .RI Move( dest ", " src )
6197 Returns an Action
6198 that moves the specified
6199 .I src
6200 file or directory to
6201 the specified
6202 .I dest
6203 file or directory.
6204 Examples:
6205
6206 .ES
6207 Execute(Move('file.destination', 'file.source'))
6208
6209 env.Command('output_file', 'input_file',
6210             [MyBuildAction,
6211              Move('$TARGET', 'file_created_by_MyBuildAction')])
6212 .EE
6213
6214 .TP
6215 .RI Touch( file )
6216 Returns an Action
6217 that updates the modification time
6218 on the specified
6219 .IR file .
6220 Examples:
6221
6222 .ES
6223 Execute(Touch('file_to_be_touched'))
6224
6225 env.Command('marker', 'input_file',
6226             [MyBuildAction,
6227              Touch('$TARGET')])
6228 .EE
6229
6230 .SS Variable Substitution
6231
6232 Before executing a command,
6233 .B scons
6234 performs construction variable interpolation on the strings that make up
6235 the command line of builders.
6236 Variables are introduced by a
6237 .B $
6238 prefix.
6239 Besides construction variables, scons provides the following
6240 variables for each command execution:
6241
6242 .IP TARGET
6243 The file name of the target being built, or the file name of the first 
6244 target if multiple targets are being built.
6245
6246 .IP TARGETS
6247 The file names of all targets being built.
6248
6249 .IP SOURCE
6250 The file name of the source of the build command, or the file name of the
6251 first source if multiple sources are being built.
6252
6253 .IP SOURCES
6254 The file names of the sources of the build command.
6255
6256 (Note that the above variables are reserved
6257 and may not be set in a construction environment.)
6258
6259 .LP 
6260 For example, given the construction variable CC='cc', targets=['foo'], and
6261 sources=['foo.c', 'bar.c']:
6262
6263 .ES
6264 action='$CC -c -o $TARGET $SOURCES'
6265 .EE
6266
6267 would produce the command line:
6268
6269 .ES
6270 cc -c -o foo foo.c bar.c
6271 .EE
6272
6273 Variable names may be surrounded by curly braces ({})
6274 to separate the name from the trailing characters.
6275 Within the curly braces, a variable name may have
6276 a Python slice subscript appended to select one
6277 or more items from a list.
6278 In the previous example, the string:
6279
6280 .ES
6281 ${SOURCES[1]}
6282 .EE
6283
6284 would produce:
6285
6286 .ES
6287 bar.c
6288 .EE
6289
6290 Additionally, a variable name may
6291 have the following special
6292 modifiers appended within the enclosing curly braces
6293 to modify the interpolated string:
6294
6295 .IP base
6296 The base path of the file name,
6297 including the directory path
6298 but excluding any suffix.
6299
6300 .IP dir
6301 The name of the directory in which the file exists.
6302
6303 .IP file
6304 The file name,
6305 minus any directory portion.
6306
6307 .IP filebase
6308 Just the basename of the file,
6309 minus any suffix
6310 and minus the directory.
6311
6312 .IP suffix
6313 Just the file suffix.
6314
6315 .IP abspath
6316 The absolute path name of the file.
6317
6318 .IP posix
6319 The POSIX form of the path,
6320 with directories separated by
6321 .B /
6322 (forward slashes)
6323 not backslashes.
6324 This is sometimes necessary on Windows systems
6325 when a path references a file on other (POSIX) systems.
6326
6327 .IP srcpath
6328 The directory and file name to the source file linked to this file
6329 through BuildDir.  If this file isn't linked, it just returns the
6330 directory and filename unchanged.
6331
6332 .IP srcdir
6333 The directory containing the source file linked to this file
6334 through BuildDir.  If this file isn't linked, it just returns the
6335 directory part of the filename.
6336
6337 .IP rsrcpath
6338 The directory and file name to the source file linked to this file
6339 through BuildDir.  If the file does not exist locally but exists in
6340 a Repository, the path in the Repository is returned.
6341 If this file isn't linked, it just returns the
6342 directory and filename unchanged.
6343
6344 .IP rsrcdir
6345 The Repository directory containing the source file linked to this file
6346 through BuildDir.  If this file isn't linked, it just returns the
6347 directory part of the filename.
6348
6349 .LP
6350 For example, the specified target will
6351 expand as follows for the corresponding modifiers:
6352
6353 .ES
6354 $TARGET              => sub/dir/file.x
6355 ${TARGET.base}       => sub/dir/file
6356 ${TARGET.dir}        => sub/dir
6357 ${TARGET.file}       => file.x
6358 ${TARGET.filebase}   => file
6359 ${TARGET.suffix}     => .x
6360 ${TARGET.abspath}    => /top/dir/sub/dir/file.x
6361
6362 SConscript('src/SConscript', build_dir='sub/dir')
6363 $SOURCE              => sub/dir/file.x
6364 ${SOURCE.srcpath}    => src/file.x
6365 ${SOURCE.srcdir}     => src
6366
6367 Repository('/usr/repository')
6368 $SOURCE              => sub/dir/file.x
6369 ${SOURCE.rsrcpath}   => /usr/repository/src/file.x
6370 ${SOURCE.rsrcdir}    => /usr/repository/src
6371 .EE
6372
6373 Lastly, a variable name
6374 may be a callable Python function
6375 associated with a
6376 construction variable in the environment.
6377 The function should
6378 take four arguments:
6379 .I target
6380 - a list of target nodes,
6381 .I source 
6382 - a list of source nodes, 
6383 .I env
6384 - the construction environment,
6385 .I for_signature
6386 - a Boolean value that specifies
6387 whether the function is being called
6388 for generating a build signature.
6389 SCons will insert whatever
6390 the called function returns
6391 into the expanded string:
6392
6393 .ES
6394 def foo(target, source, env, for_signature):
6395     return "bar"
6396
6397 # Will expand $BAR to "bar baz"
6398 env=Environment(FOO=foo, BAR="$FOO baz")
6399 .EE
6400
6401 You can use this feature to pass arguments to a
6402 Python function by creating a callable class
6403 that stores one or more arguments in an object,
6404 and then uses them when the
6405 .B __call__()
6406 method is called.
6407 Note that in this case,
6408 the entire variable expansion must
6409 be enclosed by curly braces
6410 so that the arguments will
6411 be associated with the
6412 instantiation of the class:
6413
6414 .ES
6415 class foo:
6416     def __init__(self, arg):
6417         self.arg = arg
6418
6419     def __call__(self, target, source, env, for_signature):
6420         return arg + " bar"
6421
6422 # Will expand $BAR to "my argument bar baz"
6423 env=Environment(FOO=foo, BAR="${FOO('my argument')} baz")
6424 .EE
6425
6426 .LP
6427 The special pseudo-variables
6428 .B "$("
6429 and
6430 .B "$)"
6431 may be used to surround parts of a command line
6432 that may change
6433 .I without
6434 causing a rebuild--that is,
6435 which are not included in the signature
6436 of target files built with this command.
6437 All text between
6438 .B "$("
6439 and
6440 .B "$)"
6441 will be removed from the command line
6442 before it is added to file signatures,
6443 and the
6444 .B "$("
6445 and
6446 .B "$)"
6447 will be removed before the command is executed.
6448 For example, the command line:
6449
6450 .ES
6451 echo Last build occurred $( $TODAY $). > $TARGET
6452 .EE
6453
6454 .LP
6455 would execute the command:
6456
6457 .ES
6458 echo Last build occurred $TODAY. > $TARGET
6459 .EE
6460
6461 .LP
6462 but the command signature added to any target files would be:
6463
6464 .ES
6465 echo Last build occurred  . > $TARGET
6466 .EE
6467
6468 SCons uses the following rules when converting construction variables into
6469 command lines:
6470
6471 .IP String
6472 When the value is a string it is interpreted as a space delimited list of
6473 command line arguments. 
6474
6475 .IP List
6476 When the value is a list it is interpreted as a list of command line
6477 arguments. Each element of the list is converted to a string.
6478
6479 .IP Other
6480 Anything that is not a list or string is converted to a string and
6481 interpreted as a single command line argument.
6482
6483 .IP Newline
6484 Newline characters (\\n) delimit lines. The newline parsing is done after
6485 all other parsing, so it is not possible for arguments (e.g. file names) to
6486 contain embedded newline characters. This limitation will likely go away in
6487 a future version of SCons.
6488
6489 .SS Scanner Objects
6490
6491 You can use the
6492 .B Scanner
6493 function to define
6494 objects to scan
6495 new file types for implicit dependencies.
6496 Scanner accepts the following arguments:
6497
6498 .IP function
6499 A Python function that will process
6500 the Node (file)
6501 and return a list of strings (file names)
6502 representing the implicit
6503 dependencies found in the contents.
6504 The function takes three or four arguments:
6505
6506     def scanner_function(node, env, path):
6507
6508     def scanner_function(node, env, path, arg):
6509
6510 The
6511 .B node
6512 argument is the internal
6513 SCons node representing the file.
6514 Use
6515 .B str(node)
6516 to fetch the name of the file, and
6517 .B node.get_contents()
6518 to fetch contents of the file.
6519 Note that the file is
6520 .I not
6521 guaranteed to exist before the scanner is called,
6522 so the scanner function should check that
6523 if there's any chance that the scanned file
6524 might not exist
6525 (for example, if it's built from other files).
6526
6527 The
6528 .B env
6529 argument is the construction environment for the scan.
6530 Fetch values from it using the
6531 .B env.Dictionary()
6532 method.
6533
6534 The
6535 .B path
6536 argument is a tuple (or list)
6537 of directories that can be searched
6538 for files.
6539 This will usually be the tuple returned by the
6540 .B path_function
6541 argument (see below).
6542
6543 The
6544 .B arg
6545 argument is the argument supplied
6546 when the scanner was created, if any.
6547
6548 .IP name
6549 The name of the Scanner.
6550 This is mainly used
6551 to identify the Scanner internally.
6552
6553 .IP argument
6554 An optional argument that, if specified,
6555 will be passed to the scanner function
6556 (described above)
6557 and the path function
6558 (specified below).
6559
6560 .IP skeys
6561 An optional list that can be used to
6562 determine which scanner should be used for
6563 a given Node.
6564 In the usual case of scanning for file names,
6565 this argument will be a list of suffixes
6566 for the different file types that this
6567 Scanner knows how to scan.
6568 If the argument is a string,
6569 then it will be expanded 
6570 into a list by the current environment.
6571
6572 .IP path_function
6573 A Python function that takes four or five arguments:
6574 a construction environment,
6575 a Node for the directory containing
6576 the SConscript file in which
6577 the first target was defined,
6578 a list of target nodes,
6579 a list of source nodes,
6580 and an optional argument supplied
6581 when the scanner was created.
6582 The
6583 .B path_function
6584 returns a tuple of directories
6585 that can be searched for files to be returned
6586 by this Scanner object.
6587
6588 .IP node_class
6589 The class of Node that should be returned
6590 by this Scanner object.
6591 Any strings or other objects returned
6592 by the scanner function
6593 that are not of this class
6594 will be run through the
6595 .B node_factory
6596 function.
6597
6598 .IP node_factory
6599 A Python function that will take a string
6600 or other object
6601 and turn it into the appropriate class of Node
6602 to be returned by this Scanner object.
6603
6604 .IP scan_check
6605 An optional Python function that takes two arguments,
6606 a Node (file) and a construction environment,
6607 and returns whether the
6608 Node should, in fact,
6609 be scanned for dependencies.
6610 This check can be used to eliminate unnecessary
6611 calls to the scanner function when,
6612 for example, the underlying file
6613 represented by a Node does not yet exist.
6614
6615 .IP recursive
6616 An optional flag that
6617 specifies whether this scanner should be re-invoked
6618 on the dependency files returned by the scanner.
6619 When this flag is not set,
6620 the Node subsystem will
6621 only invoke the scanner on the file being scanned,
6622 and not (for example) also on the files
6623 specified by the #include lines
6624 in the file being scanned.
6625 .I recursive
6626 may be a callable function,
6627 in which case it will be called with a list of
6628 Nodes found and
6629 should return a list of Nodes
6630 that should be scanned recursively;
6631 this can be used to select a specific subset of
6632 Nodes for additional scanning.
6633
6634 Note that
6635 .B scons
6636 has a global
6637 .B SourceFileScanner
6638 object that is used by
6639 the
6640 .BR Object (),
6641 .BR SharedObject (),
6642 and 
6643 .BR StaticObject ()
6644 builders to decide
6645 which scanner should be used
6646 for different file extensions.
6647 You can using the
6648 .BR SourceFileScanner.add_scanner ()
6649 method to add your own Scanner object
6650 to the
6651 .B scons
6652 infrastructure
6653 that builds target programs or
6654 libraries from a list of
6655 source files of different types:
6656
6657 .ES
6658 def xyz_scan(node, env, path):
6659     contents = node.get_contents()
6660     # Scan the contents and return the included files.
6661
6662 XYZScanner = Scanner(xyz_scan)
6663
6664 SourceFileScanner.add_scanner('.xyx', XYZScanner)
6665
6666 env.Program('my_prog', ['file1.c', 'file2.f', 'file3.xyz'])
6667 .EE
6668
6669 .SH SYSTEM-SPECIFIC BEHAVIOR
6670 SCons and its configuration files are very portable,
6671 due largely to its implementation in Python.
6672 There are, however, a few portability
6673 issues waiting to trap the unwary.
6674 .SS .C file suffix
6675 SCons handles the upper-case
6676 .B .C
6677 file suffix differently,
6678 depending on the capabilities of
6679 the underlying system.
6680 On a case-sensitive system
6681 such as Linux or UNIX,
6682 SCons treats a file with a 
6683 .B .C
6684 suffix as a C++ source file.
6685 On a case-insensitive system
6686 such as Windows,
6687 SCons treats a file with a 
6688 .B .C
6689 suffix as a C source file.
6690 .SS .F file suffix
6691 SCons handles the upper-case
6692 .B .F
6693 file suffix differently,
6694 depending on the capabilities of
6695 the underlying system.
6696 On a case-sensitive system
6697 such as Linux or UNIX,
6698 SCons treats a file with a 
6699 .B .F
6700 suffix as a Fortran source file
6701 that is to be first run through
6702 the standard C preprocessor.
6703 On a case-insensitive system
6704 such as Windows,
6705 SCons treats a file with a 
6706 .B .F
6707 suffix as a Fortran source file that should
6708 .I not
6709 be run through the C preprocessor.
6710 .SS Windows:  Cygwin Tools and Cygwin Python vs. Windows Pythons
6711 Cygwin supplies a set of tools and utilities
6712 that let users work on a
6713 Windows system using a more POSIX-like environment.
6714 The Cygwin tools, including Cygwin Python,
6715 do this, in part,
6716 by sharing an ability to interpret UNIX-like path names.
6717 For example, the Cygwin tools
6718 will internally translate a Cygwin path name
6719 like /cygdrive/c/mydir
6720 to an equivalent Windows pathname
6721 of C:/mydir (equivalent to C:\\mydir).
6722
6723 Versions of Python
6724 that are built for native Windows execution,
6725 such as the python.org and ActiveState versions,
6726 do not have the Cygwin path name semantics.
6727 This means that using a native Windows version of Python
6728 to build compiled programs using Cygwin tools
6729 (such as gcc, bison, and flex)
6730 may yield unpredictable results.
6731 "Mixing and matching" in this way
6732 can be made to work,
6733 but it requires careful attention to the use of path names
6734 in your SConscript files.
6735
6736 In practice, users can sidestep
6737 the issue by adopting the following rules:
6738 When using gcc,
6739 use the Cygwin-supplied Python interpreter
6740 to run SCons;
6741 when using Microsoft Visual C/C++
6742 (or some other Windows compiler)
6743 use the python.org or ActiveState version of Python
6744 to run SCons.
6745 .SS Windows:  scons.bat file
6746 On Windows systems,
6747 SCons is executed via a wrapper
6748 .B scons.bat
6749 file.
6750 This has (at least) two ramifications:
6751
6752 First, Windows command-line users
6753 that want to use variable assignment
6754 on the command line
6755 may have to put double quotes
6756 around the assignments:
6757
6758 .ES
6759 scons "FOO=BAR" "BAZ=BLEH"
6760 .EE
6761
6762 Second, the Cygwin shell does not
6763 recognize this file as being the same
6764 as an
6765 .B scons
6766 command issued at the command-line prompt.
6767 You can work around this either by
6768 executing
6769 .B scons.bat
6770 from the Cygwin command line,
6771 or by creating a wrapper shell
6772 script named
6773 .B scons .
6774
6775 .SS MinGW
6776
6777 The MinGW bin directory must be in your PATH environment variable or the
6778 PATH variable under the ENV construction variable for SCons
6779 to detect and use the MinGW tools. When running under the native Windows
6780 Python interpreter, SCons will prefer the MinGW tools over the Cygwin
6781 tools, if they are both installed, regardless of the order of the bin
6782 directories in the PATH variable. If you have both MSVC and MinGW
6783 installed and you want to use MinGW instead of MSVC,
6784 then you must explictly tell SCons to use MinGW by passing 
6785
6786 .ES
6787 tools=['mingw']
6788 .EE
6789
6790 to the Environment() function, because SCons will prefer the MSVC tools
6791 over the MinGW tools.
6792
6793 .SH EXAMPLES
6794
6795 To help you get started using SCons,
6796 this section contains a brief overview of some common tasks.
6797
6798 .SS Basic Compilation From a Single Source File
6799
6800 .ES
6801 env = Environment()
6802 env.Program(target = 'foo', source = 'foo.c')
6803 .EE
6804
6805 Note:  Build the file by specifying
6806 the target as an argument
6807 ("scons foo" or "scons foo.exe").
6808 or by specifying a dot ("scons .").
6809
6810 .SS Basic Compilation From Multiple Source Files
6811
6812 .ES
6813 env = Environment()
6814 env.Program(target = 'foo', source = Split('f1.c f2.c f3.c'))
6815 .EE
6816
6817 .SS Setting a Compilation Flag
6818
6819 .ES
6820 env = Environment(CCFLAGS = '-g')
6821 env.Program(target = 'foo', source = 'foo.c')
6822 .EE
6823
6824 .SS Search The Local Directory For .h Files
6825
6826 Note:  You do
6827 .I not
6828 need to set CCFLAGS to specify -I options by hand.
6829 SCons will construct the right -I options from CPPPATH.
6830
6831 .ES
6832 env = Environment(CPPPATH = ['.'])
6833 env.Program(target = 'foo', source = 'foo.c')
6834 .EE
6835
6836 .SS Search Multiple Directories For .h Files
6837
6838 .ES
6839 env = Environment(CPPPATH = ['include1', 'include2'])
6840 env.Program(target = 'foo', source = 'foo.c')
6841 .EE
6842
6843 .SS Building a Static Library
6844
6845 .ES
6846 env = Environment()
6847 env.StaticLibrary(target = 'foo', source = Split('l1.c l2.c'))
6848 env.StaticLibrary(target = 'bar', source = ['l3.c', 'l4.c'])
6849 .EE
6850
6851 .SS Building a Shared Library
6852
6853 .ES
6854 env = Environment()
6855 env.SharedLibrary(target = 'foo', source = ['l5.c', 'l6.c'])
6856 env.SharedLibrary(target = 'bar', source = Split('l7.c l8.c'))
6857 .EE
6858
6859 .SS Linking a Local Library Into a Program
6860
6861 .ES
6862 env = Environment(LIBS = 'mylib', LIBPATH = ['.'])
6863 env.Library(target = 'mylib', source = Split('l1.c l2.c'))
6864 env.Program(target = 'prog', source = ['p1.c', 'p2.c'])
6865 .EE
6866
6867 .SS Defining Your Own Builder Object
6868
6869 Notice that when you invoke the Builder,
6870 you can leave off the target file suffix,
6871 and SCons will add it automatically.
6872
6873 .ES
6874 bld = Builder(action = 'pdftex < $SOURCES > $TARGET'
6875               suffix = '.pdf',
6876               src_suffix = '.tex')
6877 env = Environment(BUILDERS = {'PDFBuilder' : bld})
6878 env.PDFBuilder(target = 'foo.pdf', source = 'foo.tex')
6879
6880 # The following creates "bar.pdf" from "bar.tex"
6881 env.PDFBuilder(target = 'bar', source = 'bar')
6882 .EE
6883
6884 Note also that the above initialization
6885 overwrites the default Builder objects,
6886 so the Environment created above
6887 can not be used call Builders like env.Program(),
6888 env.Object(), env.StaticLibrary(), etc.
6889
6890 .SS Adding Your Own Builder Object to an Environment
6891
6892 .ES
6893 bld = Builder(action = 'pdftex < $SOURCES > $TARGET'
6894               suffix = '.pdf',
6895               src_suffix = '.tex')
6896 env = Environment()
6897 env.Append(BUILDERS = {'PDFBuilder' : bld})
6898 env.PDFBuilder(target = 'foo.pdf', source = 'foo.tex')
6899 env.Program(target = 'bar', source = 'bar.c')
6900 .EE
6901
6902 You also can use other Pythonic techniques to add
6903 to the BUILDERS construction variable, such as:
6904
6905 .ES
6906 env = Environment()
6907 env['BUILDERS]['PDFBuilder'] = bld
6908 .EE
6909
6910 .SS Defining Your Own Scanner Object
6911
6912 .ES
6913 import re
6914
6915 '\" Note:  the \\ in the following are for the benefit of nroff/troff,
6916 '\" not inappropriate doubled escape characters within the r'' raw string.
6917 include_re = re.compile(r'^include\\s+(\\S+)$', re.M)
6918
6919 def kfile_scan(node, env, path, arg):
6920     contents = node.get_contents()
6921     includes = include_re.findall(contents)
6922     return includes
6923
6924 kscan = Scanner(name = 'kfile',
6925                 function = kfile_scan,
6926                 argument = None,
6927                 skeys = ['.k'])
6928 scanners = Environment().Dictionary('SCANNERS')
6929 env = Environment(SCANNERS = scanners + [kscan])
6930
6931 env.Command('foo', 'foo.k', 'kprocess < $SOURCES > $TARGET')
6932
6933 bar_in = File('bar.in')
6934 env.Command('bar', bar_in, 'kprocess $SOURCES > $TARGET')
6935 bar_in.target_scanner = kscan
6936 .EE
6937
6938 .SS Creating a Hierarchical Build
6939
6940 Notice that the file names specified in a subdirectory's
6941 SConscript
6942 file are relative to that subdirectory.
6943
6944 .ES
6945 SConstruct:
6946
6947     env = Environment()
6948     env.Program(target = 'foo', source = 'foo.c')
6949
6950     SConscript('sub/SConscript')
6951
6952 sub/SConscript:
6953
6954     env = Environment()
6955     # Builds sub/foo from sub/foo.c
6956     env.Program(target = 'foo', source = 'foo.c')
6957
6958     SConscript('dir/SConscript')
6959
6960 sub/dir/SConscript:
6961
6962     env = Environment()
6963     # Builds sub/dir/foo from sub/dir/foo.c
6964     env.Program(target = 'foo', source = 'foo.c')
6965 .EE
6966
6967 .SS Sharing Variables Between SConscript Files
6968
6969 You must explicitly Export() and Import() variables that
6970 you want to share between SConscript files.
6971
6972 .ES
6973 SConstruct:
6974
6975     env = Environment()
6976     env.Program(target = 'foo', source = 'foo.c')
6977
6978     Export("env")
6979     SConscript('subdirectory/SConscript')
6980
6981 subdirectory/SConscript:
6982
6983     Import("env")
6984     env.Program(target = 'foo', source = 'foo.c')
6985 .EE
6986
6987 .SS Building Multiple Variants From the Same Source
6988
6989 Use the build_dir keyword argument to
6990 the SConscript function to establish
6991 one or more separate build directories for
6992 a given source directory:
6993
6994 .ES
6995 SConstruct:
6996
6997     cppdefines = ['FOO']
6998     Export("cppdefines")
6999     SConscript('src/SConscript', build_dir='foo')
7000
7001     cppdefines = ['BAR']
7002     Export("cppdefines")
7003     SConscript('src/SConscript', build_dir='bar')
7004
7005 src/SConscript:
7006
7007     Import("cppdefines")
7008     env = Environment(CPPDEFINES = cppdefines)
7009     env.Program(target = 'src', source = 'src.c')
7010 .EE
7011
7012 Note the use of the Export() method
7013 to set the "cppdefines" variable to a different
7014 value each time we call the SConscript function.
7015
7016 .SS Hierarchical Build of Two Libraries Linked With a Program
7017
7018 .ES
7019 SConstruct:
7020
7021     env = Environment(LIBPATH = ['#libA', '#libB'])
7022     Export('env')
7023     SConscript('libA/SConscript')
7024     SConscript('libB/SConscript')
7025     SConscript('Main/SConscript')
7026
7027 libA/SConscript:
7028
7029     Import('env')
7030     env.Library('a', Split('a1.c a2.c a3.c'))
7031
7032 libB/SConscript:                                                  
7033
7034     Import('env')
7035     env.Library('b', Split('b1.c b2.c b3.c'))
7036
7037 Main/SConscript:
7038
7039     Import('env')
7040     e = env.Copy(LIBS = ['a', 'b'])
7041     e.Program('foo', Split('m1.c m2.c m3.c'))
7042 .EE
7043
7044 The '#' in the LIBPATH directories specify that they're relative to the
7045 top-level directory, so they don't turn into "Main/libA" when they're
7046 used in Main/SConscript.
7047
7048 Specifying only 'a' and 'b' for the library names
7049 allows SCons to append the appropriate library
7050 prefix and suffix for the current platform
7051 (for example, 'liba.a' on POSIX systems,
7052 'a.lib' on Windows).
7053
7054 .SS Customizing contruction variables from the command line.
7055
7056 The following would allow the C compiler to be specified on the command
7057 line or in the file custom.py. 
7058
7059 .ES
7060 opts = Options('custom.py')
7061 opts.Add('CC', 'The C compiler.')
7062 env = Environment(options=opts)
7063 Help(opts.GenerateHelpText(env))
7064 .EE
7065
7066 The user could specify the C compiler on the command line:
7067
7068 .ES
7069 scons "CC=my_cc"
7070 .EE
7071
7072 or in the custom.py file:
7073
7074 .ES
7075 CC = 'my_cc'
7076 .EE
7077
7078 or get documentation on the options:
7079
7080 .ES
7081 $ scons -h
7082
7083 CC: The C compiler.
7084     default: None
7085     actual: cc
7086
7087 .EE
7088
7089 .SS Using Microsoft Visual C++ precompiled headers
7090
7091 Since windows.h includes everything and the kitchen sink, it can take quite
7092 some time to compile it over and over again for a bunch of object files, so
7093 Microsoft provides a mechanism to compile a set of headers once and then
7094 include the previously compiled headers in any object file. This
7095 technology is called precompiled headers. The general recipe is to create a
7096 file named "StdAfx.cpp" that includes a single header named "StdAfx.h", and
7097 then include every header you want to precompile in "StdAfx.h", and finally
7098 include "StdAfx.h" as the first header in all the source files you are
7099 compiling to object files. For example:
7100
7101 StdAfx.h:
7102 .ES
7103 #include <windows.h>
7104 #include <my_big_header.h>
7105 .EE
7106
7107 StdAfx.cpp:
7108 .ES
7109 #include <StdAfx.h>
7110 .EE
7111
7112 Foo.cpp:
7113 .ES
7114 #include <StdAfx.h>
7115
7116 /* do some stuff */
7117 .EE
7118
7119 Bar.cpp:
7120 .ES
7121 #include <StdAfx.h>
7122
7123 /* do some other stuff */
7124 .EE
7125
7126 SConstruct:
7127 .ES
7128 env=Environment()
7129 env['PCHSTOP'] = 'StdAfx.h'
7130 env['PCH'] = env.PCH('StdAfx.cpp')[0]
7131 env.Program('MyApp', ['Foo.cpp', 'Bar.cpp'])
7132 .EE
7133
7134 For more information see the document for the PCH builder, and the PCH and
7135 PCHSTOP construction variables. To learn about the details of precompiled
7136 headers consult the MSDN documention for /Yc, /Yu, and /Yp.
7137
7138 .SS Using Microsoft Visual C++ external debugging information
7139
7140 Since including debugging information in programs and shared libraries can
7141 cause their size to increase significantly, Microsoft provides a mechanism
7142 for including the debugging information in an external file called a PDB
7143 file. SCons supports PDB files through the PDB construction
7144 variable. 
7145
7146 SConstruct:
7147 .ES
7148 env=Environment()
7149 env['PDB'] = 'MyApp.pdb'
7150 env.Program('MyApp', ['Foo.cpp', 'Bar.cpp'])
7151 .EE
7152
7153 For more information see the document for the PDB construction variable.
7154
7155 .SH ENVIRONMENT
7156
7157 .IP SCONS_LIB_DIR
7158 Specifies the directory that contains the SCons Python module directory
7159 (e.g. /home/aroach/scons-src-0.01/src/engine).
7160
7161 .IP SCONSFLAGS
7162 A string of options that will be used by scons in addition to those passed
7163 on the command line.
7164
7165 .SH "SEE ALSO"
7166 .B scons
7167 User Manual,
7168 .B scons
7169 Design Document,
7170 .B scons
7171 source code.
7172
7173 .SH AUTHORS
7174 Steven Knight <knight@baldmt.com>
7175 .br
7176 Anthony Roach <aroach@electriceyeball.com>
7177