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