Implement tool chains for AIX, SunOS, and HP-UX. (Steve Leblanc)
[scons.git] / doc / man / scons.1
1 .\" __COPYRIGHT__
2 .\"
3 .\" Permission is hereby granted, free of charge, to any person obtaining
4 .\" a copy of this software and associated documentation files (the
5 .\" "Software"), to deal in the Software without restriction, including
6 .\" without limitation the rights to use, copy, modify, merge, publish,
7 .\" distribute, sublicense, and/or sell copies of the Software, and to
8 .\" permit persons to whom the Software is furnished to do so, subject to
9 .\" the following conditions:
10 .\"
11 .\" The above copyright notice and this permission notice shall be included
12 .\" in all copies or substantial portions of the Software.
13 .\"
14 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
15 .\" KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
16 .\" WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 .\" NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 .\" LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 .\" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 .\" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 .\"
22 .\" __FILE__ __REVISION__ __DATE__ __DEVELOPER__
23 .\"
24 .\" ES - Example Start - indents and turns off line fill
25 .de ES
26 .RS
27 .nf
28 ..
29 .\" EE - Example End - ends indent and turns line fill back on
30 .de EE
31 .RE
32 .fi
33 ..
34 .TH SCONS 1 "April 2003"
35 .SH NAME
36 scons \- a software construction tool
37 .SH SYNOPSIS
38 .B scons
39 [
40 .IR options ...
41 ]
42 [
43 .IR name = val ...
44 ]
45 [
46 .IR targets ...
47 ]
48 .SH DESCRIPTION
49
50 The 
51 .B scons 
52 utility builds software (or other files) by determining which
53 component pieces must be rebuilt and executing the necessary commands to
54 rebuild them.
55
56 By default, 
57 .B scons 
58 searches for a file named 
59 .IR SConstruct ,
60 .IR Sconstruct ,
61 or
62 .I sconstruct
63 (in that order) in the current directory and reads its
64 configuration from the first file found.
65 An alternate file name may be
66 specified via the 
67 .B -f
68 option.
69
70 The
71 .I SConstruct
72 file can specify subsidiary
73 configuration files using the
74 .B SConscript()
75 function.
76 By convention,
77 these subsidiary files are named
78 .IR SConscript ,
79 although any name may be used.
80 (Because of this naming convention,
81 the term "SConscript files"
82 is sometimes used to refer
83 generically to all
84 .B scons
85 configuration files,
86 regardless of actual file name.)
87
88 The configuration files
89 specify the target files to be built, and
90 (optionally) the rules to build those targets.  Reasonable default
91 rules exist for building common software components (executable
92 programs, object files, libraries), so that for most software
93 projects, only the target and input files need be specified.
94
95 .B scons
96 reads and executes the SConscript files as Python scripts,
97 so you may use normal Python scripting capabilities
98 (such as flow control, data manipulation, and imported Python libraries)
99 to handle complicated build situations.
100 .BR scons ,
101 however, reads all of the SConscript files
102 .I before
103 it begins building any targets.
104 To make this obvious,
105 .B scons
106 prints the following messages about what it is doing:
107
108 .ES
109 $ scons foo.out
110 scons: Reading SConscript files ...
111 scons: done reading SConscript files.
112 scons: Building targets  ...
113 cp foo.in foo.out
114 scons: done building targets.
115 $
116 .EE
117
118 The status messages
119 (everything except the line that reads "cp foo.in foo.out")
120 may be suppressed using the
121 .B -Q
122 option.
123
124 .B scons
125 can scan known input files automatically for dependency
126 information (for example, #include statements
127 in C or C++ files) and will rebuild dependent files appropriately
128 whenever any "included" input file changes. 
129 .B scons
130 supports the
131 ability to define new scanners for unknown input file types.
132
133 .B scons
134 knows how to fetch files automatically from
135 SCCS or RCS subdirectories
136 using SCCS, RCS or BitKeeper.
137
138 .B scons
139 is normally executed in a top-level directory containing a
140 .I SConstruct
141 file, optionally specifying
142 as command-line arguments
143 the target file or files to be built.
144
145 By default, the command
146
147 .ES
148 scons
149 .EE
150
151 will build all target files in or below the current directory.
152 Explicit default targets
153 (to be built when no targets are specified on the command line)
154 may be defined the SConscript file(s)
155 using the
156 .B Default()
157 function, described below.
158
159 Even when
160 .B Default()
161 targets are specified in the SConscript file(s),
162 all target files in or below the current directory
163 may be built by explicitly specifying
164 the current directory (.)
165 as a command-line target:
166
167 .ES
168 scons .
169 .EE
170
171 Building all target files,
172 including any files outside of the current directory,
173 may be specified by supplying a command-line target
174 of the root directory (on POSIX systems):
175
176 .ES
177 scons /
178 .EE
179
180 or the path name(s) of the volume(s) in which all the targets
181 should be built (on Windows systems):
182
183 .ES
184 scons C:\ D:\
185 .EE
186
187 To build only specific targets,
188 supply them as command-line arguments:
189
190 .ES
191 scons foo bar
192 .EE
193
194 in which case only the specified targets will be built
195 (along with any derived files on which they depend).
196
197 Specifying "cleanup" targets in SConscript files is not
198 necessary.  The 
199 .B -c
200 flag removes all files
201 necessary to build the specified target:
202
203 .ES
204 scons -c .
205 .EE
206
207 to remove all target files, or:
208
209 .ES
210 scons -c build export
211 .EE
212
213 to remove target files under build and export.
214 Additional files or directories to remove can be specified using the
215 Clean() function.
216
217 A subset of a hierarchical tree may be built by
218 remaining at the top-level directory (where the 
219 .I SConstruct
220 file lives) and specifying the subdirectory as the target to be
221 built:
222
223 .ES
224 scons src/subdir
225 .EE
226
227 or by changing directory and invoking scons with the
228 .B -u
229 option, which traverses up the directory
230 hierarchy until it finds the 
231 .I SConstruct
232 file, and then builds
233 targets relatively to the current subdirectory:
234
235 .ES
236 cd src/subdir
237 scons -u .
238 .EE
239
240 .B scons
241 supports building multiple targets in parallel via a
242 .B -j
243 option that takes, as its argument, the number
244 of simultaneous tasks that may be spawned:
245
246 .ES
247 scons -j 4
248 .EE
249
250 builds four targets in parallel, for example.
251
252 .B scons
253 can maintain a cache of target (derived) files that can
254 be shared between multiple builds.  When caching is enabled in a
255 SConscript file, any target files built by 
256 .B scons
257 will be copied
258 to the cache.  If an up-to-date target file is found in the cache, it
259 will be retrieved from the cache instead of being rebuilt locally.
260 Caching behavior may be disabled and controlled in other ways by the
261 .BR --cache-force , 
262 .BR --cache-disable ,
263 and
264 .B --cache-show
265 command-line options.  The
266 .B --random
267 option is useful to prevent multiple builds
268 from trying to update the cache simultaneously.
269
270 Values of variables to be passed to the SConscript file(s)
271 may be specified on the command line:
272
273 .ES
274 scons debug=1 .
275 .EE
276
277 These variables are available in SConscript files
278 through the ARGUMENTS dictionary,
279 and can be used in the SConscript file(s) to modify
280 the build in any way:
281
282 .ES
283 if ARGUMENTS.get('debug', 0):
284     env = Environment(CCFLAGS = '-g')
285 else:
286     env = Environment()
287 .EE
288
289 .B scons
290 requires Python version 1.5.2 or later.
291 There should be no other dependencies or requirements to run
292 .B scons.
293
294 .\" The following paragraph reflects the default tool search orders
295 .\" currently in SCons/Tool/__init__.py.  If any of those search orders
296 .\" change, this documentation should change, too.
297 By default,
298 .B scons
299 knows how to search for available programming tools
300 on various systems.
301 On WIN32 systems,
302 .B scons
303 searches in order for the
304 Microsoft Visual C++ tools,
305 the MinGW tool chain,
306 the Intel compiler tools,
307 and the PharLap ETS compiler.
308 On OS/2 systems,
309 .B scons
310 searches in order for the 
311 OS/2 compiler,
312 the GCC tool chain,
313 and the Microsoft Visual C++ tools,
314 On SGI IRIX, IBM AIX, Hewlett Packard HP-UX, and Sun Solaris systems,
315 .B scons
316 searches for the native compiler tools
317 (MIPSpro, Visual Age, aCC, and Forte tools respectively)
318 and the GCC tool chain.
319 On all other platforms,
320 including POSIX (Linux and UNIX) platforms,
321 .B scons
322 searches in order
323 for the GCC tool chain,
324 the Microsoft Visual C++ tools,
325 and the Intel compiler tools.
326 You may, of course, override these default values
327 by appropriate configuration of
328 Environment construction variables.
329
330 .SH OPTIONS
331 In general, 
332 .B scons 
333 supports the same command-line options as GNU
334 .BR make , 
335 and many of those supported by 
336 .BR cons .
337
338 .TP
339 -b
340 Ignored for compatibility with non-GNU versions of
341 .BR make.
342
343 .TP
344 -c, --clean, --remove
345 Clean up by removing all target files for which a construction
346 command is specified.
347 Also remove any files or directories associated to the construction command
348 using the Clean() function.
349
350 .TP
351 --cache-disable, --no-cache
352 Disable the derived-file caching specified by
353 .BR CacheDir ().
354 .B scons
355 will neither retrieve files from the cache
356 nor copy files to the cache.
357
358 .TP
359 --cache-force, --cache-populate
360 When using
361 .BR CacheDir (),
362 populate a cache by copying any already-existing, up-to-date
363 derived files to the cache,
364 in addition to files built by this invocation.
365 This is useful to populate a new cache with
366 all the current derived files,
367 or to add to the cache any derived files
368 recently built with caching disabled via the
369 .B --cache-disable
370 option.
371
372 .TP
373 --cache-show
374 When using
375 .BR CacheDir ()
376 and retrieving a derived file from the cache,
377 show the command
378 that would have been executed to build the file,
379 instead of the usual report,
380 "Retrieved `file' from cache."
381 This will produce consistent output for build logs,
382 regardless of whether a target
383 file was rebuilt or retrieved from the cache.
384
385 .TP 
386 .RI "-C" " directory" ",  --directory=" directory
387 Change to the specified 
388 .I directory
389 before searching for the 
390 .IR SConstruct ,
391 .IR Sconstruct ,
392 or
393 .I sconstruct
394 file, or doing anything
395 else.  Multiple 
396 .B -C
397 options are interpreted
398 relative to the previous one, and the right-most
399 .B -C
400 option wins. (This option is nearly
401 equivalent to 
402 .BR "-f directory/SConstruct" ,
403 except that it will search for
404 .IR SConstruct ,
405 .IR Sconstruct , 
406 or
407 .I sconstruct
408 in the specified directory.)
409
410 .\" .TP
411 .\" -d
412 .\" Display dependencies while building target files.  Useful for
413 .\" figuring out why a specific file is being rebuilt, as well as
414 .\" general debugging of the build process.
415
416 .TP
417 -D
418 Works exactly the same way as the
419 .B -u
420 option except for the way default targets are handled.
421 When this option is used and no targets are specified on the command line,
422 all default targets are built, whether or not they are below the current
423 directory.
424
425 .TP
426 .RI --debug= type
427 Debug the build process.
428 .I type
429 specifies what type of debugging:
430
431 .TP
432 .RI --debug=pdb
433 Re-run SCons under the control of the
434 .RI pdb
435 Python debugger.
436 The
437 .RI --debug=pdb
438 argument will be stripped from the command-line,
439 but all other arguments will be passed in-order
440 to the SCons invocation run by the debugger.
441
442 .TP
443 .RI --debug=tree
444 Print the dependency tree
445 after each top-level target is built. This prints out the complete
446 dependency tree including implicit dependencies and ignored
447 dependencies.
448
449 .TP
450 .RI --debug=dtree
451 Print the dependency tree
452 after each top-level target is built. This prints out only derived files.
453
454 .TP
455 .RI --debug=time
456 Prints various time profiling information: the time spent
457 executing each build command, the total build time, the total time spent
458 executing build commands, the total time spent executing SConstruct and
459 SConscript files, and the total time spent executing SCons itself.
460
461 .TP
462 .RI --debug=includes
463 Print the include tree after each top-level target is built. 
464 This is generally used to find out what files are included by the sources
465 of a given derived file:
466
467 .ES
468 $ scons --debug=includes foo.o
469 .EE
470
471 .TP
472 -e, --environment-overrides
473 Variables from the execution environment override construction
474 variables from the SConscript files.
475
476 .TP
477 .RI -f " file" ", --file=" file ", --makefile=" file ", --sconstruct=" file
478 Use 
479 .I file 
480 as the initial SConscript file.
481
482 .TP 
483 -h, --help
484 Print a local help message for this build, if one is defined in
485 the SConscript file(s), plus a line that describes the 
486 .B -H
487 option for command-line option help.  If no local help message
488 is defined, prints the standard help message about command-line
489 options.  Exits after displaying the appropriate message.
490
491 .TP
492 -H, --help-options
493 Print the standard help message about command-line options and
494 exit.
495
496 .TP
497 -i, --ignore-errors
498 Ignore all errors from commands executed to rebuild files.
499
500 .TP 
501 .RI -I " directory" ", --include-dir=" directory
502 Specifies a 
503 .I directory
504 to search for
505 imported Python modules.  If several 
506 .B -I
507 options
508 are used, the directories are searched in the order specified.
509
510 .TP
511 --implicit-cache
512 Cache implicit dependencies. This can cause 
513 .B scons
514 to miss changes in the implicit dependencies in cases where a new implicit
515 dependency is added earlier in the implicit dependency search path
516 (e.g. CPPPATH) than a current implicit dependency with the same name.
517
518 .TP
519 --implicit-deps-changed
520 Force SCons to ignore the cached implicit dependencies. This causes the
521 implicit dependencies to be rescanned and recached. This implies
522 .BR --implicit-cache .
523
524 .TP
525 --implicit-deps-unchanged
526 Force SCons to ignore changes in the implicit dependencies.
527 This causes cached implicit dependencies to always be used.
528 This implies 
529 .BR --implicit-cache .
530
531 .TP
532 .RI -j " N" ", --jobs=" N
533 Specifies the number of jobs (commands) to run simultaneously.
534 If there is more than one 
535 .B -j 
536 option, the last one is effective.
537 .\" ??? If the 
538 .\" .B -j 
539 .\" option
540 .\" is specified without an argument,
541 .\" .B scons 
542 .\" will not limit the number of
543 .\" simultaneous jobs.
544
545 .TP
546 -k, --keep-going
547 Continue as much as possible after an error.  The target that
548 failed and those that depend on it will not be remade, but other
549 targets specified on the command line will still be processed.
550
551 .\" .TP
552 .\" .RI  -l " N" ", --load-average=" N ", --max-load=" N
553 .\" No new jobs (commands) will be started if
554 .\" there are other jobs running and the system load
555 .\" average is at least 
556 .\" .I N
557 .\" (a floating-point number).
558 .\"
559 .\" .TP
560 .\" --list-derived
561 .\" List derived files (targets, dependencies) that would be built,
562 .\" but do not build them.
563 .\" [XXX This can probably go away with the right
564 .\" combination of other options.  Revisit this issue.]
565 .\"
566 .\" .TP
567 .\" --list-actions
568 .\" List derived files that would be built, with the actions
569 .\" (commands) that build them.  Does not build the files.
570 .\" [XXX This can probably go away with the right
571 .\" combination of other options.  Revisit this issue.]
572 .\"
573 .\" .TP
574 .\" --list-where
575 .\" List derived files that would be built, plus where the file is
576 .\" defined (file name and line number).  Does not build the files.
577 .\" [XXX This can probably go away with the right
578 .\" combination of other options.  Revisit this issue.]
579
580 .TP
581 -m
582 Ignored for compatibility with non-GNU versions of
583 .BR make .
584
585 .TP
586 .RI --max-drift= SECONDS
587 Set the maximum expected drift in the modification time of files to 
588 .IR SECONDS .
589 This value determines how old a file must be before its content signature
590 is cached. The default value is 2 days, which means a file must have a
591 modification time of at least two days ago in order to have its content
592 signature cached. A negative value means to never cache the content
593 signature and to ignore the cached value if there already is one. A value
594 of 0 means to always cache the signature, no matter how old the file is.
595
596 .TP
597 -n, --just-print, --dry-run, --recon
598 No execute.  Print the commands that would be executed to build
599 any out-of-date target files, but do not execute the commands.
600
601 .\" .TP
602 .\" .RI -o " file" ", --old-file=" file ", --assume-old=" file
603 .\" Do not rebuild 
604 .\" .IR file ,
605 .\" and do
606 .\" not rebuild anything due to changes in the contents of
607 .\" .IR file .
608 .\" .TP 
609 .\" .RI --override " file"
610 .\" Read values to override specific build environment variables
611 .\" from the specified 
612 .\" .IR file .
613 .\" .TP
614 .\" -p
615 .\" Print the data base (construction environments,
616 .\" Builder and Scanner objects) that are defined
617 .\" after reading the SConscript files.
618 .\" After printing, a normal build is performed
619 .\" as usual, as specified by other command-line options.
620 .\" This also prints version information
621 .\" printed by the 
622 .\" .B -v
623 .\" option.
624 .\"
625 .\" To print the database without performing a build do:
626 .\"
627 .\" .ES
628 .\" scons -p -q
629 .\" .EE
630
631 .TP
632 .RI --profile= file
633 Run SCons under the Python profiler
634 and save the results in the specified
635 .IR file .
636 The results may be analyzed using the Python
637 pstats module.
638 .TP
639 -q, --question
640 Do not run any commands, or print anything.  Just return an exit
641 status that is zero if the specified targets are already up to
642 date, non-zero otherwise.
643 .TP
644 -Q
645 Quiets SCons status messages about
646 reading SConscript files,
647 building targets
648 and entering directories.
649 Commands that are executed
650 to rebuild target files are still printed.
651
652 .\" .TP
653 .\" -r, -R, --no-builtin-rules, --no-builtin-variables
654 .\" Clear the default construction variables.  Construction
655 .\" environments that are created will be completely empty.
656
657 .TP
658 --random
659 Build dependencies in a random order.  This is useful when
660 building multiple trees simultaneously with caching enabled,
661 to prevent multiple builds from simultaneously trying to build
662 or retrieve the same target files.
663
664 .TP
665 -s, --silent, --quiet
666 Silent.  Do not print commands that are executed to rebuild
667 target files.
668 Also suppresses SCons status messages.
669
670 .TP
671 -S, --no-keep-going, --stop
672 Ignored for compatibility with GNU 
673 .BR make .
674
675 .TP
676 -t, --touch
677 Ignored for compatibility with GNU
678 .BR make .  
679 (Touching a file to make it
680 appear up-to-date is unnecessary when using 
681 .BR scons .)
682
683 .TP
684 -u, --up, --search-up
685 Walks up the directory structure until an 
686 .I SConstruct ,
687 .I Sconstruct
688 or 
689 .I sconstruct
690 file is found, and uses that
691 as the top of the directory tree. Only targets at or below the
692 current directory will be built.
693
694 .TP
695 -U
696 Works exactly the same way as the
697 .B -u
698 option except for the way default targets are handled.
699 When this option is used and no targets are specified on the command line,
700 all default targets that are defined in the SConscript(s) in the current
701 directory are built, regardless of what directory the resultant targets end
702 up in.
703
704 .TP
705 -v, --version
706 Print the 
707 .B scons
708 version, copyright information,
709 list of authors, and any other relevant information.
710 Then exit.
711
712 .TP
713 -w, --print-directory
714 Print a message containing the working directory before and
715 after other processing.
716
717 .TP
718 .RI --warn= type ", --warn=no-" type
719 Enable or disable warnings.
720 .I type
721 specifies the type of warnings to be enabled or disabled:
722
723 .TP
724 .RI --warn=all ", " --warn=no-all
725 Enables or disables all warnings.
726
727 .TP
728 .RI --warn=dependency ", " --warn=no-dependency
729 Enables or disables warnings about dependencies.
730 These warnings are disabled by default.
731
732 .TP
733 .RI --warn=deprecated ", " --warn=no-deprecated
734 Enables or disables warnings about use of deprecated features.
735 These warnings are enabled by default.
736
737 .TP
738 --no-print-directory
739 Turn off -w, even if it was turned on implicitly.
740
741 .\" .TP
742 .\" .RI --write-filenames= file
743 .\" Write all filenames considered into
744 .\" .IR file .
745 .\"
746 .\" .TP
747 .\" .RI -W " file" ", --what-if=" file ", --new-file=" file ", --assume-new=" file
748 .\" Pretend that the target 
749 .\" .I file 
750 .\" has been
751 .\" modified.  When used with the 
752 .\" .B -n
753 .\" option, this
754 .\" show you what would be rebuilt if you were to modify that file.
755 .\" Without 
756 .\" .B -n
757 .\" ... what? XXX
758 .\"
759 .\" .TP
760 .\" --warn-undefined-variables
761 .\" Warn when an undefined variable is referenced.
762
763 .TP 
764 .RI -Y " repository" ", --repository=" repository
765 Search the specified repository for any input and target
766 files not found in the local directory hierarchy.  Multiple
767 .B -Y
768 options may specified, in which case the
769 repositories are searched in the order specified.
770
771 .SH CONFIGURATION FILE REFERENCE
772 .\" .SS Python Basics
773 .\" XXX Adding this in the future would be a help.
774 .SS Construction Environments
775 A construction environment is the basic means by which the SConscript
776 files communicate build information to 
777 .BR scons .
778 A new construction environment is created using the 
779 .B Environment 
780 function:
781
782 .ES
783 env = Environment()
784 .EE
785
786 By default, a new construction environment is
787 initialized with a set of builder methods
788 and construction variables that are appropriate
789 for the current platform.
790 An optional platform keyword argument may be
791 used to specify that an environment should
792 be initialized for a different platform:
793
794 .ES
795 env = Environment(platform = 'cygwin')
796 env = Environment(platform = 'os2')
797 env = Environment(platform = 'posix')
798 env = Environment(platform = 'win32')
799 .EE
800
801 Specifying a platform initializes the appropriate
802 construction variables in the environment
803 to use and generate file names with prefixes
804 and suffixes appropriate for the platform.
805
806 Note that the
807 .B win32
808 platform adds the
809 .B SYSTEMROOT
810 variable from the user's external environment
811 to the construction environment's
812 .B ENV
813 dictionary.
814 This is so that any executed commands
815 that use sockets to connect with other systems
816 (such as fetching source files from
817 external CVS repository specifications like 
818 .BR :pserver:anonymous:@cvs.sourceforge.net:/cvsroot/scons )
819 will work on Win32 systems.
820
821 The platform argument may be function or callable object,
822 in which case the Environment() method
823 will call the specified argument to update
824 the new construction environment:
825
826 .ES
827 def my_platform(env):
828     env['VAR'] = 'xyzzy'
829
830 env = Environment(platform = my_platform)
831 .EE
832
833 Additionally, a specific set of tools
834 with which to initialize the environment
835 may specified as an optional keyword argument:
836
837 .ES
838 env = Environment(tools = ['msvc', 'lex'])
839 .EE
840
841 The elements of the tools list may also
842 be functions or callable objects,
843 in which case the Environment() method
844 will call the specified elements
845 to update the new construction environment:
846
847 .ES
848 def my_tool(env):
849     env['XYZZY'] = 'xyzzy'
850
851 env = Environment(tools = [my_tool])
852 .EE
853
854 The tool definition (i.e. my_tool()) can use the PLATFORM variable from
855 the environment it receives to customize the tool for different platforms.
856
857 If no tool list is specified, then SCons will auto-detect the installed
858 tools using the PATH variable in the ENV construction variable and the
859 platform name when the Environment is constructed. Changing the PATH
860 variable after the Environment is constructed will not cause the tools to
861 be redetected.
862
863 SCons supports the following tool specifications
864 out of the box on all platforms:
865 .ES
866 386asm
867 ar
868 dvipdf
869 dvips
870 g++
871 g77
872 gs
873 icc
874 ifl
875 ilink
876 gas
877 gcc
878 gnulink
879 jar
880 javac
881 latex
882 lex
883 linkloc
884 masm
885 midl
886 mingw
887 mslib
888 mslink
889 msvc
890 nasm
891 pdflatex
892 pdftex
893 sgiar
894 sgias
895 sgicc
896 sgif77
897 sgilink
898 tar
899 tex
900 yacc
901 zip
902 .EE
903
904 Additionally, there is a "tool" named
905 .B default
906 which configures the
907 environment with a default set of tools for the current platform.
908
909 On posix and cygwin platforms
910 the GNU tools (e.g. gcc) are preferred by SCons,
911 on win32 the Microsoft tools (e.g. msvc)
912 followed by MinGW are preferred by SCons,
913 and in OS/2 the IBM tools (e.g. icc) are preferred by SCons.
914
915 .SS Builder Methods
916
917 Build rules are specified by calling a construction
918 environment's builder methods.
919 The arguments to the builder methods are
920 .B target
921 (a list of target files)
922 and
923 .B source
924 (a list of source files).
925
926 Because long lists of file names
927 can lead to a lot of quoting,
928 .B scons
929 supplies a
930 .B Split()
931 function that splits a single string
932 into a list, separated on
933 strings of white-space characters.
934 (This is similar to the
935 string.split() method
936 from the standard Python library.)
937
938 Like all Python arguments,
939 the target and source arguments to a builder
940 can be specified either with or without
941 the "target" and "source" keywords.
942 When the keywords are omitted,
943 the target is first,
944 followed by the source.
945 The following are equivalent examples of calling the Program builder:
946
947 .ES
948 env.Program('bar', ['bar.c', 'foo.c'])
949 env.Program('bar', Split('bar.c foo.c'))
950 env.Program(source =  ['bar.c', 'foo.c'], target = 'bar')
951 env.Program(target = 'bar', Split('bar.c foo.c'))
952 env.Program('bar', source = string.split('bar.c foo.c'))
953 .EE
954
955 When the target shares the same base name
956 as the source and only the suffix varies,
957 and if the builder has a suffix defined for the target file type,
958 then the target argument may be omitted completely,
959 and
960 .B scons
961 will deduce the target file name from
962 the source file name.
963 The following examples all build the
964 executable program
965 .B bar
966 (on POSIX systems)
967 or 
968 .B bar.exe
969 (on Windows systems)
970 from the bar.c source file:
971
972 .ES
973 env.Program(target = 'bar', source = 'bar.c')
974 env.Program('bar', source = 'bar.c')
975 env.Program(source = 'bar.c')
976 env.Program('bar.c')
977 .EE
978
979 It is possible to override or add construction variables when calling a
980 builder by passing additional keyword arguments. These overridden or added
981 variables will only be in effect when building the target, so they will not
982 affect other parts of the build. For example, if you want to add additional
983 libraries for just one program:
984
985 .ES
986 env.Program('hello', 'hello.c', LIBS=['gl', 'glut'])
987 .EE
988
989 or generate a shared library with a nonstandard suffix:
990
991 .ES
992 env.SharedLibrary('word', 'word.cpp', SHLIBSUFFIX='.ocx')
993 .EE
994
995 All Builders return a Node or a list of Nodes,
996 representing the target or targets that will be built.
997 A list of Nodes is returned if there is more than one target,
998 and a single Node is returned if there is only one target.
999 A
1000 .I Node
1001 is an internal SCons object
1002 which represents
1003 build targets or sources.
1004
1005 The returned Node(s)
1006 can be passed to other builder methods as source(s)
1007 or passed into to any SCons function or method
1008 where a filename would normally be accepted.
1009 For example, if it were necessary
1010 to add a specific
1011 .B -D
1012 flag when compiling one specific object file:
1013
1014 .ES
1015 bar_obj = env.StaticObject('bar.c', CCFLAGS='-DBAR')
1016 env.Program(source = ['foo.c', bar_obj, 'main.c'])
1017 .EE
1018
1019 Using a Node in this way
1020 makes for a more portable build
1021 by avoiding having to specify
1022 a platform-specific object suffix
1023 when calling the Program() builder.
1024
1025 The path name for a Node's file may be used
1026 by passing the Node to the Python-builtin
1027 .B str()
1028 function:
1029
1030 .ES
1031 bar_obj = env.StaticObject('bar.c', CCFLAGS='-DBAR')
1032 print "The path to bar_obj is:", str(bar_obj)
1033 .EE
1034
1035 .B scons
1036 provides the following builders:
1037
1038 .IP StaticObject
1039 Builds a static object file
1040 from one or more C, C++, or Fortran source files.
1041 Source files must have one of the following extensions:
1042 .ES
1043   .asm    assembly language file
1044   .ASM    assembly language file
1045   .c      C file
1046   .C      WIN32:  C file
1047           POSIX:  C++ file
1048   .cc     C++ file
1049   .cpp    C++ file
1050   .cxx    C++ file
1051   .cxx    C++ file
1052   .c++    C++ file
1053   .C++    C++ file
1054   .f      Fortran file
1055   .F      WIN32:  Fortran file
1056           POSIX:  Fortran file + C pre-processor
1057   .for    Fortran file
1058   .FOR    Fortran file
1059   .fpp    Fortran file + C pre-processor
1060   .FPP    Fortran file + C pre-processor
1061   .s      assembly language file
1062   .S      WIN32:  assembly language file
1063           POSIX:  assembly language file + C pre-processor
1064   .spp    assembly language file + C pre-processor
1065   .SPP    assembly language file + C pre-processor
1066 .EE
1067 .IP
1068 The target object file prefix
1069 (specified by the $OBJPREFIX construction variable; nothing by default)
1070 and suffix
1071 (specified by the $OBJSUFFIX construction variable;
1072 \.obj on Windows systems, .o on POSIX systems)
1073 are automatically added to the target if not already present.
1074 Examples:
1075
1076 .ES
1077 env.StaticObject(target = 'aaa', source = 'aaa.c')
1078 env.StaticObject(target = 'bbb.o', source = 'bbb.c++')
1079 env.StaticObject(target = 'ccc.obj', source = 'ccc.f')
1080 .EE
1081 .IP SharedObject
1082 Builds an object file for
1083 inclusion in a shared library.
1084 Source files must have one of the same set of extensions
1085 specified above for the
1086 .B StaticObject
1087 builder. On some platforms building a shared object requires additional
1088 compiler options (e.g. -fPIC for gcc) in addition to those needed to build a
1089 normal (static) object, but on some platforms there is no difference between a
1090 shared object and a normal (static) one. When there is a difference, SCons
1091 will only allow shared objects to be linked into a shared library, and will
1092 use a different suffix for shared objects. On platforms where there is no
1093 difference, SCons will allow both normal (static)
1094 and shared objects to be linked into a
1095 shared library, and will use the same suffix for shared and normal
1096 (static) objects.
1097 The target object file prefix
1098 (specified by the $SHOBJPREFIX construction variable;
1099 by default, the same as $OBJPREFIX)
1100 and suffix
1101 (specified by the $SHOBJSUFFIX construction variable)
1102 are automatically added to the target if not already present. 
1103 Examples:
1104
1105 .ES
1106 env.SharedObject(target = 'ddd', source = 'ddd.c')
1107 env.SharedObject(target = 'eee.o', source = 'eee.cpp')
1108 env.SharedObject(target = 'fff.obj', source = 'fff.for')
1109 .EE
1110
1111 .IP Object
1112 A synonym for the
1113 .B StaticObject
1114 builder.
1115
1116 .IP PCH
1117 Builds a Microsoft Visual C++ precompiled header. Calling this builder
1118 returns a list of two targets: the PCH as the first element, and the object
1119 file as the second element. Normally the object file is ignored. This builder is only
1120 provided when Microsoft Visual C++ is being used as the compiler. 
1121 The PCH builder is generally used in
1122 conjuction with the PCH construction variable to force object files to use
1123 the precompiled header:
1124
1125 .ES
1126 env['PCH'] = env.PCH('StdAfx.cpp')[0]
1127 .EE
1128
1129 .IP Program
1130 Builds an executable given one or more object files or C, C++
1131 or Fortran source files.
1132 If any C, C++ or Fortran source files are specified,
1133 then they will be automatically
1134 compiled to object files using the
1135 .B Object
1136 builder;
1137 see that builder's description for
1138 a list of legal source file suffixes
1139 and how they are interpreted.
1140 The target executable file prefix
1141 (specified by the $PROGPREFIX construction variable; nothing by default)
1142 and suffix
1143 (specified by the $PROGSUFFIX construction variable;
1144 by default, .exe on Windows systems, nothing on POSIX systems)
1145 are automatically added to the target if not already present.
1146 Example:
1147
1148 .ES
1149 env.Program(target = 'foo', source = ['foo.o', 'bar.c', 'baz.f'])
1150 .EE
1151
1152 .IP RES
1153 Builds a Microsoft Visual C++ resource file.
1154 This builder is only provided
1155 when Microsoft Visual C++ or MinGW is being used as the compiler. The
1156 .I .res
1157 (or 
1158 .I .o 
1159 for MinGW) suffix is added to the target name if no other suffix is given. The source
1160 file is scanned for implicit dependencies as though it were a C file. Example:
1161
1162 .ES
1163 env.RES('resource.rc')
1164 .EE
1165
1166 .IP StaticLibrary
1167 Builds a static library given one or more object files
1168 or C, C++ or Fortran source files.
1169 If any source files are given,
1170 then they will be automatically
1171 compiled to object files.
1172 The static library prefix and suffix (if any)
1173 are automatically added to the target.
1174 The target library file prefix
1175 (specified by the $LIBPREFIX construction variable;
1176 by default, lib on POSIX systems, nothing on Windows systems)
1177 and suffix
1178 (specified by the $LIBSUFFIX construction variable;
1179 by default, .lib on Windows systems, .a on POSIX systems)
1180 are automatically added to the target if not already present.
1181 Example:
1182
1183 .ES
1184 env.StaticLibrary(target = 'bar', source = ['bar.c', 'foo.o'])
1185 .EE
1186
1187 .IP
1188 Any object files listed in the
1189 .B source
1190 must have been built for a static library
1191 (that is, using the
1192 .B StaticObject
1193 builder).
1194 .B scons
1195 will raise an error if there is any mismatch.
1196
1197 .IP SharedLibrary
1198 Builds a shared library
1199 (.so on a POSIX system, .dll on WIN32)
1200 given one or more object files
1201 or C, C++ or Fortran source files.
1202 If any source files are given,
1203 then they will be automatically
1204 compiled to object files.
1205 The static library prefix and suffix (if any)
1206 are automatically added to the target.
1207 The target library file prefix
1208 (specified by the $SHLIBPREFIX construction variable;
1209 by default, lib on POSIX systems, nothing on Windows systems)
1210 and suffix
1211 (specified by the $SHLIBSUFFIX construction variable;
1212 by default, .dll on Windows systems, .so on POSIX systems)
1213 are automatically added to the target if not already present.
1214 Example:
1215
1216 .ES
1217 env.SharedLibrary(target = 'bar', source = ['bar.c', 'foo.o'])
1218 .EE
1219 .IP
1220 On WIN32 systems, the
1221 .B SharedLibrary
1222 builder will always build an import (.lib) library
1223 in addition to the shared (.dll) library,
1224 adding a .lib library with the same basename
1225 if there is not already a .lib file explicitly
1226 listed in the targets.
1227
1228 Any object files listed in the
1229 .B source
1230 must have been built for a shared library
1231 (that is, using the
1232 .B SharedObject
1233 builder).
1234 .B scons
1235 will raise an error if there is any mismatch.
1236 .IP
1237 On WIN32 systems, specifying "register=1" will cause the dll to be
1238 registered after it is built using REGSVR32.  The command that is run
1239 ("regsvr32" by default) is determined by $REGSVR construction
1240 variable, and the flags passed are determined by $REGSVRFLAGS.  By
1241 default, $REGSVRFLAGS includes "/s", to prevent dialogs from popping
1242 up and requiring user attention when it is run.  If you change
1243 $REGSVRFLAGS, be sure to include "/s".  For example,
1244
1245 .ES
1246 env.SharedLibrary(target = 'bar',
1247                   source = ['bar.cxx', 'foo.obj'],
1248                   register=1)
1249 .EE
1250
1251 .IP
1252 will register "bar.dll" as a COM object when it is done linking it.
1253
1254 .IP Library
1255 A synonym for the
1256 .B StaticLibrary
1257 builder.
1258
1259 .IP CFile
1260 Builds a C source file given a lex (.l) or yacc (.y) input file.
1261 The suffix specified by the $CFILESUFFIX construction variable
1262 (.c by default)
1263 is automatically added to the target
1264 if it is not already present. Example:
1265
1266 .ES
1267 # builds foo.c
1268 env.CFile(target = 'foo.c', source = 'foo.l')
1269 # builds bar.c
1270 env.CFile(target = 'bar', source = 'bar.y')
1271 .EE
1272
1273 .IP CXXFile
1274 Builds a C++ source file given a lex (.ll) or yacc (.yy) input file.
1275 The suffix specified by the $CXXFILESUFFIX construction variable
1276 (.cc by default)
1277 is automatically added to the target
1278 if it is not already present. Example:
1279
1280 .ES
1281 # builds foo.cc
1282 env.CXXFile(target = 'foo.cc', source = 'foo.ll')
1283 # builds bar.cc
1284 env.CXXFile(target = 'bar', source = 'bar.yy')
1285 .EE
1286
1287 .IP Jar
1288 Builds a Java archive (.jar) file
1289 from a source tree of .class files.
1290 .ES
1291 env.Jar(target = 'foo.jar', source = 'classes')
1292 .EE
1293
1294 .IP Java
1295 Builds one or more Java class files
1296 from a source tree of .java files.
1297 The class files will be placed underneath
1298 the specified target directory.
1299 SCons will parse each source .java file
1300 to find the classes
1301 (including inner classes)
1302 defined within that file,
1303 and from that figure out the
1304 target .class files that will be created.
1305 SCons will also search each Java file
1306 for the Java package name,
1307 which it assumes can be found on a line
1308 beginning with the string
1309 .B package
1310 in the first column;
1311 the resulting .class files
1312 will be placed in a directory reflecting
1313 the specified package name.
1314 For example,
1315 the file
1316 .I Foo.java
1317 defining a single public
1318 .I Foo
1319 class and
1320 containing a package name of
1321 .I sub.dir
1322 will generate a corresponding
1323 .IR sub/dir/Foo.class
1324 class file.
1325
1326 Example:
1327
1328 .ES
1329 env.Java(target = 'classes', source = 'src')
1330 .EE
1331
1332 .IP TypeLibrary
1333 Builds a Windows type library (.tlb) file from and input IDL file
1334 (.idl).  In addition, it will build the associated inteface stub and
1335 proxy source files.  It names them according to the base name of the .idl file.
1336 .IP
1337 For example,
1338
1339 .ES
1340 env.TypeLibrary(source="foo.idl")
1341 .EE
1342 .IP
1343 Will create foo.tlb, foo.h, foo_i.c, foo_p.c, and foo_data.c.
1344
1345 .IP DVI
1346 Builds a .dvi file from a .tex, .ltx or .latex input file.
1347 The suffix .dvi
1348 (hard-coded within TeX itself)
1349 is automatically added to the target
1350 if it is not already present. Example:
1351
1352 .ES
1353 # builds from aaa.tex
1354 env.DVI(target = 'aaa.dvi', source = 'aaa.tex')
1355 # builds bbb.dvi
1356 env.DVI(target = 'bbb', source = 'bbb.ltx')
1357 # builds from ccc.latex
1358 env.DVI(target = 'ccc.dvi', source = 'ccc.latex')
1359 .EE
1360
1361 .IP PDF
1362 Builds a .pdf file from a .dvi input file
1363 (or, by extension, a .tex, .ltx, or .latex input file).
1364 The suffix specified by the $PDFSUFFIX construction variable
1365 (.pdf by default)
1366 is added automatically to the target
1367 if it is not already present.  Example:
1368
1369 .ES
1370 # builds from aaa.tex
1371 env.PDF(target = 'aaa.pdf', source = 'aaa.tex')
1372 # builds bbb.pdf from bbb.dvi
1373 env.PDF(target = 'bbb', source = 'bbb.dvi')
1374 .EE
1375
1376 .IP PostScript
1377 Builds a .ps file from a .dvi input file
1378 (or, by extension, a .tex, .ltx, or .latex input file).
1379 The suffix specified by the $PSSUFFIX construction variable
1380 (.ps by default)
1381 is added automatically to the target
1382 if it is not already present.  Example:
1383
1384 .ES
1385 # builds from aaa.tex
1386 env.PostScript(target = 'aaa.ps', source = 'aaa.tex')
1387 # builds bbb.ps from bbb.dvi
1388 env.PostScript(target = 'bbb', source = 'bbb.dvi')
1389 .EE
1390 .LP
1391 .B scons
1392 automatically scans
1393 C source files, C++ source files,
1394 Fortran source files with
1395 .B .F
1396 (POSIX systems only),
1397 .B .fpp,
1398 or
1399 .B .FPP
1400 file extensions,
1401 and assembly language files with
1402 .B .S
1403 (POSIX systems only),
1404 .B .spp,
1405 or
1406 .B .SPP
1407 files extensions
1408 for C preprocessor dependencies,
1409 so the dependencies do not need to be specified explicitly.
1410 In addition, all builder
1411 targets automatically depend on their sources.
1412 An explicit dependency can
1413 be specified using the 
1414 .B Depends 
1415 method of a construction environment (see below).
1416
1417 .IP Tar
1418 Builds a tar archive of the specified files
1419 and/or directories.
1420 Unlike most builders,
1421 the
1422 .B Tar
1423 builder may be called multiple times
1424 for a given target;
1425 each additional call
1426 adds to the list of entries
1427 that will be built into the archive.
1428
1429 .ES
1430 env.Tar('src.tar', 'src')
1431
1432 # Create the stuff.tar file.
1433 env.Tar('stuff', ['subdir1', 'subdir2'])
1434 # Also add "another" to the stuff.tar file.
1435 env.Tar('stuff', 'another')
1436
1437 # Set TARFLAGS to create a gzip-filtered archive.
1438 env = Environment(TARFLAGS = '-c -z')
1439 env.Tar('foo.tar.gz', 'foo')
1440
1441 # Also set the suffix to .tgz.
1442 env = Environment(TARFLAGS = '-c -z',
1443                   TARSUFFIX = '.tgz')
1444 env.Tar('foo')
1445 .EE
1446
1447 .IP Zip
1448 Builds a zip archive of the specified files
1449 and/or directories.
1450 Unlike most builders,
1451 the
1452 .B Zip
1453 builder may be called multiple times
1454 for a given target;
1455 each additional call
1456 adds to the list of entries
1457 that will be built into the archive.
1458
1459 .ES
1460 env.Zip('src.zip', 'src')
1461
1462 # Create the stuff.zip file.
1463 env.Zip('stuff', ['subdir1', 'subdir2'])
1464 # Also add "another" to the stuff.tar file.
1465 env.Zip('stuff', 'another')
1466 .EE
1467
1468 .SS Other Construction Environment Methods
1469 Additional construction environment methods include:
1470
1471 .TP
1472 .RI Alias( alias ", " targets )
1473 Creates a phony target that
1474 expands to one or more other targets.
1475 Returns the Node object representing the alias,
1476 which exists outside of any file system.
1477 This Node object, or the alias name,
1478 may be used as a dependency of any other target,
1479 including another alias. Alias can be called multiple times for the same
1480 alias to add additional targets to the alias. There is also an Alias
1481 global function for creating or referencing an alias independently of
1482 any construction environment.
1483
1484 .ES
1485 env.Alias('install', ['/usr/local/bin', '/usr/local/lib'])
1486 env.Alias('install', ['/usr/local/man'])
1487 .EE
1488
1489 .TP
1490 .RI Append( key = val ", [...])"
1491 Appends the specified keyword arguments
1492 to the end of construction variables in the environment.
1493 If the Environment does not have
1494 the specified construction variable,
1495 it is simply added to the environment.
1496 If the values of the construction variable
1497 and the keyword argument are the same type,
1498 then the two values will be simply added together.
1499 Otherwise, the construction variable
1500 and the value of the keyword argument
1501 are both coerced to lists,
1502 and the lists are added together.
1503 (See also the Prepend method, below.)
1504
1505 .ES
1506 env.Append(CCFLAGS = ' -g', FOO = ['foo.yyy'])
1507 .EE
1508
1509 .TP
1510 .RI BitKeeper( )
1511 A factory function that
1512 returns a Builder object
1513 to be used to fetch source files
1514 using BitKeeper.
1515 The returned Builder
1516 is intended to be passed to the
1517 .B SourceCode
1518 function.
1519 .ES
1520 env.SourceCode('.', env.BitKeeper())
1521 .EE
1522
1523 .TP
1524 .RI Command( target ", " source ", " commands )
1525 Executes a specific action
1526 (or list of actions)
1527 to build a target file or files.
1528 This is more convenient
1529 than defining a separate Builder object
1530 for a single special-case build.
1531
1532 Note that an action can be an external command,
1533 specified as a string,
1534 or a callable Python object;
1535 see "Action Objects," below.
1536 Examples:
1537
1538 .ES
1539 env.Command('foo.out', 'foo.in',
1540             "$FOO_BUILD < $SOURCES > $TARGET")
1541
1542 env.Command('bar.out', 'bar.in',
1543             ["rm -f $TARGET",
1544              "$BAR_BUILD < $SOURCES > $TARGET"])
1545
1546 def rename(env, target, source):
1547     import os
1548     os.rename('.tmp', str(target[0]))
1549
1550 env.Command('baz.out', 'baz.in',
1551             ["$BAZ_BUILD < $SOURCES > .tmp",
1552              rename ])
1553 .EE
1554
1555 .TP
1556 .RI Copy([ key = val ", ...])"
1557 Return a separate copy of a construction environment.
1558 If there are any keyword arguments specified,
1559 they are added to the returned copy,
1560 overwriting any existing values
1561 for the keywords.
1562
1563 .ES
1564 env2 = env.Copy()
1565 env3 = env.Copy(CCFLAGS = '-g')
1566 .EE
1567
1568 .TP
1569 .RI CVS( repository ", " module )
1570 A factory function that
1571 returns a Builder object
1572 to be used to fetch source files
1573 from the specified
1574 CVS
1575 .IR repository .
1576 The returned Builder
1577 is intended to be passed to the
1578 .B SourceCode
1579 function.
1580
1581 The optional specified
1582 .I module
1583 will be added to the beginning
1584 of all repository path names;
1585 this can be used, in essence,
1586 to strip initial directory names
1587 from the repository path names,
1588 so that you only have to
1589 replicate part of the repository
1590 directory hierarchy in your
1591 local build directory:
1592
1593 .ES
1594 # Will fetch foo/bar/src.c
1595 # from /usr/local/CVSROOT/foo/bar/src.c.
1596 env.SourceCode('.', env.CVS('/usr/local/CVSROOT'))
1597
1598 # Will fetch bar/src.c
1599 # from /usr/local/CVSROOT/foo/bar/src.c.
1600 env.SourceCode('.', env.CVS('/usr/local/CVSROOT', 'foo'))
1601
1602 # Will fetch src.c
1603 # from /usr/local/CVSROOT/foo/bar/src.c.
1604 env.SourceCode('.', env.CVS('/usr/local/CVSROOT', 'foo/bar'))
1605 .EE
1606
1607 .TP
1608 .RI Depends( target ", " dependency )
1609 Specifies an explicit dependency;
1610 the target file(s) will be rebuilt
1611 whenever the dependency file(s) has changed.
1612 This should only be necessary
1613 for cases where the dependency
1614 is not caught by a Scanner
1615 for the file.
1616
1617 .ES
1618 env.Depends('foo', 'other-input-file-for-foo')
1619 .EE
1620
1621 .TP
1622 .RI Dictionary([ vars ])
1623 Returns a dictionary object
1624 containing copies of all of the
1625 construction variables in the environment.
1626 If there are any variable names specified,
1627 only the specified construction
1628 variables are returned in the dictionary.
1629
1630 .ES
1631 dict = env.Dictionary()
1632 cc_dict = env.Dictionary('CC', 'CCFLAGS', 'CCCOM')
1633 .EE
1634
1635 .TP
1636 .RI Ignore( target ", " dependency )
1637 The specified dependency file(s)
1638 will be ignored when deciding if
1639 the target file(s) need to be rebuilt.
1640
1641 .ES
1642 env.Ignore('foo', 'foo.c')
1643 env.Ignore('bar', ['bar1.h', 'bar2.h'])
1644 .EE
1645
1646 .TP
1647 .RI Install( dir ", " source )
1648 Installs one or more files in a destination directory.
1649 The file names remain the same.
1650
1651 .ES
1652 env.Install(dir = '/usr/local/bin', source = ['foo', 'bar'])
1653 .EE
1654
1655 .TP
1656 .RI InstallAs( target ", " source )
1657 Installs one or more files as specific file names,
1658 allowing changing a file name as part of the
1659 installation.
1660 It is an error if the target and source
1661 list different numbers of files.
1662
1663 .ES
1664 env.InstallAs(target = '/usr/local/bin/foo',
1665               source = 'foo_debug')
1666 env.InstallAs(target = ['../lib/libfoo.a', '../lib/libbar.a'],
1667               source = ['libFOO.a', 'libBAR.a'])
1668 .EE
1669
1670 .TP
1671 .RI Perforce( )
1672 A factory function that
1673 returns a Builder object
1674 to be used to fetch source files
1675 from the Perforce source code management system.
1676 The returned Builder
1677 is intended to be passed to the
1678 .B SourceCode
1679 function:
1680 .ES
1681 env.SourceCode('.', env.Perforce())
1682 .EE
1683 .IP
1684 Perforce uses a number of external
1685 environment variables for its operation.
1686 Consequently, this function adds the
1687 following variables from the user's external environment
1688 to the construction environment's
1689 ENV dictionary:
1690 P4CHARSET,
1691 P4CLIENT,
1692 P4LANGUAGE,
1693 P4PASSWD,
1694 P4PORT,
1695 P4USER,
1696 SYSTEMROOT,
1697 USER,
1698 and
1699 USERNAME.
1700
1701 .TP
1702 .RI Precious( target ", ...)"
1703 Marks each given
1704 .I target
1705 as precious so it is not deleted before it is rebuilt. Normally
1706 .B scons
1707 deletes a target before building it.
1708 Multiple targets can be passed in to a single call to
1709 .BR Precious ().
1710
1711 .TP
1712 .RI Prepend( key = val ", [...])"
1713 Appends the specified keyword arguments
1714 to the beginning of construction variables in the environment.
1715 If the Environment does not have
1716 the specified construction variable,
1717 it is simply added to the environment.
1718 If the values of the construction variable
1719 and the keyword argument are the same type,
1720 then the two values will be simply added together.
1721 Otherwise, the construction variable
1722 and the value of the keyword argument
1723 are both coerced to lists,
1724 and the lists are added together.
1725 (See also the Append method, above.)
1726
1727 .ES
1728 env.Prepend(CCFLAGS = '-g ', FOO = ['foo.yyy'])
1729 .EE
1730
1731 .TP
1732 .RI RCS( )
1733 A factory function that
1734 returns a Builder object
1735 to be used to fetch source files
1736 from RCS.
1737 The returned Builder
1738 is intended to be passed to the
1739 .B SourceCode
1740 function:
1741 .ES
1742 env.SourceCode('.', env.RCS())
1743 .EE
1744 Note that
1745 .B scons
1746 will fetch source files
1747 from RCS subdirectories automatically,
1748 so configuring RCS
1749 as demonstrated in the above example
1750 should only be necessary if
1751 you are fetching from
1752 RCS,v
1753 files in the same
1754 directory as the source files,
1755 or if you need to explicitly specify RCS
1756 for a specific subdirectory.
1757
1758 .TP
1759 .RI Replace( key = val ", [...])"
1760 Replaces construction variables in the Environment
1761 with the specified keyword arguments.
1762
1763 .ES
1764 env.Replace(CCFLAGS = '-g', FOO = 'foo.xxx')
1765 .EE
1766
1767 .TP
1768 .RI SCCS( )
1769 A factory function that
1770 returns a Builder object
1771 to be used to fetch source files
1772 from SCCS.
1773 The returned Builder
1774 is intended to be passed to the
1775 .B SourceCode
1776 function:
1777 .ES
1778 env.SourceCode('.', env.SCCS())
1779 .EE
1780 Note that
1781 .B scons
1782 will fetch source files
1783 from SCCS subdirectories automatically,
1784 so configuring SCCS
1785 as demonstrated in the above example
1786 should only be necessary if
1787 you are fetching from
1788 .I s.SCCS
1789 files in the same
1790 directory as the source files,
1791 or if you need to explicitly specify SCCS
1792 for a specific subdirectory.
1793
1794 .TP
1795 .RI SideEffect( side_effect , target )
1796 Declares
1797 .I side_effect
1798 as a side effect of building
1799 .IR target . 
1800 Both 
1801 .I side_effect 
1802 and
1803 .I target
1804 can be a list, a file name, or a node.
1805 A side effect is a target that is created
1806 as a side effect of building other targets.
1807 For example, a Windows PDB
1808 file is created as a side effect of building the .obj
1809 files for a static library.
1810 If a target is a side effect of multiple build commands,
1811 .B scons
1812 will ensure that only one set of commands
1813 is executed at a time.
1814 Consequently, you only need to use this method
1815 for side-effect targets that are built as a result of
1816 multiple build commands.
1817
1818 .TP
1819 .RI SourceCode( entries , builder )
1820 Arrange for non-existent source files to
1821 be fetched from a source code management system
1822 using the specified
1823 .IR builder .
1824 The specified
1825 .I entries
1826 may be a Node, string or list of both,
1827 and may represent either individual
1828 source files or directories in which
1829 source files can be found.
1830
1831 For any non-existent source files,
1832 .B scons
1833 will search up the directory tree
1834 and use the first
1835 .B SourceCode
1836 builder it finds.
1837 The specified
1838 .I builder
1839 may be
1840 .BR None ,
1841 in which case
1842 .B scons
1843 will not use a builder to fetch
1844 source files for the specified
1845 .IR entries ,
1846 even if a
1847 .B SourceCode
1848 builder has been specified
1849 for a directory higher up the tree.
1850
1851 .B scons
1852 will, by default,
1853 fetch files from SCCS or RCS subdirectories
1854 without explicit configuration.
1855 This takes some extra processing time
1856 to search for the necessary
1857 source code management files on disk.
1858 You can avoid these extra searches
1859 and speed up your build a little
1860 by disabling these searches as follows:
1861 .ES
1862 env.SourceCode('.', None)
1863 .EE
1864
1865 Note that if the specified
1866 .I builder
1867 is one you create by hand,
1868 it must have an associated
1869 construction environment to use
1870 when fetching a source file.
1871
1872 .B scons
1873 provides a set of canned factory
1874 functions that return appropriate
1875 Builders for various popular
1876 source code management systems.
1877 Canonical examples of invocation include:
1878 .ES
1879 env.SourceCode('.', env.BitKeeper('/usr/local/BKsources'))
1880 env.SourceCode('src', env.CVS('/usr/local/CVSROOT'))
1881 env.SourceCode('/', env.RCS())
1882 env.SourceCode(['f1.c', 'f2.c'], env.SCCS())
1883 env.SourceCode('no_source.c', None)
1884 .EE
1885 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion'))
1886 '\"
1887 '\".TP
1888 '\".RI Subversion( repository ", " module )
1889 '\"A factory function that
1890 '\"returns a Builder object
1891 '\"to be used to fetch source files
1892 '\"from the specified Subversion
1893 '\".IR repository .
1894 '\"The returned Builder
1895 '\"is intended to be passed to the
1896 '\".B SourceCode
1897 '\"function.
1898 '\"
1899 '\"The optional specified
1900 '\".I module
1901 '\"will be added to the beginning
1902 '\"of all repository path names;
1903 '\"this can be used, in essence,
1904 '\"to strip initial directory names
1905 '\"from the repository path names,
1906 '\"so that you only have to
1907 '\"replicate part of the repository
1908 '\"directory hierarchy in your
1909 '\"local build directory:
1910 '\"
1911 '\".ES
1912 '\"# Will fetch foo/bar/src.c
1913 '\"# from /usr/local/Subversion/foo/bar/src.c.
1914 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion'))
1915 '\"
1916 '\"# Will fetch bar/src.c
1917 '\"# from /usr/local/Subversion/foo/bar/src.c.
1918 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion', 'foo'))
1919 '\"
1920 '\"# Will fetch src.c
1921 '\"# from /usr/local/Subversion/foo/bar/src.c.
1922 '\"env.SourceCode('.', env.Subversion('file:///usr/local/Subversion', 'foo/bar'))
1923 '\".EE
1924
1925 .SS Construction Variables
1926 .\" XXX From Gary Ruben, 23 April 2002:
1927 .\" I think it would be good to have an example with each construction
1928 .\" variable description in the documentation.
1929 .\" eg.
1930 .\" CC     The C compiler
1931 .\"    Example: env["CC"] = "c68x"
1932 .\"    Default: env["CC"] = "cc"
1933 .\" 
1934 .\" CCCOM  The command line ...
1935 .\"    Example:
1936 .\"        To generate the compiler line c68x -ps -qq -mr -o $TARGET $SOURCES
1937 .\"        env["CC"] = "c68x"
1938 .\"        env["CFLAGS"] = "-ps -qq -mr"
1939 .\"        env["CCCOM"] = "$CC $CFLAGS -o $TARGET $SOURCES
1940 .\"    Default:
1941 .\"        (I dunno what this is ;-)
1942 A construction environment has an associated dictionary of construction
1943 variables that are used by built-in or user-supplied build rules. A number
1944 of useful construction variables are automatically defined by scons for
1945 each supported platform, and additional construction variables can be defined
1946 by the user. The following is a list of the automatically defined construction
1947 variables:
1948
1949 .IP AR
1950 The static library archiver.
1951
1952 .IP ARCOM
1953 The command line used to generate a static library from object files.
1954
1955 .IP ARFLAGS
1956 General options passed to the static library archiver.
1957
1958 .IP AS
1959 The assembler.
1960
1961 .IP ASCOM
1962 The command line used to generate an object file
1963 from an assembly-language source file.
1964
1965 .IP ASFLAGS
1966 General options passed to the assembler.
1967
1968 .IP ASPPCOM
1969 The command line used to assemble an assembly-language
1970 source file into an object file
1971 after first running the file through the C preprocessor.
1972 Any options specified in the $ASFLAGS and $CPPFLAGS construction variables
1973 are included on this command line.
1974
1975 .IP BITKEEPER
1976 The BitKeeper executable.
1977
1978 .IP BITKEEPERCOM
1979 The command line for
1980 fetching source files using BitKEeper.
1981
1982 .IP BITKEEPERGET
1983 The command ($BITKEEPER) and subcommand
1984 for fetching source files using BitKeeper.
1985
1986 .IP BITKEEPERGETFLAGS
1987 Options that are passed to the BitKeeper
1988 .B get
1989 subcommand.
1990
1991 .IP BUILDERS
1992 A dictionary mapping the names of the builders
1993 available through this environment
1994 to underlying Builder objects.
1995 Builders named
1996 Alias, CFile, CXXFile, DVI, Library, Object, PDF, PostScript, and Program
1997 are available by default.
1998 If you initialize this variable when an
1999 Environment is created:
2000 .ES
2001 env = Environment(BUILDERS = {'NewBuilder' : foo})
2002 .EE
2003 the default Builders will no longer be available.
2004 To use a new Builder object in addition to the default Builders,
2005 add your new Builder object like this:
2006 .ES
2007 env = Environment()
2008 env.Append(BUILDERS = {'NewBuilder' : foo})
2009 .EE
2010 or this:
2011 .ES
2012 env = Environment()
2013 env['BUILDERS]['NewBuilder'] = foo
2014 .EE
2015
2016 .IP CC 
2017 The C compiler.
2018
2019 .IP CCCOM 
2020 The command line used to compile a C source file to a (static) object file.
2021 Any options specified in the $CCFLAGS and $CPPFLAGS construction variables
2022 are included on this command line.
2023
2024 .IP CCFLAGS 
2025 General options that are passed to the C compiler.
2026
2027 .IP CFILESUFFIX
2028 The suffix for C source files.
2029 This is used by the internal CFile builder
2030 when generating C files from Lex (.l) or YACC (.y) input files.
2031 The default suffix, of course, is
2032 .I .c
2033 (lower case).
2034 On case-insensitive systems (like Win32),
2035 SCons also treats
2036 .I .C
2037 (upper case) files
2038 as C files.
2039
2040 .IP _concat
2041 A function used to produce variables like $_CPPINCFLAGS. It takes six
2042 arguments: a prefix to concatenate onto each element, a list of elements, a
2043 suffix to concatenate onto each element, a dictionary of global variables
2044 for variable interpolation, a list of local variables for variable
2045 interpolation, and an optional function that will be called to transform the list
2046 before concatenation.
2047
2048 .ES
2049 env['_CPPINCFLAGS'] = '$( ${_concat(INCPREFIX, CPPPATH, INCSUFFIX, locals(), globals(), RDirs)} $)',
2050 .EE
2051
2052 .IP CPPFLAGS
2053 C preprocessor options.
2054 These will be included in any command that uses the C preprocessor,
2055 including not just compilation of C and C++ source files
2056 via the $CCCOM, $SHCCCOM, $CXXCOM and $SHCXXCOM command lines,
2057 but also the $F77PPCOM command line
2058 used to compile a Fortran source file,
2059 and the $ASPPCOM command line
2060 used to assemble an assembly language source file,
2061 after first running each file through the C preprocessor.
2062
2063 .IP _CPPINCFLAGS
2064 An automatically-generated construction variable
2065 containing the C preprocessor command-line options
2066 for specifying directories to be searched for include files.
2067 The value of $_CPPINCFLAGS is created
2068 by appending $INCPREFIX and $INCSUFFIX
2069 to the beginning and end
2070 of each directory in $CPPPATH.
2071
2072 .IP CPPPATH
2073 The list of directories that the C preprocessor will search for include
2074 directories. The C/C++ implicit dependency scanner will search these
2075 directories for include files. Don't explicitly put include directory
2076 arguments in CCFLAGS or CXXFLAGS because the result will be non-portable
2077 and the directories will not be searched by the dependency scanner. Note:
2078 directory names in CPPPATH will be looked-up relative to the SConscript
2079 directory when they are used in a command. To force 
2080 .B scons
2081 to look-up a directory relative to the root of the source tree use #:
2082
2083 .ES
2084 env = Environment(CPPPATH='#/include')
2085 .EE
2086
2087 .IP
2088 The directory look-up can also be forced using the 
2089 .BR Dir ()
2090 function:
2091
2092 .ES
2093 include = Dir('include')
2094 env = Environment(CPPPATH=include)
2095 .EE
2096
2097 .IP
2098 The directory list will be added to command lines
2099 through the automatically-generated
2100 $_CPPINCFLAGS
2101 construction variable,
2102 which is constructed by
2103 appending the values of the
2104 $INCPREFIX and $INCSUFFIX
2105 construction variables
2106 to the beginning and end
2107 of each directory in $CPPPATH.
2108 Any command lines you define that need
2109 the CPPPATH directory list should
2110 include $_CPPINCFLAGS:
2111
2112 .ES
2113 env = Environment(CCCOM="my_compiler $_CPPINCFLAGS -c -o $TARGET $SOURCE")
2114 .EE
2115
2116 .IP CVS
2117 The CVS executable.
2118
2119 .IP CVSCOFLAGS
2120 Options that are passed to the CVS checkout subcommand.
2121
2122 .IP CVSCOM
2123 The command line used to
2124 fetch source files from a CVS repository.
2125
2126 .IP CVSFLAGS
2127 General options that are passed to CVS.
2128 By default, this is set to
2129 "-d $CVSREPOSITORY"
2130 to specify from where the files must be fetched.
2131
2132 .IP CVSREPOSITORY
2133 The path to the CVS repository.
2134 This is referenced in the default
2135 $CVSFLAGS value.
2136
2137 .IP CXX
2138 The C++ compiler.
2139
2140 .IP CXXFILESUFFIX
2141 The suffix for C++ source files.
2142 This is used by the internal CXXFile builder
2143 when generating C++ files from Lex (.ll) or YACC (.yy) input files.
2144 The default suffix is
2145 .IR .cc .
2146 SCons also treats files with the suffixes
2147 .IR .cpp ,
2148 .IR .cxx ,
2149 .IR .c++ ,
2150 and
2151 .I .C++
2152 as C++ files.
2153 On case-sensitive systems (Linux, UNIX, and other POSIX-alikes),
2154 SCons also treats
2155 .I .C
2156 (upper case) files
2157 as C++ files.
2158
2159 .IP CXXCOM
2160 The command line used to compile a C++ source file to an object file.
2161 Any options specified in the $CXXFLAGS and $CPPFLAGS construction variables
2162 are included on this command line.
2163
2164 .IP CXXFLAGS 
2165 General options that are passed to the C++ compiler.
2166
2167 .IP Dir
2168 A function that converts a file name into a Dir instance relative to the
2169 target being built. 
2170
2171 .IP DVIPDF
2172 The TeX DVI file to PDF file converter.
2173
2174 .IP DVIPDFFLAGS
2175 General options passed to the TeX DVI file to PDF file converter.
2176
2177 .IP DVIPDFCOM
2178 The command line used to convert TeX DVI files into a PDF file.
2179
2180 .IP DVIPS
2181 The TeX DVI file to PostScript converter.
2182
2183 .IP DVIPSFLAGS
2184 General options passed to the TeX DVI file to PostScript converter.
2185
2186 .IP ENV
2187 A dictionary of environment variables
2188 to use when invoking commands.
2189 Note that, by default,
2190 .B scons
2191 does
2192 .I not
2193 propagate the environment in force when you
2194 execute
2195 .B scons
2196 to the commands used to build target files.
2197 This is so that builds will be guaranteed
2198 repeatable regardless of the environment
2199 variables set at the time
2200 .B scons
2201 is invoked.
2202
2203 If you want to propagate your
2204 environment variables
2205 to the commands executed
2206 to build target files,
2207 you must do so explicitly:
2208
2209 .ES
2210 import os
2211 env = Environment(ENV = os.environ)
2212 .EE
2213
2214 .RS
2215 Note that you can choose only to propagate
2216 certain environment variables.
2217 A common example is
2218 the system
2219 .B PATH
2220 environment variable,
2221 so that
2222 .B scons
2223 uses the same utilities
2224 as the invoking shell (or other process):
2225 .RE
2226
2227 .ES
2228 import os
2229 env = Environment(ENV = {'PATH' : os.environ['PATH']})
2230 .EE
2231
2232 .IP ESCAPE
2233 A function that will be called to escape shell special characters in
2234 command lines. The function should take one argument: the command line
2235 string to escape; and should return the escaped command line.
2236
2237 .IP F77
2238 The Fortran compiler.
2239
2240 .IP F77COM 
2241 The command line used to compile a Fortran source file to an object file.
2242
2243 .IP F77FLAGS
2244 General options that are passed to the Fortran compiler.
2245
2246 .IP _F77INCFLAGS
2247 An automatically-generated construction variable
2248 containing the Fortran compiler command-line options
2249 for specifying directories to be searched for include files.
2250 The value of $_F77INCFLAGS is created
2251 by appending $INCPREFIX and $INCSUFFIX
2252 to the beginning and end
2253 of each directory in $F77PATH.
2254
2255 .IP F77PATH
2256 The list of directories that the Fortran compiler will search for include
2257 directories. The Fortran implicit dependency scanner will search these
2258 directories for include files. Don't explicitly put include directory
2259 arguments in F77FLAGS because the result will be non-portable
2260 and the directories will not be searched by the dependency scanner. Note:
2261 directory names in F77PATH will be looked-up relative to the SConscript
2262 directory when they are used in a command. To force 
2263 .B scons
2264 to look-up a directory relative to the root of the source tree use #:
2265
2266 .ES
2267 env = Environment(F77PATH='#/include')
2268 .EE
2269
2270 .IP
2271 The directory look-up can also be forced using the 
2272 .BR Dir ()
2273 function:
2274
2275 .ES
2276 include = Dir('include')
2277 env = Environment(F77PATH=include)
2278 .EE
2279
2280 .IP
2281 The directory list will be added to command lines
2282 through the automatically-generated
2283 $_F77INCFLAGS
2284 construction variable,
2285 which is constructed by
2286 appending the values of the
2287 $INCPREFIX and $INCSUFFIX
2288 construction variables
2289 to the beginning and end
2290 of each directory in $F77PATH.
2291 Any command lines you define that need
2292 the F77PATH directory list should
2293 include $_F77INCFLAGS:
2294
2295 .ES
2296 env = Environment(F77COM="my_compiler $_F77INCFLAGS -c -o $TARGET $SOURCE")
2297 .EE
2298
2299 .IP F77PPCOM 
2300 The command line used to compile a Fortran source file to an object file
2301 after first running the file through the C preprocessor.
2302 Any options specified in the $F77FLAGS and $CPPFLAGS construction variables
2303 are included on this command line.
2304
2305 .IP File
2306 A function that converts a file name into a File instance relative to the
2307 target being built. 
2308
2309 .IP GS
2310 The Ghostscript program used to convert PostScript to PDF files.
2311
2312 .IP GSFLAGS
2313 General options passed to the Ghostscript program
2314 when converting PostScript to PDF files.
2315
2316 .IP GSCOM
2317 The Ghostscript command line used to convert PostScript to PDF files.
2318
2319 .IP INCPREFIX
2320 The prefix used to specify an include directory on the C compiler command
2321 line.
2322 This will be appended to the beginning of each directory
2323 in the $CPPPATH and $F77PATH construction variables
2324 when the $_CPPINCFLAGS and $_F77INCFLAGS
2325 variables are automatically generated.
2326
2327 .IP INCSUFFIX
2328 The suffix used to specify an include directory on the C compiler command
2329 line.
2330 This will be appended to the end of each directory
2331 in the $CPPPATH and $F77PATH construction variables
2332 when the $_CPPINCFLAGS and $_F77INCFLAGS
2333 variables are automatically generated.
2334
2335 .IP INSTALL
2336 A function to be called to install a file into a
2337 destination file name.
2338 The default function copies the file into the destination
2339 (and sets the destination file's mode and permission bits
2340 to match the source file's).
2341 The function takes the following arguments:
2342
2343 .ES
2344 def install(dest, source, env):
2345 .EE
2346 .IP
2347 .I dest
2348 is the path name of the destination file.
2349 .I source
2350 is the path name of the source file.
2351 .I env
2352 is the construction environment
2353 (a dictionary of construction values)
2354 in force for this file installation.
2355
2356 .IP JAR
2357 The Java archive tool.
2358
2359 .IP JARCOM
2360 The command line used to call the Java archive tool.
2361
2362 .IP JARFLAGS
2363 General options passed to the Java archive tool.
2364 By default this is set to
2365 .B cf
2366 to create the necessary
2367 .I jar
2368 file.
2369
2370 .IP JARSUFFIX
2371 The suffix for Java archives:
2372 .B .jar
2373 by default.
2374
2375 .IP JAVAC
2376 The Java compiler.
2377
2378 .IP JAVACCOM
2379 The command line used to compile a directory tree containing
2380 Java source files to
2381 corresponding Java class files.
2382 Any options specified in the $JAVACFLAGS construction variable
2383 are included on this command line.
2384
2385 .IP JAVACFLAGS
2386 General options that are passed to the Java compiler.
2387
2388 .IP JAVACLASSSUFFIX
2389 The suffix for Java class files;
2390 .B .class
2391 by default.
2392
2393 .IP JAVASUFFIX
2394 The suffix for Java files;
2395 .B .java
2396 by default.
2397
2398 .IP LATEX
2399 The LaTeX structured formatter and typesetter.
2400
2401 .IP LATEXCOM
2402 The command line used to call the LaTeX structured formatter and typesetter.
2403
2404 .IP LATEXFLAGS
2405 General options passed to the LaTeX structured formatter and typesetter.
2406
2407 .IP LEX
2408 The lexical analyzer generator.
2409
2410 .IP LEXFLAGS
2411 General options passed to the lexical analyzer generator.
2412
2413 .IP LEXCOM
2414 The command line used to call the lexical analyzer generator
2415 to generate a source file.
2416
2417 .IP _LIBDIRFLAGS
2418 An automatically-generated construction variable
2419 containing the linker command-line options
2420 for specifying directories to be searched for library.
2421 The value of $_LIBDIRFLAGS is created
2422 by appending $LIBDIRPREFIX and $LIBDIRSUFFIX
2423 to the beginning and end
2424 of each directory in $LIBPATH.
2425
2426 .IP LIBDIRPREFIX
2427 The prefix used to specify a library directory on the linker command line.
2428 This will be appended to the beginning of each directory
2429 in the $LIBPATH construction variable
2430 when the $_LIBDIRFLAGS variable is automatically generated.
2431
2432 .IP LIBDIRSUFFIX
2433 The suffix used to specify a library directory on the linker command line.
2434 This will be appended to the end of each directory
2435 in the $LIBPATH construction variable
2436 when the $_LIBDIRFLAGS variable is automatically generated.
2437
2438 .IP _LIBFLAGS
2439 An automatically-generated construction variable
2440 containing the linker command-line options
2441 for specifying libraries to be linked with the resulting target.
2442 The value of $_LIBFLAGS is created
2443 by appending $LIBLINKPREFIX and $LIBLINKSUFFIX
2444 to the beginning and end
2445 of each directory in $LIBS.
2446
2447 .IP LIBLINKPREFIX
2448 The prefix used to specify a library to link on the linker command line.
2449 This will be appended to the beginning of each library
2450 in the $LIBS construction variable
2451 when the $_LIBFLAGS variable is automatically generated.
2452
2453 .IP LIBLINKSUFFIX
2454 The suffix used to specify a library to link on the linker command line.
2455 This will be appended to the end of each library
2456 in the $LIBS construction variable
2457 when the $_LIBFLAGS variable is automatically generated.
2458
2459 .IP LIBPATH
2460 The list of directories that will be searched for libraries.
2461 The implicit dependency scanner will search these
2462 directories for include files. Don't explicitly put include directory
2463 arguments in LINKFLAGS because the result will be non-portable
2464 and the directories will not be searched by the dependency scanner. Note:
2465 directory names in LIBPATH will be looked-up relative to the SConscript
2466 directory when they are used in a command. To force 
2467 .B scons
2468 to look-up a directory relative to the root of the source tree use #:
2469
2470 .ES
2471 env = Environment(LIBPATH='#/libs')
2472 .EE
2473
2474 .IP
2475 The directory look-up can also be forced using the 
2476 .BR Dir ()
2477 function:
2478
2479 .ES
2480 libs = Dir('libs')
2481 env = Environment(LIBPATH=libs)
2482 .EE
2483
2484 .IP
2485 The directory list will be added to command lines
2486 through the automatically-generated
2487 $_LIBDIRFLAGS
2488 construction variable,
2489 which is constructed by
2490 appending the values of the
2491 $LIBDIRPREFIX and $LIBDIRSUFFIX
2492 construction variables
2493 to the beginning and end
2494 of each directory in $LIBPATH.
2495 Any command lines you define that need
2496 the LIBPATH directory list should
2497 include $_LIBDIRFLAGS:
2498
2499 .ES
2500 env = Environment(LINKCOM="my_linker $_LIBDIRFLAGS $_LIBFLAGS -o $TARGET $SOURCE")
2501 .EE
2502
2503 .IP LIBPREFIX
2504 The prefix used for (static) library file names.
2505
2506 .IP LIBPREFIXES
2507 An array of legal prefixes for library file names.
2508
2509 .IP LIBS
2510 A list of one or more libraries
2511 that will be linked with
2512 any executable programs
2513 created by this environment.
2514
2515 .IP
2516 The library list will be added to command lines
2517 through the automatically-generated
2518 $_LIBFLAGS
2519 construction variable,
2520 which is constructed by
2521 appending the values of the
2522 $LIBLINKPREFIX and $LIBLINKSUFFIX
2523 construction variables
2524 to the beginning and end
2525 of each directory in $LIBS.
2526 Any command lines you define that need
2527 the LIBS library list should
2528 include $_LIBFLAGS:
2529
2530 .ES
2531 env = Environment(LINKCOM="my_linker $_LIBDIRFLAGS $_LIBFLAGS -o $TARGET $SOURCE")
2532 .EE
2533
2534 .IP LIBSUFFIX 
2535 The suffix used for (static) library file names.
2536
2537 .IP LIBSUFFIXES
2538 An array of legal suffixes for library file names.
2539
2540 .IP LINK
2541 The linker.
2542
2543 .IP LINKFLAGS
2544 General options passed to the linker.
2545
2546 .IP LINKCOM
2547 The command line used to link object files into an executable.
2548
2549 .IP OBJPREFIX 
2550 The prefix used for (static) object file names.
2551
2552 .IP OBJSUFFIX 
2553 The suffix used for (static) object file names.
2554
2555 .IP P4
2556 The Perforce executable.
2557
2558 .IP P4COM
2559 The command line used to
2560 fetch source files from Perforce.
2561
2562 .IP P4FLAGS
2563 General options that are passed to Perforce.
2564
2565 .IP PCH
2566 The Microsoft Visual C++ precompiled header that will be used when compiling
2567 object files. This variable is ignored by tools other than Microsoft Visual C++.
2568 When this variable is
2569 defined SCons will add options to the compiler command line to
2570 cause it to use the precompiled header, and will also set up the
2571 dependencies for the PCH file. Example: 
2572
2573 .ES
2574 env['PCH'] = 'StdAfx.pch'
2575 .EE
2576
2577 .IP PCHSTOP
2578 This variable specifies how much of a source file is precompiled. This
2579 variable is ignored by tools other than Microsoft Visual C++, or when
2580 the PCH variable is not being used. When this variable is define it
2581 must be a string that is the name of the header that
2582 is included at the end of the precompiled portion of the source files, or
2583 the empty string if the "#pragma hrdstop" construct is being used:
2584
2585 .ES
2586 env['PCHSTOP'] = 'StdAfx.h'
2587 .EE
2588
2589 .IP PDB
2590 The Microsoft Visual C++ PDB file that will store debugging information for
2591 object files, shared libraries, and programs. This variable is ignored by
2592 tools other than Microsoft Visual C++.
2593 When this variable is
2594 defined SCons will add options to the compiler and linker command line to
2595 cause them to generate external debugging information, and will also set up the
2596 dependencies for the PDB file. Example:
2597
2598 .ES
2599 env['PDB'] = 'hello.pdb'
2600 .EE
2601
2602 .IP PDFCOM
2603 A deprecated synonym for $DVIPDFCOM.
2604
2605 .IP PDFPREFIX
2606 The prefix used for PDF file names.
2607
2608 .IP PDFSUFFIX
2609 The suffix used for PDF file names.
2610
2611 .IP PLATFORM
2612 The name of the platform used to create the Environment.  If no platform is
2613 specified when the Environment is created,
2614 .B SCons
2615 autodetects the platform.
2616
2617 .ES
2618 env = Environment(tools = [])
2619 if env['PLATFORM'] == 'cygwin':
2620     Tool('mingw')(env)
2621 else:
2622     Tool('msvc')(env)
2623 .EE
2624
2625 .IP PROGPREFIX
2626 The prefix used for executable file names.
2627
2628 .IP PROGSUFFIX
2629 The suffix used for executable file names.
2630
2631 .IP PSCOM
2632 The command line used to convert TeX DVI files into a PostScript file.
2633
2634 .IP PSPREFIX
2635 The prefix used for PostScript file names.
2636
2637 .IP PSSUFFIX
2638 The prefix used for PostScript file names.
2639
2640 .IP RANLIB
2641 The archive indexer.
2642
2643 .IP RANLIBFLAGS
2644 General options passed to the archive indexer.
2645
2646 .IP RC
2647 The resource compiler used by the RES builder.
2648
2649 .IP RCCOM
2650 The command line used by the RES builder.
2651
2652 .IP RCFLAGS
2653 The flags passed to the resource compiler by the RES builder.
2654
2655 .IP RCS
2656 The RCS executable.
2657 Note that this variable is not actually used
2658 for the command to fetch source files from RCS;
2659 see the
2660 .B RCS_CO
2661 construction variable, below.
2662
2663 .IP RCS_CO 
2664 The RCS "checkout" executable,
2665 used to fetch source files from RCS.
2666
2667 .IP RCS_COCOM
2668 The command line used to
2669 fetch (checkout) source files from RCS.
2670
2671 .IP RCS_COFLAGS
2672 Options that are passed to the $RCS_CO command.
2673
2674 .IP RDirs
2675 A function that converts a file name into a list of Dir instances by
2676 searching the repositories. 
2677
2678 .IP SCANNERS
2679 A list of the available implicit dependency scanners. [CScan] by default.
2680
2681 .IP SCCS
2682 The SCCS executable.
2683
2684 .IP SCCSCOM
2685 The command line used to
2686 fetch source files from SCCS.
2687
2688 .IP SCCSFLAGS
2689 General options that are passed to SCCS.
2690
2691 .IP SCCSGETFLAGS
2692 Options that are passed specifically to the SCCS "get" subcommand.
2693 This can be set, for example, to
2694 .I -e
2695 to check out editable files from SCCS.
2696
2697 .IP SHCC
2698 The C compiler used for generating shared-library objects.
2699
2700 .IP SHCCCOM
2701 The command line used to compile a C source file
2702 to a shared-library object file.
2703 Any options specified in the $SHCCFLAGS and $CPPFLAGS construction variables
2704 are included on this command line.
2705
2706 .IP SHCCFLAGS
2707 Options that are passed to the C compiler
2708 to generate shared-library objects.
2709
2710 .IP SHCXX
2711 The C++ compiler used for generating shared-library objects.
2712
2713 .IP SHCXXCOM
2714 The command line used to compile a C++ source file
2715 to a shared-library object file.
2716 Any options specified in the $SHCXXFLAGS and $CPPFLAGS construction variables
2717 are included on this command line.
2718
2719 .IP SHCXXFLAGS
2720 Options that are passed to the C++ compiler
2721 to generate shared-library objects.
2722
2723 .IP SHELL
2724 A string naming the shell program that will be passed to the 
2725 .I SPAWN 
2726 function. 
2727 See the 
2728 .I SPAWN 
2729 construction variable for more information.
2730
2731 .IP SHF77
2732 The Fortran compiler used for generating shared-library objects.
2733
2734 .IP SHF77COM
2735 The command line used to compile a Fortran source file
2736 to a shared-library object file.
2737
2738 .IP SHF77FLAGS
2739 Options that are passed to the Fortran compiler
2740 to generated shared-library objects.
2741
2742 .IP SHF77PPCOM
2743 The command line used to compile a Fortran source file to a
2744 shared-library object file
2745 after first running the file through the C preprocessor.
2746 Any options specified in the $SHF77FLAGS and $CPPFLAGS construction variables
2747 are included on this command line.
2748
2749 .IP SHLIBPREFIX
2750 The prefix used for shared library file names.
2751
2752 .IP SHLIBSUFFIX
2753 The suffix used for shared library file names.
2754
2755 .IP SHLINK
2756 The linker for programs that use shared libraries.
2757
2758 .IP SHLINKFLAGS
2759 General options passed to the linker for programs using shared libraries.
2760
2761 .IP SHOBJPREFIX 
2762 The prefix used for shared object file names.
2763
2764 .IP SHOBJSUFFIX 
2765 The suffix used for shared object file names.
2766
2767 .IP SOURCE
2768 A reserved variable name
2769 that may not be set or used in a construction environment.
2770 (See "Variable Substitution," below.)
2771
2772 .IP SOURCES
2773 A reserved variable name
2774 that may not be set or used in a construction environment.
2775 (See "Variable Substitution," below.)
2776
2777 .IP SPAWN
2778 A command interpreter function that will be called to execute command line
2779 strings. The function must expect 4 arguments:
2780
2781 .ES
2782 def spawn(shell, escape, cmd, args, env):
2783 .EE
2784 .IP
2785 .I sh
2786 is a string naming the shell program to use.
2787 .I escape
2788 is a function that can be called to escape shell special characters in
2789 the command line. 
2790 .I cmd
2791 is the path to the command to be executed.
2792 .I args
2793 is that arguments to the command.
2794 .I env
2795 is a dictionary of the environment variables
2796 in which the command should be executed.
2797 '\"
2798 '\".IP SVN
2799 '\"The Subversion executable (usually named
2800 '\".BR svn ).
2801 '\"
2802 '\".IP SVNCOM
2803 '\"The command line used to
2804 '\"fetch source files from a Subversion repository.
2805 '\"
2806 '\".IP SVNFLAGS
2807 '\"General options that are passed to Subversion.
2808
2809 .IP TAR
2810 The tar archiver.
2811
2812 .IP TARCOM
2813 The command line used to call the tar archiver.
2814
2815 .IP TARFLAGS
2816 General options passed to the tar archiver.
2817
2818 .IP TARGET
2819 A reserved variable name
2820 that may not be set or used in a construction environment.
2821 (See "Variable Substitution," below.)
2822
2823 .IP TARGETS
2824 A reserved variable name
2825 that may not be set or used in a construction environment.
2826 (See "Variable Substitution," below.)
2827
2828 .IP TARSUFFIX 
2829 The suffix used for tar file names.
2830
2831 .IP TEX
2832 The TeX formatter and typesetter.
2833
2834 .IP TEXCOM
2835 The command line used to call the TeX formatter and typesetter.
2836
2837 .IP TEXFLAGS
2838 General options passed to the TeX formatter and typesetter.
2839
2840 .IP WIN32_INSERT_DEF
2841 When this is set to true,
2842 a library build of a WIN32 shared library (.dll file)
2843 will also build a corresponding .def file at the same time,
2844 if a .def file is not already listed as a build target.
2845 The default is 0 (do not build a .def file).
2846
2847 .IP WIN32DEFPREFIX
2848 The prefix used for WIN32 .def file names.
2849
2850 .IP WIN32DEFSUFFIX
2851 The suffix used for WIN32 .def file names.
2852
2853 .IP YACC
2854 The parser generator.
2855
2856 .IP YACCCOM
2857 The command line used to call the parser generator
2858 to generate a source file.
2859
2860 .IP YACCFLAGS
2861 General options passed to the parser generator.
2862
2863 .IP ZIP
2864 The zip compression and file packaging utility.
2865
2866 .IP ZIPCOM
2867 The command line used to call the zip utility.
2868
2869 .IP ZIPFLAGS
2870 General options passed to the zip utility.
2871
2872 .LP
2873 Construction variables can be retrieved and set using the 
2874 .B Dictionary 
2875 method of the construction environment:
2876
2877 .ES
2878 dict = env.Dictionary()
2879 dict["CC"] = "cc"
2880 .EE
2881
2882 or using the [] operator:
2883
2884 .ES
2885 env["CC"] = "cc"
2886 .EE
2887
2888 Construction variables can also be passed to the construction environment
2889 constructor:
2890
2891 .ES
2892 env = Environment(CC="cc")
2893 .EE
2894
2895 or when copying a construction environment using the 
2896 .B Copy 
2897 method:
2898
2899 .ES
2900 env2 = env.Copy(CC="cl.exe")
2901 .EE
2902
2903 .SS Configure contexts
2904
2905 .B scons
2906 supports
2907 .I configure contexts,
2908 an integrated mechanism similar to the
2909 various AC_CHECK macros in GNU autoconf
2910 for testing for the existence of C header
2911 files, libraries, etc.
2912 In contrast to autoconf,
2913 .B scons
2914 does not maintain an explicit cache of the tested values,
2915 but uses its normal dependency tracking to keep the checked values
2916 up to date. 
2917 The following methods can be used to perform checks:
2918
2919 .TP
2920 .RI Configure( env ", [" custom_tests ", " conf_dir ", " log_file ])
2921 This creates a configure context, which can be used to perform checks.
2922 .I env
2923 specifies the environment for building the tests.
2924 This environment may be modified when performing checks.
2925 .I custom_tests
2926 is a dictionary containing custom tests.
2927 See also the section about custom tests below. 
2928 By default, no custom tests are added to the configure context.
2929 .I conf_dir
2930 specifies a directory where the test cases are built.
2931 Note that this directory is not used for building
2932 normal targets.
2933 The default value is the directory
2934 #/.sconf_temp.
2935 .I log_file
2936 specifies a file which collects the output from commands
2937 that are executed to check for the existence of header files, libraries, etc.
2938 The default is the file #/config.log.
2939 If you are using the
2940 .B BuildDir
2941 method,
2942 you may want to specify a subdirectory under your build directory.
2943
2944 .EE
2945 A created
2946 .B Configure
2947 instance has the following associated methods:
2948
2949 .TP 
2950 .RI Configure.Finish( self )
2951 This method should be called after configuration is done.
2952 It returns the environment as modified
2953 by the configuration checks performed.
2954 After this method is called, no further checks can be performed
2955 with this configuration context.
2956 However, you can create a new 
2957 .RI Configure 
2958 context to perform additional checks.
2959 Only one context should be active at a time.
2960
2961 The following Checks are predefined.
2962 (This list will likely grow larger as time
2963 goes by and developers contribute new useful tests.)
2964
2965 .TP
2966 .RI Configure.CheckCHeader( self ", " header )
2967 Checks if 
2968 .I header
2969 is usable in the C-language.
2970 Returns 1 on success and 0 on failure.
2971
2972 .TP
2973 .RI Configure.CheckCXXHeader( self ", " header )
2974 Checks if 
2975 .I header
2976 is usable in the C++ language.
2977 Returns 1 on success and 0 on failure.
2978
2979 .TP 
2980 .RI Configure.CheckLib( self ", [" library ", " symbol ", " autoadd ])
2981 Checks if 
2982 .I library 
2983 provides 
2984 .IR symbol .
2985 If the value of
2986 .I autoadd
2987 is 1 and the library provides the specified
2988 .IR symbol ,
2989 appends the library to the LIBS construction environment variable.
2990 .I library 
2991 may also be None (the default),
2992 in which case 
2993 .I symbol 
2994 is checked with the current LIBS variable.
2995 The default
2996 .I symbol
2997 is "main",
2998 which just check if
2999 you can link against the specified
3000 .IR library .
3001 The default value for
3002 .I autoadd
3003 is 1.
3004 It is assumed, that the C-language is used.
3005 This method returns 1 on success and 0 on error.
3006
3007 .TP 
3008 .RI Configure.CheckLibWithHeader( self ", " library ", " header ", " language ", [" call ", " autoadd ])
3009
3010 In contrast to the 
3011 .RI Configure.CheckLib 
3012 call, this call provides a more sophisticated way to check against libraries.
3013 Again, 
3014 .I library
3015 specifies the library to check. 
3016 .I header
3017 specifies a header to check for.
3018 .I language
3019 may be one of 'C','c','CXX','cxx','C++' and 'c++'.
3020 .I call
3021 can be any valid expression (with a trailing ';'). The default is 'main();'.
3022 .I autoadd
3023 specifies whether to add the library to the environment (only if the check 
3024 succeeds). This method returns 1 on success and 0 on error.
3025
3026 .EE
3027 Example of a typical Configure usage:
3028
3029 .ES
3030 env = Environment()
3031 conf = Configure( env )
3032 if not conf.CheckCHeader( 'math.h' ):
3033     print 'We really need math.h!'
3034     Exit(1)
3035 if conf.CheckLibWithHeader( 'qt', 'qapp.h', 'c++', 'QApplication qapp(0,0);' ):
3036     # do stuff for qt - usage, e.g.
3037     conf.env.Append( CPPFLAGS = '-DWITH_QT' )
3038 env = conf.Finish() 
3039 .EE
3040
3041 .EE
3042 You can define your own custom checks. 
3043 in addition to the predefined checks.
3044 These are passed in a dictionary to the Configure function.
3045 This dictionary maps the names of the checks
3046 to user defined Python callables 
3047 (either Python functions or class instances implementing the
3048 .I __call__
3049 method).
3050 The first argument of the call is always a 
3051 .I CheckContext
3052 instance followed by the arguments,
3053 which must be supplied by the user of the check.
3054 These CheckContext instances define the following methods:
3055
3056 .TP 
3057 .RI CheckContext.Message( self ", " text )
3058
3059 Usually called before the check is started. 
3060 .I text
3061 will be displayed to the user, e.g. 'Checking for library X...'
3062
3063 .TP
3064 .RI CheckContext.Result( self, ", " res )
3065
3066 Usually called after the check is done. 
3067 .I res
3068 can be either an integer or a string. In the former case, 'ok' (res != 0) 
3069 or 'failed' (res == 0) is displayed to the user, in the latter case the 
3070 given string is displayed.
3071
3072 .TP
3073 .RI CheckContext.TryCompile( self ", " text ", " extension )
3074 Checks if a file with the specified 
3075 .I extension
3076 (e.g. '.c') containing 
3077 .I text 
3078 can be compiled using the environment's
3079 .B Object 
3080 builder. Returns 1 on success and 0 on failure.
3081
3082 .TP 
3083 .RI CheckContext.TryLink( self ", " text ", " extension )
3084 Checks, if a file with the specified
3085 .I extension
3086 (e.g. '.c') containing 
3087 .I text 
3088 can be compiled using the environment's
3089 .B Program
3090 builder. Returns 1 on success and 0 on failure.
3091
3092 .TP
3093 .RI CheckContext.TryRun( self ", " text ", " extension )
3094 Checks, if a file with the specified
3095 .I extension
3096 (e.g. '.c') containing 
3097 .I text 
3098 can be compiled using the environment's
3099 .B Program
3100 builder. On success, the program is run. If the program
3101 executes successfully
3102 (that is, its return status is 0),
3103 a tuple
3104 .I (1, outputStr)
3105 is returned, where
3106 .I outputStr
3107 is the standard output of the
3108 program.
3109 If the program fails execution
3110 (its return status is non-zero),
3111 then (0, '') is returned.
3112
3113 .TP
3114 .RI CheckContext.TryAction( self ", " action ", [" text ", " extension ])
3115 Checks if the specified
3116 .I action 
3117 with an optional source file (contents
3118 .I text
3119 , extension 
3120 .I extension
3121 = ''
3122 ) can be executed. 
3123 .I action 
3124 may be anything which can be converted to a 
3125 .B scons
3126 .RI Action.
3127 On success,
3128 .I (1, outputStr)
3129 is returned, where
3130 .I outputStr
3131 is the content of the target file.
3132 On failure
3133 .I (0, '')
3134 is returned.
3135
3136 .TP
3137 .RI CheckContext.TryBuild( self ", " builder ", [" text ", " extension ])
3138 Low level implementation for testing specific builds;
3139 the methods above are based on this metho.
3140 Given the Builder instance
3141 .I builder
3142 and the optional 
3143 .I text
3144 of a source file with optional
3145 .IR extension ,
3146 this method returns 1 on success and 0 on failure. In addition, 
3147 .I self.lastTarget 
3148 is set to the build target node, if the build was successful.
3149
3150 .EE
3151 Example for implementing and using custom tests:
3152
3153 .ES
3154 def CheckQt(context, qtdir):
3155     context.Message( 'Checking for qt ...' )
3156     lastLIBS = context.env['LIBS']
3157     lastLIBPATH = context.env['LIBPATH']
3158     lastCPPPATH= context.env['CPPPATH']
3159     context.env.Append(LIBS = 'qt', LIBPATH = qtdir + '/lib', CPPPATH = qtdir + '/include' )
3160     ret = context.TryLink("""
3161 #include <qapp.h>
3162 int main(int argc, char **argv) { 
3163   QApplication qapp(argc, argv);
3164   return 0;
3165 }
3166 """
3167     if not ret:
3168         context.env.Replace(LIBS = lastLIBS, LIBPATH=lastLIBPATH, CPPPATH=lastCPPPATH)
3169     context.Result( ret )
3170     return ret
3171
3172 env = Environment()
3173 conf = Configure( env, custom_tests = 'CheckQt' : CheckQt )
3174 if not conf.CheckQt('/usr/lib/qt'):
3175     print 'We really need qt!'
3176     Exit(1)
3177 env = conf.Finish() 
3178 .EE
3179
3180 .SS Construction Variable Options
3181
3182 Often when building software, various options need to be specified at build
3183 time that are not known when the SConstruct/SConscript files are
3184 written. For example, libraries needed for the build may be in non-standard
3185 locations, or site-specific compiler options may need to be passed to the
3186 compiler. 
3187 .B scons
3188 provides a mechanism for overridding construction variables from the
3189 command line or a text-based SConscript file through an Options
3190 object. To create an Options object, call the Options() function:
3191
3192 .TP
3193 .RI Options([ files ])
3194 This creates an Options object that will read construction variables from
3195 the file or list of filenames given in the  
3196 .I files
3197 argument. If no files are given, then no files will be read. Example:
3198
3199 .ES
3200 opts = Options('custom.py')
3201 .EE
3202
3203 Options objects have the following methods:
3204
3205 .TP
3206 .RI Add( key ", [" help ", " default ", " validater ", " converter ])
3207 This adds a customizable construction variable to the Options object. 
3208 .I key
3209 is the name of the variable. 
3210 .I help 
3211 is the help text for the variable.
3212 .I default 
3213 is the default value of the variable.
3214 .I validater
3215 is called to validate the value of the variable, and should take three
3216 arguments: key, value, and environment
3217 .I converter
3218 is called to convert the value before putting it in the environment, and
3219 should take a single argument: value. Example:
3220
3221 .ES
3222 opts.Add('CC', 'The C compiler')
3223 .EE
3224
3225 .TP
3226 .RI Update( env )
3227 This updates a construction environment
3228 .I env
3229 with the customized construction variables. Normally this method is not
3230 called directly, but is called indirectly by passing the Options object to
3231 the Environment() function:
3232
3233 .ES
3234 env = Environment(options=opts)
3235 .EE
3236
3237 .TP
3238 .RI Save( filename ", " env )
3239 This saves the currently set options into a script file named  
3240 .I filename
3241 that can be used on the next invocation to automatically load the current
3242 settings.  This method combined with the Options method can be used to
3243 support caching of options between runs.
3244
3245 .ES
3246 env = Environment()
3247 opts = Options(['options.cache', 'custom.py'])
3248 opts.Add(...)
3249 opts.Update(env)
3250 opts.Save('options.cache', env)
3251 .EE
3252
3253 .TP
3254 .RI GenerateHelpText( env ", [" sort ])
3255 This generates help text documenting the customizable construction
3256 variables suitable to passing in to the Help() function. 
3257 .I env
3258 is the construction environment that will be used to get the actual values
3259 of customizable variables. Calling with 
3260 an optional
3261 .I sort
3262 function
3263 will cause the output to be sorted
3264 by the specified argument.
3265 The specific
3266 .I sort
3267 function
3268 should take two arguments
3269 and return
3270 -1, 0 or 1
3271 (like the standard Python
3272 .I cmp
3273 function).
3274
3275 .ES
3276 Help(opts.GenerateHelpText(env))
3277 Help(opts.GenerateHelpText(env, sort=cmp))
3278 .EE
3279
3280 The text based SConscript file is executed as a Python script, and the
3281 global variables are queried for customizable construction
3282 variables. Example:
3283
3284 .ES
3285 CC = 'my_cc'
3286 .EE
3287
3288 .SS Other Functions
3289
3290 .B scons
3291 also provides various additional functions,
3292 not associated with a construction environment,
3293 that SConscript files can use:
3294
3295 .TP 
3296 .RI AddPostAction ( target, action )
3297 Arranges for the specified
3298 .I action
3299 to be performed
3300 after the specified
3301 .I target
3302 has been built.
3303 The specified action(s) may be
3304 an Action object, or anything that
3305 can be converted into an Action object
3306 (see below).
3307
3308 .TP 
3309 .RI AddPreAction ( target, action )
3310 Arranges for the specified
3311 .I action
3312 to be performed
3313 before the specified
3314 .I target
3315 is built.
3316 The specified action(s) may be
3317 an Action object, or anything that
3318 can be converted into an Action object
3319 (see below).
3320
3321 .TP
3322 .RI Alias ( name )
3323 Creates or references an alias independent of the construction environment.
3324
3325 .ES
3326 Alias('install')
3327 .EE
3328
3329 .TP
3330 .RI BuildDir( build_dir ", " src_dir ", [" duplicate ])
3331 This specifies a build directory
3332 .I build_dir
3333 in which to build all derived files
3334 that would normally be built under
3335 .IR src_dir .
3336 Multiple build directories can be set up for multiple build variants, for
3337 example. 
3338 .I src_dir
3339 must be underneath the SConstruct file's directory,
3340 and
3341 .I build_dir
3342 may not be underneath the
3343 .I src_dir .
3344
3345 The default behavior is for
3346 .B scons
3347 to duplicate all of the files in the tree underneath
3348 .I src_dir
3349 into
3350 .IR build_dir ,
3351 and then build the derived files within the copied tree.
3352 (The duplication is performed by
3353 linking or copying,
3354 depending on the platform.)
3355 This guarantees correct builds
3356 regardless of whether intermediate source files
3357 are generated during the build,
3358 where preprocessors or other scanners search
3359 for included files,
3360 or whether individual compilers or other invoked tools
3361 are hard-coded to put derived files in the same directory as source files.
3362
3363 This behavior of making a complete copy of the source tree
3364 may be disabled by setting
3365 .I duplicate
3366 to 0.
3367 This will cause
3368 .B scons
3369 to invoke Builders using the
3370 path names of source files in
3371 .I src_dir
3372 and the path names of derived files within
3373 .IR build_dir .
3374 This is always more efficient than
3375 .IR duplicate =1,
3376 and is usually safe for most builds.
3377 Specifying
3378 .IR duplicate =0,
3379 however,
3380 may cause build problems
3381 if source files are generated during the build,
3382 if any invoked tools are hard-coded to
3383 put derived files in the same directory as the source files.
3384
3385 Note that specifying a
3386 .B BuildDir
3387 works most naturally
3388 with a subsidiary SConscript file
3389 in the source directory.
3390 However,
3391 you would then call the subsidiary SConscript file
3392 not in the source directory,
3393 but in the
3394 .I build_dir ,
3395 as if
3396 .B scons
3397 had made a virtual copy of the source tree
3398 regardless of the value of 
3399 .IR duplicate .
3400 This is how you tell
3401 .B scons
3402 which variant of a source tree to build.
3403 For example:
3404
3405 .ES
3406 BuildDir('build-variant1', 'src')
3407 SConscript('build-variant1/SConscript')
3408 BuildDir('build-variant2', 'src')
3409 SConscript('build-variant2/SConscript')
3410 .EE
3411
3412 See also the
3413 .BR SConscript ()
3414 function, described below,
3415 for another way to 
3416 specify a build directory
3417 in conjunction with calling a subsidiary
3418 SConscript file.)
3419
3420 .TP 
3421 .RI AddPostAction ( target, action )
3422 Arranges for the specified
3423 .I action
3424 to be performed
3425 after the specified
3426 .I target
3427 has been built.
3428 The specified action(s) may be
3429 an Action object, or anything that
3430 can be converted into an Action object
3431 (see below).
3432
3433 .TP 
3434 .RI CacheDir ( cache_dir )
3435 Specifies that
3436 .B scons
3437 will maintain a cache of derived files in
3438 .I cache_dir .
3439 The derived files in the cache will be shared
3440 among all the builds using the same
3441 .BR CacheDir ()
3442 call.
3443
3444 When a
3445 .BR CacheDir ()
3446 is being used and
3447 .B scons
3448 finds a derived file that needs to be rebuilt,
3449 it will first look in the cache to see if a
3450 derived file has already been built
3451 from identical input files and an identical build action
3452 (as incorporated into the MD5 build signature).
3453 If so,
3454 .B scons
3455 will retrieve the file from the cache.
3456 If the derived file is not present in the cache,
3457 .B scons
3458 will rebuild it and
3459 then place a copy of the built file in the cache
3460 (identified by its MD5 build signature),
3461 so that it may be retrieved by other
3462 builds that need to build the same derived file
3463 from identical inputs.
3464
3465 Use of a specified
3466 .BR CacheDir()
3467 may be disabled for any invocation
3468 by using the
3469 .B --cache-disable
3470 option.
3471
3472 If the
3473 .B --cache-force
3474 option is used,
3475 .B scons
3476 will place a copy of
3477 .I all
3478 derived files in the cache,
3479 even if they already existed
3480 and were not built by this invocation.
3481 This is useful to populate a cache
3482 the first time
3483 .BR CacheDir ()
3484 is added to a build,
3485 or after using the
3486 .B --cache-disable
3487 option.
3488
3489 When using
3490 .BR CacheDir (),
3491 .B scons
3492 will report,
3493 "Retrieved `file' from cache,"
3494 unless the
3495 .B --cache-show
3496 option is being used.
3497 When the
3498 .B --cache-show
3499 option is used,
3500 .B scons
3501 will print the action that
3502 .I would
3503 have been used to build the file,
3504 without any indication that
3505 the file was actually retrieved from the cache.
3506 This is useful to generate build logs
3507 that are equivalent regardless of whether
3508 a given derived file has been built in-place
3509 or retrieved from the cache.
3510
3511 .TP 
3512 .RI Clean ( target, files_or_dirs )
3513 This specifies a list of files or directories which should be removed
3514 whenever the target is specified with the
3515 .B -c
3516 command line option.
3517 Multiple calls to
3518 .BR Clean ()
3519 are legal,
3520 and create a new target or add files and directories to the
3521 clean list for the specified target.
3522
3523 Multiple files or directories should be specified
3524 either as separate arguments to the
3525 .BR Clean ()
3526 method, or as a list.
3527 .BR Clean ()
3528 will also accept the return value of any of the construction environment
3529 Builder methods.
3530 Examples:
3531
3532 .ES
3533 Clean('foo', ['bar', 'baz'])
3534 Clean('dist', env.Program('hello', 'hello.c'))
3535 .EE
3536
3537 .TP 
3538 .RI Default( targets )
3539 This specifies a list of default targets,
3540 which will be built by
3541 .B scons
3542 if no explicit targets are given on the command line.
3543 Multiple calls to
3544 .BR Default ()
3545 are legal,
3546 and add to the list of default targets.
3547
3548 Multiple targets should be specified as
3549 separate arguments to the
3550 .BR Default ()
3551 method, or as a list.
3552 .BR Default ()
3553 will also accept the Node returned by any
3554 of a construction environment's
3555 builder methods.
3556 Examples:
3557
3558 .ES
3559 Default('foo', 'bar', 'baz')
3560 Default(['a', 'b', 'c'])
3561 hello = env.Program('hello', 'hello.c')
3562 Default(hello)
3563 .EE
3564
3565 An argument to
3566 .BR Default ()
3567 of
3568 .B None
3569 will clear all default targets.
3570 Later calls to
3571 .BR Default ()
3572 will add to the (now empty) default-target list
3573 like normal.
3574
3575 .TP
3576 .RI Dir( name ", [" directory ])
3577 This returns an object that represents a given directory 
3578 .IR name . 
3579 .I name
3580 can be a relative or absolute path. 
3581 .I directory
3582 is an optional directory that will be used as the parent directory. 
3583
3584 .TP
3585 .RI EnsurePythonVersion( major ", " minor )
3586 Ensure that the Python version is at least 
3587 .IR major . minor . 
3588 This function will
3589 print out an error message and exit SCons with a non-zero exit code if the
3590 actual Python version is not late enough.
3591
3592 .ES
3593 EnsurePythonVersion(2,2)
3594 .EE
3595
3596 .TP
3597 .RI EnsureSConsVersion( major ", " minor )
3598 Ensure that the SCons version is at least 
3599 .IR major . minor . 
3600 This function will
3601 print out an error message and exit SCons with a non-zero exit code if the
3602 actual SCons version is not late enough.
3603
3604 .ES
3605 EnsureSConsVersion(0,9)
3606 .EE
3607
3608 .TP
3609 .RI Exit([ value ])
3610 This tells
3611 .B scons
3612 to exit immediately
3613 with the specified
3614 .IR value .
3615 A default exit value of
3616 .B 0
3617 (zero)
3618 is used if no value is specified.
3619
3620 .TP
3621 .RI Export( vars )
3622 This tells 
3623 .B scons
3624 to export a list of variables from the current
3625 SConscript file to all other SConscript files.
3626 The exported variables are kept in a global collection,
3627 so subsequent calls to
3628 .BR Export ()
3629 will over-write previous exports that have the same name. 
3630 Multiple variable names can be passed to
3631 .BR Export ()
3632 as separate arguments or as a list. A dictionary can be used to map
3633 variables to a different name when exported. Both local variables and
3634 global variables can be exported.
3635 Examples:
3636
3637 .ES
3638 env = Environment()
3639 # Make env available for all SConscript files to Import().
3640 Export("env")
3641
3642 package = 'my_name'
3643 # Make env and package available for all SConscript files:.
3644 Export("env", "package")
3645
3646 # Make env and package available for all SConscript files:
3647 Export(["env", "package"])
3648
3649 # Make env available using the name debug:.
3650 Export({"debug":env})
3651 .EE
3652
3653 .IP
3654 Note that the
3655 .BR SConscript ()
3656 function supports an
3657 .I exports
3658 argument that makes it easier to to export a variable or
3659 set of variables to a single SConscript file.
3660 See the description of the
3661 .BR SConscript ()
3662 function, below.
3663
3664 .TP 
3665 .RI File( name ", [" directory ])
3666 This returns an object that represents a given file 
3667 .IR name . 
3668 .I name
3669 can be a relative or absolute path. 
3670 .I directory
3671 is an optional directory that will be used as the parent directory. 
3672
3673 .TP
3674 .RI FindFile( file ", " dirs )
3675 Search for 
3676 .I file 
3677 in the path specified by 
3678 .IR dirs .
3679 .I file
3680 may be a list of file names or a single file name. In addition to searching
3681 for files that exist in the filesytem, this function also searches for
3682 derived files that have not yet been built.
3683
3684 .ES
3685 foo = FindFile('foo', ['dir1', 'dir2'])
3686 .EE
3687 .\"
3688 .\".TP
3689 .\".RI GetBuildPath( XXX )
3690 .\"XXX
3691 .\"
3692 .\".TP
3693 .\".RI GetLaunchDir( XXX )
3694 .\"XXX
3695
3696 .TP
3697 .RI GetJobs()
3698 Get the number of jobs (commands) that will be run simultaneously. See also 
3699 .I -j
3700 and
3701 .IR SetJobs() .
3702
3703 .TP
3704 .RI Help( text )
3705 This specifies help text to be printed if the 
3706 .B -h 
3707 argument is given to
3708 .BR scons .
3709 .B scons
3710 will exit after printing out the help text.
3711
3712 .TP 
3713 .RI Import( vars )
3714 This tells 
3715 .B scons
3716 to import a list of variables into the current SConscript file. This
3717 will import variables that were exported with
3718 .BR Export ()
3719 or in the 
3720 .I exports
3721 argument to 
3722 .BR SConscript ().
3723 Variables exported by 
3724 .BR SConscript ()
3725 have precedence.
3726 Multiple variable names can be passed to 
3727 .BR Import ()
3728 as separate arguments or as a list. The variable "*" can be used
3729 to import all variables.
3730 Examples:
3731
3732 .ES
3733 Import("env")
3734 Import("env", "variable")
3735 Import(["env", "variable"])
3736 Import("*")
3737 .EE
3738
3739 .TP
3740 .RI Literal( string )
3741 The specified
3742 .I string
3743 will be preserved as-is
3744 and not have construction variables expanded.
3745
3746 .TP
3747 .RI Local( targets )
3748 The specified
3749 .I targets
3750 will have copies made in the local tree,
3751 even if an already up-to-date copy
3752 exists in a repository.
3753
3754 .TP
3755 .RI ParseConfig( env , command ", [" function ])
3756 Calls the specified
3757 .I function
3758 to modify the specified environment
3759 .I env
3760 as specified by the output of
3761 .I command .
3762 The default
3763 .I function
3764 expects the output of a typical
3765 .I *-config command
3766 (for example,
3767 .BR gtk-config )
3768 and parses the returned
3769 .BR -L ,
3770 .BR -l ,
3771 .B -I
3772 and other options
3773 into the
3774 .BR LIBPATH ,
3775 .BR LIBS ,
3776 .B CPPPATH
3777 and
3778 .B CCFLAGS
3779 variables,
3780 respectively.
3781
3782 .TP
3783 .RI Platform( string )
3784 Returns a callable object
3785 that can be used to initialize
3786 a construction environment using the
3787 platform keyword of the Environment() method.
3788
3789 .ES
3790 env = Environment(platform = Platform('win32'))
3791 .EE
3792 .IP
3793 Note that the
3794 .B win32
3795 platform adds the
3796 .B SYSTEMROOT
3797 variable from the user's external environment
3798 to the construction environment's
3799 .B ENV
3800 dictionary.
3801 This is so that any executed commands
3802 that use sockets to connect with other systems
3803 (such as fetching source files from
3804 external CVS repository specifications like 
3805 .BR :pserver:anonymous:@cvs.sourceforge.net:/cvsroot/scons )
3806 will work on Win32 systems.
3807
3808 .TP
3809 .RI Repository( directory )
3810 Specifies that
3811 .I directory
3812 is a repository to be searched for files.
3813 Multiple calls to
3814 .BR Repository ()
3815 are legal,
3816 and each one adds to the list of
3817 repositories that will be searched.
3818
3819 To
3820 .BR scons ,
3821 a repository is a copy of the source tree,
3822 from the top-level directory on down,
3823 which may contain
3824 both source files and derived files
3825 that can be used to build targets in
3826 the local source tree.
3827 The canonical example would be an
3828 official source tree maintained by an integrator.
3829 If the repository contains derived files,
3830 then the derived files should have been built using
3831 .BR scons ,
3832 so that the repository contains the necessary
3833 signature information to allow
3834 .B scons
3835 to figure out when it is appropriate to
3836 use the repository copy of a derived file,
3837 instead of building one locally.
3838
3839 Note that if an up-to-date derived file
3840 already exists in a repository,
3841 .B scons
3842 will
3843 .I not
3844 make a copy in the local directory tree.
3845 In order to guarantee that a local copy
3846 will be made,
3847 use the
3848 .B Local()
3849 method.
3850
3851 .TP
3852 .RI Return( vars )
3853 This tells
3854 .B scons
3855 what variable(s) to use as the return value(s) of the current SConscript
3856 file. These variables will be returned to the "calling" SConscript file
3857 as the return value(s) of 
3858 .BR SConscript ().
3859 Multiple variable names should be passed to 
3860 .BR Return ()
3861 as a list. Example:
3862
3863 .ES
3864 Return("foo")
3865 Return(["foo", "bar"])
3866 .EE
3867
3868 .TP
3869 .RI SConscript( script ", [" exports ", " build_dir ", " src_dir ", " duplicate ])
3870 This tells
3871 .B scons
3872 to execute
3873 .I script
3874 as a SConscript (configuration) file.
3875
3876 The optional 
3877 .I exports
3878 argument provides a list of variable names or a dictionary of
3879 named values to export to
3880 .IR script ". "
3881 These variables are locally exported only to the specified
3882 .IR script ,
3883 and do not affect the
3884 global pool of variables used by
3885 the
3886 .BR Export ()
3887 function.
3888 '\"If multiple dirs are provided,
3889 '\"each script gets a fresh export.
3890 The subsidiary
3891 .I script
3892 file must use the
3893 .BR Import ()
3894 function to import the variables.
3895
3896 The optional
3897 .I build_dir
3898 argument specifies that all of the target files
3899 (for example, object files and executables)
3900 that would normally be built in the subdirectory in which
3901 .I script
3902 resides should actually
3903 be built in
3904 .IR build_dir .
3905 The optional
3906 .I src_dir
3907 argument specifies that the
3908 source files from which
3909 the target files should be built
3910 can be found in
3911 .IR src_dir .
3912 By default,
3913 .B scons
3914 will link or copy (depending on the platform)
3915 all the source files into the build directory.
3916 This behavior may be disabled by
3917 setting the optional
3918 .I duplicate
3919 argument to 0
3920 (it is set to 1 by default),
3921 in which case
3922 .B scons
3923 will refer directly to
3924 the source files in their source directory
3925 when building target files.
3926 (Setting
3927 .IR duplicate =0
3928 is usually safe, and always more efficient
3929 than the default of
3930 .IR duplicate =1,
3931 but it may cause build problems in certain end-cases,
3932 such as compiling from source files that
3933 are generated by the build.)
3934
3935 Any variables returned by 
3936 .I script 
3937 using 
3938 .BR Return ()
3939 will be returned by the call to
3940 .BR SConscript (). 
3941
3942 Examples:
3943
3944 .ES
3945 SConscript('subdir/SConscript')
3946 foo = SConscript('sub/SConscript', exports='env')
3947 SConscript('dir/SConscript', exports=['env', 'variable'])
3948 SConscript('src/SConscript', build_dir='build', duplicate=0)
3949 SConscript('bld/SConscript', src_dir='src', exports='env')
3950 .EE
3951
3952 .TP
3953 .RI SConscriptChdir( value )
3954 By default,
3955 .B scons
3956 changes its working directory
3957 to the directory in which each
3958 subsidiary SConscript file lives.
3959 This behavior may be disabled
3960 by specifying:
3961 .ES
3962 SConscriptChdir(0)
3963 .EE
3964 in which case
3965 .B scons
3966 will stay in the top-level directory
3967 while reading all SConscript files.
3968 (This may be necessary when building from repositories,
3969 when all the directories in which SConscript files may be found
3970 don't necessarily exist locally.)
3971
3972 You may enable and disable
3973 this ability by calling
3974 SConscriptChdir()
3975 multiple times:
3976
3977 .ES
3978 SConscriptChdir(0)
3979 SConscript('foo/SConscript')    # will not chdir to foo
3980 SConscriptChdir(1)
3981 SConscript('bar/SConscript')    # will chdir to bar
3982 .EE
3983
3984 .TP 
3985 .RI SetBuildSignatureType( type )
3986
3987 This function tells SCons what type of build signature to use: "build" or
3988 "content". "build" means to concatenate the signatures of all source files
3989 of a derived file to make its signature, and "content" means to use
3990 the derived files content signature as its signature. "build" signatures
3991 are usually faster to compute, but "content" signatures can prevent
3992 redundant rebuilds. The default is "build".
3993
3994 .TP
3995 .RI SetContentSignatureType( type )
3996
3997 This function tells SCons what type of content signature to use: "MD5" or
3998 "timestamp". "MD5" means to use the MD5 checksum of a files contents as
3999 its signature, and "timestamp" means to use a files timestamp as its
4000 signature. When using "timestamp" signatures, changes in the
4001 command line will not cause files to be rebuilt. "MD5" signatures take
4002 longer to compute, but "timestamp" signatures are less accurate. The
4003 default is "MD5".
4004
4005 .TP
4006 .RI SetJobs( num )
4007 Specifies the number of jobs (commands) to run simultaneously. 
4008 .I -j
4009 overrides this function. See also 
4010 .I -j
4011 and 
4012 .IR GetJobs() .
4013
4014 .TP
4015 .RI Split( arg )
4016 Returns a list of file names or other objects.
4017 If arg is a string,
4018 it will be split on strings of white-space characters
4019 within the string,
4020 making it easier to write long lists of file names.
4021 If arg is already a list,
4022 the list will be returned untouched.
4023 If arg is any other type of object,
4024 it will be returned as a list
4025 containing just the object.
4026
4027 .ES
4028 files = Split("f1.c f2.c f3.c")
4029 files = Split("""
4030         f4.c
4031         f5.c
4032         f6.c
4033 """)
4034 .EE
4035
4036 .TP
4037 .RI Tool( string )
4038 Returns a callable object
4039 that can be used to initialize
4040 a construction environment using the
4041 tools keyword of the Environment() method.
4042
4043 .ES
4044 env = Environment(tools = [ Tool('msvc') ])
4045 .EE
4046
4047 .TP
4048 .RI WhereIs( program ", [" path  ", [" pathext ]])
4049
4050 Searches for the specified executable
4051 .I program,
4052 returning the full path name to the program
4053 if it is found,
4054 and returning None if not.
4055 Searches the specified
4056 .I path,
4057 or the user's current PATH
4058 (os.environ['PATH'])
4059 by default.
4060 On Win32 systems, searches for executable
4061 programs with any of the file extensions
4062 listed in the specified
4063 .I pathext,
4064 or the user's current PATHEXT
4065 (os.environ['PATHEXT'])
4066 by default.
4067
4068 .SH EXTENDING SCONS
4069 .SS Builder Objects
4070 .B scons
4071 can be extended by adding new builders to a construction
4072 environment using the 
4073 .B Builder 
4074 function.
4075 The
4076 .B Builder
4077 function accepts the following arguments:
4078
4079 .IP action
4080 The command line string used to build the target from the source. 
4081 .B action
4082 can also be:
4083 a list of strings representing the command
4084 to be executed and its arguments
4085 (suitable for enclosing white space in an argument),
4086 a dictionary
4087 mapping source file name suffixes to
4088 any combination of command line strings
4089 (if the builder should accept multiple source file extensions),
4090 a Python function;
4091 an Action object
4092 (see the next section);
4093 or a list of any of the above.
4094
4095 An action function
4096 takes three arguments:
4097 .I source 
4098 - a list of source nodes, 
4099 .I target
4100 - a list of target nodes,
4101 .I env
4102 - the construction environment.
4103
4104 .IP multi
4105 Specifies whether this builder is allowed to be called multiple times for
4106 the same target file(s). The default is 0, which means the builder
4107 can not be called multiple times for the same target file(s). Calling a
4108 builder multiple times for the same target simply adds additional source
4109 files to the target; it is not allowed to change the environment associated
4110 with the target, specify addition environment overrides, or associate a different
4111 builder with the target. 
4112
4113 .IP prefix 
4114 The prefix that will be prepended to the target file name.
4115
4116 .IP suffix
4117 The suffix that will be appended to the target file name.
4118
4119 .IP src_suffix
4120 The expected source file name suffix.
4121
4122 .IP src_builder
4123 Specifies a builder to use when a source file name suffix does not match
4124 any of the suffixes of the builder. Using this argument produces a
4125 multi-stage builder.
4126
4127 .IP emitter
4128 A function that is passed the target, source, and environment,
4129 and which returns a tuple containing two lists,
4130 the list of targets to be built by this builder,
4131 and the list of sources for this builder.
4132 This allows the target and source lists to
4133 be manipulated before the target(s) are actually built.
4134
4135 The emitter function
4136 takes three arguments:
4137 .I source 
4138 - a list of source nodes, 
4139 .I target
4140 - a list of target nodes,
4141 .I env
4142 - the construction environment.
4143
4144 Example:
4145
4146 .ES
4147 def e(target, source, env):
4148     return (target + ['foo.foo'], source + ['foo.src'])
4149
4150 b = Builder(emitter=e)
4151 .EE
4152
4153 .IP generator
4154 A function that returns a list of actions that will be executed to build
4155 the target(s) from the source(s).
4156 The returned action(s) may be
4157 an Action object, or anything that
4158 can be converted into an Action object
4159 (see the next section).
4160
4161 The generator function
4162 takes four arguments:
4163 .I source 
4164 - a list of source nodes, 
4165 .I target
4166 - a list of target nodes,
4167 .I env
4168 - the construction environment.
4169 .I for_signature
4170 - a Boolean value that specifies
4171 whether the generator is being called
4172 for generating a build signature
4173 (as opposed to actually executing the command).
4174 Example:
4175
4176 .ES
4177 def g(source, target, env, for_signature):
4178     return [["gcc", "-c", "-o"] + target + source] 
4179
4180 b = Builder(generator=g)
4181 .EE
4182
4183 The 
4184 .I generator
4185 and
4186 .I action
4187 arguments must not both be used for the same Builder.
4188
4189 .IP env
4190 A construction environment that can be used
4191 to fetch source code using this Builder.
4192 (Note that this environment is
4193 .I not
4194 used for normal builds of normal target files,
4195 which use the environment that was
4196 used to call the Builder for the target file.)
4197
4198 .IP overrides
4199 A dictionary of construction variables
4200 that will be set in the executing
4201 construction environment when this
4202 Builder is invoked.
4203 The canonical example here would be
4204 to set a construction variable to 
4205 the repository of a source code system.
4206
4207 Any additional keyword arguments supplied
4208 when a Builder object is called
4209 will be associated with the target
4210 (and any other files built as a
4211 result of the call).
4212
4213 .ES
4214 b = Builder(action="build < $SOURCE > $TARGET")
4215 env = Environment(BUILDERS = {'MyBuild' : b})
4216 env.MyBuild('foo.out', 'foo.in', my_arg = 'xyzzy')
4217 .EE
4218
4219 These extra keyword arguments are passed to the
4220 following functions:
4221 command generator functions,
4222 function Actions,
4223 and emitter functions.
4224
4225 .SS Action Objects
4226
4227 The Builder function will turn its
4228 .B action
4229 keyword argument into an appropriate
4230 internal Action object.
4231 Occasionally, it may be more efficient
4232 to create an explicit Action object
4233 and use it to initialize multiple
4234 Builder objects,
4235 rather than let each separate Builder object
4236 create a separate Action.
4237
4238 The Action method takes one or two arguments
4239 and returns an appropriate object for the action
4240 represented by the type of the first argument:
4241
4242 .IP Action
4243 If the first argument is already an Action object,
4244 the object is simply returned.
4245
4246 .IP String
4247 If the first argument is a string,
4248 a command-line Action is returned.
4249
4250 .ES
4251 Action('$CC -c -o $TARGET $SOURCES')
4252 .EE
4253
4254 .\" XXX From Gary Ruben, 23 April 2002:
4255 .\" What would be useful is a discussion of how you execute command
4256 .\" shell commands ie. what is the process used to spawn the shell, pass
4257 .\" environment variables to it etc., whether there is one shell per
4258 .\" environment or one per command etc.  It might help to look at the Gnu
4259 .\" make documentation to see what they think is important to discuss about
4260 .\" a build system. I'm sure you can do a better job of organising the
4261 .\" documentation than they have :-)
4262
4263
4264 .IP List
4265 If the first argument is a list,
4266 then a list of Action objects is returned.
4267 An Action object is created as necessary
4268 for each element in the list.
4269 If an element
4270 .I within
4271 the list is itself a list,
4272 the internal list is the
4273 command and arguments to be executed via
4274 the command line.
4275 This allows white space to be enclosed
4276 in an argument by defining
4277 a command in a list within a list:
4278 .ES
4279 Action([['cc', '-c', '-DWHITE SPACE', '-o', '$TARGET', '$SOURCES']])
4280 .EE
4281
4282 .IP Function
4283 If the first argument is a Python function,
4284 a function Action is returned.
4285 The Python function takes three keyword arguments,
4286 .B target
4287 (a Node object representing the target file),
4288 .B source
4289 (a Node object representing the source file)
4290 and
4291 .B env
4292 (the construction environment
4293 used for building the target file).
4294 The
4295 .B target
4296 and
4297 .B source
4298 arguments may be lists of Node objects if there is
4299 more than one target file or source file.
4300 The actual target and source file name(s) may
4301 be retrieved from their Node objects
4302 via the built-in Python str() function:
4303 .ES
4304 target_file_name = str(target)
4305 source_file_names = map(lambda x: str(x), source)
4306 .EE
4307 .IP
4308 The function should return
4309 .B 0
4310 or
4311 .B None
4312 to indicate a successful build of the target file(s).
4313 The function may raise an exception
4314 or return a non-zero exit status
4315 to indicate an unsuccessful build.
4316
4317 .ES
4318 def build_it(target = None, source = None, env = None):
4319     # build the target from the source
4320     return 0
4321  
4322 a = Action(build_it)
4323 .EE
4324
4325 The second, optional argument
4326 is a Python function that returns
4327 a string to be printed to describe the action being executed.
4328 Like the function to build a file,
4329 this function takes three arguments:
4330 .B target
4331 (a Node object representing the target file),
4332 .B source
4333 (a Node object representing the source file)
4334 and
4335 .BR env
4336 (a construction environment).
4337 The
4338 .B target
4339 and
4340 .B source
4341 arguments may be lists of Node objects if there is
4342 more than one target file or source file.
4343 Examples:
4344
4345 .ES
4346 def build_it(target, source, env):
4347     # build the target from the source
4348     return 0
4349
4350 def string_it(target, source, env):
4351     return "building '%s' from '%s'" % (target[0], source[0])
4352
4353 # Use a positional argument.
4354 a = Action(build_it, string_it)
4355
4356 # Alternatively, use a keyword argument.
4357 a = Action(build_it, strfunction=string_it)
4358 .EE
4359
4360 The third, also optional argument
4361 is a list of construction variables
4362 whose values will be included
4363 in the signature of the Action
4364 when deciding whether a target should
4365 be rebuilt because the action changed.
4366 This is necessary whenever you want a target to
4367 be rebuilt when a specific
4368 construction variable changes,
4369 because the underlying Python code for a function
4370 will not change when the value of the construction variable does.
4371
4372 .ES
4373 def build_it(target, source, env):
4374     # build the target from the 'XXX' construction variable
4375     open(target[0], 'w').write(env['XXX'])
4376     return 0
4377
4378 def string_it(target, source):
4379     return "building '%s' from '%s'" % (target[0], source[0])
4380
4381 # Use positional arguments.
4382 a = Action(build_it, string_it, ['XXX'])
4383
4384 # Alternatively, use a keyword argument.
4385 a = Action(build_it, varlist=['XXX'])
4386 .EE
4387 .PP
4388 If the action argument is not one of the above,
4389 None is returned.
4390
4391 .SS Variable Substitution
4392
4393 Before executing a command,
4394 .B scons
4395 performs construction variable interpolation on the strings that make up
4396 the command line of builders.
4397 Variables are introduced by a
4398 .B $
4399 prefix.
4400 Besides construction variables, scons provides the following
4401 variables for each command execution:
4402
4403 .IP TARGET
4404 The file name of the target being built, or the file name of the first 
4405 target if multiple targets are being built.
4406
4407 .IP TARGETS
4408 The file names of all targets being built.
4409
4410 .IP SOURCE
4411 The file name of the source of the build command, or the file name of the
4412 first source if multiple sources are being built.
4413
4414 .IP SOURCES
4415 The file names of the sources of the build command.
4416
4417 (Note that the above variables are reserved
4418 and may not be set in a construction environment.)
4419
4420 .LP 
4421 For example, given the construction variable CC='cc', targets=['foo'], and
4422 sources=['foo.c', 'bar.c']:
4423
4424 .ES
4425 action='$CC -c -o $TARGET $SOURCES'
4426 .EE
4427
4428 would produce the command line:
4429
4430 .ES
4431 cc -c -o foo foo.c bar.c
4432 .EE
4433
4434 Variable names may be surrounded by curly braces ({})
4435 to separate the name from the trailing characters.
4436 Within the curly braces, a variable name may have
4437 a Python slice subscript appended to select one
4438 or more items from a list.
4439 In the previous example, the string:
4440
4441 .ES
4442 ${SOURCES[1]}
4443 .EE
4444
4445 would produce:
4446
4447 .ES
4448 bar.c
4449 .EE
4450
4451 Additionally, a variable name may
4452 have the following special
4453 modifiers appended within the enclosing curly braces
4454 to modify the interpolated string:
4455
4456 .IP base
4457 The base path of the file name,
4458 including the directory path
4459 but excluding any suffix.
4460
4461 .IP dir
4462 The name of the directory in which the file exists.
4463
4464 .IP file
4465 The file name,
4466 minus any directory portion.
4467
4468 .IP filebase
4469 Just the basename of the file,
4470 minus any suffix
4471 and minus the directory.
4472
4473 .IP suffix
4474 Just the file suffix.
4475
4476 .IP abspath
4477 The absolute path name of the file.
4478
4479 .IP posix
4480 The POSIX form of the path,
4481 with directories separated by
4482 .B /
4483 (forward slashes)
4484 not backslashes.
4485 This is sometimes necessary on Win32 systems
4486 when a path references a file on other (POSIX) systems.
4487
4488 .IP srcpath
4489 The directory and file name to the source file linked to this file
4490 through BuildDir.  If this file isn't linked, it just returns the
4491 directory and filename unchanged.
4492
4493 .IP srcdir
4494 The directory containing the source file linked to this file
4495 through BuildDir.  If this file isn't linked, it just returns the
4496 directory part of the filename.
4497
4498 .LP
4499 For example, the specified target will
4500 expand as follows for the corresponding modifiers:
4501
4502 .ES
4503 $TARGET              => sub/dir/file.x
4504 ${TARGET.base}       => sub/dir/file
4505 ${TARGET.dir}        => sub/dir
4506 ${TARGET.file}       => file.x
4507 ${TARGET.filebase}   => file
4508 ${TARGET.suffix}     => .x
4509 ${TARGET.abspath}    => /top/dir/sub/dir/file.x
4510
4511 BuildDir('sub/dir','src')
4512 $SOURCE              => sub/dir/file.x
4513 ${SOURCE.srcpath}    => src/file.x
4514 ${SOURCE.srcdir}     => src
4515 .EE
4516
4517 Lastly, a variable name
4518 may be a callable Python function
4519 associated with a
4520 construction variable in the environment.
4521 The function should
4522 take three arguments:
4523 .I target
4524 - a list of target nodes,
4525 .I source 
4526 - a list of source nodes, 
4527 .I env
4528 - the construction environment.
4529 SCons will insert whatever
4530 the called function returns
4531 into the expanded string:
4532
4533 .ES
4534 def foo(target, source, env):
4535     return "bar"
4536
4537 # Will expand $BAR to "bar baz"
4538 env=Environment(FOO=foo, BAR="$FOO baz")
4539 .EE
4540
4541 You can use this feature to pass arguments to a
4542 Python function by creating a callable class
4543 that stores one or more arguments in an object,
4544 and then uses them when the
4545 .B __call__()
4546 method is called.
4547 Note that in this case,
4548 the entire variable expansion must
4549 be enclosed by curly braces
4550 so that the arguments will
4551 be associated with the
4552 instantiation of the class:
4553
4554 .ES
4555 class foo:
4556     def __init__(self, arg):
4557         self.arg = arg
4558
4559     def __call__(self, target, source, env):
4560         return arg + " bar"
4561
4562 # Will expand $BAR to "my argument bar baz"
4563 env=Environment(FOO=foo, BAR="${FOO('my argument')} baz")
4564 .EE
4565
4566 .LP
4567 The special pseudo-variables
4568 .R $(
4569 and
4570 .R $)
4571 may be used to surround parts of a command line
4572 that may change
4573 .I without
4574 causing a rebuild--that is,
4575 which are not included in the signature
4576 of target files built with this command.
4577 All text between
4578 .R $(
4579 and
4580 .R $)
4581 will be removed from the command line
4582 before it is added to file signatures,
4583 and the
4584 .R $(
4585 and
4586 .R $)
4587 will be removed before the command is executed.
4588 For example, the command line:
4589
4590 .ES
4591 echo Last build occurred $( $TODAY $). > $TARGET
4592 .EE
4593
4594 .LP
4595 would execute the command:
4596
4597 .ES
4598 echo Last build occurred $TODAY. > $TARGET
4599 .EE
4600
4601 .LP
4602 but the command signature added to any target files would be:
4603
4604 .ES
4605 echo Last build occurred  . > $TARGET
4606 .EE
4607
4608 SCons uses the following rules when converting construction variables into
4609 command lines:
4610
4611 .IP String
4612 When the value is a string it is interpreted as a space delimited list of
4613 command line arguments. 
4614
4615 .IP List
4616 When the value is a list it is interpreted as a list of command line
4617 arguments. Each element of the list is converted to a string.
4618
4619 .IP Other
4620 Anything that is not a list or string is converted to a string and
4621 interpreted as a single command line argument.
4622
4623 .IP Newline
4624 Newline characters (\\n) delimit lines. The newline parsing is done after
4625 all other parsing, so it is not possible for arguments (e.g. file names) to
4626 contain embedded newline characters. This limitation will likely go away in
4627 a future version of SCons.
4628
4629 .SS Scanner Objects
4630
4631 You can use the
4632 .B Scanner
4633 function to define
4634 objects to scan
4635 new file types for implicit dependencies.
4636 Scanner accepts the following arguments:
4637
4638 .IP function
4639 A Python function that will process
4640 the Node (file)
4641 and return a list of strings (file names)
4642 representing the implicit
4643 dependencies found in the contents.
4644 The function takes three or four arguments:
4645
4646     def scanner_function(node, env, path):
4647
4648     def scanner_function(node, env, path, arg):
4649
4650 The
4651 .B node
4652 argument is the internal
4653 SCons node representing the file.
4654 Use
4655 .B str(node)
4656 to fetch the name of the file, and
4657 .B node.get_contents()
4658 to fetch contents of the file.
4659
4660 The
4661 .B env
4662 argument is the construction environment for the scan.
4663 Fetch values from it using the
4664 .B env.Dictionary()
4665 method.
4666
4667 The
4668 .B path
4669 argument is a tuple (or list)
4670 of directories that can be searched
4671 for files.
4672 This will usually be the tuple returned by the
4673 .B path_function
4674 argument (see below).
4675
4676 The
4677 .B arg
4678 argument is the argument supplied
4679 when the scanner was created, if any.
4680
4681 .IP name
4682 The name of the Scanner.
4683 This is mainly used
4684 to identify the Scanner internally.
4685
4686 .IP argument
4687 An optional argument that, if specified,
4688 will be passed to the scanner function
4689 (described above)
4690 and the path function
4691 (specified below).
4692
4693 .IP skeys
4694 An optional list that can be used to
4695 determine which scanner should be used for
4696 a given Node.
4697 In the usual case of scanning for file names,
4698 this array will be a list of suffixes
4699 for the different file types that this
4700 Scanner knows how to scan.
4701
4702 .IP path_function
4703 A Python function that takes
4704 two or three arguments:
4705 a construction environment, directory Node,
4706 and optional argument supplied
4707 when the scanner was created.
4708 The
4709 .B path_function
4710 returns a tuple of directories
4711 that can be searched for files to be returned
4712 by this Scanner object.
4713
4714 .IP node_class
4715 The class of Node that should be returned
4716 by this Scanner object.
4717 Any strings or other objects returned
4718 by the scanner function
4719 that are not of this class
4720 will be run through the
4721 .B node_factory
4722 function.
4723
4724 .IP node_factory
4725 A Python function that will take a string
4726 or other object
4727 and turn it into the appropriate class of Node
4728 to be returned by this Scanner object.
4729
4730 .IP scan_check
4731 An optional Python function that takes a Node (file)
4732 as an argument and returns whether the
4733 Node should, in fact,
4734 be scanned for dependencies.
4735 This check can be used to eliminate unnecessary
4736 calls to the scanner function when,
4737 for example, the underlying file
4738 represented by a Node does not yet exist.
4739
4740 .IP recursive
4741 An optional flag that
4742 specifies whether this scanner should be re-invoked
4743 on the dependency files returned by the scanner.
4744 When this flag is not set,
4745 the Node subsystem will
4746 only invoke the scanner on the file being scanned,
4747 and not (for example) also on the files
4748 specified by the #include lines
4749 in the file being scanned.
4750
4751 .SH SYSTEM-SPECIFIC BEHAVIOR
4752 SCons and its configuration files are very portable,
4753 due largely to its implementation in Python.
4754 There are, however, a few portability
4755 issues waiting to trap the unwary.
4756 .SS .C file suffix
4757 SCons handles the upper-case
4758 .B .C
4759 file suffix differently,
4760 depending on the capabilities of
4761 the underlying system.
4762 On a case-sensitive system
4763 such as Linux or UNIX,
4764 SCons treats a file with a 
4765 .B .C
4766 suffix as a C++ source file.
4767 On a case-insensitive system
4768 such as Windows,
4769 SCons treats a file with a 
4770 .B .C
4771 suffix as a C source file.
4772 .SS .F file suffix
4773 SCons handles the upper-case
4774 .B .F
4775 file suffix differently,
4776 depending on the capabilities of
4777 the underlying system.
4778 On a case-sensitive system
4779 such as Linux or UNIX,
4780 SCons treats a file with a 
4781 .B .F
4782 suffix as a Fortran source file
4783 that is to be first run through
4784 the standard C preprocessor.
4785 On a case-insensitive system
4786 such as Windows,
4787 SCons treats a file with a 
4788 .B .F
4789 suffix as a Fortran source file that should
4790 .I not
4791 be run through the C preprocessor.
4792 .SS WIN32:  Cygwin Tools and Cygwin Python vs. Windows Pythons
4793 Cygwin supplies a set of tools and utilities
4794 that let users work on a
4795 Windows system using a more POSIX-like environment.
4796 The Cygwin tools, including Cygwin Python,
4797 do this, in part,
4798 by sharing an ability to interpret UNIX-like path names.
4799 For example, the Cygwin tools
4800 will internally translate a Cygwin path name
4801 like /cygdrive/c/mydir
4802 to an equivalent Windows pathname
4803 of C:/mydir (equivalent to C:\\mydir).
4804
4805 Versions of Python
4806 that are built for native Windows execution,
4807 such as the python.org and ActiveState versions,
4808 do not have the Cygwin path name semantics.
4809 This means that using a native Windows version of Python
4810 to build compiled programs using Cygwin tools
4811 (such as gcc, bison, and flex)
4812 may yield unpredictable results.
4813 "Mixing and matching" in this way
4814 can be made to work,
4815 but it requires careful attention to the use of path names
4816 in your SConscript files.
4817
4818 In practice, users can sidestep
4819 the issue by adopting the following rules:
4820 When using gcc,
4821 use the Cygwin-supplied Python interpreter
4822 to run SCons;
4823 when using Microsoft Visual C/C++
4824 (or some other Windows compiler)
4825 use the python.org or ActiveState version of Python
4826 to run SCons.
4827 .SS WIN32:  scons.bat file
4828 On WIN32 systems,
4829 SCons is executed via a wrapper
4830 .B scons.bat
4831 file.
4832 This has (at least) two ramifications:
4833
4834 First, Windows command-line users
4835 that want to use variable assignment
4836 on the command line
4837 may have to put double quotes
4838 around the assignments:
4839
4840 .ES
4841 scons "FOO=BAR" "BAZ=BLEH"
4842 .EE
4843
4844 Second, the Cygwin shell does not
4845 recognize this file as being the same
4846 as an
4847 .B scons
4848 command issued at the command-line prompt.
4849 You can work around this either by
4850 executing
4851 .B scons.bat
4852 from the Cygwin command line,
4853 or by creating a wrapper shell
4854 script named
4855 .B scons .
4856
4857 .SS MinGW
4858
4859 The MinGW bin directory must be in your PATH environment variable or the
4860 PATH variable under the ENV construction variable for SCons
4861 to detect and use the MinGW tools. When running under the native Windows
4862 Python interpreter, SCons will prefer the MinGW tools over the Cygwin
4863 tools, if they are both installed, regardless of the order of the bin
4864 directories in the PATH variable. If you have both MSVC and MinGW
4865 installed and you want to use MinGW instead of MSVC,
4866 then you must explictly tell SCons to use MinGW by passing 
4867
4868 .ES
4869 tools=['mingw']
4870 .EE
4871
4872 to the Environment() function, because SCons will prefer the MSVC tools
4873 over the MinGW tools.
4874
4875 .SH EXAMPLES
4876
4877 To help you get started using SCons,
4878 this section contains a brief overview of some common tasks.
4879
4880 NOTE:  SCons does
4881 .I not
4882 build all of its targets by default,
4883 like other build tools do.
4884 The canonical way to invoke SCons
4885 is with a target of '.' (dot)
4886 to represent all targets in and below the current directory:
4887
4888 .ES
4889 scons .
4890 .EE
4891
4892 One or more default targets may be specified
4893 via the Default() method
4894 in the SConstruct file.
4895
4896 .SS Basic Compilation From a Single Source File
4897
4898 .ES
4899 env = Environment()
4900 env.Program(target = 'foo', source = 'foo.c')
4901 .EE
4902
4903 Note:  Build the file by specifying
4904 the target as an argument
4905 ("scons foo" or "scons foo.exe").
4906 or by specifying a dot ("scons .").
4907
4908 .SS Basic Compilation From Multiple Source Files
4909
4910 .ES
4911 env = Environment()
4912 env.Program(target = 'foo', source = Split('f1.c f2.c f3.c'))
4913 .EE
4914
4915 .SS Setting a Compilation Flag
4916
4917 .ES
4918 env = Environment(CCFLAGS = '-g')
4919 env.Program(target = 'foo', source = 'foo.c')
4920 .EE
4921
4922 .SS Search The Local Directory For .h Files
4923
4924 Note:  You do
4925 .I not
4926 need to set CCFLAGS to specify -I options by hand.
4927 SCons will construct the right -I options from CPPPATH.
4928
4929 .ES
4930 env = Environment(CPPPATH = ['.'])
4931 env.Program(target = 'foo', source = 'foo.c')
4932 .EE
4933
4934 .SS Search Multiple Directories For .h Files
4935
4936 .ES
4937 env = Environment(CPPPATH = ['include1', 'include2'])
4938 env.Program(target = 'foo', source = 'foo.c')
4939 .EE
4940
4941 .SS Building a Static Library
4942
4943 .ES
4944 env = Environment()
4945 env.StaticLibrary(target = 'foo', source = Split('l1.c l2.c'))
4946 env.StaticLibrary(target = 'bar', source = ['l3.c', 'l4.c'])
4947 .EE
4948
4949 .SS Building a Shared Library
4950
4951 .ES
4952 env = Environment()
4953 env.SharedLibrary(target = 'foo', source = ['l5.c', 'l6.c'])
4954 env.SharedLibrary(target = 'bar', source = Split('l7.c l8.c'))
4955 .EE
4956
4957 .SS Linking a Local Library Into a Program
4958
4959 .ES
4960 env = Environment(LIBS = 'mylib', LIBPATH = ['.'])
4961 env.Library(target = 'mylib', source = Split('l1.c l2.c'))
4962 env.Program(target = 'prog', source = ['p1.c', 'p2.c'])
4963 .EE
4964
4965 .SS Defining Your Own Builder Object
4966
4967 Notice that when you invoke the Builder,
4968 you can leave off the target file suffix,
4969 and SCons will add it automatically.
4970
4971 .ES
4972 bld = Builder(action = 'pdftex < $SOURCES > $TARGET'
4973               suffix = '.pdf',
4974               src_suffix = '.tex')
4975 env = Environment(BUILDERS = {'PDFBuilder' : bld})
4976 env.PDFBuilder(target = 'foo.pdf', source = 'foo.tex')
4977
4978 # The following creates "bar.pdf" from "bar.tex"
4979 env.PDFBuilder(target = 'bar', source = 'bar')
4980 .EE
4981
4982 Note also that the above initialization
4983 overwrites the default Builder objects,
4984 so the Environment created above
4985 can not be used call Builders like env.Program(),
4986 env.Object(), env.StaticLibrary(), etc.
4987
4988 .SS Adding Your Own Builder Object to an Environment
4989
4990 .ES
4991 bld = Builder(action = 'pdftex < $SOURCES > $TARGET'
4992               suffix = '.pdf',
4993               src_suffix = '.tex')
4994 env = Environment()
4995 env.Append(BUILDERS = {'PDFBuilder' : bld})
4996 env.PDFBuilder(target = 'foo.pdf', source = 'foo.tex')
4997 env.Program(target = 'bar', source = 'bar.c')
4998 .EE
4999
5000 You also can use other Pythonic techniques to add
5001 to the BUILDERS construction variable, such as:
5002
5003 .ES
5004 env = Environment()
5005 env.['BUILDERS]['PDFBuilder'] = bld
5006 .EE
5007
5008 .SS Defining Your Own Scanner Object
5009
5010 .ES
5011 import re
5012
5013 include_re = re.compile(r'^include\\s+(\\S+)$', re.M)
5014
5015 def kfile_scan(node, env, path, arg):
5016     contents = node.get_contents()
5017     includes = include_re.findall(contents)
5018     return includes
5019
5020 kscan = Scanner(name = 'kfile',
5021                 function = kfile_scan,
5022                 argument = None,
5023                 skeys = ['.k'])
5024 scanners = Environment().Dictionary('SCANNERS')
5025 env = Environment(SCANNERS = scanners + [kscan])
5026
5027 env.Command('foo', 'foo.k', 'kprocess < $SOURCES > $TARGET')
5028
5029 bar_in = File('bar.in')
5030 env.Command('bar', bar_in, 'kprocess $SOURCES > $TARGET')
5031 bar_in.target_scanner = kscan
5032 .EE
5033
5034 .SS Creating a Hierarchical Build
5035
5036 Notice that the file names specified in a subdirectory's
5037 SConscript
5038 file are relative to that subdirectory.
5039
5040 .ES
5041 SConstruct:
5042
5043     env = Environment()
5044     env.Program(target = 'foo', source = 'foo.c')
5045
5046     SConscript('sub/SConscript')
5047
5048 sub/SConscript:
5049
5050     env = Environment()
5051     # Builds sub/foo from sub/foo.c
5052     env.Program(target = 'foo', source = 'foo.c')
5053
5054     SConscript('dir/SConscript')
5055
5056 sub/dir/SConscript:
5057
5058     env = Environment()
5059     # Builds sub/dir/foo from sub/dir/foo.c
5060     env.Program(target = 'foo', source = 'foo.c')
5061 .EE
5062
5063 .SS Sharing Variables Between SConscript Files
5064
5065 You must explicitly Export() and Import() variables that
5066 you want to share between SConscript files.
5067
5068 .ES
5069 SConstruct:
5070
5071     env = Environment()
5072     env.Program(target = 'foo', source = 'foo.c')
5073
5074     Export("env")
5075     SConscript('subdirectory/SConscript')
5076
5077 subdirectory/SConscript:
5078
5079     Import("env")
5080     env.Program(target = 'foo', source = 'foo.c')
5081 .EE
5082
5083 .SS Building Multiple Variants From the Same Source
5084
5085 Use the BuildDir() method to establish
5086 one or more separate build directories for
5087 a given source directory,
5088 then use the SConscript() method
5089 to specify the SConscript files
5090 in the build directories:
5091
5092 .ES
5093 SConstruct:
5094
5095     ccflags = '-DFOO'
5096     Export("ccflags")
5097     BuildDir('foo', 'src')
5098     SConscript('foo/SConscript')
5099
5100     ccflags = '-DBAR'
5101     Export("ccflags")
5102     BuildDir('bar', 'src')
5103     SConscript('bar/SConscript')
5104
5105 src/SConscript:
5106
5107     Import("ccflags")
5108     env = Environment(CCFLAGS = ccflags)
5109     env.Program(target = 'src', source = 'src.c')
5110 .EE
5111
5112 Note the use of the Export() method
5113 to set the "ccflags" variable to a different
5114 value for each variant build.
5115
5116 .SS Hierarchical Build of Two Libraries Linked With a Program
5117
5118 .ES
5119 SConstruct:
5120
5121     env = Environment(LIBPATH = ['#libA', '#libB'])
5122     Export('env')
5123     SConscript('libA/SConscript')
5124     SConscript('libB/SConscript')
5125     SConscript('Main/SConscript')
5126
5127 libA/SConscript:
5128
5129     Import('env')
5130     env.Library('a', Split('a1.c a2.c a3.c'))
5131
5132 libB/SConscript:                                                  
5133
5134     Import('env')
5135     env.Library('b', Split('b1.c b2.c b3.c'))
5136
5137 Main/SConscript:
5138
5139     Import('env')
5140     e = env.Copy(LIBS = ['a', ','b'])
5141     e.Program('foo', Split('m1.c m2.c m3.c'))
5142 .EE
5143
5144 The '#' in the LIBPATH directories specify that they're relative to the
5145 top-level directory, so they don't turn into "Main/libA" when they're
5146 used in Main/SConscript.
5147
5148 Specifying only 'a' and 'b' for the library names
5149 allows SCons to append the appropriate library
5150 prefix and suffix for the current platform
5151 (for example, 'liba.a' on POSIX systems,
5152 'a.lib' on Windows).
5153
5154 .SS Customizing contruction variables from the command line.
5155
5156 The following would allow the C compiler to be specified on the command
5157 line or in the file custom.py. 
5158
5159 .ES
5160 opts = Options('custom.py')
5161 opts.Add('CC', 'The C compiler.')
5162 env = Environment(options=opts)
5163 Help(opts.GenerateHelpText(env))
5164 .EE
5165
5166 The user could specify the C compiler on the command line:
5167
5168 .ES
5169 scons "CC=my_cc"
5170 .EE
5171
5172 or in the custom.py file:
5173
5174 .ES
5175 CC = 'my_cc'
5176 .EE
5177
5178 or get documentation on the options:
5179
5180 .ES
5181 $ scons -h
5182
5183 CC: The C compiler.
5184     default: None
5185     actual: cc
5186
5187 .EE
5188
5189 .SS Using Microsoft Visual C++ precompiled headers
5190
5191 Since windows.h includes everything and the kitchen sink, it can take quite
5192 some time to compile it over and over again for a bunch of object files, so
5193 Microsoft provides a mechanism to compile a set of headers once and then
5194 include the previously compiled headers in any object file. This
5195 technology is called precompiled headers. The general recipe is to create a
5196 file named "StdAfx.cpp" that includes a single header named "StdAfx.h", and
5197 then include every header you want to precompile in "StdAfx.h", and finally
5198 include "StdAfx.h" as the first header in all the source files you are
5199 compiling to object files. For example:
5200
5201 StdAfx.h:
5202 .ES
5203 #include <windows.h>
5204 #include <my_big_header.h>
5205 .EE
5206
5207 StdAfx.cpp:
5208 .ES
5209 #include <StdAfx.h>
5210 .EE
5211
5212 Foo.cpp:
5213 .ES
5214 #include <StdAfx.h>
5215
5216 /* do some stuff */
5217 .EE
5218
5219 Bar.cpp:
5220 .ES
5221 #include <StdAfx.h>
5222
5223 /* do some other stuff */
5224 .EE
5225
5226 SConstruct:
5227 .ES
5228 env=Environment()
5229 env['PCHSTOP'] = 'StdAfx.h'
5230 env['PCH'] = env.PCH('StdAfx.cpp')[0]
5231 env.Program('MyApp', ['Foo.cpp', 'Bar.cpp'])
5232 .EE
5233
5234 For more information see the document for the PCH builder, and the PCH and
5235 PCHSTOP construction variables. To learn about the details of precompiled
5236 headers consult the MSDN documention for /Yc, /Yu, and /Yp.
5237
5238 .SS Using Microsoft Visual C++ external debugging information
5239
5240 Since including debugging information in programs and shared libraries can
5241 cause their size to increase significantly, Microsoft provides a mechanism
5242 for including the debugging information in an external file called a PDB
5243 file. SCons supports PDB files through the PDB construction
5244 variable. 
5245
5246 SConstruct:
5247 .ES
5248 env=Environment()
5249 env['PDB'] = 'MyApp.pdb'
5250 env.Program('MyApp', ['Foo.cpp', 'Bar.cpp'])
5251 .EE
5252
5253 For more information see the document for the PDB construction variable.
5254
5255 .SH ENVIRONMENT
5256
5257 .IP SCONS_LIB_DIR
5258 Specifies the directory that contains the SCons Python module directory
5259 (e.g. /home/aroach/scons-src-0.01/src/engine).
5260
5261 .IP SCONSFLAGS
5262 A string of options that will be used by scons in addition to those passed
5263 on the command line.
5264
5265 .SH "SEE ALSO"
5266 .B scons
5267 User Manual,
5268 .B scons
5269 Design Document,
5270 .B scons
5271 source code.
5272
5273 .SH AUTHORS
5274 Steven Knight <knight@baldmt.com>
5275 .br
5276 Anthony Roach <aroach@electriceyeball.com>
5277