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