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