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