Typos from issue 2159 plus some others I found
[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 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 (This will be officially deprecated some day.)
2763
2764 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2765 .TP
2766 .RI Builder( action ", [" arguments ])
2767 .TP
2768 .RI env.Builder( action ", [" arguments ])
2769 Creates a Builder object for
2770 the specified
2771 .IR action .
2772 See the section "Builder Objects,"
2773 below, for a complete explanation of the arguments and behavior.
2774
2775 Note that the
2776 .BR env.Builder ()
2777 form of the invocation will expand
2778 construction variables in any arguments strings,
2779 including the
2780 .I action
2781 argument,
2782 at the time it is called
2783 using the construction variables in the
2784 .B env
2785 construction environment through which
2786 .BR env.Builder ()
2787 was called.
2788 The
2789 .BR Builder ()
2790 form delays all variable expansion
2791 until after the Builder object is actually called.
2792
2793 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2794 .TP
2795 .RI CacheDir( cache_dir )
2796 .TP
2797 .RI env.CacheDir( cache_dir )
2798 Specifies that
2799 .B scons
2800 will maintain a cache of derived files in
2801 .I cache_dir .
2802 The derived files in the cache will be shared
2803 among all the builds using the same
2804 .BR CacheDir ()
2805 call.
2806 Specifying a
2807 .I cache_dir
2808 of
2809 .B None
2810 disables derived file caching.
2811
2812 Calling
2813 .BR env.CacheDir ()
2814 will only affect targets built
2815 through the specified construction environment.
2816 Calling
2817 .BR CacheDir ()
2818 sets a global default
2819 that will be used by all targets built
2820 through construction environments
2821 that do
2822 .I not
2823 have an
2824 .BR env.CacheDir ()
2825 specified.
2826
2827 When a
2828 .BR CacheDir ()
2829 is being used and
2830 .B scons
2831 finds a derived file that needs to be rebuilt,
2832 it will first look in the cache to see if a
2833 derived file has already been built
2834 from identical input files and an identical build action
2835 (as incorporated into the MD5 build signature).
2836 If so,
2837 .B scons
2838 will retrieve the file from the cache.
2839 If the derived file is not present in the cache,
2840 .B scons
2841 will rebuild it and
2842 then place a copy of the built file in the cache
2843 (identified by its MD5 build signature),
2844 so that it may be retrieved by other
2845 builds that need to build the same derived file
2846 from identical inputs.
2847
2848 Use of a specified
2849 .BR CacheDir()
2850 may be disabled for any invocation
2851 by using the
2852 .B --cache-disable
2853 option.
2854
2855 If the
2856 .B --cache-force
2857 option is used,
2858 .B scons
2859 will place a copy of
2860 .I all
2861 derived files in the cache,
2862 even if they already existed
2863 and were not built by this invocation.
2864 This is useful to populate a cache
2865 the first time
2866 .BR CacheDir ()
2867 is added to a build,
2868 or after using the
2869 .B --cache-disable
2870 option.
2871
2872 When using
2873 .BR CacheDir (),
2874 .B scons
2875 will report,
2876 "Retrieved `file' from cache,"
2877 unless the
2878 .B --cache-show
2879 option is being used.
2880 When the
2881 .B --cache-show
2882 option is used,
2883 .B scons
2884 will print the action that
2885 .I would
2886 have been used to build the file,
2887 without any indication that
2888 the file was actually retrieved from the cache.
2889 This is useful to generate build logs
2890 that are equivalent regardless of whether
2891 a given derived file has been built in-place
2892 or retrieved from the cache.
2893
2894 The
2895 .BR NoCache ()
2896 method can be used to disable caching of specific files.  This can be
2897 useful if inputs and/or outputs of some tool are impossible to
2898 predict or prohibitively large.
2899
2900 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2901 .TP
2902 .RI Clean( targets ", " files_or_dirs )
2903 .TP
2904 .RI env.Clean( targets ", " files_or_dirs )
2905 This specifies a list of files or directories which should be removed
2906 whenever the targets are specified with the
2907 .B -c
2908 command line option.
2909 The specified targets may be a list
2910 or an individual target.
2911 Multiple calls to
2912 .BR Clean ()
2913 are legal,
2914 and create new targets or add files and directories to the
2915 clean list for the specified targets.
2916
2917 Multiple files or directories should be specified
2918 either as separate arguments to the
2919 .BR Clean ()
2920 method, or as a list.
2921 .BR Clean ()
2922 will also accept the return value of any of the construction environment
2923 Builder methods.
2924 Examples:
2925
2926 The related
2927 .BR NoClean ()
2928 function overrides calling
2929 .BR Clean ()
2930 for the same target,
2931 and any targets passed to both functions will
2932 .I not
2933 be removed by the
2934 .B -c
2935 option.
2936
2937 Examples:
2938
2939 .ES
2940 Clean('foo', ['bar', 'baz'])
2941 Clean('dist', env.Program('hello', 'hello.c'))
2942 Clean(['foo', 'bar'], 'something_else_to_clean')
2943 .EE
2944
2945 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2946 .TP
2947 .RI Command( target ", " source ", " action ", [" key = val ", ...])"
2948 .TP
2949 .RI env.Command( target ", " source ", " action ", [" key = val ", ...])"
2950 Executes a specific action
2951 (or list of actions)
2952 to build a target file or files.
2953 This is more convenient
2954 than defining a separate Builder object
2955 for a single special-case build.
2956
2957 As a special case, the
2958 .B source_scanner
2959 keyword argument can
2960 be used to specify
2961 a Scanner object
2962 that will be used to scan the sources.
2963 (The global
2964 .B DirScanner
2965 object can be used
2966 if any of the sources will be directories
2967 that must be scanned on-disk for
2968 changes to files that aren't
2969 already specified in other Builder of function calls.)
2970
2971 Any other keyword arguments specified override any
2972 same-named existing construction variables.
2973
2974 An action can be an external command,
2975 specified as a string,
2976 or a callable Python object;
2977 see "Action Objects," below,
2978 for more complete information.
2979 Also note that a string specifying an external command
2980 may be preceded by an
2981 .B @
2982 (at-sign)
2983 to suppress printing the command in question,
2984 or by a
2985 .B \-
2986 (hyphen)
2987 to ignore the exit status of the external command.
2988
2989 Examples:
2990
2991 .ES
2992 env.Command('foo.out', 'foo.in',
2993             "$FOO_BUILD < $SOURCES > $TARGET")
2994
2995 env.Command('bar.out', 'bar.in',
2996             ["rm -f $TARGET",
2997              "$BAR_BUILD < $SOURCES > $TARGET"],
2998             ENV = {'PATH' : '/usr/local/bin/'})
2999
3000 def rename(env, target, source):
3001     import os
3002     os.rename('.tmp', str(target[0]))
3003
3004 env.Command('baz.out', 'baz.in',
3005             ["$BAZ_BUILD < $SOURCES > .tmp",
3006              rename ])
3007 .EE
3008
3009 .IP
3010 Note that the
3011 .BR Command ()
3012 function will usually assume, by default,
3013 that the specified targets and/or sources are Files,
3014 if no other part of the configuration
3015 identifies what type of entry it is.
3016 If necessary, you can explicitly specify
3017 that targets or source nodes should
3018 be treated as directoriese
3019 by using the
3020 .BR Dir ()
3021 or
3022 .BR env.Dir ()
3023 functions.
3024
3025 Examples:
3026
3027 .ES
3028 env.Command('ddd.list', Dir('ddd'), 'ls -l $SOURCE > $TARGET')
3029
3030 env['DISTDIR'] = 'destination/directory'
3031 env.Command(env.Dir('$DISTDIR')), None, make_distdir)
3032 .EE
3033
3034 .IP
3035 (Also note that SCons will usually
3036 automatically create any directory necessary to hold a target file,
3037 so you normally don't need to create directories by hand.)
3038
3039 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3040 .TP
3041 .RI Configure( env ", [" custom_tests ", " conf_dir ", " log_file ", " config_h ])
3042 .TP
3043 .RI env.Configure([ custom_tests ", " conf_dir ", " log_file ", " config_h ])
3044 Creates a Configure object for integrated
3045 functionality similar to GNU autoconf.
3046 See the section "Configure Contexts,"
3047 below, for a complete explanation of the arguments and behavior.
3048
3049 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3050 .TP
3051 .RI env.Clone([ key = val ", ...])"
3052 Return a separate copy of a construction environment.
3053 If there are any keyword arguments specified,
3054 they are added to the returned copy,
3055 overwriting any existing values
3056 for the keywords.
3057
3058 Example:
3059
3060 .ES
3061 env2 = env.Clone()
3062 env3 = env.Clone(CCFLAGS = '-g')
3063 .EE
3064 .IP
3065 Additionally, a list of tools and a toolpath may be specified, as in
3066 the Environment constructor:
3067
3068 .ES
3069 def MyTool(env): env['FOO'] = 'bar'
3070 env4 = env.Clone(tools = ['msvc', MyTool])
3071 .EE
3072
3073 The
3074 .I parse_flags
3075 keyword argument is also recognized:
3076
3077 .ES
3078 # create an environment for compiling programs that use wxWidgets
3079 wx_env = env.Clone(parse_flags = '!wx-config --cflags --cxxflags')
3080 .EE
3081
3082 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3083 .TP
3084 .RI env.Copy([ key = val ", ...])"
3085 A now-deprecated synonym for
3086 .BR env.Clone() .
3087
3088 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3089 .TP
3090 .RI env.CVS( repository ", " module )
3091 A factory function that
3092 returns a Builder object
3093 to be used to fetch source files
3094 from the specified
3095 CVS
3096 .IR repository .
3097 The returned Builder
3098 is intended to be passed to the
3099 .B SourceCode
3100 function.
3101
3102 The optional specified
3103 .I module
3104 will be added to the beginning
3105 of all repository path names;
3106 this can be used, in essence,
3107 to strip initial directory names
3108 from the repository path names,
3109 so that you only have to
3110 replicate part of the repository
3111 directory hierarchy in your
3112 local build directory.
3113
3114 Examples:
3115
3116 .ES
3117 # Will fetch foo/bar/src.c
3118 # from /usr/local/CVSROOT/foo/bar/src.c.
3119 env.SourceCode('.', env.CVS('/usr/local/CVSROOT'))
3120
3121 # Will fetch bar/src.c
3122 # from /usr/local/CVSROOT/foo/bar/src.c.
3123 env.SourceCode('.', env.CVS('/usr/local/CVSROOT', 'foo'))
3124
3125 # Will fetch src.c
3126 # from /usr/local/CVSROOT/foo/bar/src.c.
3127 env.SourceCode('.', env.CVS('/usr/local/CVSROOT', 'foo/bar'))
3128 .EE
3129
3130 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3131 .TP
3132 .RI Decider( function )
3133 .TP
3134 .RI env.Decider( function )
3135 Specifies that all up-to-date decisions for
3136 targets built through this construction environment
3137 will be handled by the specified
3138 .IR function .
3139 The
3140 .I function
3141 can be one of the following strings
3142 that specify the type of decision function
3143 to be performed:
3144
3145 .RS 10
3146 .HP 6
3147 .B timestamp-newer
3148 Specifies that a target shall be considered out of date and rebuilt
3149 if the dependency's timestamp is newer than the target file's timestamp.
3150 This is the behavior of the classic Make utility,
3151 and
3152 .B make
3153 can be used a synonym for
3154 .BR timestamp-newer .
3155
3156 .HP 6
3157 .B timestamp-match
3158 Specifies that a target shall be considered out of date and rebuilt
3159 if the dependency's timestamp is different than the
3160 timestamp recorded the last time the target was built.
3161 This provides behavior very similar to the classic Make utility
3162 (in particular, files are not opened up so that their
3163 contents can be checksummed)
3164 except that the target will also be rebuilt if a
3165 dependency file has been restored to a version with an
3166 .I earlier
3167 timestamp, such as can happen when restoring files from backup archives.
3168
3169 .HP 6
3170 .B MD5
3171 Specifies that a target shall be considered out of date and rebuilt
3172 if the dependency's content has changed sine the last time
3173 the target was built,
3174 as determined be performing an MD5 checksum
3175 on the dependency's contents
3176 and comparing it to the checksum recorded the
3177 last time the target was built.
3178 .B content
3179 can be used as a synonym for
3180 .BR MD5 .
3181
3182 .HP 6
3183 .B MD5-timestamp
3184 Specifies that a target shall be considered out of date and rebuilt
3185 if the dependency's content has changed sine the last time
3186 the target was built,
3187 except that dependencies with a timestamp that matches
3188 the last time the target was rebuilt will be
3189 assumed to be up-to-date and
3190 .I not
3191 rebuilt.
3192 This provides behavior very similar
3193 to the
3194 .B MD5
3195 behavior of always checksumming file contents,
3196 with an optimization of not checking
3197 the contents of files whose timestamps haven't changed.
3198 The drawback is that SCons will
3199 .I not
3200 detect if a file's content has changed
3201 but its timestamp is the same,
3202 as might happen in an automated script
3203 that runs a build,
3204 updates a file,
3205 and runs the build again,
3206 all within a single second.
3207 .RE
3208
3209 .IP
3210 Examples:
3211
3212 .ES
3213 # Use exact timestamp matches by default.
3214 Decider('timestamp-match')
3215
3216 # Use MD5 content signatures for any targets built
3217 # with the attached construction environment.
3218 env.Decider('content')
3219 .EE
3220
3221 .IP
3222 In addition to the above already-available functions,
3223 the
3224 .I function
3225 argument may be an actual Python function
3226 that takes the following three arguments:
3227
3228 .RS 10
3229 .IP dependency
3230 The Node (file) which
3231 should cause the
3232 .I target
3233 to be rebuilt
3234 if it has "changed" since the last tme
3235 .I target was built.
3236
3237 .IP target
3238 The Node (file) being built.
3239 In the normal case,
3240 this is what should get rebuilt
3241 if the
3242 .I dependency
3243 has "changed."
3244
3245 .IP prev_ni
3246 Stored information about the state of the
3247 .I dependency
3248 the last time the
3249 .I target
3250 was built.
3251 This can be consulted to match various
3252 file characteristics
3253 such as the timestamp,
3254 size, or content signature.
3255 .RE
3256
3257 .IP
3258 The
3259 .I function
3260 should return a
3261 .B True
3262 (non-zero)
3263 value if the
3264 .I dependency
3265 has "changed" since the last time
3266 the
3267 .I target
3268 was built
3269 (indicating that the target
3270 .I should
3271 be rebuilt),
3272 and
3273 .B False
3274 (zero)
3275 otherwise
3276 (indicating that the target should
3277 .I not
3278 be rebuilt).
3279 Note that the decision can be made
3280 using whatever criteria are appopriate.
3281 Ignoring some or all of the function arguments
3282 is perfectly normal.
3283
3284 Example:
3285
3286 .ES
3287 def my_decider(dependency, target, prev_ni):
3288     return not os.path.exists(str(target))
3289
3290 env.Decider(my_decider)
3291 .EE
3292
3293 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3294 .TP
3295 .RI Default( targets )
3296 .TP
3297 .RI env.Default( targets )
3298 This specifies a list of default targets,
3299 which will be built by
3300 .B scons
3301 if no explicit targets are given on the command line.
3302 Multiple calls to
3303 .BR Default ()
3304 are legal,
3305 and add to the list of default targets.
3306
3307 Multiple targets should be specified as
3308 separate arguments to the
3309 .BR Default ()
3310 method, or as a list.
3311 .BR Default ()
3312 will also accept the Node returned by any
3313 of a construction environment's
3314 builder methods.
3315
3316 Examples:
3317
3318 .ES
3319 Default('foo', 'bar', 'baz')
3320 env.Default(['a', 'b', 'c'])
3321 hello = env.Program('hello', 'hello.c')
3322 env.Default(hello)
3323 .EE
3324 .IP
3325 An argument to
3326 .BR Default ()
3327 of
3328 .B None
3329 will clear all default targets.
3330 Later calls to
3331 .BR Default ()
3332 will add to the (now empty) default-target list
3333 like normal.
3334
3335 The current list of targets added using the
3336 .BR Default ()
3337 function or method is available in the
3338 .B DEFAULT_TARGETS
3339 list;
3340 see below.
3341
3342 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3343 .TP
3344 .RI DefaultEnvironment([ args ])
3345 Creates and returns a default construction environment object.
3346 This construction environment is used internally by SCons
3347 in order to execute many of the global functions in this list,
3348 and to fetch source files transparently
3349 from source code management systems.
3350
3351 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3352 .TP
3353 .RI Depends( target ", " dependency )
3354 .TP
3355 .RI env.Depends( target ", " dependency )
3356 Specifies an explicit dependency;
3357 the
3358 .I target
3359 will be rebuilt
3360 whenever the
3361 .I dependency
3362 has changed.
3363 Both the specified
3364 .I target
3365 and
3366 .I dependency
3367 can be a string
3368 (usually the path name of a file or directory)
3369 or Node objects,
3370 or a list of strings or Node objects
3371 (such as returned by a Builder call).
3372 This should only be necessary
3373 for cases where the dependency
3374 is not caught by a Scanner
3375 for the file.
3376
3377 Example:
3378
3379 .ES
3380 env.Depends('foo', 'other-input-file-for-foo')
3381
3382 mylib = env.Library('mylib.c')
3383 installed_lib = env.Install('lib', mylib)
3384 bar = env.Program('bar.c')
3385
3386 # Arrange for the library to be copied into the installation
3387 # directory before trying to build the "bar" program.
3388 # (Note that this is for example only.  A "real" library
3389 # dependency would normally be configured through the $LIBS
3390 # and $LIBPATH variables, not using an env.Depends() call.)
3391
3392 env.Depends(bar, installed_lib)
3393 .EE
3394
3395 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3396 .TP
3397 .RI env.Dictionary([ vars ])
3398 Returns a dictionary object
3399 containing copies of all of the
3400 construction variables in the environment.
3401 If there are any variable names specified,
3402 only the specified construction
3403 variables are returned in the dictionary.
3404
3405 Example:
3406
3407 .ES
3408 dict = env.Dictionary()
3409 cc_dict = env.Dictionary('CC', 'CCFLAGS', 'CCCOM')
3410 .EE
3411
3412 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3413 .TP
3414 .RI Dir( name ", [" directory ])
3415 .TP
3416 .RI env.Dir( name ", [" directory ])
3417 This returns a Directory Node,
3418 an object that represents the specified directory
3419 .IR name .
3420 .I name
3421 can be a relative or absolute path.
3422 .I directory
3423 is an optional directory that will be used as the parent directory.
3424 If no
3425 .I directory
3426 is specified, the current script's directory is used as the parent.
3427
3428 If
3429 .I name
3430 is a list, SCons returns a list of Dir nodes.
3431 Construction variables are expanded in
3432 .IR name .
3433
3434 Directory Nodes can be used anywhere you
3435 would supply a string as a directory name
3436 to a Builder method or function.
3437 Directory Nodes have attributes and methods
3438 that are useful in many situations;
3439 see "File and Directory Nodes," below.
3440
3441 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3442 .TP
3443 .RI env.Dump([ key ])
3444 Returns a pretty printable representation of the environment.
3445 .IR key ,
3446 if not
3447 .IR None ,
3448 should be a string containing the name of the variable of interest.
3449
3450 This SConstruct:
3451 .ES
3452 env=Environment()
3453 print env.Dump('CCCOM')
3454 .EE
3455 .IP
3456 will print:
3457 .ES
3458 \&'$CC $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES'
3459 .EE
3460
3461 .ES
3462 env=Environment()
3463 print env.Dump()
3464 .EE
3465 .IP
3466 will print:
3467 .ES
3468 { 'AR': 'ar',
3469   'ARCOM': '$AR $ARFLAGS $TARGET $SOURCES\n$RANLIB $RANLIBFLAGS $TARGET',
3470   'ARFLAGS': ['r'],
3471   'AS': 'as',
3472   'ASCOM': '$AS $ASFLAGS -o $TARGET $SOURCES',
3473   'ASFLAGS': [],
3474   ...
3475 .EE
3476
3477 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3478 .TP
3479 .RI EnsurePythonVersion( major ", " minor )
3480 .TP
3481 .RI env.EnsurePythonVersion( major ", " minor )
3482 Ensure that the Python version is at least
3483 .IR major . minor .
3484 This function will
3485 print out an error message and exit SCons with a non-zero exit code if the
3486 actual Python version is not late enough.
3487
3488 Example:
3489
3490 .ES
3491 EnsurePythonVersion(2,2)
3492 .EE
3493
3494 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3495 .TP
3496 .RI EnsureSConsVersion( major ", " minor ", [" revision ])
3497 .TP
3498 .RI env.EnsureSConsVersion( major ", " minor ", [" revision ])
3499 Ensure that the SCons version is at least
3500 .IR major.minor ,
3501 or
3502 .IR major.minor.revision .
3503 if
3504 .I revision
3505 is specified.
3506 This function will
3507 print out an error message and exit SCons with a non-zero exit code if the
3508 actual SCons version is not late enough.
3509
3510 Examples:
3511
3512 .ES
3513 EnsureSConsVersion(0,14)
3514
3515 EnsureSConsVersion(0,96,90)
3516 .EE
3517
3518 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3519 .TP
3520 .RI Environment([ key = value ", ...])"
3521 .TP
3522 .RI env.Environment([ key = value ", ...])"
3523 Return a new construction environment
3524 initialized with the specified
3525 .IR key = value
3526 pairs.
3527
3528 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3529 .TP
3530 .RI Execute( action ", [" strfunction ", " varlist ])
3531 .TP
3532 .RI env.Execute( action ", [" strfunction ", " varlist ])
3533 Executes an Action object.
3534 The specified
3535 .IR action
3536 may be an Action object
3537 (see the section "Action Objects,"
3538 below, for a complete explanation of the arguments and behavior),
3539 or it may be a command-line string,
3540 list of commands,
3541 or executable Python function,
3542 each of which will be converted
3543 into an Action object
3544 and then executed.
3545 The exit value of the command
3546 or return value of the Python function
3547 will be returned.
3548
3549 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3550 .TP
3551 .RI Exit([ value ])
3552 .TP
3553 .RI env.Exit([ value ])
3554 This tells
3555 .B scons
3556 to exit immediately
3557 with the specified
3558 .IR value .
3559 A default exit value of
3560 .B 0
3561 (zero)
3562 is used if no value is specified.
3563
3564 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3565 .TP
3566 .RI Export( vars )
3567 .TP
3568 .RI env.Export( vars )
3569 This tells
3570 .B scons
3571 to export a list of variables from the current
3572 SConscript file to all other SConscript files.
3573 The exported variables are kept in a global collection,
3574 so subsequent calls to
3575 .BR Export ()
3576 will over-write previous exports that have the same name.
3577 Multiple variable names can be passed to
3578 .BR Export ()
3579 as separate arguments or as a list. A dictionary can be used to map
3580 variables to a different name when exported. Both local variables and
3581 global variables can be exported.
3582
3583 Examples:
3584
3585 .ES
3586 env = Environment()
3587 # Make env available for all SConscript files to Import().
3588 Export("env")
3589
3590 package = 'my_name'
3591 # Make env and package available for all SConscript files:.
3592 Export("env", "package")
3593
3594 # Make env and package available for all SConscript files:
3595 Export(["env", "package"])
3596
3597 # Make env available using the name debug:.
3598 Export({"debug":env})
3599 .EE
3600
3601 .IP
3602 Note that the
3603 .BR SConscript ()
3604 function supports an
3605 .I exports
3606 argument that makes it easier to to export a variable or
3607 set of variables to a single SConscript file.
3608 See the description of the
3609 .BR SConscript ()
3610 function, below.
3611
3612 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3613 .TP
3614 .RI File( name ", [" directory ])
3615 .TP
3616 .RI env.File( name ", [" directory ])
3617 This returns a
3618 File Node,
3619 an object that represents the specified file
3620 .IR name .
3621 .I name
3622 can be a relative or absolute path.
3623 .I directory
3624 is an optional directory that will be used as the parent directory.
3625
3626 If
3627 .I name
3628 is a list, SCons returns a list of File nodes.
3629 Construction variables are expanded in
3630 .IR name .
3631
3632 File Nodes can be used anywhere you
3633 would supply a string as a file name
3634 to a Builder method or function.
3635 File Nodes have attributes and methods
3636 that are useful in many situations;
3637 see "File and Directory Nodes," below.
3638
3639 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3640 .TP
3641 .RI FindFile( file ", " dirs )
3642 .TP
3643 .RI env.FindFile( file ", " dirs )
3644 Search for
3645 .I file
3646 in the path specified by
3647 .IR dirs .
3648 .I file
3649 may be a list of file names or a single file name. In addition to searching
3650 for files that exist in the filesytem, this function also searches for
3651 derived files that have not yet been built.
3652
3653 Example:
3654
3655 .ES
3656 foo = env.FindFile('foo', ['dir1', 'dir2'])
3657 .EE
3658
3659 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3660 .TP
3661 .RI FindInstalledFiles( )
3662 .TP
3663 .RI env.FindInstalledFiles( )
3664 Returns the list of targets set up by the
3665 .B Install()
3666 or
3667 .B InstallAs()
3668 builders.
3669
3670 This function serves as a convenient method to select the contents of
3671 a binary package.
3672
3673 Example:
3674
3675 .ES
3676 Install( '/bin', [ 'executable_a', 'executable_b' ] )
3677
3678 # will return the file node list
3679 # [ '/bin/executable_a', '/bin/executable_b' ]
3680 FindInstalledFiles()
3681
3682 Install( '/lib', [ 'some_library' ] )
3683
3684 # will return the file node list
3685 # [ '/bin/executable_a', '/bin/executable_b', '/lib/some_library' ]
3686 FindInstalledFiles()
3687 .EE
3688
3689 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3690 .TP
3691 .RI FindSourceFiles( node = '"."' )
3692 .TP
3693 .RI env.FindSourceFiles( node = '"."' )
3694
3695 Returns the list of nodes which serve as the source of the built files.
3696 It does so by inspecting the dependency tree starting at the optional
3697 argument
3698 .B node
3699 which defaults to the '"."'-node. It will then return all leaves of
3700 .B node.
3701 These are all children which have no further children.
3702
3703 This function is a convenient method to select the contents of a Source
3704 Package.
3705
3706 Example:
3707
3708 .ES
3709 Program( 'src/main_a.c' )
3710 Program( 'src/main_b.c' )
3711 Program( 'main_c.c' )
3712
3713 # returns ['main_c.c', 'src/main_a.c', 'SConstruct', 'src/main_b.c']
3714 FindSourceFiles()
3715
3716 # returns ['src/main_b.c', 'src/main_a.c' ]
3717 FindSourceFiles( 'src' )
3718 .EE
3719
3720 .IP
3721 As you can see build support files (SConstruct in the above example)
3722 will also be returned by this function.
3723
3724 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3725 .TP
3726 .RI FindPathDirs( variable )
3727 Returns a function
3728 (actually a callable Python object)
3729 intended to be used as the
3730 .B path_function
3731 of a Scanner object.
3732 The returned object will look up the specified
3733 .I variable
3734 in a construction environment
3735 and treat the construction variable's value as a list of
3736 directory paths that should be searched
3737 (like
3738 .BR CPPPATH ,
3739 .BR LIBPATH ,
3740 etc.).
3741
3742 Note that use of
3743 .BR FindPathDirs ()
3744 is generally preferable to
3745 writing your own
3746 .B path_function
3747 for the following reasons:
3748 1) The returned list will contain all appropriate directories
3749 found in source trees
3750 (when
3751 .BR VariantDir ()
3752 is used)
3753 or in code repositories
3754 (when
3755 .BR Repository ()
3756 or the
3757 .B \-Y
3758 option are used).
3759 2) scons will identify expansions of
3760 .I variable
3761 that evaluate to the same list of directories as,
3762 in fact, the same list,
3763 and avoid re-scanning the directories for files,
3764 when possible.
3765
3766 Example:
3767
3768 .ES
3769 def my_scan(node, env, path, arg):
3770     # Code to scan file contents goes here...
3771     return include_files
3772
3773 scanner = Scanner(name = 'myscanner',
3774                   function = my_scan,
3775                   path_function = FindPathDirs('MYPATH'))
3776 .EE
3777
3778 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3779 .TP
3780 .RI Flatten( sequence )
3781 .TP
3782 .RI env.Flatten( sequence )
3783 Takes a sequence (that is, a Python list or tuple)
3784 that may contain nested sequences
3785 and returns a flattened list containing
3786 all of the individual elements in any sequence.
3787 This can be helpful for collecting
3788 the lists returned by calls to Builders;
3789 other Builders will automatically
3790 flatten lists specified as input,
3791 but direct Python manipulation of
3792 these lists does not.
3793
3794 Examples:
3795
3796 .ES
3797 foo = Object('foo.c')
3798 bar = Object('bar.c')
3799
3800 # Because `foo' and `bar' are lists returned by the Object() Builder,
3801 # `objects' will be a list containing nested lists:
3802 objects = ['f1.o', foo, 'f2.o', bar, 'f3.o']
3803
3804 # Passing such a list to another Builder is all right because
3805 # the Builder will flatten the list automatically:
3806 Program(source = objects)
3807
3808 # If you need to manipulate the list directly using Python, you need to
3809 # call Flatten() yourself, or otherwise handle nested lists:
3810 for object in Flatten(objects):
3811     print str(object)
3812 .EE
3813
3814 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3815 .TP
3816 .RI GetBuildFailures()
3817 Returns a list of exceptions for the
3818 actions that failed while
3819 attempting to build targets.
3820 Each element in the returned list is a
3821 .B BuildError
3822 object
3823 with the following attributes
3824 that record various aspects
3825 of the build failure:
3826
3827 .B .node
3828 The node that was being built
3829 when the build failure occurred.
3830
3831 .B .status
3832 The numeric exit status
3833 returned by the command or Python function
3834 that failed when trying to build the
3835 specified Node.
3836
3837 .B .errstr
3838 The SCons error string
3839 describing the build failure.
3840 (This is often a generic
3841 message like "Error 2"
3842 to indicate that an executed
3843 command exited with a status of 2.)
3844
3845 .B .filename
3846 The name of the file or
3847 directory that actually caused the failure.
3848 This may be different from the
3849 .B .node
3850 attribute.
3851 For example,
3852 if an attempt to build a target named
3853 .B sub/dir/target
3854 fails because the
3855 .B sub/dir
3856 directory could not be created,
3857 then the
3858 .B .node
3859 attribute will be
3860 .B sub/dir/target
3861 but the
3862 .B .filename
3863 attribute will be
3864 .BR sub/dir .
3865
3866 .B .executor
3867 The SCons Executor object
3868 for the target Node
3869 being built.
3870 This can be used to retrieve
3871 the construction environment used
3872 for the failed action.
3873
3874 .B .action
3875 The actual SCons Action object that failed.
3876 This will be one specific action
3877 out of the possible list of
3878 actions that would have been
3879 executed to build the target.
3880
3881 .B .command
3882 The actual expanded command that was executed and failed,
3883 after expansion of
3884 .BR $TARGET ,
3885 .BR $SOURCE ,
3886 and other construction variables.
3887
3888 Note that the
3889 .BR GetBuildFailures ()
3890 function
3891 will always return an empty list
3892 until any build failure has occurred,
3893 which means that
3894 .BR GetBuildFailures ()
3895 will always return an empty list
3896 while the
3897 .B SConscript
3898 files are being read.
3899 Its primary intended use is
3900 for functions that will be
3901 executed before SCons exits
3902 by passing them to the
3903 standard Python
3904 .BR atexit.register ()
3905 function.
3906 Example:
3907
3908 .ES
3909 import atexit
3910
3911 def print_build_failures():
3912     from SCons.Script import GetBuildFailures
3913     for bf in GetBuildFailures():
3914         print "%s failed: %s" % (bf.node, bf.errstr)
3915
3916 atexit.register(print_build_failures)
3917 .EE
3918
3919 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3920 .TP
3921 .RI GetBuildPath( file ", [" ... ])
3922 .TP
3923 .RI env.GetBuildPath( file ", [" ... ])
3924 Returns the
3925 .B scons
3926 path name (or names) for the specified
3927 .I file
3928 (or files).
3929 The specified
3930 .I file
3931 or files
3932 may be
3933 .B scons
3934 Nodes or strings representing path names.
3935
3936 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3937 .TP
3938 .RI GetLaunchDir()
3939 .TP
3940 .RI env.GetLaunchDir()
3941 Returns the absolute path name of the directory from which
3942 .B scons
3943 was initially invoked.
3944 This can be useful when using the
3945 .BR \-u ,
3946 .BR \-U
3947 or
3948 .BR \-D
3949 options, which internally
3950 change to the directory in which the
3951 .B SConstruct
3952 file is found.
3953
3954 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
3955 .TP
3956 .RI GetOption( name )
3957 .TP
3958 .RI env.GetOption( name )
3959 This function provides a way to query the value of
3960 SCons options set on scons command line
3961 (or set using the
3962 .IR SetOption ()
3963 function).
3964 The options supported are:
3965
3966 .RS 10
3967 .TP 6
3968 .B cache_debug
3969 .TP 6
3970 which corresponds to --cache-debug;
3971 .TP 6
3972 .B cache_disable
3973 which corresponds to --cache-disable;
3974 .TP 6
3975 .B cache_force
3976 which corresponds to --cache-force;
3977 .TP 6
3978 .B cache_show
3979 which corresponds to --cache-show;
3980 .TP 6
3981 .B clean
3982 which corresponds to -c, --clean and --remove;
3983 .TP 6
3984 .B config
3985 which corresponds to --config;
3986 .TP 6
3987 .B directory
3988 which corresponds to -C and --directory;
3989 .TP 6
3990 .B diskcheck
3991 which corresponds to --diskcheck
3992 .TP 6
3993 .B duplicate
3994 which corresponds to --duplicate;
3995 .TP 6
3996 .B file
3997 which corresponds to -f, --file, --makefile and --sconstruct;
3998 .TP 6
3999 .B help
4000 which corresponds to -h and --help;
4001 .TP 6
4002 .B ignore_errors
4003 which corresponds to --ignore-errors;
4004 .TP 6
4005 .B implicit_cache
4006 which corresponds to --implicit-cache;
4007 .TP 6
4008 .B implicit_deps_changed
4009 which corresponds to --implicit-deps-changed;
4010 .TP 6
4011 .B implicit_deps_unchanged
4012 which corresponds to --implicit-deps-unchanged;
4013 .TP 6
4014 .B interactive
4015 which corresponds to --interact and --interactive;
4016 .TP 6
4017 .B keep_going
4018 which corresponds to -k and --keep-going;
4019 .TP 6
4020 .B max_drift
4021 which corresponds to --max-drift;
4022 .TP 6
4023 .B no_exec
4024 which corresponds to -n, --no-exec, --just-print, --dry-run and --recon;
4025 .TP 6
4026 .B no_site_dir
4027 which corresponds to --no-site-dir;
4028 .TP 6
4029 .B num_jobs
4030 which corresponds to -j and --jobs;
4031 .TP 6
4032 .B profile_file
4033 which corresponds to --profile;
4034 .TP 6
4035 .B question
4036 which corresponds to -q and --question;
4037 .TP 6
4038 .B random
4039 which corresponds to --random;
4040 .TP 6
4041 .B repository
4042 which corresponds to -Y, --repository and --srcdir;
4043 .TP 6
4044 .B silent
4045 which corresponds to -s, --silent and --quiet;
4046 .TP 6
4047 .B site_dir
4048 which corresponds to --site-dir;
4049 .TP 6
4050 .B stack_size
4051 which corresponds to --stack-size;
4052 .TP 6
4053 .B taskmastertrace_file
4054 which corresponds to --taskmastertrace; and
4055 .TP 6
4056 .B warn
4057 which corresponds to --warn and --warning.
4058 .RE
4059
4060 .IP
4061 See the documentation for the
4062 corresponding command line object for information about each specific
4063 option.
4064
4065 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4066 .TP
4067 .RI Glob( pattern ", [" ondisk ", " source ", " strings ])
4068 .TP
4069 .RI env.Glob( pattern ", [" ondisk ", " source ", " strings ])
4070 Returns Nodes (or strings) that match the specified
4071 .IR pattern ,
4072 relative to the directory of the current
4073 .B SConscript
4074 file.
4075 The
4076 .BR env.Glob ()
4077 form performs string substition on
4078 .I pattern
4079 and returns whatever matches
4080 the resulting expanded pattern.
4081
4082 The specified
4083 .I pattern
4084 uses Unix shell style metacharacters for matching:
4085
4086 .ES
4087   *       matches everything
4088   ?       matches any single character
4089   [seq]   matches any character in seq
4090   [!seq]  matches any char not in seq
4091 .EE
4092
4093 .IP
4094 Character matches do
4095 .I not
4096 span directory separators.
4097
4098 The
4099 .BR Glob ()
4100 knows about
4101 repositories
4102 (see the
4103 .BR Repository ()
4104 function)
4105 and source directories
4106 (see the
4107 .BR VariantDir ()
4108 function)
4109 and
4110 returns a Node (or string, if so configured)
4111 in the local (SConscript) directory
4112 if matching Node is found
4113 anywhere in a corresponding
4114 repository or source directory.
4115
4116 The
4117 .B ondisk
4118 argument may be set to
4119 .B False
4120 (or any other non-true value)
4121 to disable the search for matches on disk,
4122 thereby only returning matches among
4123 already-configured File or Dir Nodes.
4124 The default behavior is to
4125 return corresponding Nodes
4126 for any on-disk matches found.
4127
4128 The
4129 .B source
4130 argument may be set to
4131 .B True
4132 (or any equivalent value)
4133 to specify that,
4134 when the local directory is a
4135 .BR VariantDir (),
4136 the returned Nodes should be from the
4137 corresponding source directory,
4138 not the local directory.
4139
4140 The
4141 .B strings
4142 argument may be set to
4143 .B True
4144 (or any equivalent value)
4145 to have the
4146 .BR Glob ()
4147 function return strings, not Nodes,
4148 that represent the matched files or directories.
4149 The returned strings will be relative to
4150 the local (SConscript) directory.
4151 (Note that This may make it easier to perform
4152 arbitrary manipulation of file names,
4153 but if the returned strings are
4154 passed to a different
4155 .B SConscript
4156 file,
4157 any Node translation will be relative
4158 to the other
4159 .B SConscript
4160 directory,
4161 not the original
4162 .B SConscript
4163 directory.)
4164
4165 Example:
4166
4167 .ES
4168 Program('foo', Glob('*.c'))
4169 .EE
4170
4171 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4172 '\".TP
4173 '\".RI GlobalBuilders( flag )
4174 '\"When
4175 '\".B flag
4176 '\"is non-zero,
4177 '\"adds the names of the default builders
4178 '\"(Program, Library, etc.)
4179 '\"to the global name space
4180 '\"so they can be called without an explicit construction environment.
4181 '\"(This is the default.)
4182 '\"When
4183 '\".B
4184 '\"flag is zero,
4185 '\"the names of the default builders are removed
4186 '\"from the global name space
4187 '\"so that an explicit construction environment is required
4188 '\"to call all builders.
4189
4190 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4191 .TP
4192 .RI Help( text )
4193 .TP
4194 .RI env.Help( text )
4195 This specifies help text to be printed if the
4196 .B -h
4197 argument is given to
4198 .BR scons .
4199 If
4200 .BR Help
4201 is called multiple times, the text is appended together in the order
4202 that
4203 .BR Help
4204 is called.
4205
4206 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4207 .TP
4208 .RI Ignore( target ", " dependency )
4209 .TP
4210 .RI env.Ignore( target ", " dependency )
4211 The specified dependency file(s)
4212 will be ignored when deciding if
4213 the target file(s) need to be rebuilt.
4214
4215 Examples:
4216
4217 .ES
4218 env.Ignore('foo', 'foo.c')
4219 env.Ignore('bar', ['bar1.h', 'bar2.h'])
4220 .EE
4221
4222 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4223 .TP
4224 .RI Import( vars )
4225 .TP
4226 .RI env.Import( vars )
4227 This tells
4228 .B scons
4229 to import a list of variables into the current SConscript file. This
4230 will import variables that were exported with
4231 .BR Export ()
4232 or in the
4233 .I exports
4234 argument to
4235 .BR SConscript ().
4236 Variables exported by
4237 .BR SConscript ()
4238 have precedence.
4239 Multiple variable names can be passed to
4240 .BR Import ()
4241 as separate arguments or as a list. The variable "*" can be used
4242 to import all variables.
4243
4244 Examples:
4245
4246 .ES
4247 Import("env")
4248 Import("env", "variable")
4249 Import(["env", "variable"])
4250 Import("*")
4251 .EE
4252
4253 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4254 .TP
4255 .RI Literal( string )
4256 .TP
4257 .RI env.Literal( string )
4258 The specified
4259 .I string
4260 will be preserved as-is
4261 and not have construction variables expanded.
4262
4263 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4264 .TP
4265 .RI Local( targets )
4266 .TP
4267 .RI env.Local( targets )
4268 The specified
4269 .I targets
4270 will have copies made in the local tree,
4271 even if an already up-to-date copy
4272 exists in a repository.
4273 Returns a list of the target Node or Nodes.
4274
4275 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4276 .TP
4277 .RI env.MergeFlags( arg ", [" unique ])
4278 Merges the specified
4279 .I arg
4280 values to the construction envrionment's construction variables.
4281 If the
4282 .I arg
4283 argument is not a dictionary,
4284 it is converted to one by calling
4285 .B env.ParseFlags()
4286 on the argument
4287 before the values are merged.
4288 Note that
4289 .I arg
4290 must be a single value,
4291 so multiple strings must
4292 be passed in as a list,
4293 not as separate arguments to
4294 .BR env.MergeFlags ().
4295
4296 By default,
4297 duplicate values are eliminated;
4298 you can, however, specify
4299 .B unique=0
4300 to allow duplicate
4301 values to be added.
4302 When eliminating duplicate values,
4303 any construction variables that end with
4304 the string
4305 .B PATH
4306 keep the left-most unique value.
4307 All other construction variables keep
4308 the right-most unique value.
4309
4310 Examples:
4311
4312 .ES
4313 # Add an optimization flag to $CCFLAGS.
4314 env.MergeFlags('-O3')
4315
4316 # Combine the flags returned from running pkg-config with an optimization
4317 # flag and merge the result into the construction variables.
4318 env.MergeFlags(['!pkg-config gtk+-2.0 --cflags', '-O3'])
4319
4320 # Combine an optimization flag with the flags returned from running pkg-config
4321 # twice and merge the result into the construction variables.
4322 env.MergeFlags(['-O3',
4323                '!pkg-config gtk+-2.0 --cflags --libs',
4324                '!pkg-config libpng12 --cflags --libs'])
4325 .EE
4326
4327 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4328 .TP
4329 .RI NoCache( target ", ...)"
4330 .TP
4331 .RI env.NoCache( target ", ...)"
4332 Specifies a list of files which should
4333 .I not
4334 be cached whenever the
4335 .BR CacheDir ()
4336 method has been activated.
4337 The specified targets may be a list
4338 or an individual target.
4339
4340 Multiple files should be specified
4341 either as separate arguments to the
4342 .BR NoCache ()
4343 method, or as a list.
4344 .BR NoCache ()
4345 will also accept the return value of any of the construction environment
4346 Builder methods.
4347
4348 Calling
4349 .BR NoCache ()
4350 on directories and other non-File Node types has no effect because
4351 only File Nodes are cached.
4352
4353 Examples:
4354
4355 .ES
4356 NoCache('foo.elf')
4357 NoCache(env.Program('hello', 'hello.c'))
4358 .EE
4359
4360 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4361 .TP
4362 .RI NoClean( target ", ...)"
4363 .TP
4364 .RI env.NoClean( target ", ...)"
4365 Specifies a list of files or directories which should
4366 .I not
4367 be removed whenever the targets (or their dependencies)
4368 are specified with the
4369 .B -c
4370 command line option.
4371 The specified targets may be a list
4372 or an individual target.
4373 Multiple calls to
4374 .BR NoClean ()
4375 are legal,
4376 and prevent each specified target
4377 from being removed by calls to the
4378 .B -c
4379 option.
4380
4381 Multiple files or directories should be specified
4382 either as separate arguments to the
4383 .BR NoClean ()
4384 method, or as a list.
4385 .BR NoClean ()
4386 will also accept the return value of any of the construction environment
4387 Builder methods.
4388
4389 Calling
4390 .BR NoClean ()
4391 for a target overrides calling
4392 .BR Clean ()
4393 for the same target,
4394 and any targets passed to both functions will
4395 .I not
4396 be removed by the
4397 .B -c
4398 option.
4399
4400 Examples:
4401
4402 .ES
4403 NoClean('foo.elf')
4404 NoClean(env.Program('hello', 'hello.c'))
4405 .EE
4406
4407 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4408 .TP
4409 .RI env.ParseConfig( command ", [" function ", " unique ])
4410 Calls the specified
4411 .I function
4412 to modify the environment as specified by the output of
4413 .I command .
4414 The default
4415 .I function
4416 is
4417 .BR env.MergeFlags (),
4418 which expects the output of a typical
4419 .I *-config command
4420 (for example,
4421 .BR gtk-config )
4422 and adds the options
4423 to the appropriate construction variables.
4424 By default,
4425 duplicate values are not
4426 added to any construction variables;
4427 you can specify
4428 .B unique=0
4429 to allow duplicate
4430 values to be added.
4431
4432 Interpreted options
4433 and the construction variables they affect
4434 are as specified for the
4435 .BR env.ParseFlags ()
4436 method (which this method calls).
4437 See that method's description, below,
4438 for a table of options and construction variables.
4439
4440 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4441 .TP
4442 .RI ParseDepends( filename ", [" must_exist ", " only_one ])
4443 .TP
4444 .RI env.ParseDepends( filename ", [" must_exist ", " only_one ])
4445 Parses the contents of the specified
4446 .I filename
4447 as a list of dependencies in the style of
4448 .BR Make
4449 or
4450 .BR mkdep ,
4451 and explicitly establishes all of the listed dependencies.
4452
4453 By default,
4454 it is not an error
4455 if the specified
4456 .I filename
4457 does not exist.
4458 The optional
4459 .I must_exist
4460 argument may be set to a non-zero
4461 value to have
4462 scons
4463 throw an exception and
4464 generate an error if the file does not exist,
4465 or is otherwise inaccessible.
4466
4467 The optional
4468 .I only_one
4469 argument may be set to a non-zero
4470 value to have
4471 scons
4472 thrown an exception and
4473 generate an error
4474 if the file contains dependency
4475 information for more than one target.
4476 This can provide a small sanity check
4477 for files intended to be generated
4478 by, for example, the
4479 .B gcc -M
4480 flag,
4481 which should typically only
4482 write dependency information for
4483 one output file into a corresponding
4484 .B .d
4485 file.
4486
4487 The
4488 .I filename
4489 and all of the files listed therein
4490 will be interpreted relative to
4491 the directory of the
4492 .I SConscript
4493 file which calls the
4494 .B ParseDepends
4495 function.
4496
4497 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4498 .TP
4499 .RI env.ParseFlags( flags ", ...)"
4500 Parses one or more strings containing
4501 typical command-line flags for GCC tool chains
4502 and returns a dictionary with the flag values
4503 separated into the appropriate SCons construction variables.
4504 This is intended as a companion to the
4505 .BR env.MergeFlags ()
4506 method, but allows for the values in the returned dictionary
4507 to be modified, if necessary,
4508 before merging them into the construction environment.
4509 (Note that
4510 .BR env.MergeFlags ()
4511 will call this method if its argument is not a dictionary,
4512 so it is usually not necessary to call
4513 .BR env.ParseFlags ()
4514 directly unless you want to manipulate the values.)
4515
4516 If the first character in any string is
4517 an exclamation mark (!),
4518 the rest of the string is executed as a command,
4519 and the output from the command is
4520 parsed as GCC tool chain command-line flags
4521 and added to the resulting dictionary.
4522
4523 Flag values are translated accordig to the prefix found,
4524 and added to the following construction variables:
4525
4526 .ES
4527 -arch               CCFLAGS, LINKFLAGS
4528 -D                  CPPDEFINES
4529 -framework          FRAMEWORKS
4530 -frameworkdir=      FRAMEWORKPATH
4531 -include            CCFLAGS
4532 -isysroot           CCFLAGS, LINKFLAGS
4533 -I                  CPPPATH
4534 -l                  LIBS
4535 -L                  LIBPATH
4536 -mno-cygwin         CCFLAGS, LINKFLAGS
4537 -mwindows           LINKFLAGS
4538 -pthread            CCFLAGS, LINKFLAGS
4539 -std=               CFLAGS
4540 -Wa,                ASFLAGS, CCFLAGS
4541 -Wl,-rpath=         RPATH
4542 -Wl,-R,             RPATH
4543 -Wl,-R              RPATH
4544 -Wl,                LINKFLAGS
4545 -Wp,                CPPFLAGS
4546 -                   CCFLAGS
4547 +                   CCFLAGS, LINKFLAGS
4548 .EE
4549
4550 .IP
4551 Any other strings not associated with options
4552 are assumed to be the names of libraries
4553 and added to the
4554 .B LIBS
4555 construction variable.
4556
4557 Examples (all of which produce the same result):
4558
4559 .ES
4560 dict = env.ParseFlags('-O2 -Dfoo -Dbar=1')
4561 dict = env.ParseFlags('-O2', '-Dfoo', '-Dbar=1')
4562 dict = env.ParseFlags(['-O2', '-Dfoo -Dbar=1'])
4563 dict = env.ParseFlags('-O2', '!echo -Dfoo -Dbar=1')
4564 .EE
4565
4566 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4567 .TP
4568 env.Perforce()
4569 A factory function that
4570 returns a Builder object
4571 to be used to fetch source files
4572 from the Perforce source code management system.
4573 The returned Builder
4574 is intended to be passed to the
4575 .B SourceCode
4576 function.
4577
4578 Example:
4579
4580 .ES
4581 env.SourceCode('.', env.Perforce())
4582 .EE
4583 .IP
4584 Perforce uses a number of external
4585 environment variables for its operation.
4586 Consequently, this function adds the
4587 following variables from the user's external environment
4588 to the construction environment's
4589 ENV dictionary:
4590 P4CHARSET,
4591 P4CLIENT,
4592 P4LANGUAGE,
4593 P4PASSWD,
4594 P4PORT,
4595 P4USER,
4596 SYSTEMROOT,
4597 USER,
4598 and
4599 USERNAME.
4600
4601 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4602 .TP
4603 .RI Platform( string )
4604 Returns a callable object
4605 that can be used to initialize
4606 a construction environment using the
4607 platform keyword of the Environment() method.
4608
4609 Example:
4610
4611 .ES
4612 env = Environment(platform = Platform('win32'))
4613 .EE
4614 .TP
4615 .RI env.Platform( string )
4616 Applies the callable object for the specified platform
4617 .I string
4618 to the environment through which the method was called.
4619
4620 .ES
4621 env.Platform('posix')
4622 .EE
4623 .IP
4624 Note that the
4625 .B win32
4626 platform adds the
4627 .B SYSTEMDRIVE
4628 and
4629 .B SYSTEMROOT
4630 variables from the user's external environment
4631 to the construction environment's
4632 .B ENV
4633 dictionary.
4634 This is so that any executed commands
4635 that use sockets to connect with other systems
4636 (such as fetching source files from
4637 external CVS repository specifications like
4638 .BR :pserver:anonymous@cvs.sourceforge.net:/cvsroot/scons )
4639 will work on Windows systems.
4640
4641 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4642 .TP
4643 .RI Progress( callable ", [" interval ])
4644 .TP
4645 .RI Progress( string ", [" interval ", " file ", " overwrite ])
4646 .TP
4647 .RI Progress( list_of_strings ", [" interval ", " file ", " overwrite ])
4648 Allows SCons to show progress made during the build
4649 by displaying a string or calling a function while
4650 evaluating Nodes (e.g. files).
4651
4652 If the first specified argument is a Python callable
4653 (a function or an object that has a
4654 .BR __call__ ()
4655 method),
4656 the function will be called
4657 once every
4658 .I interval
4659 times a Node is evaluated.
4660 The callable will be passed the evaluated Node
4661 as its only argument.
4662 (For future compatibility,
4663 it's a good idea to also add
4664 .B *args
4665 and
4666 .B **kw
4667 as arguments to your function or method.
4668 This will prevent the code from breaking
4669 if SCons ever changes the interface
4670 to call the function with additional arguments in the future.)
4671
4672 An example of a simple custom progress function
4673 that prints a string containing the Node name
4674 every 10 Nodes:
4675
4676 .ES
4677 def my_progress_function(node, *args, **kw):
4678     print 'Evaluating node %s!' % node
4679 Progress(my_progress_function, interval=10)
4680 .EE
4681 .IP
4682 A more complicated example of a custom progress display object
4683 that prints a string containing a count
4684 every 100 evaluated Nodes.
4685 Note the use of
4686 .B \\\\r
4687 (a carriage return)
4688 at the end so that the string
4689 will overwrite itself on a display:
4690
4691 .ES
4692 import sys
4693 class ProgressCounter:
4694     count = 0
4695     def __call__(self, node, *args, **kw):
4696         self.count += 100
4697         sys.stderr.write('Evaluated %s nodes\\r' % self.count)
4698 Progress(ProgressCounter(), interval=100)
4699 .EE
4700 .IP
4701 If the first argument
4702 .BR Progress ()
4703 is a string,
4704 the string will be displayed
4705 every
4706 .I interval
4707 evaluated Nodes.
4708 The default is to print the string on standard output;
4709 an alternate output stream
4710 may be specified with the
4711 .B file=
4712 argument.
4713 The following will print a series of dots
4714 on the error output,
4715 one dot for every 100 evaluated Nodes:
4716
4717 .ES
4718 import sys
4719 Progress('.', interval=100, file=sys.stderr)
4720 .EE
4721 .IP
4722 If the string contains the verbatim substring
4723 .B $TARGET,
4724 it will be replaced with the Node.
4725 Note that, for performance reasons, this is
4726 .I not
4727 a regular SCons variable substition,
4728 so you can not use other variables
4729 or use curly braces.
4730 The following example will print the name of
4731 every evaluated Node,
4732 using a
4733 .B \\\\r
4734 (carriage return) to cause each line to overwritten by the next line,
4735 and the
4736 .B overwrite=
4737 keyword argument to make sure the previously-printed
4738 file name is overwritten with blank spaces:
4739
4740 .ES
4741 import sys
4742 Progress('$TARGET\\r', overwrite=True)
4743 .EE
4744 .IP
4745 If the first argument to
4746 .BR Progress ()
4747 is a list of strings,
4748 then each string in the list will be displayed
4749 in rotating fashion every
4750 .I interval
4751 evaluated Nodes.
4752 This can be used to implement a "spinner"
4753 on the user's screen as follows:
4754
4755 .ES
4756 Progress(['-\\r', '\\\\\\r', '|\\r', '/\\r'], interval=5)
4757 .EE
4758
4759 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4760 .TP
4761 .RI Precious( target ", ...)"
4762 .TP
4763 .RI env.Precious( target ", ...)"
4764 Marks each given
4765 .I target
4766 as precious so it is not deleted before it is rebuilt. Normally
4767 .B scons
4768 deletes a target before building it.
4769 Multiple targets can be passed in to a single call to
4770 .BR Precious ().
4771
4772 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4773 .TP
4774 .RI env.Prepend( key = val ", [...])"
4775 Appends the specified keyword arguments
4776 to the beginning of construction variables in the environment.
4777 If the Environment does not have
4778 the specified construction variable,
4779 it is simply added to the environment.
4780 If the values of the construction variable
4781 and the keyword argument are the same type,
4782 then the two values will be simply added together.
4783 Otherwise, the construction variable
4784 and the value of the keyword argument
4785 are both coerced to lists,
4786 and the lists are added together.
4787 (See also the Append method, above.)
4788
4789 Example:
4790
4791 .ES
4792 env.Prepend(CCFLAGS = '-g ', FOO = ['foo.yyy'])
4793 .EE
4794
4795 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4796 .TP
4797 .RI env.PrependENVPath( name ", " newpath ", [" envname ", " sep ])
4798 This appends new path elements to the given path in the
4799 specified external environment
4800 .RB ( ENV
4801 by default).
4802 This will only add
4803 any particular path once (leaving the first one it encounters and
4804 ignoring the rest, to preserve path order),
4805 and to help assure this,
4806 will normalize all paths (using
4807 .B os.path.normpath
4808 and
4809 .BR os.path.normcase ).
4810 This can also handle the
4811 case where the given old path variable is a list instead of a
4812 string, in which case a list will be returned instead of a string.
4813
4814 Example:
4815
4816 .ES
4817 print 'before:',env['ENV']['INCLUDE']
4818 include_path = '/foo/bar:/foo'
4819 env.PrependENVPath('INCLUDE', include_path)
4820 print 'after:',env['ENV']['INCLUDE']
4821 .EE
4822
4823 The above exmaple will print:
4824
4825 .ES
4826 before: /biz:/foo
4827 after: /foo/bar:/foo:/biz
4828 .EE
4829
4830 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4831 .TP
4832 .RI env.PrependUnique( key = val ", [...])"
4833 Appends the specified keyword arguments
4834 to the beginning of construction variables in the environment.
4835 If the Environment does not have
4836 the specified construction variable,
4837 it is simply added to the environment.
4838 If the construction variable being appended to is a list,
4839 then any value(s) that already exist in the
4840 construction variable will
4841 .I not
4842 be added again to the list.
4843
4844 Example:
4845
4846 .ES
4847 env.PrependUnique(CCFLAGS = '-g', FOO = ['foo.yyy'])
4848 .EE
4849
4850 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4851 .TP
4852 env.RCS()
4853 A factory function that
4854 returns a Builder object
4855 to be used to fetch source files
4856 from RCS.
4857 The returned Builder
4858 is intended to be passed to the
4859 .B SourceCode
4860 function:
4861
4862 Examples:
4863
4864 .ES
4865 env.SourceCode('.', env.RCS())
4866 .EE
4867 .IP
4868 Note that
4869 .B scons
4870 will fetch source files
4871 from RCS subdirectories automatically,
4872 so configuring RCS
4873 as demonstrated in the above example
4874 should only be necessary if
4875 you are fetching from
4876 RCS,v
4877 files in the same
4878 directory as the source files,
4879 or if you need to explicitly specify RCS
4880 for a specific subdirectory.
4881
4882 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4883 .TP
4884 .RI env.Replace( key = val ", [...])"
4885 Replaces construction variables in the Environment
4886 with the specified keyword arguments.
4887
4888 Example:
4889
4890 .ES
4891 env.Replace(CCFLAGS = '-g', FOO = 'foo.xxx')
4892 .EE
4893
4894 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4895 .TP
4896 .RI Repository( directory )
4897 .TP
4898 .RI env.Repository( directory )
4899 Specifies that
4900 .I directory
4901 is a repository to be searched for files.
4902 Multiple calls to
4903 .BR Repository ()
4904 are legal,
4905 and each one adds to the list of
4906 repositories that will be searched.
4907
4908 To
4909 .BR scons ,
4910 a repository is a copy of the source tree,
4911 from the top-level directory on down,
4912 which may contain
4913 both source files and derived files
4914 that can be used to build targets in
4915 the local source tree.
4916 The canonical example would be an
4917 official source tree maintained by an integrator.
4918 If the repository contains derived files,
4919 then the derived files should have been built using
4920 .BR scons ,
4921 so that the repository contains the necessary
4922 signature information to allow
4923 .B scons
4924 to figure out when it is appropriate to
4925 use the repository copy of a derived file,
4926 instead of building one locally.
4927
4928 Note that if an up-to-date derived file
4929 already exists in a repository,
4930 .B scons
4931 will
4932 .I not
4933 make a copy in the local directory tree.
4934 In order to guarantee that a local copy
4935 will be made,
4936 use the
4937 .B Local()
4938 method.
4939
4940 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4941 .TP
4942 .RI Requires( target ", " prerequisite )
4943 .TP
4944 .RI env.Requires( target ", " prerequisite )
4945 Specifies an order-only relationship
4946 between the specified target file(s)
4947 and the specified prerequisite file(s).
4948 The prerequisite file(s)
4949 will be (re)built, if necessary,
4950 .I before
4951 the target file(s),
4952 but the target file(s) do not actually
4953 depend on the prerequisites
4954 and will not be rebuilt simply because
4955 the prerequisite file(s) change.
4956
4957 Example:
4958
4959 .ES
4960 env.Requires('foo', 'file-that-must-be-built-before-foo')
4961 .EE
4962
4963 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4964 .TP
4965 .RI Return([ vars "... , " stop= ])
4966 By default,
4967 this stops processing the current SConscript
4968 file and returns to the calling SConscript file
4969 the values of the variables named in the
4970 .I vars
4971 string arguments.
4972 Multiple strings contaning variable names may be passed to
4973 .BR Return ().
4974 Any strings that contain white space
4975
4976 The optional
4977 .B stop=
4978 keyword argument may be set to a false value
4979 to continue processing the rest of the SConscript
4980 file after the
4981 .BR Return ()
4982 call.
4983 This was the default behavior prior to SCons 0.98.
4984 However, the values returned
4985 are still the values of the variables in the named
4986 .I vars
4987 at the point
4988 .BR Return ()
4989 is called.
4990
4991 Examples:
4992
4993 .ES
4994 # Returns without returning a value.
4995 Return()
4996
4997 # Returns the value of the 'foo' Python variable.
4998 Return("foo")
4999
5000 # Returns the values of the Python variables 'foo' and 'bar'.
5001 Return("foo", "bar")
5002
5003 # Returns the values of Python variables 'val1' and 'val2'.
5004 Return('val1 val2')
5005 .EE
5006
5007 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5008 .TP
5009 .RI Scanner( function ", [" argument ", " keys ", " path_function ", " node_class ", " node_factory ", " scan_check ", " recursive ])
5010 .TP
5011 .RI env.Scanner( function ", [" argument ", " keys ", " path_function ", " node_class ", " node_factory ", " scan_check ", " recursive ])
5012 Creates a Scanner object for
5013 the specified
5014 .IR function .
5015 See the section "Scanner Objects,"
5016 below, for a complete explanation of the arguments and behavior.
5017
5018 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5019 .TP
5020 env.SCCS()
5021 A factory function that
5022 returns a Builder object
5023 to be used to fetch source files
5024 from SCCS.
5025 The returned Builder
5026 is intended to be passed to the
5027 .B SourceCode
5028 function.
5029
5030 Example:
5031
5032 .ES
5033 env.SourceCode('.', env.SCCS())
5034 .EE
5035 .IP
5036 Note that
5037 .B scons
5038 will fetch source files
5039 from SCCS subdirectories automatically,
5040 so configuring SCCS
5041 as demonstrated in the above example
5042 should only be necessary if
5043 you are fetching from
5044 .I s.SCCS
5045 files in the same
5046 directory as the source files,
5047 or if you need to explicitly specify SCCS
5048 for a specific subdirectory.
5049
5050 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5051 .TP
5052 .RI SConscript( scripts ", [" exports ", " variant_dir ", " src_dir ", " duplicate ])
5053 .TP
5054 .RI env.SConscript( scripts ", [" exports ", " variant_dir ", " src_dir ", " duplicate ])
5055 .TP
5056 .RI SConscript(dirs= subdirs ", [name=" script ", " exports ", " variant_dir ", " src_dir ", " duplicate ])
5057 .TP
5058 .RI env.SConscript(dirs= subdirs ", [name=" script ", " exports ", " variant_dir ", " src_dir ", " duplicate ])
5059 This tells
5060 .B scons
5061 to execute
5062 one or more subsidiary SConscript (configuration) files.
5063 There are two ways to call the
5064 .BR SConscript ()
5065 function.
5066
5067 The first way you can call
5068 .BR SConscript ()
5069 is to explicitly specify one or more
5070 .I scripts
5071 as the first argument.
5072 A single script may be specified as a string;
5073 multiple scripts must be specified as a list
5074 (either explicitly or as created by
5075 a function like
5076 .BR Split ()).
5077
5078 The second way you can call
5079 .BR SConscript ()
5080 is to specify a list of (sub)directory names
5081 as a
5082 .RI dirs= subdirs
5083 keyword argument.
5084 In this case,
5085 .B scons
5086 will, by default,
5087 execute a subsidiary configuration file named
5088 .B SConscript
5089 in each of the specified directories.
5090 You may specify a name other than
5091 .B SConscript
5092 by supplying an optional
5093 .RI name= script
5094 keyword argument.
5095
5096 The optional
5097 .I exports
5098 argument provides a list of variable names or a dictionary of
5099 named values to export to the
5100 .IR script(s) .
5101 These variables are locally exported only to the specified
5102 .IR script(s) ,
5103 and do not affect the global pool of variables used by the
5104 .BR Export ()
5105 function.
5106 '\"If multiple dirs are provided, each script gets a fresh export.
5107 The subsidiary
5108 .I script(s)
5109 must use the
5110 .BR Import ()
5111 function to import the variables.
5112
5113 If the optional
5114 .I variant_dir
5115 argument is present, it causes an effect equivalent to
5116 .BR VariantDir (
5117 .IR variant_dir ,
5118 .IR src_dir ,
5119 .IR duplicate )
5120 to be executed prior to reading the
5121 .IR script (s).
5122 (If
5123 .I variant_dir
5124 is not present, the
5125 .I src_dir
5126 and
5127 .I duplicate
5128 arguments are ignored.)
5129 The
5130 .I variant_dir
5131 and
5132 .I src_dir
5133 arguments are interpreted relative to the directory
5134 of the calling SConscript file.
5135 If
5136 .I src_dir
5137 is not specified, the directory of the calling SConscript file is assumed.
5138 See the description of the
5139 .BR VariantDir ()
5140 function below for additional details and restrictions.
5141
5142 Any variables returned by
5143 .I script
5144 using
5145 .BR Return ()
5146 will be returned by the call to
5147 .BR SConscript ().
5148
5149 Examples:
5150
5151 .ES
5152 SConscript('subdir/SConscript')
5153 foo = SConscript('sub/SConscript', exports='env')
5154 SConscript('dir/SConscript', exports=['env', 'variable'])
5155 SConscript('dir/SConscript', exports='env variable')
5156 SConscript(dirs=['sub1', 'sub2'])
5157 SConscript(dirs=['sub3', 'sub4'], name='MySConscript')
5158 .EE
5159
5160 .ES
5161 SConscript('bld/SConscript', variant_dir='bld', duplicate=0)
5162 .EE
5163 which is equivalent to
5164 .ES
5165 VariantDir('bld', '.', duplicate=0)
5166 SConscript('bld/SConscript')
5167 .EE
5168 '\"TODO: SConscript('bld/SConscript', src_dir='src', exports='env variable')
5169
5170 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5171 .TP
5172 .RI SConscriptChdir( value )
5173 .TP
5174 .RI env.SConscriptChdir( value )
5175 By default,
5176 .B scons
5177 changes its working directory
5178 to the directory in which each
5179 subsidiary SConscript file lives.
5180 This behavior may be disabled
5181 by specifying either:
5182
5183 .ES
5184 SConscriptChdir(0)
5185 env.SConscriptChdir(0)
5186 .EE
5187 .IP
5188 in which case
5189 .B scons
5190 will stay in the top-level directory
5191 while reading all SConscript files.
5192 (This may be necessary when building from repositories,
5193 when all the directories in which SConscript files may be found
5194 don't necessarily exist locally.)
5195 You may enable and disable
5196 this ability by calling
5197 SConscriptChdir()
5198 multiple times.
5199
5200 Example:
5201
5202 .ES
5203 env = Environment()
5204 SConscriptChdir(0)
5205 SConscript('foo/SConscript')    # will not chdir to foo
5206 env.SConscriptChdir(1)
5207 SConscript('bar/SConscript')    # will chdir to bar
5208 .EE
5209
5210 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5211 .TP
5212 .RI SConsignFile([ file , dbm_module ])
5213 .TP
5214 .RI env.SConsignFile([ file , dbm_module ])
5215 This tells
5216 .B scons
5217 to store all file signatures
5218 in the specified database
5219 .IR file .
5220 If the
5221 .I file
5222 name is omitted,
5223 .B .sconsign
5224 is used by default.
5225 (The actual file name(s) stored on disk
5226 may have an appropriated suffix appended
5227 by the
5228 .IR  dbm_module .)
5229 If
5230 .I file
5231 is not an absolute path name,
5232 the file is placed in the same directory as the top-level
5233 .B SConstruct
5234 file.
5235
5236 If
5237 .I file
5238 is
5239 .BR None ,
5240 then
5241 .B scons
5242 will store file signatures
5243 in a separate
5244 .B .sconsign
5245 file in each directory,
5246 not in one global database file.
5247 (This was the default behavior
5248 prior to SCons 0.96.91 and 0.97.)
5249
5250 The optional
5251 .I dbm_module
5252 argument can be used to specify
5253 which Python database module
5254 The default is to use a custom
5255 .B SCons.dblite
5256 module that uses pickled
5257 Python data structures,
5258 and which works on all Python versions from 1.5.2 on.
5259
5260 Examples:
5261
5262 .ES
5263 # Explicitly stores signatures in ".sconsign.dblite"
5264 # in the top-level SConstruct directory (the
5265 # default behavior).
5266 SConsignFile()
5267
5268 # Stores signatures in the file "etc/scons-signatures"
5269 # relative to the top-level SConstruct directory.
5270 SConsignFile("etc/scons-signatures")
5271
5272 # Stores signatures in the specified absolute file name.
5273 SConsignFile("/home/me/SCons/signatures")
5274
5275 # Stores signatures in a separate .sconsign file
5276 # in each directory.
5277 SConsignFile(None)
5278 .EE
5279
5280 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5281 .TP
5282 .RI env.SetDefault(key = val ", [...])"
5283 Sets construction variables to default values specified with the keyword
5284 arguments if (and only if) the variables are not already set.
5285 The following statements are equivalent:
5286
5287 .ES
5288 env.SetDefault(FOO = 'foo')
5289
5290 if not env.has_key('FOO'): env['FOO'] = 'foo'
5291 .EE
5292
5293 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5294 .TP
5295 .RI SetOption( name ", " value )
5296 .TP
5297 .RI env.SetOption( name ", " value )
5298 This function provides a way to set a select subset of the scons command
5299 line options from a SConscript file. The options supported are:
5300
5301 .RS 10
5302 .TP 6
5303 .B clean
5304 which corresponds to -c, --clean and --remove;
5305 .TP 6
5306 .B duplicate
5307 which corresponds to --duplicate;
5308 .TP 6
5309 .B help
5310 which corresponds to -h and --help;
5311 .TP 6
5312 .B implicit_cache
5313 which corresponds to --implicit-cache;
5314 .TP 6
5315 .B max_drift
5316 which corresponds to --max-drift;
5317 .TP 6
5318 .B no_exec
5319 which corresponds to -n, --no-exec, --just-print, --dry-run and --recon;
5320 .TP 6
5321 .B num_jobs
5322 which corresponds to -j and --jobs;
5323 .TP 6
5324 .B random
5325 which corresponds to --random; and
5326 .TP 6
5327 .B stack_size
5328 which corresponds to --stack-size.
5329 .RE
5330
5331 .IP
5332 See the documentation for the
5333 corresponding command line object for information about each specific
5334 option.
5335
5336 Example:
5337
5338 .ES
5339 SetOption('max_drift', 1)
5340 .EE
5341
5342 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5343 .TP
5344 .RI SideEffect( side_effect ", " target )
5345 .TP
5346 .RI env.SideEffect( side_effect ", " target )
5347 Declares
5348 .I side_effect
5349 as a side effect of building
5350 .IR target .
5351 Both
5352 .I side_effect
5353 and
5354 .I target
5355 can be a list, a file name, or a node.
5356 A side effect is a target file that is created or updated
5357 as a side effect of building other targets.
5358 For example, a Windows PDB
5359 file is created as a side effect of building the .obj
5360 files for a static library,
5361 and various log files are created updated
5362 as side effects of various TeX commands.
5363 If a target is a side effect of multiple build commands,
5364 .B scons
5365 will ensure that only one set of commands
5366 is executed at a time.
5367 Consequently, you only need to use this method
5368 for side-effect targets that are built as a result of
5369 multiple build commands.
5370
5371 Because multiple build commands may update
5372 the same side effect file,
5373 by default the
5374 .I side_effect
5375 target is
5376 .I not
5377 automatically removed
5378 when the
5379 .I target
5380 is removed by the
5381 .B -c
5382 option.
5383 (Note, however, that the
5384 .I side_effect
5385 might be removed as part of
5386 cleaning the directory in which it lives.)
5387 If you want to make sure the
5388 .I side_effect
5389 is cleaned whenever a specific
5390 .I target
5391 is cleaned,
5392 you must specify this explicitly
5393 with the
5394 .BR Clean ()
5395 or
5396 .BR env.Clean ()
5397 function.
5398
5399 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5400 .TP
5401 .RI SourceCode( entries ", " builder )
5402 .TP
5403 .RI env.SourceCode( entries ", " builder )
5404 Arrange for non-existent source files to
5405 be fetched from a source code management system
5406 using the specified
5407 .IR builder .
5408 The specified
5409 .I entries
5410 may be a Node, string or list of both,
5411 and may represent either individual
5412 source files or directories in which
5413 source files can be found.
5414
5415 For any non-existent source files,
5416 .B scons
5417 will search up the directory tree
5418 and use the first
5419 .B SourceCode
5420 builder it finds.
5421 The specified
5422 .I builder
5423 may be
5424 .BR None ,
5425 in which case
5426 .B scons
5427 will not use a builder to fetch
5428 source files for the specified
5429 .IR entries ,
5430 even if a
5431 .B SourceCode
5432 builder has been specified
5433 for a directory higher up the tree.
5434
5435 .B scons
5436 will, by default,
5437 fetch files from SCCS or RCS subdirectories
5438 without explicit configuration.
5439 This takes some extra processing time
5440 to search for the necessary
5441 source code management files on disk.
5442 You can avoid these extra searches
5443 and speed up your build a little
5444 by disabling these searches as follows:
5445
5446 .ES
5447 env.SourceCode('.', None)
5448 .EE
5449
5450 .IP
5451 Note that if the specified
5452 .I builder
5453 is one you create by hand,
5454 it must have an associated
5455 construction environment to use
5456 when fetching a source file.
5457
5458 .B scons
5459 provides a set of canned factory
5460 functions that return appropriate
5461 Builders for various popular
5462 source code management systems.
5463 Canonical examples of invocation include:
5464
5465 .ES
5466 env.SourceCode('.', env.BitKeeper('/usr/local/BKsources'))
5467 env.SourceCode('src', env.CVS('/usr/local/CVSROOT'))
5468 env.SourceCode('/', env.RCS())
5469 env.SourceCode(['f1.c', 'f2.c'], env.SCCS())
5470 env.SourceCode('no_source.c', None)
5471 .EE
5472 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion'))
5473
5474 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5475 .TP
5476 .RI env.subst( input ", [" raw ", " target ", " source ", " conv ])
5477 Performs construction variable interpolation
5478 on the specified string or sequence argument
5479 .IR input .
5480
5481 By default,
5482 leading or trailing white space will
5483 be removed from the result.
5484 and all sequences of white space
5485 will be compressed to a single space character.
5486 Additionally, any
5487 .B $(
5488 and
5489 .B $)
5490 character sequences will be stripped from the returned string,
5491 The optional
5492 .I raw
5493 argument may be set to
5494 .B 1
5495 if you want to preserve white space and
5496 .BR $( - $)
5497 sequences.
5498 The
5499 .I raw
5500 argument may be set to
5501 .B 2
5502 if you want to strip
5503 all characters between
5504 any
5505 .B $(
5506 and
5507 .B $)
5508 pairs
5509 (as is done for signature calculation).
5510
5511 If the input is a sequence
5512 (list or tuple),
5513 the individual elements of
5514 the sequence will be expanded,
5515 and the results will be returned as a list.
5516
5517 The optional
5518 .I target
5519 and
5520 .I source
5521 keyword arguments
5522 must be set to lists of
5523 target and source nodes, respectively,
5524 if you want the
5525 .BR $TARGET ,
5526 .BR $TARGETS ,
5527 .BR $SOURCE
5528 and
5529 .BR $SOURCES
5530 to be available for expansion.
5531 This is usually necessary if you are
5532 calling
5533 .BR env.subst ()
5534 from within a Python function used
5535 as an SCons action.
5536
5537 Returned string values or sequence elements
5538 are converted to their string representation by default.
5539 The optional
5540 .I conv
5541 argument
5542 may specify a conversion function
5543 that will be used in place of
5544 the default.
5545 For example, if you want Python objects
5546 (including SCons Nodes)
5547 to be returned as Python objects,
5548 you can use the Python
5549 .B lambda
5550 idiom to pass in an unnamed function
5551 that simply returns its unconverted argument.
5552
5553 Example:
5554
5555 .ES
5556 print env.subst("The C compiler is: $CC")
5557
5558 def compile(target, source, env):
5559     sourceDir = env.subst("${SOURCE.srcdir}",
5560                           target=target,
5561                           source=source)
5562
5563 source_nodes = env.subst('$EXPAND_TO_NODELIST',
5564                          conv=lambda x: x)
5565 .EE
5566
5567 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5568 '\".TP
5569 '\".RI Subversion( repository ", " module )
5570 '\"A factory function that
5571 '\"returns a Builder object
5572 '\"to be used to fetch source files
5573 '\"from the specified Subversion
5574 '\".IR repository .
5575 '\"The returned Builder
5576 '\"is intended to be passed to the
5577 '\".B SourceCode
5578 '\"function.
5579 '\"
5580 '\"The optional specified
5581 '\".I module
5582 '\"will be added to the beginning
5583 '\"of all repository path names;
5584 '\"this can be used, in essence,
5585 '\"to strip initial directory names
5586 '\"from the repository path names,
5587 '\"so that you only have to
5588 '\"replicate part of the repository
5589 '\"directory hierarchy in your
5590 '\"local build directory.
5591 '\"
5592 '\"Example:
5593 '\"
5594 '\".ES
5595 '\"# Will fetch foo/bar/src.c
5596 '\"# from /usr/local/Subversion/foo/bar/src.c.
5597 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion'))
5598 '\"
5599 '\"# Will fetch bar/src.c
5600 '\"# from /usr/local/Subversion/foo/bar/src.c.
5601 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion', 'foo'))
5602 '\"
5603 '\"# Will fetch src.c
5604 '\"# from /usr/local/Subversion/foo/bar/src.c.
5605 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion', 'foo/bar'))
5606 '\".EE
5607
5608 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5609 .TP
5610 .RI SourceSignatures( type )
5611 .TP
5612 .RI env.SourceSignatures( type )
5613 Note:  Although it is not yet officially deprecated,
5614 use of this function is discouraged.
5615 See the
5616 .BR Decider ()
5617 function for a more flexible and straightforward way
5618 to configure SCons' decision-making.
5619
5620 The
5621 .BR SourceSignatures ()
5622 function tells
5623 .B scons
5624 how to decide if a source file
5625 (a file that is not built from any other files)
5626 has changed since the last time it
5627 was used to build a particular target file.
5628 Legal values are
5629 .B "MD5"
5630 or
5631 .BR "timestamp" .
5632
5633 If the environment method is used,
5634 the specified type of source signature
5635 is only used when deciding whether targets
5636 built with that environment are up-to-date or must be rebuilt.
5637 If the global function is used,
5638 the specified type of source signature becomes the default
5639 used for all decisions
5640 about whether targets are up-to-date.
5641
5642 .B "MD5"
5643 means
5644 .B scons
5645 decides that a source file has changed
5646 if the MD5 checksum of its contents has changed since
5647 the last time it was used to rebuild a particular target file.
5648
5649 .B "timestamp"
5650 means
5651 .B scons
5652 decides that a source file has changed
5653 if its timestamp (modification time) has changed since
5654 the last time it was used to rebuild a particular target file.
5655 (Note that although this is similar to the behavior of Make,
5656 by default it will also rebuild if the dependency is
5657 .I older
5658 than the last time it was used to rebuild the target file.)
5659
5660 There is no different between the two behaviors
5661 for Python
5662 .BR Value ()
5663 node objects.
5664
5665 .B "MD5"
5666 signatures take longer to compute,
5667 but are more accurate than
5668 .B "timestamp"
5669 signatures.
5670 The default value is
5671 .BR "MD5" .
5672
5673 Note that the default
5674 .BR TargetSignatures ()
5675 setting (see below)
5676 is to use this
5677 .BR SourceSignatures ()
5678 setting for any target files that are used
5679 to build other target files.
5680 Consequently, changing the value of
5681 .BR SourceSignatures ()
5682 will, by default,
5683 affect the up-to-date decision for all files in the build
5684 (or all files built with a specific construction environment
5685 when
5686 .BR env.SourceSignatures ()
5687 is used).
5688
5689 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5690 .TP
5691 .RI Split( arg )
5692 .TP
5693 .RI env.Split( arg )
5694 Returns a list of file names or other objects.
5695 If arg is a string,
5696 it will be split on strings of white-space characters
5697 within the string,
5698 making it easier to write long lists of file names.
5699 If arg is already a list,
5700 the list will be returned untouched.
5701 If arg is any other type of object,
5702 it will be returned as a list
5703 containing just the object.
5704
5705 Example:
5706
5707 .ES
5708 files = Split("f1.c f2.c f3.c")
5709 files = env.Split("f4.c f5.c f6.c")
5710 files = Split("""
5711         f7.c
5712         f8.c
5713         f9.c
5714 """)
5715 .EE
5716
5717 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5718 .TP
5719 .RI Tag( node ", " tags )
5720 Annotates file or directory Nodes with
5721 information about how the
5722 .BR Package ()
5723 Builder should package those files or directories.
5724 All tags are optional.
5725
5726 Examples:
5727
5728 .ES
5729 # makes sure the built library will be installed with 0644 file
5730 # access mode
5731 Tag( Library( 'lib.c' ), UNIX_ATTR="0644" )
5732
5733 # marks file2.txt to be a documentation file
5734 Tag( 'file2.txt', DOC )
5735 .EE
5736
5737 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5738 .TP
5739 .RI TargetSignatures( type )
5740 .TP
5741 .RI env.TargetSignatures( type )
5742 Note:  Although it is not yet officially deprecated,
5743 use of this function is discouraged.
5744 See the
5745 .BR Decider ()
5746 function for a more flexible and straightforward way
5747 to configure SCons' decision-making.
5748
5749 The
5750 .BR TargetSignatures ()
5751 function tells
5752 .B scons
5753 how to decide if a target file
5754 (a file that
5755 .I is
5756 built from any other files)
5757 has changed since the last time it
5758 was used to build some other target file.
5759 Legal values are
5760 .BR "build" ;
5761 .BR "content"
5762 (or its synonym
5763 .BR "MD5" );
5764 .BR "timestamp" ;
5765 or
5766 .BR "source" .
5767
5768 If the environment method is used,
5769 the specified type of target signature is only used
5770 for targets built with that environment.
5771 If the global function is used,
5772 the specified type of signature becomes the default
5773 used for all target files that
5774 don't have an explicit target signature type
5775 specified for their environments.
5776
5777 .B "content"
5778 (or its synonym
5779 .BR "MD5" )
5780 means
5781 .B scons
5782 decides that a target file has changed
5783 if the MD5 checksum of its contents has changed since
5784 the last time it was used to rebuild some other target file.
5785 This means
5786 .B scons
5787 will open up
5788 MD5 sum the contents
5789 of target files after they're built,
5790 and may decide that it does not need to rebuild
5791 "downstream" target files if a file was
5792 rebuilt with exactly the same contents as the last time.
5793
5794 .B "timestamp"
5795 means
5796 .B scons
5797 decides that a target file has changed
5798 if its timestamp (modification time) has changed since
5799 the last time it was used to rebuild some other target file.
5800 (Note that although this is similar to the behavior of Make,
5801 by default it will also rebuild if the dependency is
5802 .I older
5803 than the last time it was used to rebuild the target file.)
5804
5805 .B "source"
5806 means
5807 .B scons
5808 decides that a target file has changed
5809 as specified by the corresponding
5810 .BR SourceSignatures ()
5811 setting
5812 .BR "" ( "MD5"
5813 or
5814 .BR "timestamp" ).
5815 This means that
5816 .B scons
5817 will treat all input files to a target the same way,
5818 regardless of whether they are source files
5819 or have been built from other files.
5820
5821 .B "build"
5822 means
5823 .B scons
5824 decides that a target file has changed
5825 if it has been rebuilt in this invocation
5826 or if its content or timestamp have changed
5827 as specified by the corresponding
5828 .BR SourceSignatures ()
5829 setting.
5830 This "propagates" the status of a rebuilt file
5831 so that other "downstream" target files
5832 will always be rebuilt,
5833 even if the contents or the timestamp
5834 have not changed.
5835
5836 .B "build"
5837 signatures are fastest because
5838 .B "content"
5839 (or
5840 .BR "MD5" )
5841 signatures take longer to compute,
5842 but are more accurate than
5843 .B "timestamp"
5844 signatures,
5845 and can prevent unnecessary "downstream" rebuilds
5846 when a target file is rebuilt to the exact same contents
5847 as the previous build.
5848 The
5849 .B "source"
5850 setting provides the most consistent behavior
5851 when other target files may be rebuilt from
5852 both source and target input files.
5853 The default value is
5854 .BR "source" .
5855
5856 Because the default setting is
5857 .BR "source" ,
5858 using
5859 .BR SourceSignatures ()
5860 is generally preferable to
5861 .BR TargetSignatures () ,
5862 so that the up-to-date decision
5863 will be consistent for all files
5864 (or all files built with a specific construction environment).
5865 Use of
5866 .BR TargetSignatures ()
5867 provides specific control for how built target files
5868 affect their "downstream" dependencies.
5869
5870 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5871 .TP
5872 .RI Tool( string [, toolpath ", " **kw ])
5873 Returns a callable object
5874 that can be used to initialize
5875 a construction environment using the
5876 tools keyword of the Environment() method.
5877 The object may be called with a construction
5878 environment as an argument,
5879 in which case the object will
5880 add the necessary variables
5881 to the construction environment
5882 and the name of the tool will be added to the
5883 .B $TOOLS
5884 construction variable.
5885
5886 Additional keyword arguments are passed to the tool's
5887 .B generate()
5888 method.
5889
5890 Examples:
5891
5892 .ES
5893 env = Environment(tools = [ Tool('msvc') ])
5894
5895 env = Environment()
5896 t = Tool('msvc')
5897 t(env)  # adds 'msvc' to the TOOLS variable
5898 u = Tool('opengl', toolpath = ['tools'])
5899 u(env)  # adds 'opengl' to the TOOLS variable
5900 .EE
5901 .TP
5902 .RI env.Tool( string [, toolpath ", " **kw ])
5903 Applies the callable object for the specified tool
5904 .I string
5905 to the environment through which the method was called.
5906
5907 Additional keyword arguments are passed to the tool's
5908 .B generate()
5909 method.
5910
5911 .ES
5912 env.Tool('gcc')
5913 env.Tool('opengl', toolpath = ['build/tools'])
5914 .EE
5915
5916 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5917 .TP
5918 .RI Value( value ", [" built_value ])
5919 .TP
5920 .RI env.Value( value ", [" built_value ])
5921 Returns a Node object representing the specified Python value.  Value
5922 Nodes can be used as dependencies of targets.  If the result of
5923 calling
5924 .BR str( value )
5925 changes between SCons runs, any targets depending on
5926 .BR Value( value )
5927 will be rebuilt.
5928 (This is true even when using timestamps to decide if
5929 files are up-to-date.)
5930 When using timestamp source signatures, Value Nodes'
5931 timestamps are equal to the system time when the Node is created.
5932
5933 The returned Value Node object has a
5934 .BR write ()
5935 method that can be used to "build" a Value Node
5936 by setting a new value.
5937 The optional
5938 .I built_value
5939 argument can be specified
5940 when the Value Node is created
5941 to indicate the Node should already be considered
5942 "built."
5943 There is a corresponding
5944 .BR read ()
5945 method that will return the built value of the Node.
5946
5947 Examples:
5948
5949 .ES
5950 env = Environment()
5951
5952 def create(target, source, env):
5953     # A function that will write a 'prefix=$SOURCE'
5954     # string into the file name specified as the
5955     # $TARGET.
5956     f = open(str(target[0]), 'wb')
5957     f.write('prefix=' + source[0].get_contents())
5958
5959 # Fetch the prefix= argument, if any, from the command
5960 # line, and use /usr/local as the default.
5961 prefix = ARGUMENTS.get('prefix', '/usr/local')
5962
5963 # Attach a .Config() builder for the above function action
5964 # to the construction environment.
5965 env['BUILDERS']['Config'] = Builder(action = create)
5966 env.Config(target = 'package-config', source = Value(prefix))
5967
5968 def build_value(target, source, env):
5969     # A function that "builds" a Python Value by updating
5970     # the the Python value with the contents of the file
5971     # specified as the source of the Builder call ($SOURCE).
5972     target[0].write(source[0].get_contents())
5973
5974 output = env.Value('before')
5975 input = env.Value('after')
5976
5977 # Attach a .UpdateValue() builder for the above function
5978 # action to the construction environment.
5979 env['BUILDERS']['UpdateValue'] = Builder(action = build_value)
5980 env.UpdateValue(target = Value(output), source = Value(input))
5981 .EE
5982
5983 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
5984 .TP
5985 .RI VariantDir( variant_dir ", " src_dir ", [" duplicate ])
5986 .TP
5987 .RI env.VariantDir( variant_dir ", " src_dir ", [" duplicate ])
5988 Use the
5989 .BR VariantDir ()
5990 function to create a copy of your sources in another location:
5991 if a name under
5992 .IR variant_dir
5993 is not found but exists under
5994 .IR src_dir ,
5995 the file or directory is copied to
5996 .IR variant_dir .
5997 Target files can be built in a different directory than the original sources
5998 by simply refering to the sources (and targets) within the variant tree.
5999
6000 .BR VariantDir ()
6001 can be called multiple times with the same
6002 .I  src_dir
6003 to set up multiple builds with different options
6004 .RI ( variants ).
6005 The
6006 .I src_dir
6007 location must be in or underneath the SConstruct file's directory, and
6008 .I variant_dir
6009 may not be underneath
6010 .IR src_dir .
6011 '\"TODO: Can the above restrictions be clarified or relaxed?
6012 '\"TODO: The latter restriction is clearly not completely right;
6013 '\"TODO: src_dir = '.' works fine with a build dir under it.
6014
6015 The default behavior is for
6016 .B scons
6017 to physically duplicate the source files in the variant tree.
6018 Thus, a build performed in the variant tree is guaranteed to be identical
6019 to a build performed in the source tree even if
6020 intermediate source files are generated during the build,
6021 or preprocessors or other scanners search for included files
6022 relative to the source file,
6023 or individual compilers or other invoked tools are hard-coded
6024 to put derived files in the same directory as source files.
6025
6026 If possible on the platform,
6027 the duplication is performed by linking rather than copying;
6028 see also the
6029 .IR --duplicate
6030 command-line option.
6031 Moreover, only the files needed for the build are duplicated;
6032 files and directories that are not used are not present in
6033 .IR variant_dir .
6034
6035 Duplicating the source tree may be disabled by setting the
6036 .I duplicate
6037 argument to 0.
6038 This will cause
6039 .B scons
6040 to invoke Builders using the path names of source files in
6041 .I src_dir
6042 and the path names of derived files within
6043 .IR variant_dir .
6044 This is always more efficient than
6045 .IR duplicate =1,
6046 and is usually safe for most builds
6047 (but see above for cases that may cause problems).
6048
6049 Note that
6050 .BR VariantDir ()
6051 works most naturally with a subsidiary SConscript file.
6052 However, you would then call the subsidiary SConscript file
6053 not in the source directory, but in the
6054 .I variant_dir ,
6055 regardless of the value of
6056 .IR duplicate .
6057 This is how you tell
6058 .B scons
6059 which variant of a source tree to build:
6060
6061 .ES
6062 # run src/SConscript in two variant directories
6063 VariantDir('build/variant1', 'src')
6064 SConscript('build/variant1/SConscript')
6065 VariantDir('build/variant2', 'src')
6066 SConscript('build/variant2/SConscript')
6067 .EE
6068
6069 .IP
6070 See also the
6071 .BR SConscript ()
6072 function, described above,
6073 for another way to specify a variant directory
6074 in conjunction with calling a subsidiary SConscript file.
6075
6076 Examples:
6077
6078 .ES
6079 # use names in the build directory, not the source directory
6080 VariantDir('build', 'src', duplicate=0)
6081 Program('build/prog', 'build/source.c')
6082 .EE
6083
6084 .ES
6085 # this variant builds both the source and docs
6086 VariantDir('build', '.', duplicate=0)
6087 SConscript(dirs=['build/src','build/doc'])
6088 .EE
6089 Or, equivalently:
6090 .ES
6091 SConscript(dirs=['build/src','build/doc'],
6092         variant_dir = 'build', duplicate = 0)
6093 .EE
6094
6095 .ES
6096 SConscript('build/SConscript', variant_dir = 'build', duplicate = 0)
6097 .EE
6098 Note that in the last example, the
6099 .I src_dir
6100 is not given, so the current directory is assumed, and the
6101 .B SConstruct
6102 and the
6103 .B SConscript
6104 are actually in the same directory, even though the
6105 .B SConscript
6106 is treated as if it were in the
6107 .B build
6108 subdirectory.
6109
6110 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6111 .TP
6112 .RI WhereIs( program ", [" path  ", " pathext ", " reject ])
6113 .TP
6114 .RI env.WhereIs( program ", [" path  ", " pathext ", " reject ])
6115
6116 Searches for the specified executable
6117 .I program,
6118 returning the full path name to the program
6119 if it is found,
6120 and returning None if not.
6121 Searches the specified
6122 .I path,
6123 the value of the calling environment's PATH
6124 (env['ENV']['PATH']),
6125 or the user's current external PATH
6126 (os.environ['PATH'])
6127 by default.
6128 On Windows systems, searches for executable
6129 programs with any of the file extensions
6130 listed in the specified
6131 .I pathext,
6132 the calling environment's PATHEXT
6133 (env['ENV']['PATHEXT'])
6134 or the user's current PATHEXT
6135 (os.environ['PATHEXT'])
6136 by default.
6137 Will not select any
6138 path name or names
6139 in the specified
6140 .I reject
6141 list, if any.
6142
6143 .SS SConscript Variables
6144 In addition to the global functions and methods,
6145 .B scons
6146 supports a number of Python variables
6147 that can be used in SConscript files
6148 to affect how you want the build to be performed.
6149 These variables may be accessed from custom Python modules that you
6150 import into an SConscript file by adding the following
6151 to the Python module:
6152
6153 .ES
6154 from SCons.Script import *
6155 .EE
6156
6157 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6158 .TP
6159 ARGLIST
6160 A list
6161 .IR keyword = value
6162 arguments specified on the command line.
6163 Each element in the list is a tuple
6164 containing the
6165 .RI ( keyword , value )
6166 of the argument.
6167 The separate
6168 .I keyword
6169 and
6170 .I value
6171 elements of the tuple
6172 can be accessed by
6173 subscripting for element
6174 .B [0]
6175 and
6176 .B [1]
6177 of the tuple, respectively.
6178
6179 Example:
6180
6181 .ES
6182 print "first keyword, value =", ARGLIST[0][0], ARGLIST[0][1]
6183 print "second keyword, value =", ARGLIST[1][0], ARGLIST[1][1]
6184 third_tuple = ARGLIST[2]
6185 print "third keyword, value =", third_tuple[0], third_tuple[1]
6186 for key, value in ARGLIST:
6187     # process key and value
6188 .EE
6189
6190 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6191 .TP
6192 ARGUMENTS
6193 A dictionary of all the
6194 .IR keyword = value
6195 arguments specified on the command line.
6196 The dictionary is not in order,
6197 and if a given keyword has
6198 more than one value assigned to it
6199 on the command line,
6200 the last (right-most) value is
6201 the one in the
6202 .B ARGUMENTS
6203 dictionary.
6204
6205 Example:
6206
6207 .ES
6208 if ARGUMENTS.get('debug', 0):
6209     env = Environment(CCFLAGS = '-g')
6210 else:
6211     env = Environment()
6212 .EE
6213
6214 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6215 .TP
6216 BUILD_TARGETS
6217 A list of the targets which
6218 .B scons
6219 will actually try to build,
6220 regardless of whether they were specified on
6221 the command line or via the
6222 .BR Default ()
6223 function or method.
6224 The elements of this list may be strings
6225 .I or
6226 nodes, so you should run the list through the Python
6227 .B str
6228 function to make sure any Node path names
6229 are converted to strings.
6230
6231 Because this list may be taken from the
6232 list of targets specified using the
6233 .BR Default ()
6234 function or method,
6235 the contents of the list may change
6236 on each successive call to
6237 .BR Default ().
6238 See the
6239 .B DEFAULT_TARGETS
6240 list, below,
6241 for additional information.
6242
6243 Example:
6244
6245 .ES
6246 if 'foo' in BUILD_TARGETS:
6247     print "Don't forget to test the `foo' program!"
6248 if 'special/program' in BUILD_TARGETS:
6249     SConscript('special')
6250 .EE
6251 .IP
6252 Note that the
6253 .B BUILD_TARGETS
6254 list only contains targets expected listed
6255 on the command line or via calls to the
6256 .BR Default ()
6257 function or method.
6258 It does
6259 .I not
6260 contain all dependent targets that will be built as
6261 a result of making the sure the explicitly-specified
6262 targets are up to date.
6263
6264 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6265 .TP
6266 COMMAND_LINE_TARGETS
6267 A list of the targets explicitly specified on
6268 the command line.
6269 If there are no targets specified on the command line,
6270 the list is empty.
6271 This can be used, for example,
6272 to take specific actions only
6273 when a certain target or targets
6274 is explicitly being built.
6275
6276 Example:
6277
6278 .ES
6279 if 'foo' in COMMAND_LINE_TARGETS:
6280     print "Don't forget to test the `foo' program!"
6281 if 'special/program' in COMMAND_LINE_TARGETS:
6282     SConscript('special')
6283 .EE
6284
6285 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6286 .TP
6287 DEFAULT_TARGETS
6288 A list of the target
6289 .I nodes
6290 that have been specified using the
6291 .BR Default ()
6292 function or method.
6293 The elements of the list are nodes,
6294 so you need to run them through the Python
6295 .B str
6296 function to get at the path name for each Node.
6297
6298 Example:
6299
6300 .ES
6301 print str(DEFAULT_TARGETS[0])
6302 if 'foo' in map(str, DEFAULT_TARGETS):
6303     print "Don't forget to test the `foo' program!"
6304 .EE
6305 .IP
6306 The contents of the
6307 .B DEFAULT_TARGETS
6308 list change on on each successive call to the
6309 .BR Default ()
6310 function:
6311
6312 .ES
6313 print map(str, DEFAULT_TARGETS)   # originally []
6314 Default('foo')
6315 print map(str, DEFAULT_TARGETS)   # now a node ['foo']
6316 Default('bar')
6317 print map(str, DEFAULT_TARGETS)   # now a node ['foo', 'bar']
6318 Default(None)
6319 print map(str, DEFAULT_TARGETS)   # back to []
6320 .EE
6321 .IP
6322 Consequently, be sure to use
6323 .B DEFAULT_TARGETS
6324 only after you've made all of your
6325 .BR Default ()
6326 calls,
6327 or else simply be careful of the order
6328 of these statements in your SConscript files
6329 so that you don't look for a specific
6330 default target before it's actually been added to the list.
6331
6332 .SS Construction Variables
6333 .\" XXX From Gary Ruben, 23 April 2002:
6334 .\" I think it would be good to have an example with each construction
6335 .\" variable description in the documentation.
6336 .\" eg.
6337 .\" CC     The C compiler
6338 .\"    Example: env["CC"] = "c68x"
6339 .\"    Default: env["CC"] = "cc"
6340 .\"
6341 .\" CCCOM  The command line ...
6342 .\"    Example:
6343 .\"        To generate the compiler line c68x -ps -qq -mr -o $TARGET $SOURCES
6344 .\"        env["CC"] = "c68x"
6345 .\"        env["CFLAGS"] = "-ps -qq -mr"
6346 .\"        env["CCCOM"] = "$CC $CFLAGS -o $TARGET $SOURCES
6347 .\"    Default:
6348 .\"        (I dunno what this is ;-)
6349 A construction environment has an associated dictionary of
6350 .I construction variables
6351 that are used by built-in or user-supplied build rules.
6352 Construction variables must follow the same rules for
6353 Python identifiers:
6354 the initial character must be an underscore or letter,
6355 followed by any number of underscores, letters, or digits.
6356
6357 A number of useful construction variables are automatically defined by
6358 scons for each supported platform, and additional construction variables
6359 can be defined by the user. The following is a list of the automatically
6360 defined construction variables:
6361
6362 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6363 '\" BEGIN GENERATED CONSTRUCTION VARIABLE DESCRIPTIONS
6364 '\"
6365 '\" The descriptions below of the various SCons construction variables
6366 '\" are generated from the .xml files that live next to the various
6367 '\" Python modules in the build enginer library.  If you're reading
6368 '\" this [gnt]roff file with an eye towards patching this man page,
6369 '\" you can still submit a diff against this text, but it will have to
6370 '\" be translated to a diff against the underlying .xml file before the
6371 '\" patch is actually accepted.  If you do that yourself, it will make
6372 '\" it easier to integrate the patch.
6373 '\"
6374 '\" BEGIN GENERATED CONSTRUCTION VARIABLE DESCRIPTIONS
6375 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6376 .so variables.man
6377 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6378 '\" END GENERATED CONSTRUCTION VARIABLE DESCRIPTIONS
6379 '\"
6380 '\" The descriptions above of the various SCons construction variables
6381 '\" are generated from the .xml files that live next to the various
6382 '\" Python modules in the build enginer library.  If you're reading
6383 '\" this [gnt]roff file with an eye towards patching this man page,
6384 '\" you can still submit a diff against this text, but it will have to
6385 '\" be translated to a diff against the underlying .xml file before the
6386 '\" patch is actually accepted.  If you do that yourself, it will make
6387 '\" it easier to integrate the patch.
6388 '\"
6389 '\" END GENERATED CONSTRUCTION VARIABLE DESCRIPTIONS
6390 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6391
6392 .LP
6393 Construction variables can be retrieved and set using the
6394 .B Dictionary
6395 method of the construction environment:
6396
6397 .ES
6398 dict = env.Dictionary()
6399 dict["CC"] = "cc"
6400 .EE
6401
6402 or using the [] operator:
6403
6404 .ES
6405 env["CC"] = "cc"
6406 .EE
6407
6408 Construction variables can also be passed to the construction environment
6409 constructor:
6410
6411 .ES
6412 env = Environment(CC="cc")
6413 .EE
6414
6415 or when copying a construction environment using the
6416 .B Clone
6417 method:
6418
6419 .ES
6420 env2 = env.Clone(CC="cl.exe")
6421 .EE
6422
6423 .SS Configure Contexts
6424
6425 .B scons
6426 supports
6427 .I configure contexts,
6428 an integrated mechanism similar to the
6429 various AC_CHECK macros in GNU autoconf
6430 for testing for the existence of C header
6431 files, libraries, etc.
6432 In contrast to autoconf,
6433 .B scons
6434 does not maintain an explicit cache of the tested values,
6435 but uses its normal dependency tracking to keep the checked values
6436 up to date. However, users may override this behaviour with the
6437 .B --config
6438 command line option.
6439
6440 The following methods can be used to perform checks:
6441
6442 .TP
6443 .RI Configure( env ", [" custom_tests ", " conf_dir ", " log_file ", " config_h ", " clean ", " help])
6444 .TP
6445 .RI env.Configure([ custom_tests ", " conf_dir ", " log_file ", " config_h ", " clean ", " help])
6446 This creates a configure context, which can be used to perform checks.
6447 .I env
6448 specifies the environment for building the tests.
6449 This environment may be modified when performing checks.
6450 .I custom_tests
6451 is a dictionary containing custom tests.
6452 See also the section about custom tests below.
6453 By default, no custom tests are added to the configure context.
6454 .I conf_dir
6455 specifies a directory where the test cases are built.
6456 Note that this directory is not used for building
6457 normal targets.
6458 The default value is the directory
6459 #/.sconf_temp.
6460 .I log_file
6461 specifies a file which collects the output from commands
6462 that are executed to check for the existence of header files, libraries, etc.
6463 The default is the file #/config.log.
6464 If you are using the
6465 .BR VariantDir ()
6466 method,
6467 you may want to specify a subdirectory under your variant directory.
6468 .I config_h
6469 specifies a C header file where the results of tests
6470 will be written, e.g. #define HAVE_STDIO_H, #define HAVE_LIBM, etc.
6471 The default is to not write a
6472 .B config.h
6473 file.
6474 You can specify the same
6475 .B config.h
6476 file in multiple calls to Configure,
6477 in which case
6478 .B scons
6479 will concatenate all results in the specified file.
6480 Note that SCons
6481 uses its normal dependency checking
6482 to decide if it's necessary to rebuild
6483 the specified
6484 .I config_h
6485 file.
6486 This means that the file is not necessarily re-built each
6487 time scons is run,
6488 but is only rebuilt if its contents will have changed
6489 and some target that depends on the
6490 .I config_h
6491 file is being built.
6492
6493 The optional
6494 .B clean
6495 and
6496 .B help
6497 arguments can be used to suppress execution of the configuration
6498 tests when the
6499 .B -c/--clean
6500 or
6501 .B -H/-h/--help
6502 options are used, respectively.
6503 The default behavior is always to execute
6504 configure context tests,
6505 since the results of the tests may
6506 affect the list of targets to be cleaned
6507 or the help text.
6508 If the configure tests do not affect these,
6509 then you may add the
6510 .B clean=False
6511 or
6512 .B help=False
6513 arguments
6514 (or both)
6515 to avoid unnecessary test execution.
6516
6517 .EE
6518 A created
6519 .B Configure
6520 instance has the following associated methods:
6521
6522 .TP
6523 .RI Configure.Finish()
6524 This method should be called after configuration is done.
6525 It returns the environment as modified
6526 by the configuration checks performed.
6527 After this method is called, no further checks can be performed
6528 with this configuration context.
6529 However, you can create a new
6530 .RI Configure
6531 context to perform additional checks.
6532 Only one context should be active at a time.
6533
6534 The following Checks are predefined.
6535 (This list will likely grow larger as time
6536 goes by and developers contribute new useful tests.)
6537
6538 .TP
6539 .RI Configure.CheckHeader( header ", [" include_quotes ", " language ])
6540 Checks if
6541 .I header
6542 is usable in the specified language.
6543 .I header
6544 may be a list,
6545 in which case the last item in the list
6546 is the header file to be checked,
6547 and the previous list items are
6548 header files whose
6549 .B #include
6550 lines should precede the
6551 header line being checked for.
6552 The optional argument
6553 .I include_quotes
6554 must be
6555 a two character string, where the first character denotes the opening
6556 quote and the second character denotes the closing quote.
6557 By default, both characters  are " (double quote).
6558 The optional argument
6559 .I language
6560 should be either
6561 .B C
6562 or
6563 .B C++
6564 and selects the compiler to be used for the check.
6565 Returns 1 on success and 0 on failure.
6566
6567 .TP
6568 .RI Configure.CheckCHeader( header ", [" include_quotes ])
6569 This is a wrapper around
6570 .B Configure.CheckHeader
6571 which checks if
6572 .I header
6573 is usable in the C language.
6574 .I header
6575 may be a list,
6576 in which case the last item in the list
6577 is the header file to be checked,
6578 and the previous list items are
6579 header files whose
6580 .B #include
6581 lines should precede the
6582 header line being checked for.
6583 The optional argument
6584 .I include_quotes
6585 must be
6586 a two character string, where the first character denotes the opening
6587 quote and the second character denotes the closing quote (both default
6588 to \N'34').
6589 Returns 1 on success and 0 on failure.
6590
6591 .TP
6592 .RI Configure.CheckCXXHeader( header ", [" include_quotes ])
6593 This is a wrapper around
6594 .B Configure.CheckHeader
6595 which checks if
6596 .I header
6597 is usable in the C++ language.
6598 .I header
6599 may be a list,
6600 in which case the last item in the list
6601 is the header file to be checked,
6602 and the previous list items are
6603 header files whose
6604 .B #include
6605 lines should precede the
6606 header line being checked for.
6607 The optional argument
6608 .I include_quotes
6609 must be
6610 a two character string, where the first character denotes the opening
6611 quote and the second character denotes the closing quote (both default
6612 to \N'34').
6613 Returns 1 on success and 0 on failure.
6614
6615 .TP
6616 .RI Configure.CheckFunc( function_name ", [" header ", " language ])
6617 Checks if the specified
6618 C or C++ function is available.
6619 .I function_name
6620 is the name of the function to check for.
6621 The optional
6622 .I header
6623 argument is a string
6624 that will be
6625 placed at the top
6626 of the test file
6627 that will be compiled
6628 to check if the function exists;
6629 the default is:
6630 .ES
6631 #ifdef __cplusplus
6632 extern "C"
6633 #endif
6634 char function_name();
6635 .EE
6636 The optional
6637 .I language
6638 argument should be
6639 .B C
6640 or
6641 .B C++
6642 and selects the compiler to be used for the check;
6643 the default is "C".
6644
6645 .TP
6646 .RI Configure.CheckLib([ library ", " symbol ", " header ", " language ", " autoadd=1 ])
6647 Checks if
6648 .I library
6649 provides
6650 .IR symbol .
6651 If the value of
6652 .I autoadd
6653 is 1 and the library provides the specified
6654 .IR symbol ,
6655 appends the library to the LIBS construction environment variable.
6656 .I library
6657 may also be None (the default),
6658 in which case
6659 .I symbol
6660 is checked with the current LIBS variable,
6661 or a list of library names,
6662 in which case each library in the list
6663 will be checked for
6664 .IR symbol .
6665 If
6666 .I symbol
6667 is not set or is
6668 .BR None ,
6669 then
6670 .BR Configure.CheckLib ()
6671 just checks if
6672 you can link against the specified
6673 .IR library .
6674 The optional
6675 .I language
6676 argument should be
6677 .B C
6678 or
6679 .B C++
6680 and selects the compiler to be used for the check;
6681 the default is "C".
6682 The default value for
6683 .I autoadd
6684 is 1.
6685 This method returns 1 on success and 0 on error.
6686
6687 .TP
6688 .RI Configure.CheckLibWithHeader( library ", " header ", " language ", [" call ", " autoadd ])
6689
6690 In contrast to the
6691 .RI Configure.CheckLib
6692 call, this call provides a more sophisticated way to check against libraries.
6693 Again,
6694 .I library
6695 specifies the library or a list of libraries to check.
6696 .I header
6697 specifies a header to check for.
6698 .I header
6699 may be a list,
6700 in which case the last item in the list
6701 is the header file to be checked,
6702 and the previous list items are
6703 header files whose
6704 .B #include
6705 lines should precede the
6706 header line being checked for.
6707 .I language
6708 may be one of 'C','c','CXX','cxx','C++' and 'c++'.
6709 .I call
6710 can be any valid expression (with a trailing ';').
6711 If
6712 .I call
6713 is not set,
6714 the default simply checks that you
6715 can link against the specified
6716 .IR library .
6717 .I autoadd
6718 specifies whether to add the library to the environment (only if the check
6719 succeeds). This method returns 1 on success and 0 on error.
6720
6721 .TP
6722 .RI Configure.CheckType( type_name ", [" includes ", " language ])
6723 Checks for the existence of a type defined by
6724 .BR typedef .
6725 .I type_name
6726 specifies the typedef name to check for.
6727 .I includes
6728 is a string containing one or more
6729 .B #include
6730 lines that will be inserted into the program
6731 that will be run to test for the existence of the type.
6732 The optional
6733 .I language
6734 argument should be
6735 .B C
6736 or
6737 .B C++
6738 and selects the compiler to be used for the check;
6739 the default is "C".
6740
6741 .EE
6742 Example of a typical Configure usage:
6743
6744 .ES
6745 env = Environment()
6746 conf = Configure( env )
6747 if not conf.CheckCHeader( 'math.h' ):
6748     print 'We really need math.h!'
6749     Exit(1)
6750 if conf.CheckLibWithHeader( 'qt', 'qapp.h', 'c++', 'QApplication qapp(0,0);' ):
6751     # do stuff for qt - usage, e.g.
6752     conf.env.Append( CPPFLAGS = '-DWITH_QT' )
6753 env = conf.Finish()
6754 .EE
6755
6756 .TP
6757 .RI Configure.CheckTypeSize( type_name ", [" header ", " language ", " expect ])
6758 Checks for the size of a type defined by
6759 .BR typedef .
6760 .I type_name
6761 specifies the typedef name to check for.
6762 The optional
6763 .I header
6764 argument is a string
6765 that will be
6766 placed at the top
6767 of the test file
6768 that will be compiled
6769 to check if the function exists;
6770 the default is empty.
6771 The optional
6772 .I language
6773 argument should be
6774 .B C
6775 or
6776 .B C++
6777 and selects the compiler to be used for the check;
6778 the default is "C".
6779 The optional
6780 .I expect
6781 argument should be an integer.
6782 If this argument is used,
6783 the function will only check whether the type
6784 given in type_name has the expected size (in bytes).
6785 For example,
6786 .B "CheckTypeSize('short', expect = 2)"
6787 will return success only if short is two bytes.
6788
6789 .ES
6790 .EE
6791
6792 .TP
6793 .RI Configure.CheckDeclaration( symbol ", [" includes ", " language ])
6794 Checks if the specified
6795 .I symbol
6796 is declared.
6797 .I includes
6798 is a string containing one or more
6799 .B #include
6800 lines that will be inserted into the program
6801 that will be run to test for the existence of the type.
6802 The optional
6803 .I language
6804 argument should be
6805 .B C
6806 or
6807 .B C++
6808 and selects the compiler to be used for the check;
6809 the default is "C".
6810
6811 .TP
6812 .RI Configure.Define( symbol ", [" value ", " comment ])
6813 This function does not check for anything, but defines a
6814 preprocessor symbol that will be added to the configuration header file.
6815 It is the equivalent of AC_DEFINE,
6816 and defines the symbol
6817 .I name
6818 with the optional
6819 .B value
6820 and the optional comment
6821 .BR comment .
6822
6823 .IP
6824 Examples:
6825
6826 .ES
6827 env = Environment()
6828 conf = Configure( env )
6829
6830 # Puts the following line in the config header file:
6831 #    #define A_SYMBOL
6832 conf.Define('A_SYMBOL')
6833
6834 # Puts the following line in the config header file:
6835 #    #define A_SYMBOL 1
6836 conf.Define('A_SYMBOL', 1)
6837 .EE
6838
6839 .IP
6840 Be careful about quoting string values, though:
6841
6842 .ES
6843 env = Environment()
6844 conf = Configure( env )
6845
6846 # Puts the following line in the config header file:
6847 #    #define A_SYMBOL YA
6848 conf.Define('A_SYMBOL', "YA")
6849
6850 # Puts the following line in the config header file:
6851 #    #define A_SYMBOL "YA"
6852 conf.Define('A_SYMBOL', '"YA"')
6853 .EE
6854
6855 .IP
6856 For comment:
6857
6858 .ES
6859 env = Environment()
6860 conf = Configure( env )
6861
6862 # Puts the following lines in the config header file:
6863 #    /* Set to 1 if you have a symbol */
6864 #    #define A_SYMBOL 1
6865 conf.Define('A_SYMBOL', 1, 'Set to 1 if you have a symbol')
6866 .EE
6867
6868 .EE
6869 You can define your own custom checks.
6870 in addition to the predefined checks.
6871 These are passed in a dictionary to the Configure function.
6872 This dictionary maps the names of the checks
6873 to user defined Python callables
6874 (either Python functions or class instances implementing the
6875 .I __call__
6876 method).
6877 The first argument of the call is always a
6878 .I CheckContext
6879 instance followed by the arguments,
6880 which must be supplied by the user of the check.
6881 These CheckContext instances define the following methods:
6882
6883 .TP
6884 .RI CheckContext.Message( self ", " text )
6885
6886 Usually called before the check is started.
6887 .I text
6888 will be displayed to the user, e.g. 'Checking for library X...'
6889
6890 .TP
6891 .RI CheckContext.Result( self, ", " res )
6892
6893 Usually called after the check is done.
6894 .I res
6895 can be either an integer or a string. In the former case, 'ok' (res != 0)
6896 or 'failed' (res == 0) is displayed to the user, in the latter case the
6897 given string is displayed.
6898
6899 .TP
6900 .RI CheckContext.TryCompile( self ", " text ", " extension )
6901 Checks if a file with the specified
6902 .I extension
6903 (e.g. '.c') containing
6904 .I text
6905 can be compiled using the environment's
6906 .B Object
6907 builder. Returns 1 on success and 0 on failure.
6908
6909 .TP
6910 .RI CheckContext.TryLink( self ", " text ", " extension )
6911 Checks, if a file with the specified
6912 .I extension
6913 (e.g. '.c') containing
6914 .I text
6915 can be compiled using the environment's
6916 .B Program
6917 builder. Returns 1 on success and 0 on failure.
6918
6919 .TP
6920 .RI CheckContext.TryRun( self ", " text ", " extension )
6921 Checks, if a file with the specified
6922 .I extension
6923 (e.g. '.c') containing
6924 .I text
6925 can be compiled using the environment's
6926 .B Program
6927 builder. On success, the program is run. If the program
6928 executes successfully
6929 (that is, its return status is 0),
6930 a tuple
6931 .I (1, outputStr)
6932 is returned, where
6933 .I outputStr
6934 is the standard output of the
6935 program.
6936 If the program fails execution
6937 (its return status is non-zero),
6938 then (0, '') is returned.
6939
6940 .TP
6941 .RI CheckContext.TryAction( self ", " action ", [" text ", " extension ])
6942 Checks if the specified
6943 .I action
6944 with an optional source file (contents
6945 .I text
6946 , extension
6947 .I extension
6948 = ''
6949 ) can be executed.
6950 .I action
6951 may be anything which can be converted to a
6952 .B scons
6953 .RI Action.
6954 On success,
6955 .I (1, outputStr)
6956 is returned, where
6957 .I outputStr
6958 is the content of the target file.
6959 On failure
6960 .I (0, '')
6961 is returned.
6962
6963 .TP
6964 .RI CheckContext.TryBuild( self ", " builder ", [" text ", " extension ])
6965 Low level implementation for testing specific builds;
6966 the methods above are based on this method.
6967 Given the Builder instance
6968 .I builder
6969 and the optional
6970 .I text
6971 of a source file with optional
6972 .IR extension ,
6973 this method returns 1 on success and 0 on failure. In addition,
6974 .I self.lastTarget
6975 is set to the build target node, if the build was successful.
6976
6977 .EE
6978 Example for implementing and using custom tests:
6979
6980 .ES
6981 def CheckQt(context, qtdir):
6982     context.Message( 'Checking for qt ...' )
6983     lastLIBS = context.env['LIBS']
6984     lastLIBPATH = context.env['LIBPATH']
6985     lastCPPPATH= context.env['CPPPATH']
6986     context.env.Append(LIBS = 'qt', LIBPATH = qtdir + '/lib', CPPPATH = qtdir + '/include' )
6987     ret = context.TryLink("""
6988 #include <qapp.h>
6989 int main(int argc, char **argv) {
6990   QApplication qapp(argc, argv);
6991   return 0;
6992 }
6993 """)
6994     if not ret:
6995         context.env.Replace(LIBS = lastLIBS, LIBPATH=lastLIBPATH, CPPPATH=lastCPPPATH)
6996     context.Result( ret )
6997     return ret
6998
6999 env = Environment()
7000 conf = Configure( env, custom_tests = { 'CheckQt' : CheckQt } )
7001 if not conf.CheckQt('/usr/lib/qt'):
7002     print 'We really need qt!'
7003     Exit(1)
7004 env = conf.Finish()
7005 .EE
7006
7007 .SS Command-Line Construction Variables
7008
7009 Often when building software,
7010 some variables must be specified at build time.
7011 For example, libraries needed for the build may be in non-standard
7012 locations, or site-specific compiler options may need to be passed to the
7013 compiler.
7014 .B scons
7015 provides a
7016 .B Variables
7017 object to support overriding construction variables
7018 on the command line:
7019 .ES
7020 $ scons VARIABLE=foo
7021 .EE
7022 The variable values can also be specified in a text-based SConscript file.
7023 To create a Variables object, call the Variables() function:
7024
7025 .TP
7026 .RI Variables([ files "], [" args ])
7027 This creates a Variables object that will read construction variables from
7028 the file or list of filenames specified in
7029 .IR files .
7030 If no files are specified,
7031 or the
7032 .I files
7033 argument is
7034 .BR None ,
7035 then no files will be read.
7036 The optional argument
7037 .I args
7038 is a dictionary of
7039 values that will override anything read from the specified files;
7040 it is primarily intended to be passed the
7041 .B ARGUMENTS
7042 dictionary that holds variables
7043 specified on the command line.
7044 Example:
7045
7046 .ES
7047 vars = Variables('custom.py')
7048 vars = Variables('overrides.py', ARGUMENTS)
7049 vars = Variables(None, {FOO:'expansion', BAR:7})
7050 .EE
7051
7052 Variables objects have the following methods:
7053
7054 .TP
7055 .RI Add( key ", [" help ", " default ", " validator ", " converter ])
7056 This adds a customizable construction variable to the Variables object.
7057 .I key
7058 is the name of the variable.
7059 .I help
7060 is the help text for the variable.
7061 .I default
7062 is the default value of the variable;
7063 if the default value is
7064 .B None
7065 and there is no explicit value specified,
7066 the construction variable will
7067 .I not
7068 be added to the construction environment.
7069 .I validator
7070 is called to validate the value of the variable, and should take three
7071 arguments: key, value, and environment.
7072 The recommended way to handle an invalid value is
7073 to raise an exception (see example below).
7074 .I converter
7075 is called to convert the value before putting it in the environment, and
7076 should take either a value, or the value and environment, as parameters.
7077 The
7078 .I converter
7079 must return a value,
7080 which will be converted into a string
7081 before being validated by the
7082 .I validator
7083 (if any)
7084 and then added to the environment.
7085
7086 Examples:
7087
7088 .ES
7089 vars.Add('CC', 'The C compiler')
7090
7091 def validate_color(key, val, env):
7092     if not val in ['red', 'blue', 'yellow']:
7093         raise "Invalid color value '%s'" % val
7094 vars.Add('COLOR', validator=valid_color)
7095 .EE
7096
7097 .TP
7098 .RI AddVariables( list )
7099 A wrapper script that adds
7100 multiple customizable construction variables
7101 to a Variables object.
7102 .I list
7103 is a list of tuple or list objects
7104 that contain the arguments
7105 for an individual call to the
7106 .B Add
7107 method.
7108
7109 .ES
7110 opt.AddVariables(
7111        ('debug', '', 0),
7112        ('CC', 'The C compiler'),
7113        ('VALIDATE', 'An option for testing validation',
7114         'notset', validator, None),
7115     )
7116 .EE
7117
7118 .TP
7119 .RI Update( env ", [" args ])
7120 This updates a construction environment
7121 .I env
7122 with the customized construction variables.
7123 Any specified variables that are
7124 .I not
7125 configured for the Variables object
7126 will be saved and may be
7127 retrieved with the
7128 .BR UnknownVariables ()
7129 method, below.
7130
7131 Normally this method is not called directly,
7132 but is called indirectly by passing the Variables object to
7133 the Environment() function:
7134
7135 .ES
7136 env = Environment(variables=vars)
7137 .EE
7138
7139 .IP
7140 The text file(s) that were specified
7141 when the Variables object was created
7142 are executed as Python scripts,
7143 and the values of (global) Python variables set in the file
7144 are added to the construction environment.
7145
7146 Example:
7147
7148 .ES
7149 CC = 'my_cc'
7150 .EE
7151
7152 .TP
7153 .RI UnknownVariables( )
7154 Returns a dictionary containing any
7155 variables that were specified
7156 either in the files or the dictionary
7157 with which the Variables object was initialized,
7158 but for which the Variables object was
7159 not configured.
7160
7161 .ES
7162 env = Environment(variables=vars)
7163 for key, value in vars.UnknownVariables():
7164     print "unknown variable:  %s=%s" % (key, value)
7165 .EE
7166
7167 .TP
7168 .RI Save( filename ", " env )
7169 This saves the currently set variables into a script file named
7170 .I filename
7171 that can be used on the next invocation to automatically load the current
7172 settings.  This method combined with the Variables method can be used to
7173 support caching of variables between runs.
7174
7175 .ES
7176 env = Environment()
7177 vars = Variables(['variables.cache', 'custom.py'])
7178 vars.Add(...)
7179 vars.Update(env)
7180 vars.Save('variables.cache', env)
7181 .EE
7182
7183 .TP
7184 .RI GenerateHelpText( env ", [" sort ])
7185 This generates help text documenting the customizable construction
7186 variables suitable to passing in to the Help() function.
7187 .I env
7188 is the construction environment that will be used to get the actual values
7189 of customizable variables. Calling with
7190 an optional
7191 .I sort
7192 function
7193 will cause the output to be sorted
7194 by the specified argument.
7195 The specific
7196 .I sort
7197 function
7198 should take two arguments
7199 and return
7200 -1, 0 or 1
7201 (like the standard Python
7202 .I cmp
7203 function).
7204
7205 .ES
7206 Help(vars.GenerateHelpText(env))
7207 Help(vars.GenerateHelpText(env, sort=cmp))
7208 .EE
7209
7210 .TP
7211 .RI FormatVariableHelpText( env ", " opt ", " help ", " default ", " actual )
7212 This method returns a formatted string
7213 containing the printable help text
7214 for one option.
7215 It is normally not called directly,
7216 but is called by the
7217 .IR GenerateHelpText ()
7218 method to create the returned help text.
7219 It may be overridden with your own
7220 function that takes the arguments specified above
7221 and returns a string of help text formatted to your liking.
7222 Note that the
7223 .IR GenerateHelpText ()
7224 will not put any blank lines or extra
7225 characters in between the entries,
7226 so you must add those characters to the returned
7227 string if you want the entries separated.
7228
7229 .ES
7230 def my_format(env, opt, help, default, actual):
7231     fmt = "\n%s: default=%s actual=%s (%s)\n"
7232     return fmt % (opt, default. actual, help)
7233 vars.FormatVariableHelpText = my_format
7234 .EE
7235
7236 To make it more convenient to work with customizable Variables,
7237 .B scons
7238 provides a number of functions
7239 that make it easy to set up
7240 various types of Variables:
7241
7242 .TP
7243 .RI BoolVariable( key ", " help ", " default )
7244 Return a tuple of arguments
7245 to set up a Boolean option.
7246 The option will use
7247 the specified name
7248 .IR key ,
7249 have a default value of
7250 .IR default ,
7251 and display the specified
7252 .I help
7253 text.
7254 The option will interpret the values
7255 .BR y ,
7256 .BR yes ,
7257 .BR t ,
7258 .BR true ,
7259 .BR 1 ,
7260 .B on
7261 and
7262 .B all
7263 as true,
7264 and the values
7265 .BR n ,
7266 .BR no ,
7267 .BR f ,
7268 .BR false ,
7269 .BR 0 ,
7270 .B off
7271 and
7272 .B none
7273 as false.
7274
7275 .TP
7276 .RI EnumVariable( key ", " help ", " default ", " allowed_values ", [" map ", " ignorecase ])
7277 Return a tuple of arguments
7278 to set up an option
7279 whose value may be one
7280 of a specified list of legal enumerated values.
7281 The option will use
7282 the specified name
7283 .IR key ,
7284 have a default value of
7285 .IR default ,
7286 and display the specified
7287 .I help
7288 text.
7289 The option will only support those
7290 values in the
7291 .I allowed_values
7292 list.
7293 The optional
7294 .I map
7295 argument is a dictionary
7296 that can be used to convert
7297 input values into specific legal values
7298 in the
7299 .I allowed_values
7300 list.
7301 If the value of
7302 .I ignore_case
7303 is
7304 .B 0
7305 (the default),
7306 then the values are case-sensitive.
7307 If the value of
7308 .I ignore_case
7309 is
7310 .BR 1 ,
7311 then values will be matched
7312 case-insensitive.
7313 If the value of
7314 .I ignore_case
7315 is
7316 .BR 1 ,
7317 then values will be matched
7318 case-insensitive,
7319 and all input values will be
7320 converted to lower case.
7321
7322 .TP
7323 .RI ListVariable( key ", " help ", " default ", " names ", [", map ])
7324 Return a tuple of arguments
7325 to set up an option
7326 whose value may be one or more
7327 of a specified list of legal enumerated values.
7328 The option will use
7329 the specified name
7330 .IR key ,
7331 have a default value of
7332 .IR default ,
7333 and display the specified
7334 .I help
7335 text.
7336 The option will only support the values
7337 .BR all ,
7338 .BR none ,
7339 or the values in the
7340 .I names
7341 list.
7342 More than one value may be specified,
7343 with all values separated by commas.
7344 The default may be a string of
7345 comma-separated default values,
7346 or a list of the default values.
7347 The optional
7348 .I map
7349 argument is a dictionary
7350 that can be used to convert
7351 input values into specific legal values
7352 in the
7353 .I names
7354 list.
7355
7356 .TP
7357 .RI PackageVariable( key ", " help ", " default )
7358 Return a tuple of arguments
7359 to set up an option
7360 whose value is a path name
7361 of a package that may be
7362 enabled, disabled or
7363 given an explicit path name.
7364 The option will use
7365 the specified name
7366 .IR key ,
7367 have a default value of
7368 .IR default ,
7369 and display the specified
7370 .I help
7371 text.
7372 The option will support the values
7373 .BR yes ,
7374 .BR true ,
7375 .BR on ,
7376 .BR enable
7377 or
7378 .BR search ,
7379 in which case the specified
7380 .I default
7381 will be used,
7382 or the option may be set to an
7383 arbitrary string
7384 (typically the path name to a package
7385 that is being enabled).
7386 The option will also support the values
7387 .BR no ,
7388 .BR false ,
7389 .BR off
7390 or
7391 .BR disable
7392 to disable use of the specified option.
7393
7394 .TP
7395 .RI PathVariable( key ", " help ", " default ", [" validator ])
7396 Return a tuple of arguments
7397 to set up an option
7398 whose value is expected to be a path name.
7399 The option will use
7400 the specified name
7401 .IR key ,
7402 have a default value of
7403 .IR default ,
7404 and display the specified
7405 .I help
7406 text.
7407 An additional
7408 .I validator
7409 may be specified
7410 that will be called to
7411 verify that the specified path
7412 is acceptable.
7413 SCons supplies the
7414 following ready-made validators:
7415 .BR PathVariable.PathExists
7416 (the default),
7417 which verifies that the specified path exists;
7418 .BR PathVariable.PathIsFile ,
7419 which verifies that the specified path is an existing file;
7420 .BR PathVariable.PathIsDir ,
7421 which verifies that the specified path is an existing directory;
7422 .BR PathVariable.PathIsDirCreate ,
7423 which verifies that the specified path is a directory
7424 and will create the specified directory if the path does not exist;
7425 and
7426 .BR PathVariable.PathAccept ,
7427 which simply accepts the specific path name argument without validation,
7428 and which is suitable if you want your users
7429 to be able to specify a directory path that will be
7430 created as part of the build process, for example.
7431 You may supply your own
7432 .I validator
7433 function,
7434 which must take three arguments
7435 .RI ( key ,
7436 the name of the variable to be set;
7437 .IR val ,
7438 the specified value being checked;
7439 and
7440 .IR env ,
7441 the construction environment)
7442 and should raise an exception
7443 if the specified value is not acceptable.
7444
7445 .RE
7446 These functions make it
7447 convenient to create a number
7448 of variables with consistent behavior
7449 in a single call to the
7450 .B AddVariables
7451 method:
7452
7453 .ES
7454 vars.AddVariables(
7455     BoolVariable('warnings', 'compilation with -Wall and similiar', 1),
7456     EnumVariable('debug', 'debug output and symbols', 'no'
7457                allowed_values=('yes', 'no', 'full'),
7458                map={}, ignorecase=0),  # case sensitive
7459     ListVariable('shared',
7460                'libraries to build as shared libraries',
7461                'all',
7462                names = list_of_libs),
7463     PackageVariable('x11',
7464                   'use X11 installed here (yes = search some places)',
7465                   'yes'),
7466     PathVariable('qtdir', 'where the root of Qt is installed', qtdir),
7467     PathVariable('foopath', 'where the foo library is installed', foopath,
7468                PathVariable.PathIsDir),
7469
7470 )
7471 .EE
7472
7473 .SS File and Directory Nodes
7474
7475 The
7476 .IR File ()
7477 and
7478 .IR Dir ()
7479 functions return
7480 .I File
7481 and
7482 .I Dir
7483 Nodes, respectively.
7484 python objects, respectively.
7485 Those objects have several user-visible attributes
7486 and methods that are often useful:
7487
7488 .IP path
7489 The build path
7490 of the given
7491 file or directory.
7492 This path is relative to the top-level directory
7493 (where the
7494 .B SConstruct
7495 file is found).
7496 The build path is the same as the source path if
7497 .I variant_dir
7498 is not being used.
7499
7500 .IP abspath
7501 The absolute build path of the given file or directory.
7502
7503 .IP srcnode()
7504 The
7505 .IR srcnode ()
7506 method
7507 returns another
7508 .I File
7509 or
7510 .I Dir
7511 object representing the
7512 .I source
7513 path of the given
7514 .I File
7515 or
7516 .IR Dir .
7517 The
7518
7519 .ES
7520 # Get the current build dir's path, relative to top.
7521 Dir('.').path
7522 # Current dir's absolute path
7523 Dir('.').abspath
7524 # Next line is always '.', because it is the top dir's path relative to itself.
7525 Dir('#.').path
7526 File('foo.c').srcnode().path   # source path of the given source file.
7527
7528 # Builders also return File objects:
7529 foo = env.Program('foo.c')
7530 print "foo will be built in %s"%foo.path
7531 .EE
7532
7533 A
7534 .I Dir
7535 Node or
7536 .I File
7537 Node can also be used to create
7538 file and subdirectory Nodes relative to the generating Node.
7539 A
7540 .I Dir
7541 Node will place the new Nodes within the directory it represents.
7542 A
7543 .I File
7544 node will place the new Nodes within its parent directory
7545 (that is, "beside" the file in question).
7546 If
7547 .I d
7548 is a
7549 .I Dir
7550 (directory) Node and
7551 .I f
7552 is a
7553 .I File
7554 (file) Node,
7555 then these methods are available:
7556
7557 .TP
7558 .IR d .Dir( name )
7559 Returns a directory Node for a subdirectory of
7560 .I d
7561 named
7562 .IR name .
7563
7564 .TP
7565 .IR d .File( name )
7566 Returns a file Node for a file within
7567 .I d
7568 named
7569 .IR name .
7570
7571 .TP
7572 .IR d .Entry( name )
7573 Returns an unresolved Node within
7574 .I d
7575 named
7576 .IR name .
7577
7578 .TP
7579 .IR f .Dir( name )
7580 Returns a directory named
7581 .I name
7582 within the parent directory of
7583 .IR f .
7584
7585 .TP
7586 .IR f .File( name )
7587 Returns a file named
7588 .I name
7589 within the parent directory of
7590 .IR f .
7591
7592 .TP
7593 .IR f .Entry( name )
7594 Returns an unresolved Node named
7595 .I name
7596 within the parent directory of
7597 .IR f .
7598
7599 .RE
7600 For example:
7601
7602 .ES
7603 # Get a Node for a file within a directory
7604 incl = Dir('include')
7605 f = incl.File('header.h')
7606
7607 # Get a Node for a subdirectory within a directory
7608 dist = Dir('project-3.2.1)
7609 src = dist.Dir('src')
7610
7611 # Get a Node for a file in the same directory
7612 cfile = File('sample.c')
7613 hfile = cfile.File('sample.h')
7614
7615 # Combined example
7616 docs = Dir('docs')
7617 html = docs.Dir('html')
7618 index = html.File('index.html')
7619 css = index.File('app.css')
7620 .EE
7621
7622 .SH EXTENDING SCONS
7623 .SS Builder Objects
7624 .B scons
7625 can be extended to build different types of targets
7626 by adding new Builder objects
7627 to a construction environment.
7628 .IR "In general" ,
7629 you should only need to add a new Builder object
7630 when you want to build a new type of file or other external target.
7631 If you just want to invoke a different compiler or other tool
7632 to build a Program, Object, Library, or any other
7633 type of output file for which
7634 .B scons
7635 already has an existing Builder,
7636 it is generally much easier to
7637 use those existing Builders
7638 in a construction environment
7639 that sets the appropriate construction variables
7640 (CC, LINK, etc.).
7641
7642 Builder objects are created
7643 using the
7644 .B Builder
7645 function.
7646 The
7647 .B Builder
7648 function accepts the following arguments:
7649
7650 .IP action
7651 The command line string used to build the target from the source.
7652 .B action
7653 can also be:
7654 a list of strings representing the command
7655 to be executed and its arguments
7656 (suitable for enclosing white space in an argument),
7657 a dictionary
7658 mapping source file name suffixes to
7659 any combination of command line strings
7660 (if the builder should accept multiple source file extensions),
7661 a Python function;
7662 an Action object
7663 (see the next section);
7664 or a list of any of the above.
7665
7666 An action function
7667 takes three arguments:
7668 .I source
7669 - a list of source nodes,
7670 .I target
7671 - a list of target nodes,
7672 .I env
7673 - the construction environment.
7674
7675 .IP prefix
7676 The prefix that will be prepended to the target file name.
7677 This may be specified as a:
7678
7679 .RS 10
7680 .HP 6
7681 *
7682 .IR string ,
7683
7684 .HP 6
7685 *
7686 .I callable object
7687 - a function or other callable that takes
7688 two arguments (a construction environment and a list of sources)
7689 and returns a prefix,
7690
7691 .HP 6
7692 *
7693 .I dictionary
7694 - specifies a mapping from a specific source suffix (of the first
7695 source specified) to a corresponding target prefix.  Both the source
7696 suffix and target prefix specifications may use environment variable
7697 substitution, and the target prefix (the 'value' entries in the
7698 dictionary) may also be a callable object.  The default target prefix
7699 may be indicated by a dictionary entry with a key value of None.
7700 .RE
7701 .P
7702
7703 .ES
7704 b = Builder("build_it < $SOURCE > $TARGET"
7705             prefix = "file-")
7706
7707 def gen_prefix(env, sources):
7708     return "file-" + env['PLATFORM'] + '-'
7709 b = Builder("build_it < $SOURCE > $TARGET",
7710             prefix = gen_prefix)
7711
7712 b = Builder("build_it < $SOURCE > $TARGET",
7713             suffix = { None: "file-",
7714                        "$SRC_SFX_A": gen_prefix })
7715 .EE
7716
7717 .IP suffix
7718 The suffix that will be appended to the target file name.
7719 This may be specified in the same manner as the prefix above.
7720 If the suffix is a string, then
7721 .B scons
7722 will append a '.' to the beginning of the suffix if it's not already
7723 there.  The string returned by callable object (or obtained from the
7724 dictionary) is untouched and must append its own '.'  to the beginning
7725 if one is desired.
7726
7727 .ES
7728 b = Builder("build_it < $SOURCE > $TARGET"
7729             suffix = "-file")
7730
7731 def gen_suffix(env, sources):
7732     return "." + env['PLATFORM'] + "-file"
7733 b = Builder("build_it < $SOURCE > $TARGET",
7734             suffix = gen_suffix)
7735
7736 b = Builder("build_it < $SOURCE > $TARGET",
7737             suffix = { None: ".sfx1",
7738                        "$SRC_SFX_A": gen_suffix })
7739 .EE
7740
7741 .IP ensure_suffix
7742 When set to any true value, causes
7743 .B scons
7744 to add the target suffix specified by the
7745 .I suffix
7746 keyword to any target strings
7747 that have a different suffix.
7748 (The default behavior is to leave untouched
7749 any target file name that looks like it already has any suffix.)
7750
7751 .ES
7752 b1 = Builder("build_it < $SOURCE > $TARGET"
7753              suffix = ".out")
7754 b2 = Builder("build_it < $SOURCE > $TARGET"
7755              suffix = ".out",
7756              ensure_suffix)
7757 env = Environment()
7758 env['BUILDERS']['B1'] = b1
7759 env['BUILDERS']['B2'] = b2
7760
7761 # Builds "foo.txt" because ensure_suffix is not set.
7762 env.B1('foo.txt', 'foo.in')
7763
7764 # Builds "bar.txt.out" because ensure_suffix is set.
7765 env.B2('bar.txt', 'bar.in')
7766 .EE
7767
7768 .IP src_suffix
7769 The expected source file name suffix.  This may be a string or a list
7770 of strings.
7771
7772 .IP target_scanner
7773 A Scanner object that
7774 will be invoked to find
7775 implicit dependencies for this target file.
7776 This keyword argument should be used
7777 for Scanner objects that find
7778 implicit dependencies
7779 based only on the target file
7780 and the construction environment,
7781 .I not
7782 for implicit
7783 (See the section "Scanner Objects," below,
7784 for information about creating Scanner objects.)
7785
7786 .IP source_scanner
7787 A Scanner object that
7788 will be invoked to
7789 find implicit dependences in
7790 any source files
7791 used to build this target file.
7792 This is where you would
7793 specify a scanner to
7794 find things like
7795 .B #include
7796 lines in source files.
7797 The pre-built
7798 .B DirScanner
7799 Scanner object may be used to
7800 indicate that this Builder
7801 should scan directory trees
7802 for on-disk changes to files
7803 that
7804 .B scons
7805 does not know about from other Builder or function calls.
7806 (See the section "Scanner Objects," below,
7807 for information about creating your own Scanner objects.)
7808
7809 .IP target_factory
7810 A factory function that the Builder will use
7811 to turn any targets specified as strings into SCons Nodes.
7812 By default,
7813 SCons assumes that all targets are files.
7814 Other useful target_factory
7815 values include
7816 .BR Dir ,
7817 for when a Builder creates a directory target,
7818 and
7819 .BR Entry ,
7820 for when a Builder can create either a file
7821 or directory target.
7822
7823 Example:
7824
7825 .ES
7826 MakeDirectoryBuilder = Builder(action=my_mkdir, target_factory=Dir)
7827 env = Environment()
7828 env.Append(BUILDERS = {'MakeDirectory':MakeDirectoryBuilder})
7829 env.MakeDirectory('new_directory', [])
7830 .EE
7831
7832 .IP
7833 Note that the call to the MakeDirectory Builder
7834 needs to specify an empty source list
7835 to make the string represent the builder's target;
7836 without that, it would assume the argument is the source,
7837 and would try to deduce the target name from it,
7838 which in the absence of an automatically-added prefix or suffix
7839 would lead to a matching target and source name
7840 and a circular dependency.
7841
7842 .IP source_factory
7843 A factory function that the Builder will use
7844 to turn any sources specified as strings into SCons Nodes.
7845 By default,
7846 SCons assumes that all source are files.
7847 Other useful source_factory
7848 values include
7849 .BR Dir ,
7850 for when a Builder uses a directory as a source,
7851 and
7852 .BR Entry ,
7853 for when a Builder can use files
7854 or directories (or both) as sources.
7855
7856 Example:
7857
7858 .ES
7859 CollectBuilder = Builder(action=my_mkdir, source_factory=Entry)
7860 env = Environment()
7861 env.Append(BUILDERS = {'Collect':CollectBuilder})
7862 env.Collect('archive', ['directory_name', 'file_name'])
7863 .EE
7864
7865 .IP emitter
7866 A function or list of functions to manipulate the target and source
7867 lists before dependencies are established
7868 and the target(s) are actually built.
7869 .B emitter
7870 can also be a string containing a construction variable to expand
7871 to an emitter function or list of functions,
7872 or a dictionary mapping source file suffixes
7873 to emitter functions.
7874 (Only the suffix of the first source file
7875 is used to select the actual emitter function
7876 from an emitter dictionary.)
7877
7878 An emitter function
7879 takes three arguments:
7880 .I source
7881 - a list of source nodes,
7882 .I target
7883 - a list of target nodes,
7884 .I env
7885 - the construction environment.
7886 An emitter must return a tuple containing two lists,
7887 the list of targets to be built by this builder,
7888 and the list of sources for this builder.
7889
7890 Example:
7891
7892 .ES
7893 def e(target, source, env):
7894     return (target + ['foo.foo'], source + ['foo.src'])
7895
7896 # Simple association of an emitter function with a Builder.
7897 b = Builder("my_build < $TARGET > $SOURCE",
7898             emitter = e)
7899
7900 def e2(target, source, env):
7901     return (target + ['bar.foo'], source + ['bar.src'])
7902
7903 # Simple association of a list of emitter functions with a Builder.
7904 b = Builder("my_build < $TARGET > $SOURCE",
7905             emitter = [e, e2])
7906
7907 # Calling an emitter function through a construction variable.
7908 env = Environment(MY_EMITTER = e)
7909 b = Builder("my_build < $TARGET > $SOURCE",
7910             emitter = '$MY_EMITTER')
7911
7912 # Calling a list of emitter functions through a construction variable.
7913 env = Environment(EMITTER_LIST = [e, e2])
7914 b = Builder("my_build < $TARGET > $SOURCE",
7915             emitter = '$EMITTER_LIST')
7916
7917 # Associating multiple emitters with different file
7918 # suffixes using a dictionary.
7919 def e_suf1(target, source, env):
7920     return (target + ['another_target_file'], source)
7921 def e_suf2(target, source, env):
7922     return (target, source + ['another_source_file'])
7923 b = Builder("my_build < $TARGET > $SOURCE",
7924             emitter = {'.suf1' : e_suf1,
7925                        '.suf2' : e_suf2})
7926 .EE
7927
7928 .IP multi
7929 Specifies whether this builder is allowed to be called multiple times for
7930 the same target file(s). The default is 0, which means the builder
7931 can not be called multiple times for the same target file(s). Calling a
7932 builder multiple times for the same target simply adds additional source
7933 files to the target; it is not allowed to change the environment associated
7934 with the target, specify addition environment overrides, or associate a different
7935 builder with the target.
7936
7937 .IP env
7938 A construction environment that can be used
7939 to fetch source code using this Builder.
7940 (Note that this environment is
7941 .I not
7942 used for normal builds of normal target files,
7943 which use the environment that was
7944 used to call the Builder for the target file.)
7945
7946 .IP generator
7947 A function that returns a list of actions that will be executed to build
7948 the target(s) from the source(s).
7949 The returned action(s) may be
7950 an Action object, or anything that
7951 can be converted into an Action object
7952 (see the next section).
7953
7954 The generator function
7955 takes four arguments:
7956 .I source
7957 - a list of source nodes,
7958 .I target
7959 - a list of target nodes,
7960 .I env
7961 - the construction environment,
7962 .I for_signature
7963 - a Boolean value that specifies
7964 whether the generator is being called
7965 for generating a build signature
7966 (as opposed to actually executing the command).
7967 Example:
7968
7969 .ES
7970 def g(source, target, env, for_signature):
7971     return [["gcc", "-c", "-o"] + target + source]
7972
7973 b = Builder(generator=g)
7974 .EE
7975
7976 .IP
7977 The
7978 .I generator
7979 and
7980 .I action
7981 arguments must not both be used for the same Builder.
7982
7983 .IP src_builder
7984 Specifies a builder to use when a source file name suffix does not match
7985 any of the suffixes of the builder. Using this argument produces a
7986 multi-stage builder.
7987
7988 .IP single_source
7989 Specifies that this builder expects exactly one source file per call. Giving
7990 more than one source files without target files results in implicitely calling
7991 the builder multiple times (once for each source given). Giving multiple
7992 source files together with target files results in a UserError exception.
7993
7994 .RE
7995 .IP
7996 The
7997 .I generator
7998 and
7999 .I action
8000 arguments must not both be used for the same Builder.
8001
8002 .IP source_ext_match
8003 When the specified
8004 .I action
8005 argument is a dictionary,
8006 the default behavior when a builder is passed
8007 multiple source files is to make sure that the
8008 extensions of all the source files match.
8009 If it is legal for this builder to be
8010 called with a list of source files with different extensions,
8011 this check can be suppressed by setting
8012 .B source_ext_match
8013 to
8014 .B None
8015 or some other non-true value.
8016 When
8017 .B source_ext_match
8018 is disable,
8019 .B scons
8020 will use the suffix of the first specified
8021 source file to select the appropriate action from the
8022 .I action
8023 dictionary.
8024
8025 In the following example,
8026 the setting of
8027 .B source_ext_match
8028 prevents
8029 .B scons
8030 from exiting with an error
8031 due to the mismatched suffixes of
8032 .B foo.in
8033 and
8034 .BR foo.extra .
8035
8036 .ES
8037 b = Builder(action={'.in' : 'build $SOURCES > $TARGET'},
8038             source_ext_match = None)
8039
8040 env = Environment(BUILDERS = {'MyBuild':b})
8041 env.MyBuild('foo.out', ['foo.in', 'foo.extra'])
8042 .EE
8043
8044 .IP env
8045 A construction environment that can be used
8046 to fetch source code using this Builder.
8047 (Note that this environment is
8048 .I not
8049 used for normal builds of normal target files,
8050 which use the environment that was
8051 used to call the Builder for the target file.)
8052
8053 .ES
8054 b = Builder(action="build < $SOURCE > $TARGET")
8055 env = Environment(BUILDERS = {'MyBuild' : b})
8056 env.MyBuild('foo.out', 'foo.in', my_arg = 'xyzzy')
8057 .EE
8058
8059 .IP chdir
8060 A directory from which scons
8061 will execute the
8062 action(s) specified
8063 for this Builder.
8064 If the
8065 .B chdir
8066 argument is
8067 a string or a directory Node,
8068 scons will change to the specified directory.
8069 If the
8070 .B chdir
8071 is not a string or Node
8072 and is non-zero,
8073 then scons will change to the
8074 target file's directory.
8075
8076 Note that scons will
8077 .I not
8078 automatically modify
8079 its expansion of
8080 construction variables like
8081 .B $TARGET
8082 and
8083 .B $SOURCE
8084 when using the chdir
8085 keyword argument--that is,
8086 the expanded file names
8087 will still be relative to
8088 the top-level SConstruct directory,
8089 and consequently incorrect
8090 relative to the chdir directory.
8091 Builders created using chdir keyword argument,
8092 will need to use construction variable
8093 expansions like
8094 .B ${TARGET.file}
8095 and
8096 .B ${SOURCE.file}
8097 to use just the filename portion of the
8098 targets and source.
8099
8100 .ES
8101 b = Builder(action="build < ${SOURCE.file} > ${TARGET.file}",
8102             chdir=1)
8103 env = Environment(BUILDERS = {'MyBuild' : b})
8104 env.MyBuild('sub/dir/foo.out', 'sub/dir/foo.in')
8105 .EE
8106
8107 .B WARNING:
8108 Python only keeps one current directory
8109 location for all of the threads.
8110 This means that use of the
8111 .B chdir
8112 argument
8113 will
8114 .I not
8115 work with the SCons
8116 .B -j
8117 option,
8118 because individual worker threads spawned
8119 by SCons interfere with each other
8120 when they start changing directory.
8121
8122 .RE
8123 Any additional keyword arguments supplied
8124 when a Builder object is created
8125 (that is, when the Builder() function is called)
8126 will be set in the executing construction
8127 environment when the Builder object is called.
8128 The canonical example here would be
8129 to set a construction variable to
8130 the repository of a source code system.
8131
8132 Any additional keyword arguments supplied
8133 when a Builder
8134 .I object
8135 is called
8136 will only be associated with the target
8137 created by that particular Builder call
8138 (and any other files built as a
8139 result of the call).
8140
8141 These extra keyword arguments are passed to the
8142 following functions:
8143 command generator functions,
8144 function Actions,
8145 and emitter functions.
8146
8147 .SS Action Objects
8148
8149 The
8150 .BR Builder()
8151 function will turn its
8152 .B action
8153 keyword argument into an appropriate
8154 internal Action object.
8155 You can also explicity create Action objects
8156 using the
8157 .BR Action ()
8158 global function,
8159 which can then be passed to the
8160 .BR Builder ()
8161 function.
8162 This can be used to configure
8163 an Action object more flexibly,
8164 or it may simply be more efficient
8165 than letting each separate Builder object
8166 create a separate Action
8167 when multiple
8168 Builder objects need to do the same thing.
8169
8170 The
8171 .BR Action ()
8172 global function
8173 returns an appropriate object for the action
8174 represented by the type of the first argument:
8175
8176 .IP Action
8177 If the first argument is already an Action object,
8178 the object is simply returned.
8179
8180 .IP String
8181 If the first argument is a string,
8182 a command-line Action is returned.
8183 Note that the command line string
8184 may be preceded by an
8185 .B @
8186 (at-sign)
8187 to suppress printing of the
8188 specified command line,
8189 or by a
8190 .B \-
8191 (hyphen)
8192 to ignore the exit status from
8193 the specified command.
8194 Examples:
8195
8196 .ES
8197 Action('$CC -c -o $TARGET $SOURCES')
8198
8199 # Doesn't print the line being executed.
8200 Action('@build $TARGET $SOURCES')
8201
8202 # Ignores
8203 Action('-build $TARGET $SOURCES')
8204 .EE
8205
8206 .\" XXX From Gary Ruben, 23 April 2002:
8207 .\" What would be useful is a discussion of how you execute command
8208 .\" shell commands ie. what is the process used to spawn the shell, pass
8209 .\" environment variables to it etc., whether there is one shell per
8210 .\" environment or one per command etc.  It might help to look at the Gnu
8211 .\" make documentation to see what they think is important to discuss about
8212 .\" a build system. I'm sure you can do a better job of organising the
8213 .\" documentation than they have :-)
8214
8215
8216 .IP List
8217 If the first argument is a list,
8218 then a list of Action objects is returned.
8219 An Action object is created as necessary
8220 for each element in the list.
8221 If an element
8222 .I within
8223 the list is itself a list,
8224 the internal list is the
8225 command and arguments to be executed via
8226 the command line.
8227 This allows white space to be enclosed
8228 in an argument by defining
8229 a command in a list within a list:
8230
8231 .ES
8232 Action([['cc', '-c', '-DWHITE SPACE', '-o', '$TARGET', '$SOURCES']])
8233 .EE
8234
8235 .IP Function
8236 If the first argument is a Python function,
8237 a function Action is returned.
8238 The Python function takes three keyword arguments,
8239 .B target
8240 (a Node object representing the target file),
8241 .B source
8242 (a Node object representing the source file)
8243 and
8244 .B env
8245 (the construction environment
8246 used for building the target file).
8247 The
8248 .B target
8249 and
8250 .B source
8251 arguments may be lists of Node objects if there is
8252 more than one target file or source file.
8253 The actual target and source file name(s) may
8254 be retrieved from their Node objects
8255 via the built-in Python str() function:
8256
8257 .ES
8258 target_file_name = str(target)
8259 source_file_names = map(lambda x: str(x), source)
8260 .EE
8261 .IP
8262 The function should return
8263 .B 0
8264 or
8265 .B None
8266 to indicate a successful build of the target file(s).
8267 The function may raise an exception
8268 or return a non-zero exit status
8269 to indicate an unsuccessful build.
8270
8271 .ES
8272 def build_it(target = None, source = None, env = None):
8273     # build the target from the source
8274     return 0
8275
8276 a = Action(build_it)
8277 .EE
8278
8279 If the action argument is not one of the above,
8280 None is returned.
8281 .PP
8282
8283 The second, optional argument
8284 is used to define the output which is printed
8285 when the Action is actually performed.
8286 In the absence of this parameter, or if it's an
8287 empty string, a default output depending on the type of the action
8288 is used. For example, a command-line action will print
8289 the executed command. The argument is either a python function
8290 or a string.
8291
8292 In the first case, it's a function that returns
8293 a string to be printed to describe the action being executed.
8294 Like a function to build a file,
8295 this function takes three arguments:
8296 .B target
8297 (a Node object representing the target file),
8298 .B source
8299 (a Node object representing the source file)
8300 and
8301 .BR env
8302 (a construction environment).
8303 The
8304 .B target
8305 and
8306 .B source
8307 arguments may be lists of Node objects if there is
8308 more than one target file or source file.
8309
8310 In the second case, you provide the string itself.
8311 The string typically contains variables, notably
8312 $TARGET(S) and $SOURCE(S), or consists of just a single
8313 variable, which is optionally defined somewhere else.
8314 SCons itself heavily uses the latter variant.
8315
8316 Examples:
8317
8318 .ES
8319 def build_it(target, source, env):
8320     # build the target from the source
8321     return 0
8322
8323 def string_it(target, source, env):
8324     return "building '%s' from '%s'" % (target[0], source[0])
8325
8326 # Use a positional argument.
8327 f = Action(build_it, string_it)
8328 s = Action(build_it, "building '$TARGET' from '$SOURCE'")
8329
8330 # Alternatively, use a keyword argument.
8331 f = Action(build_it, strfunction=string_it)
8332 s = Action(build_it, cmdstr="building '$TARGET' from '$SOURCE'")
8333
8334 # You can provide a configurable variable.
8335 l = Action(build_it, '$STRINGIT')
8336 .EE
8337
8338 The third, also optional argument
8339 is a list of construction variables
8340 whose values will be included
8341 in the signature of the Action
8342 when deciding whether a target should
8343 be rebuilt because the action changed.
8344 This is necessary whenever you want a target to
8345 be rebuilt when a specific
8346 construction variable changes,
8347 because the underlying Python code for a function
8348 will not change when the value of the construction variable does.
8349
8350 .ES
8351 def build_it(target, source, env):
8352     # build the target from the 'XXX' construction variable
8353     open(target[0], 'w').write(env['XXX'])
8354     return 0
8355
8356 # Use positional arguments.
8357 a = Action(build_it, '$STRINGIT', ['XXX'])
8358
8359 # Alternatively, use a keyword argument.
8360 a = Action(build_it, varlist=['XXX'])
8361 .EE
8362
8363 The
8364 .BR Action ()
8365 global function
8366 also takes a
8367 .B chdir
8368 keyword argument
8369 which specifies that
8370 scons will execute the action
8371 after changing to the specified directory.
8372 If the chdir argument is
8373 a string or a directory Node,
8374 scons will change to the specified directory.
8375 If the chdir argument
8376 is not a string or Node
8377 and is non-zero,
8378 then scons will change to the
8379 target file's directory.
8380
8381 Note that scons will
8382 .I not
8383 automatically modify
8384 its expansion of
8385 construction variables like
8386 .B $TARGET
8387 and
8388 .B $SOURCE
8389 when using the chdir
8390 keyword argument--that is,
8391 the expanded file names
8392 will still be relative to
8393 the top-level SConstruct directory,
8394 and consequently incorrect
8395 relative to the chdir directory.
8396 Builders created using chdir keyword argument,
8397 will need to use construction variable
8398 expansions like
8399 .B ${TARGET.file}
8400 and
8401 .B ${SOURCE.file}
8402 to use just the filename portion of the
8403 targets and source.
8404
8405 .ES
8406 a = Action("build < ${SOURCE.file} > ${TARGET.file}",
8407            chdir=1)
8408 .EE
8409
8410 The
8411 .BR Action ()
8412 global function
8413 also takes an
8414 .B exitstatfunc
8415 keyword argument
8416 which specifies a function
8417 that is passed the exit status
8418 (or return value)
8419 from the specified action
8420 and can return an arbitrary
8421 or modified value.
8422 This can be used, for example,
8423 to specify that an Action object's
8424 return value should be ignored
8425 and SCons should, therefore,
8426 consider that the action always suceeds:
8427
8428 .ES
8429 def always_succeed(s):
8430     # Always return 0, which indicates success.
8431     return 0
8432 a = Action("build < ${SOURCE.file} > ${TARGET.file}",
8433            exitstatfunc=always_succeed)
8434 .EE
8435
8436 .SS Miscellaneous Action Functions
8437
8438 .B scons
8439 supplies a number of functions
8440 that arrange for various common
8441 file and directory manipulations
8442 to be performed.
8443 These are similar in concept to "tasks" in the
8444 Ant build tool,
8445 although the implementation is slightly different.
8446 These functions do not actually
8447 perform the specified action
8448 at the time the function is called,
8449 but instead return an Action object
8450 that can be executed at the
8451 appropriate time.
8452 (In Object-Oriented terminology,
8453 these are actually
8454 Action
8455 .I Factory
8456 functions
8457 that return Action objects.)
8458
8459 In practice,
8460 there are two natural ways
8461 that these
8462 Action Functions
8463 are intended to be used.
8464
8465 First,
8466 if you need
8467 to perform the action
8468 at the time the SConscript
8469 file is being read,
8470 you can use the
8471 .B Execute
8472 global function to do so:
8473 .ES
8474 Execute(Touch('file'))
8475 .EE
8476
8477 Second,
8478 you can use these functions
8479 to supply Actions in a list
8480 for use by the
8481 .B Command
8482 method.
8483 This can allow you to
8484 perform more complicated
8485 sequences of file manipulation
8486 without relying
8487 on platform-specific
8488 external commands:
8489 that
8490 .ES
8491 env = Environment(TMPBUILD = '/tmp/builddir')
8492 env.Command('foo.out', 'foo.in',
8493             [Mkdir('$TMPBUILD'),
8494              Copy('$TMPBUILD', '${SOURCE.dir}'),
8495              "cd $TMPBUILD && make",
8496              Delete('$TMPBUILD')])
8497 .EE
8498
8499 .TP
8500 .RI Chmod( dest ", " mode )
8501 Returns an Action object that
8502 changes the permissions on the specified
8503 .I dest
8504 file or directory to the specified
8505 .IR mode .
8506 Examples:
8507
8508 .ES
8509 Execute(Chmod('file', 0755))
8510
8511 env.Command('foo.out', 'foo.in',
8512             [Copy('$TARGET', '$SOURCE'),
8513              Chmod('$TARGET', 0755)])
8514 .EE
8515
8516 .TP
8517 .RI Copy( dest ", " src )
8518 Returns an Action object
8519 that will copy the
8520 .I src
8521 source file or directory to the
8522 .I dest
8523 destination file or directory.
8524 Examples:
8525
8526 .ES
8527 Execute(Copy('foo.output', 'foo.input'))
8528
8529 env.Command('bar.out', 'bar.in',
8530             Copy('$TARGET', '$SOURCE'))
8531 .EE
8532
8533 .TP
8534 .RI Delete( entry ", [" must_exist ])
8535 Returns an Action that
8536 deletes the specified
8537 .IR entry ,
8538 which may be a file or a directory tree.
8539 If a directory is specified,
8540 the entire directory tree
8541 will be removed.
8542 If the
8543 .I must_exist
8544 flag is set,
8545 then a Python error will be thrown
8546 if the specified entry does not exist;
8547 the default is
8548 .BR must_exist=0 ,
8549 that is, the Action will silently do nothing
8550 if the entry does not exist.
8551 Examples:
8552
8553 .ES
8554 Execute(Delete('/tmp/buildroot'))
8555
8556 env.Command('foo.out', 'foo.in',
8557             [Delete('${TARGET.dir}'),
8558              MyBuildAction])
8559
8560 Execute(Delete('file_that_must_exist', must_exist=1))
8561 .EE
8562
8563 .TP
8564 .RI Mkdir( dir )
8565 Returns an Action
8566 that creates the specified
8567 directory
8568 .I dir .
8569 Examples:
8570
8571 .ES
8572 Execute(Mkdir('/tmp/outputdir'))
8573
8574 env.Command('foo.out', 'foo.in',
8575             [Mkdir('/tmp/builddir',
8576              Copy('$SOURCE', '/tmp/builddir/foo.in')
8577              "cd /tmp/builddir && make",
8578              Copy('/tmp/builddir/foo.out', '$TARGET')])
8579 .EE
8580
8581 .TP
8582 .RI Move( dest ", " src )
8583 Returns an Action
8584 that moves the specified
8585 .I src
8586 file or directory to
8587 the specified
8588 .I dest
8589 file or directory.
8590 Examples:
8591
8592 .ES
8593 Execute(Move('file.destination', 'file.source'))
8594
8595 env.Command('output_file', 'input_file',
8596             [MyBuildAction,
8597              Move('$TARGET', 'file_created_by_MyBuildAction')])
8598 .EE
8599
8600 .TP
8601 .RI Touch( file )
8602 Returns an Action
8603 that updates the modification time
8604 on the specified
8605 .IR file .
8606 Examples:
8607
8608 .ES
8609 Execute(Touch('file_to_be_touched'))
8610
8611 env.Command('marker', 'input_file',
8612             [MyBuildAction,
8613              Touch('$TARGET')])
8614 .EE
8615
8616 .SS Variable Substitution
8617
8618 Before executing a command,
8619 .B scons
8620 performs construction variable interpolation on the strings that make up
8621 the command line of builders.
8622 Variables are introduced by a
8623 .B $
8624 prefix.
8625 Besides construction variables, scons provides the following
8626 variables for each command execution:
8627
8628 .IP TARGET
8629 The file name of the target being built, or the file name of the first
8630 target if multiple targets are being built.
8631
8632 .IP TARGETS
8633 The file names of all targets being built.
8634
8635 .IP SOURCE
8636 The file name of the source of the build command, or the file name of the
8637 first source if multiple sources are being built.
8638
8639 .IP SOURCES
8640 The file names of the sources of the build command.
8641
8642 (Note that the above variables are reserved
8643 and may not be set in a construction environment.)
8644
8645 .LP
8646 For example, given the construction variable CC='cc', targets=['foo'], and
8647 sources=['foo.c', 'bar.c']:
8648
8649 .ES
8650 action='$CC -c -o $TARGET $SOURCES'
8651 .EE
8652
8653 would produce the command line:
8654
8655 .ES
8656 cc -c -o foo foo.c bar.c
8657 .EE
8658
8659 Variable names may be surrounded by curly braces ({})
8660 to separate the name from the trailing characters.
8661 Within the curly braces, a variable name may have
8662 a Python slice subscript appended to select one
8663 or more items from a list.
8664 In the previous example, the string:
8665
8666 .ES
8667 ${SOURCES[1]}
8668 .EE
8669
8670 would produce:
8671
8672 .ES
8673 bar.c
8674 .EE
8675
8676 Additionally, a variable name may
8677 have the following special
8678 modifiers appended within the enclosing curly braces
8679 to modify the interpolated string:
8680
8681 .IP base
8682 The base path of the file name,
8683 including the directory path
8684 but excluding any suffix.
8685
8686 .IP dir
8687 The name of the directory in which the file exists.
8688
8689 .IP file
8690 The file name,
8691 minus any directory portion.
8692
8693 .IP filebase
8694 Just the basename of the file,
8695 minus any suffix
8696 and minus the directory.
8697
8698 .IP suffix
8699 Just the file suffix.
8700
8701 .IP abspath
8702 The absolute path name of the file.
8703
8704 .IP posix
8705 The POSIX form of the path,
8706 with directories separated by
8707 .B /
8708 (forward slashes)
8709 not backslashes.
8710 This is sometimes necessary on Windows systems
8711 when a path references a file on other (POSIX) systems.
8712
8713 .IP srcpath
8714 The directory and file name to the source file linked to this file through
8715 .BR VariantDir ().
8716 If this file isn't linked,
8717 it just returns the directory and filename unchanged.
8718
8719 .IP srcdir
8720 The directory containing the source file linked to this file through
8721 .BR VariantDir ().
8722 If this file isn't linked,
8723 it just returns the directory part of the filename.
8724
8725 .IP rsrcpath
8726 The directory and file name to the source file linked to this file through
8727 .BR VariantDir ().
8728 If the file does not exist locally but exists in a Repository,
8729 the path in the Repository is returned.
8730 If this file isn't linked, it just returns the
8731 directory and filename unchanged.
8732
8733 .IP rsrcdir
8734 The Repository directory containing the source file linked to this file through
8735 .BR VariantDir ().
8736 If this file isn't linked,
8737 it just returns the directory part of the filename.
8738
8739 .LP
8740 For example, the specified target will
8741 expand as follows for the corresponding modifiers:
8742
8743 .ES
8744 $TARGET              => sub/dir/file.x
8745 ${TARGET.base}       => sub/dir/file
8746 ${TARGET.dir}        => sub/dir
8747 ${TARGET.file}       => file.x
8748 ${TARGET.filebase}   => file
8749 ${TARGET.suffix}     => .x
8750 ${TARGET.abspath}    => /top/dir/sub/dir/file.x
8751
8752 SConscript('src/SConscript', variant_dir='sub/dir')
8753 $SOURCE              => sub/dir/file.x
8754 ${SOURCE.srcpath}    => src/file.x
8755 ${SOURCE.srcdir}     => src
8756
8757 Repository('/usr/repository')
8758 $SOURCE              => sub/dir/file.x
8759 ${SOURCE.rsrcpath}   => /usr/repository/src/file.x
8760 ${SOURCE.rsrcdir}    => /usr/repository/src
8761 .EE
8762
8763 Note that curly braces braces may also be used
8764 to enclose arbitrary Python code to be evaluated.
8765 (In fact, this is how the above modifiers are substituted,
8766 they are simply attributes of the Python objects
8767 that represent TARGET, SOURCES, etc.)
8768 See the section "Python Code Substitution," below,
8769 for more thorough examples of
8770 how this can be used.
8771
8772 Lastly, a variable name
8773 may be a callable Python function
8774 associated with a
8775 construction variable in the environment.
8776 The function should
8777 take four arguments:
8778 .I target
8779 - a list of target nodes,
8780 .I source
8781 - a list of source nodes,
8782 .I env
8783 - the construction environment,
8784 .I for_signature
8785 - a Boolean value that specifies
8786 whether the function is being called
8787 for generating a build signature.
8788 SCons will insert whatever
8789 the called function returns
8790 into the expanded string:
8791
8792 .ES
8793 def foo(target, source, env, for_signature):
8794     return "bar"
8795
8796 # Will expand $BAR to "bar baz"
8797 env=Environment(FOO=foo, BAR="$FOO baz")
8798 .EE
8799
8800 You can use this feature to pass arguments to a
8801 Python function by creating a callable class
8802 that stores one or more arguments in an object,
8803 and then uses them when the
8804 .B __call__()
8805 method is called.
8806 Note that in this case,
8807 the entire variable expansion must
8808 be enclosed by curly braces
8809 so that the arguments will
8810 be associated with the
8811 instantiation of the class:
8812
8813 .ES
8814 class foo:
8815     def __init__(self, arg):
8816         self.arg = arg
8817
8818     def __call__(self, target, source, env, for_signature):
8819         return self.arg + " bar"
8820
8821 # Will expand $BAR to "my argument bar baz"
8822 env=Environment(FOO=foo, BAR="${FOO('my argument')} baz")
8823 .EE
8824
8825 .LP
8826 The special pseudo-variables
8827 .B "$("
8828 and
8829 .B "$)"
8830 may be used to surround parts of a command line
8831 that may change
8832 .I without
8833 causing a rebuild--that is,
8834 which are not included in the signature
8835 of target files built with this command.
8836 All text between
8837 .B "$("
8838 and
8839 .B "$)"
8840 will be removed from the command line
8841 before it is added to file signatures,
8842 and the
8843 .B "$("
8844 and
8845 .B "$)"
8846 will be removed before the command is executed.
8847 For example, the command line:
8848
8849 .ES
8850 echo Last build occurred $( $TODAY $). > $TARGET
8851 .EE
8852
8853 .LP
8854 would execute the command:
8855
8856 .ES
8857 echo Last build occurred $TODAY. > $TARGET
8858 .EE
8859
8860 .LP
8861 but the command signature added to any target files would be:
8862
8863 .ES
8864 echo Last build occurred  . > $TARGET
8865 .EE
8866
8867 .SS Python Code Substitution
8868
8869 Any python code within
8870 .BR "${" - "}"
8871 pairs gets evaluated by python 'eval', with the python globals set to
8872 the current environment's set of construction variables.
8873 So in the following case:
8874 .ES
8875 env['COND'] = 0
8876 env.Command('foo.out', 'foo.in',
8877    '''echo ${COND==1 and 'FOO' or 'BAR'} > $TARGET''')
8878 .EE
8879 the command executed will be either
8880 .ES
8881 echo FOO > foo.out
8882 .EE
8883 or
8884 .ES
8885 echo BAR > foo.out
8886 .EE
8887 according to the current value of env['COND'] when the command is
8888 executed.  The evaluation occurs when the target is being
8889 built, not when the SConscript is being read.  So if env['COND'] is changed
8890 later in the SConscript, the final value will be used.
8891
8892 Here's a more interesting example.  Note that all of COND, FOO, and
8893 BAR are environment variables, and their values are substituted into
8894 the final command.  FOO is a list, so its elements are interpolated
8895 separated by spaces.
8896
8897 .ES
8898 env=Environment()
8899 env['COND'] = 0
8900 env['FOO'] = ['foo1', 'foo2']
8901 env['BAR'] = 'barbar'
8902 env.Command('foo.out', 'foo.in',
8903     'echo ${COND==1 and FOO or BAR} > $TARGET')
8904
8905 # Will execute this:
8906 #  echo foo1 foo2 > foo.out
8907 .EE
8908
8909 SCons uses the following rules when converting construction variables into
8910 command lines:
8911
8912 .IP String
8913 When the value is a string it is interpreted as a space delimited list of
8914 command line arguments.
8915
8916 .IP List
8917 When the value is a list it is interpreted as a list of command line
8918 arguments. Each element of the list is converted to a string.
8919
8920 .IP Other
8921 Anything that is not a list or string is converted to a string and
8922 interpreted as a single command line argument.
8923
8924 .IP Newline
8925 Newline characters (\\n) delimit lines. The newline parsing is done after
8926 all other parsing, so it is not possible for arguments (e.g. file names) to
8927 contain embedded newline characters. This limitation will likely go away in
8928 a future version of SCons.
8929
8930 .SS Scanner Objects
8931
8932 You can use the
8933 .B Scanner
8934 function to define
8935 objects to scan
8936 new file types for implicit dependencies.
8937 Scanner accepts the following arguments:
8938
8939 .IP function
8940 This can be either:
8941 1) a Python function that will process
8942 the Node (file)
8943 and return a list of strings (file names)
8944 representing the implicit
8945 dependencies found in the contents;
8946 or:
8947 2) a dictionary that maps keys
8948 (typically the file suffix, but see below for more discussion)
8949 to other Scanners that should be called.
8950
8951 If the argument is actually a Python function,
8952 the function must take three or four arguments:
8953
8954     def scanner_function(node, env, path):
8955
8956     def scanner_function(node, env, path, arg=None):
8957
8958 The
8959 .B node
8960 argument is the internal
8961 SCons node representing the file.
8962 Use
8963 .B str(node)
8964 to fetch the name of the file, and
8965 .B node.get_contents()
8966 to fetch contents of the file.
8967 Note that the file is
8968 .I not
8969 guaranteed to exist before the scanner is called,
8970 so the scanner function should check that
8971 if there's any chance that the scanned file
8972 might not exist
8973 (for example, if it's built from other files).
8974
8975 The
8976 .B env
8977 argument is the construction environment for the scan.
8978 Fetch values from it using the
8979 .B env.Dictionary()
8980 method.
8981
8982 The
8983 .B path
8984 argument is a tuple (or list)
8985 of directories that can be searched
8986 for files.
8987 This will usually be the tuple returned by the
8988 .B path_function
8989 argument (see below).
8990
8991 The
8992 .B arg
8993 argument is the argument supplied
8994 when the scanner was created, if any.
8995
8996 .IP name
8997 The name of the Scanner.
8998 This is mainly used
8999 to identify the Scanner internally.
9000
9001 .IP argument
9002 An optional argument that, if specified,
9003 will be passed to the scanner function
9004 (described above)
9005 and the path function
9006 (specified below).
9007
9008 .IP skeys
9009 An optional list that can be used to
9010 determine which scanner should be used for
9011 a given Node.
9012 In the usual case of scanning for file names,
9013 this argument will be a list of suffixes
9014 for the different file types that this
9015 Scanner knows how to scan.
9016 If the argument is a string,
9017 then it will be expanded
9018 into a list by the current environment.
9019
9020 .IP path_function
9021 A Python function that takes four or five arguments:
9022 a construction environment,
9023 a Node for the directory containing
9024 the SConscript file in which
9025 the first target was defined,
9026 a list of target nodes,
9027 a list of source nodes,
9028 and an optional argument supplied
9029 when the scanner was created.
9030 The
9031 .B path_function
9032 returns a tuple of directories
9033 that can be searched for files to be returned
9034 by this Scanner object.
9035 (Note that the
9036 .BR FindPathDirs ()
9037 function can be used to return a ready-made
9038 .B path_function
9039 for a given construction variable name,
9040 instead of having to write your own function from scratch.)
9041
9042 .IP node_class
9043 The class of Node that should be returned
9044 by this Scanner object.
9045 Any strings or other objects returned
9046 by the scanner function
9047 that are not of this class
9048 will be run through the
9049 .B node_factory
9050 function.
9051
9052 .IP node_factory
9053 A Python function that will take a string
9054 or other object
9055 and turn it into the appropriate class of Node
9056 to be returned by this Scanner object.
9057
9058 .IP scan_check
9059 An optional Python function that takes two arguments,
9060 a Node (file) and a construction environment,
9061 and returns whether the
9062 Node should, in fact,
9063 be scanned for dependencies.
9064 This check can be used to eliminate unnecessary
9065 calls to the scanner function when,
9066 for example, the underlying file
9067 represented by a Node does not yet exist.
9068
9069 .IP recursive
9070 An optional flag that
9071 specifies whether this scanner should be re-invoked
9072 on the dependency files returned by the scanner.
9073 When this flag is not set,
9074 the Node subsystem will
9075 only invoke the scanner on the file being scanned,
9076 and not (for example) also on the files
9077 specified by the #include lines
9078 in the file being scanned.
9079 .I recursive
9080 may be a callable function,
9081 in which case it will be called with a list of
9082 Nodes found and
9083 should return a list of Nodes
9084 that should be scanned recursively;
9085 this can be used to select a specific subset of
9086 Nodes for additional scanning.
9087
9088 Note that
9089 .B scons
9090 has a global
9091 .B SourceFileScanner
9092 object that is used by
9093 the
9094 .BR Object (),
9095 .BR SharedObject (),
9096 and
9097 .BR StaticObject ()
9098 builders to decide
9099 which scanner should be used
9100 for different file extensions.
9101 You can using the
9102 .BR SourceFileScanner.add_scanner ()
9103 method to add your own Scanner object
9104 to the
9105 .B scons
9106 infrastructure
9107 that builds target programs or
9108 libraries from a list of
9109 source files of different types:
9110
9111 .ES
9112 def xyz_scan(node, env, path):
9113     contents = node.get_contents()
9114     # Scan the contents and return the included files.
9115
9116 XYZScanner = Scanner(xyz_scan)
9117
9118 SourceFileScanner.add_scanner('.xyx', XYZScanner)
9119
9120 env.Program('my_prog', ['file1.c', 'file2.f', 'file3.xyz'])
9121 .EE
9122
9123 .SH SYSTEM-SPECIFIC BEHAVIOR
9124 SCons and its configuration files are very portable,
9125 due largely to its implementation in Python.
9126 There are, however, a few portability
9127 issues waiting to trap the unwary.
9128 .SS .C file suffix
9129 SCons handles the upper-case
9130 .B .C
9131 file suffix differently,
9132 depending on the capabilities of
9133 the underlying system.
9134 On a case-sensitive system
9135 such as Linux or UNIX,
9136 SCons treats a file with a
9137 .B .C
9138 suffix as a C++ source file.
9139 On a case-insensitive system
9140 such as Windows,
9141 SCons treats a file with a
9142 .B .C
9143 suffix as a C source file.
9144 .SS .F file suffix
9145 SCons handles the upper-case
9146 .B .F
9147 file suffix differently,
9148 depending on the capabilities of
9149 the underlying system.
9150 On a case-sensitive system
9151 such as Linux or UNIX,
9152 SCons treats a file with a
9153 .B .F
9154 suffix as a Fortran source file
9155 that is to be first run through
9156 the standard C preprocessor.
9157 On a case-insensitive system
9158 such as Windows,
9159 SCons treats a file with a
9160 .B .F
9161 suffix as a Fortran source file that should
9162 .I not
9163 be run through the C preprocessor.
9164 .SS Windows:  Cygwin Tools and Cygwin Python vs. Windows Pythons
9165 Cygwin supplies a set of tools and utilities
9166 that let users work on a
9167 Windows system using a more POSIX-like environment.
9168 The Cygwin tools, including Cygwin Python,
9169 do this, in part,
9170 by sharing an ability to interpret UNIX-like path names.
9171 For example, the Cygwin tools
9172 will internally translate a Cygwin path name
9173 like /cygdrive/c/mydir
9174 to an equivalent Windows pathname
9175 of C:/mydir (equivalent to C:\\mydir).
9176
9177 Versions of Python
9178 that are built for native Windows execution,
9179 such as the python.org and ActiveState versions,
9180 do not have the Cygwin path name semantics.
9181 This means that using a native Windows version of Python
9182 to build compiled programs using Cygwin tools
9183 (such as gcc, bison, and flex)
9184 may yield unpredictable results.
9185 "Mixing and matching" in this way
9186 can be made to work,
9187 but it requires careful attention to the use of path names
9188 in your SConscript files.
9189
9190 In practice, users can sidestep
9191 the issue by adopting the following rules:
9192 When using gcc,
9193 use the Cygwin-supplied Python interpreter
9194 to run SCons;
9195 when using Microsoft Visual C/C++
9196 (or some other Windows compiler)
9197 use the python.org or ActiveState version of Python
9198 to run SCons.
9199 .SS Windows:  scons.bat file
9200 On Windows systems,
9201 SCons is executed via a wrapper
9202 .B scons.bat
9203 file.
9204 This has (at least) two ramifications:
9205
9206 First, Windows command-line users
9207 that want to use variable assignment
9208 on the command line
9209 may have to put double quotes
9210 around the assignments:
9211
9212 .ES
9213 scons "FOO=BAR" "BAZ=BLEH"
9214 .EE
9215
9216 Second, the Cygwin shell does not
9217 recognize this file as being the same
9218 as an
9219 .B scons
9220 command issued at the command-line prompt.
9221 You can work around this either by
9222 executing
9223 .B scons.bat
9224 from the Cygwin command line,
9225 or by creating a wrapper shell
9226 script named
9227 .B scons .
9228
9229 .SS MinGW
9230
9231 The MinGW bin directory must be in your PATH environment variable or the
9232 PATH variable under the ENV construction variable for SCons
9233 to detect and use the MinGW tools. When running under the native Windows
9234 Python interpreter, SCons will prefer the MinGW tools over the Cygwin
9235 tools, if they are both installed, regardless of the order of the bin
9236 directories in the PATH variable. If you have both MSVC and MinGW
9237 installed and you want to use MinGW instead of MSVC,
9238 then you must explictly tell SCons to use MinGW by passing
9239
9240 .ES
9241 tools=['mingw']
9242 .EE
9243
9244 to the Environment() function, because SCons will prefer the MSVC tools
9245 over the MinGW tools.
9246
9247 .SH EXAMPLES
9248
9249 To help you get started using SCons,
9250 this section contains a brief overview of some common tasks.
9251
9252 .SS Basic Compilation From a Single Source File
9253
9254 .ES
9255 env = Environment()
9256 env.Program(target = 'foo', source = 'foo.c')
9257 .EE
9258
9259 Note:  Build the file by specifying
9260 the target as an argument
9261 ("scons foo" or "scons foo.exe").
9262 or by specifying a dot ("scons .").
9263
9264 .SS Basic Compilation From Multiple Source Files
9265
9266 .ES
9267 env = Environment()
9268 env.Program(target = 'foo', source = Split('f1.c f2.c f3.c'))
9269 .EE
9270
9271 .SS Setting a Compilation Flag
9272
9273 .ES
9274 env = Environment(CCFLAGS = '-g')
9275 env.Program(target = 'foo', source = 'foo.c')
9276 .EE
9277
9278 .SS Search The Local Directory For .h Files
9279
9280 Note:  You do
9281 .I not
9282 need to set CCFLAGS to specify -I options by hand.
9283 SCons will construct the right -I options from CPPPATH.
9284
9285 .ES
9286 env = Environment(CPPPATH = ['.'])
9287 env.Program(target = 'foo', source = 'foo.c')
9288 .EE
9289
9290 .SS Search Multiple Directories For .h Files
9291
9292 .ES
9293 env = Environment(CPPPATH = ['include1', 'include2'])
9294 env.Program(target = 'foo', source = 'foo.c')
9295 .EE
9296
9297 .SS Building a Static Library
9298
9299 .ES
9300 env = Environment()
9301 env.StaticLibrary(target = 'foo', source = Split('l1.c l2.c'))
9302 env.StaticLibrary(target = 'bar', source = ['l3.c', 'l4.c'])
9303 .EE
9304
9305 .SS Building a Shared Library
9306
9307 .ES
9308 env = Environment()
9309 env.SharedLibrary(target = 'foo', source = ['l5.c', 'l6.c'])
9310 env.SharedLibrary(target = 'bar', source = Split('l7.c l8.c'))
9311 .EE
9312
9313 .SS Linking a Local Library Into a Program
9314
9315 .ES
9316 env = Environment(LIBS = 'mylib', LIBPATH = ['.'])
9317 env.Library(target = 'mylib', source = Split('l1.c l2.c'))
9318 env.Program(target = 'prog', source = ['p1.c', 'p2.c'])
9319 .EE
9320
9321 .SS Defining Your Own Builder Object
9322
9323 Notice that when you invoke the Builder,
9324 you can leave off the target file suffix,
9325 and SCons will add it automatically.
9326
9327 .ES
9328 bld = Builder(action = 'pdftex < $SOURCES > $TARGET'
9329               suffix = '.pdf',
9330               src_suffix = '.tex')
9331 env = Environment(BUILDERS = {'PDFBuilder' : bld})
9332 env.PDFBuilder(target = 'foo.pdf', source = 'foo.tex')
9333
9334 # The following creates "bar.pdf" from "bar.tex"
9335 env.PDFBuilder(target = 'bar', source = 'bar')
9336 .EE
9337
9338 Note also that the above initialization
9339 overwrites the default Builder objects,
9340 so the Environment created above
9341 can not be used call Builders like env.Program(),
9342 env.Object(), env.StaticLibrary(), etc.
9343
9344 .SS Adding Your Own Builder Object to an Environment
9345
9346 .ES
9347 bld = Builder(action = 'pdftex < $SOURCES > $TARGET'
9348               suffix = '.pdf',
9349               src_suffix = '.tex')
9350 env = Environment()
9351 env.Append(BUILDERS = {'PDFBuilder' : bld})
9352 env.PDFBuilder(target = 'foo.pdf', source = 'foo.tex')
9353 env.Program(target = 'bar', source = 'bar.c')
9354 .EE
9355
9356 You also can use other Pythonic techniques to add
9357 to the BUILDERS construction variable, such as:
9358
9359 .ES
9360 env = Environment()
9361 env['BUILDERS]['PDFBuilder'] = bld
9362 .EE
9363
9364 .SS Defining Your Own Scanner Object
9365
9366 The following example shows an extremely simple scanner (the
9367 .BR kfile_scan ()
9368 function)
9369 that doesn't use a search path at all
9370 and simply returns the
9371 file names present on any
9372 .B include
9373 lines in the scanned file.
9374 This would implicitly assume that all included
9375 files live in the top-level directory:
9376
9377 .ES
9378 import re
9379
9380 '\" Note:  the \\ in the following are for the benefit of nroff/troff,
9381 '\" not inappropriate doubled escape characters within the r'' raw string.
9382 include_re = re.compile(r'^include\\s+(\\S+)$', re.M)
9383
9384 def kfile_scan(node, env, path, arg):
9385     contents = node.get_contents()
9386     includes = include_re.findall(contents)
9387     return includes
9388
9389 kscan = Scanner(name = 'kfile',
9390                 function = kfile_scan,
9391                 argument = None,
9392                 skeys = ['.k'])
9393 scanners = Environment().Dictionary('SCANNERS')
9394 env = Environment(SCANNERS = scanners + [kscan])
9395
9396 env.Command('foo', 'foo.k', 'kprocess < $SOURCES > $TARGET')
9397
9398 bar_in = File('bar.in')
9399 env.Command('bar', bar_in, 'kprocess $SOURCES > $TARGET')
9400 bar_in.target_scanner = kscan
9401 .EE
9402
9403 Here is a similar but more complete example that searches
9404 a path of directories
9405 (specified as the
9406 .B MYPATH
9407 construction variable)
9408 for files that actually exist:
9409
9410 .ES
9411 include_re = re.compile(r'^include\\s+(\\S+)$', re.M)
9412
9413 def my_scan(node, env, path, arg):
9414    contents = node.get_contents()
9415    includes = include_re.findall(contents)
9416    if includes == []:
9417         return []
9418     results = []
9419     for inc in includes:
9420         for dir in path:
9421             file = dir + os.sep + inc
9422             if os.path.exists(file):
9423                 results.append(file)
9424                 break
9425     return results
9426
9427 scanner = Scanner(name = 'myscanner',
9428                  function = my_scan,
9429                  argument = None,
9430                  skeys = ['.x'],
9431                  path_function = FindPathDirs('MYPATH'),
9432                  )
9433 scanners = Environment().Dictionary('SCANNERS')
9434 env = Environment(SCANNERS = scanners + [scanner])
9435 .EE
9436
9437 The
9438 .BR FindPathDirs ()
9439 function used in the previous example returns a function
9440 (actually a callable Python object)
9441 that will return a list of directories
9442 specified in the
9443 .B $MYPATH
9444 construction variable.
9445 If you need to customize how the search path is derived,
9446 you would provide your own
9447 .B path_function
9448 argument when creating the Scanner object,
9449 as follows:
9450
9451 .ES
9452 # MYPATH is a list of directories to search for files in
9453 def pf(env, dir, target, source, arg):
9454     top_dir = Dir('#').abspath
9455     results = []
9456     if env.has_key('MYPATH'):
9457         for p in env['MYPATH']:
9458             results.append(top_dir + os.sep + p)
9459     return results
9460
9461 scanner = Scanner(name = 'myscanner',
9462                  function = my_scan,
9463                  argument = None,
9464                  skeys = ['.x'],
9465                  path_function = pf,
9466                  )
9467 .EE
9468
9469 .SS Creating a Hierarchical Build
9470
9471 Notice that the file names specified in a subdirectory's
9472 SConscript
9473 file are relative to that subdirectory.
9474
9475 .ES
9476 SConstruct:
9477
9478     env = Environment()
9479     env.Program(target = 'foo', source = 'foo.c')
9480
9481     SConscript('sub/SConscript')
9482
9483 sub/SConscript:
9484
9485     env = Environment()
9486     # Builds sub/foo from sub/foo.c
9487     env.Program(target = 'foo', source = 'foo.c')
9488
9489     SConscript('dir/SConscript')
9490
9491 sub/dir/SConscript:
9492
9493     env = Environment()
9494     # Builds sub/dir/foo from sub/dir/foo.c
9495     env.Program(target = 'foo', source = 'foo.c')
9496 .EE
9497
9498 .SS Sharing Variables Between SConscript Files
9499
9500 You must explicitly Export() and Import() variables that
9501 you want to share between SConscript files.
9502
9503 .ES
9504 SConstruct:
9505
9506     env = Environment()
9507     env.Program(target = 'foo', source = 'foo.c')
9508
9509     Export("env")
9510     SConscript('subdirectory/SConscript')
9511
9512 subdirectory/SConscript:
9513
9514     Import("env")
9515     env.Program(target = 'foo', source = 'foo.c')
9516 .EE
9517
9518 .SS Building Multiple Variants From the Same Source
9519
9520 Use the variant_dir keyword argument to
9521 the SConscript function to establish
9522 one or more separate variant build directory trees
9523 for a given source directory:
9524
9525 .ES
9526 SConstruct:
9527
9528     cppdefines = ['FOO']
9529     Export("cppdefines")
9530     SConscript('src/SConscript', variant_dir='foo')
9531
9532     cppdefines = ['BAR']
9533     Export("cppdefines")
9534     SConscript('src/SConscript', variant_dir='bar')
9535
9536 src/SConscript:
9537
9538     Import("cppdefines")
9539     env = Environment(CPPDEFINES = cppdefines)
9540     env.Program(target = 'src', source = 'src.c')
9541 .EE
9542
9543 Note the use of the Export() method
9544 to set the "cppdefines" variable to a different
9545 value each time we call the SConscript function.
9546
9547 .SS Hierarchical Build of Two Libraries Linked With a Program
9548
9549 .ES
9550 SConstruct:
9551
9552     env = Environment(LIBPATH = ['#libA', '#libB'])
9553     Export('env')
9554     SConscript('libA/SConscript')
9555     SConscript('libB/SConscript')
9556     SConscript('Main/SConscript')
9557
9558 libA/SConscript:
9559
9560     Import('env')
9561     env.Library('a', Split('a1.c a2.c a3.c'))
9562
9563 libB/SConscript:
9564
9565     Import('env')
9566     env.Library('b', Split('b1.c b2.c b3.c'))
9567
9568 Main/SConscript:
9569
9570     Import('env')
9571     e = env.Copy(LIBS = ['a', 'b'])
9572     e.Program('foo', Split('m1.c m2.c m3.c'))
9573 .EE
9574
9575 The '#' in the LIBPATH directories specify that they're relative to the
9576 top-level directory, so they don't turn into "Main/libA" when they're
9577 used in Main/SConscript.
9578
9579 Specifying only 'a' and 'b' for the library names
9580 allows SCons to append the appropriate library
9581 prefix and suffix for the current platform
9582 (for example, 'liba.a' on POSIX systems,
9583 \&'a.lib' on Windows).
9584
9585 .SS Customizing construction variables from the command line.
9586
9587 The following would allow the C compiler to be specified on the command
9588 line or in the file custom.py.
9589
9590 .ES
9591 vars = Variables('custom.py')
9592 vars.Add('CC', 'The C compiler.')
9593 env = Environment(variables=vars)
9594 Help(vars.GenerateHelpText(env))
9595 .EE
9596
9597 The user could specify the C compiler on the command line:
9598
9599 .ES
9600 scons "CC=my_cc"
9601 .EE
9602
9603 or in the custom.py file:
9604
9605 .ES
9606 CC = 'my_cc'
9607 .EE
9608
9609 or get documentation on the options:
9610
9611 .ES
9612 $ scons -h
9613
9614 CC: The C compiler.
9615     default: None
9616     actual: cc
9617
9618 .EE
9619
9620 .SS Using Microsoft Visual C++ precompiled headers
9621
9622 Since windows.h includes everything and the kitchen sink, it can take quite
9623 some time to compile it over and over again for a bunch of object files, so
9624 Microsoft provides a mechanism to compile a set of headers once and then
9625 include the previously compiled headers in any object file. This
9626 technology is called precompiled headers. The general recipe is to create a
9627 file named "StdAfx.cpp" that includes a single header named "StdAfx.h", and
9628 then include every header you want to precompile in "StdAfx.h", and finally
9629 include "StdAfx.h" as the first header in all the source files you are
9630 compiling to object files. For example:
9631
9632 StdAfx.h:
9633 .ES
9634 #include <windows.h>
9635 #include <my_big_header.h>
9636 .EE
9637
9638 StdAfx.cpp:
9639 .ES
9640 #include <StdAfx.h>
9641 .EE
9642
9643 Foo.cpp:
9644 .ES
9645 #include <StdAfx.h>
9646
9647 /* do some stuff */
9648 .EE
9649
9650 Bar.cpp:
9651 .ES
9652 #include <StdAfx.h>
9653
9654 /* do some other stuff */
9655 .EE
9656
9657 SConstruct:
9658 .ES
9659 env=Environment()
9660 env['PCHSTOP'] = 'StdAfx.h'
9661 env['PCH'] = env.PCH('StdAfx.cpp')[0]
9662 env.Program('MyApp', ['Foo.cpp', 'Bar.cpp'])
9663 .EE
9664
9665 For more information see the document for the PCH builder, and the PCH and
9666 PCHSTOP construction variables. To learn about the details of precompiled
9667 headers consult the MSDN documention for /Yc, /Yu, and /Yp.
9668
9669 .SS Using Microsoft Visual C++ external debugging information
9670
9671 Since including debugging information in programs and shared libraries can
9672 cause their size to increase significantly, Microsoft provides a mechanism
9673 for including the debugging information in an external file called a PDB
9674 file. SCons supports PDB files through the PDB construction
9675 variable.
9676
9677 SConstruct:
9678 .ES
9679 env=Environment()
9680 env['PDB'] = 'MyApp.pdb'
9681 env.Program('MyApp', ['Foo.cpp', 'Bar.cpp'])
9682 .EE
9683
9684 For more information see the document for the PDB construction variable.
9685
9686 .SH ENVIRONMENT
9687
9688 .IP SCONS_LIB_DIR
9689 Specifies the directory that contains the SCons Python module directory
9690 (e.g. /home/aroach/scons-src-0.01/src/engine).
9691
9692 .IP SCONSFLAGS
9693 A string of options that will be used by scons in addition to those passed
9694 on the command line.
9695
9696 .SH "SEE ALSO"
9697 .B scons
9698 User Manual,
9699 .B scons
9700 Design Document,
9701 .B scons
9702 source code.
9703
9704 .SH AUTHORS
9705 Steven Knight <knight@baldmt.com>
9706 .br
9707 Anthony Roach <aroach@electriceyeball.com>
9708