ca03f60ebb654090fa92ff3e55f3d9b2be9febcb
[scons.git] / doc / man / scons.1
1 .\" Copyright (c) 2001 Steven Knight
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 intend and turns line fill back on
30 .de EE
31 .RE
32 .fi
33 ..
34 .TH SCONS 1 "December 2001"
35 .SH NAME
36 scons \- software constructor
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.  An alternate file name may be
65 specified via the 
66 .B -f
67 option. If the specified file is not
68 in the local directory, 
69 .B scons 
70 will internally change its working
71 directory (chdir) to the directory containing the file.
72
73 The configuration file specifies the files to be built, and
74 (optionally) the rules to build those files.  Reasonable default
75 rules exist for building common software components (executable
76 programs, object files, libraries), so that for simple software
77 projects, only the target and input files need be specified.
78
79 .B scons
80 can scan known input files automatically for dependency
81 information (for example, #include statements
82 in C or C++ files) and will rebuild dependent files appropriately
83 whenever any "included" input file changes. 
84 .B scons
85 supports the
86 ability to define new scanners for unknown input file types.
87
88 .B scons
89 is normally executed in a top-level directory containing a
90 .I SConstruct
91 file, specifying the target or targets to be built as
92 command-line arguments.  The command
93
94 .ES
95 scons .
96 .EE
97
98 will build all target files in or below the current directory 
99 .RI ( . ")."
100
101 .ES
102 scons /
103 .EE
104
105 will build all target files in or below the root directory (i.e.,
106 all files).  Specific targets may be supplied:
107
108 .ES
109 scons foo bar
110 .EE
111
112 Targets may be omitted from the command line,
113 in which case the targets specified
114 in the configuration file(s) as
115 .B Default
116 targets will be built:
117
118 .ES
119 scons
120 .EE
121
122 Specifying "cleanup" targets in configuration files is not
123 necessary.  The 
124 .B -c
125 flag removes all files
126 necessary to build the specified target:
127
128 .ES
129 scons -c .
130 .EE
131
132 to remove all target files, or:
133
134 .ES
135 scons -c build export
136 .EE
137
138 to remove target files under build and export.
139
140 A subset of a hierarchical tree may be built by
141 remaining at the top-level directory (where the 
142 .I SConstruct
143 file lives) and specifying the subdirectory as the target to be
144 built:
145
146 .ES
147 scons src/subdir
148 .EE
149
150 .\" or changing directory and invoking scons with the
151 .\" .B -u
152 .\" option, which traverses up the directory
153 .\" hierarchy until it finds the 
154 .\" .I SConstruct
155 .\" file, and then builds
156 .\" targets relatively to the current subdirectory:
157 .\" 
158 .\" .ES
159 .\" cd src/subdir
160 .\" scons -u .
161 .\" .EE
162
163 .B scons
164 supports building multiple targets in parallel via a
165 .B -j
166 option that takes, as its argument, the number
167 of simultaneous tasks that may be spawned:
168
169 .ES
170 scons -j 4
171 .EE
172
173 builds four targets in parallel, for example.
174
175 Values of variables to be passed to the configuration file(s)
176 may be specified on the command line:
177
178 .ES
179 scons debug=1 .
180 .EE
181
182 These variables can be used in the configuration file(s) to modify
183 the build in any way.
184
185 .\" .B scons
186 .\" can maintain a cache of target (derived) files that can
187 .\" be shared between multiple builds.  When caching is enabled in a
188 .\" configuration file, any target files built by 
189 .\" .B scons
190 .\" will be copied
191 .\" to the cache.  If an up-to-date target file is found in the cache, it
192 .\" will be retrieved from the cache instead of being rebuilt locally.
193 .\" Caching behavior may be disabled and controlled in other ways by the
194 .\" .BR --cache-force , 
195 .\" .BR --cache-disable ,
196 .\" and
197 .\" .B --cache-show
198 .\" command-line options.  The
199 .\" .B --random
200 .\" option is useful whenever multiple builds may be
201 .\" trying to update the cache simultaneously.
202
203 .SH OPTIONS
204 In general, 
205 .B scons 
206 supports the same command-line options as GNU
207 .BR make , 
208 and many of those supported by 
209 .BR cons .
210
211 .TP
212 -b
213 Ignored for compatibility with non-GNU versions of
214 .BR make.
215
216 .TP
217 -c, --clean, --remove
218 Clean up by removing all target files for which a construction
219 command is specified.
220
221 .\" .TP
222 .\" --cache-disable, --no-cache
223 .\" Disable caching.  Will neither retrieve files from cache nor flush
224 .\" files to cache.  Has no effect if use of caching is not specified
225 .\" in a configuration file.
226 .\"
227 .\" .TP
228 .\" --cache-force, --cache-populate
229 .\" Populate a cache by forcing any already-existing up-to-date
230 .\" target files to the cache, in addition to files built by this
231 .\" invocation.  This is useful to populate a new cache with
232 .\" appropriate target files, or to make available in the cache
233 .\" any target files recently built with caching disabled via the
234 .\" .B --cache-disable
235 .\" option.
236 .\"
237 .\" .TP
238 .\" --cache-show
239 .\" When retrieving a target file from a cache, show the command
240 .\" that would have been executed to build the file.  This produces
241 .\" consistent output for build logs, regardless of whether a target
242 .\" file was rebuilt or retrieved from cache.
243
244 .TP 
245 .RI "-C" " directory" ",  --directory=" directory
246 Change to the specified 
247 .I directory
248 before searching for the 
249 .IR SConstruct ,
250 .IR Sconstruct ,
251 or
252 .I sconstruct
253 file, or doing anything
254 else.  Multiple 
255 .B -C
256 options are interpreted
257 relative to the previous one, and the right-most
258 .B -C
259 option wins. (This option is nearly
260 equivalent to 
261 .BR "-f directory/SConstruct" ,
262 except that it will search for
263 .IR SConstruct ,
264 .IR Sconstruct , 
265 or
266 .I sconstruct
267 in the specified directory.)
268
269 .\" .TP
270 .\" -d
271 .\" Display dependencies while building target files.  Useful for
272 .\" figuring out why a specific file is being rebuilt, as well as
273 .\" general debugging of the build process.
274
275 .TP
276 .RI --debug= type
277 Print debugging information durring the build process.
278 .I type
279 specifies what type of of debugging information to print. Currently the
280 only supported type is
281 .I tree
282 which causes the dependency tree to be printed after each top-level
283 target is built.
284
285 .TP
286 -e, --environment-overrides
287 Variables from the execution environment override construction
288 variables from the configuration files.
289
290 .TP
291 .RI -f " file" ", --file=" file ", --makefile=" file ", --sconstruct=" file
292 Use 
293 .I file 
294 as the initial configuration
295 file. If 
296 .I file
297 is in another directory,
298 .B scons 
299 will change to that directory before building targets.
300
301 .TP 
302 -h, --help
303 Print a local help message for this build, if one is defined in
304 the configuration file(s), plus a line that describes the 
305 .B -H
306 option for command-line option help.  If no local help message
307 is defined, prints the standard help message about command-line
308 options.  Exits after displaying the appropriate message.
309
310 .TP
311 -H, --help-options
312 Print the standard help message about command-line options and
313 exit.
314
315 .TP
316 -i, --ignore-errors
317 Ignore all errors from commands executed to rebuild files.
318
319 .TP 
320 .RI -I " directory" ", --include-dir=" directory
321 Specifies a 
322 .I directory
323 to search for
324 imported Python modules.  If several 
325 .B -I
326 options
327 are used, the directories are searched in the order specified.
328
329 .TP
330 .RI -j " N" ", --jobs=" N
331 Specifies the number of jobs (commands) to run simultaneously.
332 If there is more than one 
333 .B -j 
334 option, the last one is effective.
335 .\" ??? If the 
336 .\" .B -j 
337 .\" option
338 .\" is specified without an argument,
339 .\" .B scons 
340 .\" will not limit the number of
341 .\" simultaneous jobs.
342
343 .TP
344 -k, --keep-going
345 Continue as much as possible after an error.  The target that
346 failed and those that depend on it will not be remade, but other
347 targets specified on the command line will still be processed.
348
349 .\" .TP
350 .\" .RI  -l " N" ", --load-average=" N ", --max-load=" N
351 .\" No new jobs (commands) will be started if
352 .\" there are other jobs running and the system load
353 .\" average is at least 
354 .\" .I N
355 .\" (a floating-point number).
356 .\"
357 .\" .TP
358 .\" --list-derived
359 .\" List derived files (targets, dependencies) that would be built,
360 .\" but do not build them.
361 .\" [XXX This can probably go away with the right
362 .\" combination of other options.  Revisit this issue.]
363 .\"
364 .\" .TP
365 .\" --list-actions
366 .\" List derived files that would be built, with the actions
367 .\" (commands) that build them.  Does not build the files.
368 .\" [XXX This can probably go away with the right
369 .\" combination of other options.  Revisit this issue.]
370 .\"
371 .\" .TP
372 .\" --list-where
373 .\" List derived files that would be built, plus where the file is
374 .\" defined (file name and line number).  Does not build the files.
375 .\" [XXX This can probably go away with the right
376 .\" combination of other options.  Revisit this issue.]
377
378 .TP
379 -m
380 Ignored for compatibility with non-GNU versions of
381 .BR make .
382
383 .TP
384 -n, --just-print, --dry-run, --recon
385 No execute.  Print the commands that would be executed to build
386 any out-of-date target files, but do not execute the commands.
387
388 .\" .TP
389 .\" .RI -o " file" ", --old-file=" file ", --assume-old=" file
390 .\" Do not rebuild 
391 .\" .IR file ,
392 .\" and do
393 .\" not rebuild anything due to changes in the contents of
394 .\" .IR file .
395 .\" .TP 
396 .\" .RI --override " file"
397 .\" Read values to override specific build environment variables
398 .\" from the specified 
399 .\" .IR file .
400 .\" .TP
401 .\" -p
402 .\" Print the data base (construction environments,
403 .\" Builder and Scanner objects) that are defined
404 .\" after reading the configuration files.
405 .\" After printing, a normal build is performed
406 .\" as usual, as specified by other command-line options.
407 .\" This also prints version information
408 .\" printed by the 
409 .\" .B -v
410 .\" option.
411 .\"
412 .\" To print the database without performing a build do:
413 .\"
414 .\" .ES
415 .\" scons -p -q
416 .\" .EE
417 .\"
418 .\" .TP
419 .\" -q, --question
420 .\" Do not run any commands, or print anything.  Just return an exit
421 .\" status that is zero if the specified targets are already up to
422 .\" date, nonzero otherwise.
423 .\"
424 .\" .TP
425 .\" -r, -R, --no-builtin-rules, --no-builtin-variables
426 .\" Clear the default construction variables.  Construction
427 .\" environments that are created will be completely empty.
428 .\"
429 .\" .TP
430 .\" --random
431 .\" Build dependencies in a random order.  This is useful when
432 .\" building multiple trees simultaneously with caching enabled as a
433 .\" way to prevent multiple builds from simultaneously trying to build
434 .\" or retrieve the same target files.
435
436 .TP
437 -s, --silent, --quiet
438 Silent.  Do not print commands that are executed to rebuild
439 target files.
440
441 .TP
442 -S, --no-keep-going, --stop
443 Ignored for compatibility with GNU 
444 .BR make .
445
446 .TP
447 -t, --touch
448 Ignored for compatibility with GNU
449 .BR make .  
450 (Touching a file to make it
451 appear up-to-date is unnecessary when using 
452 .BR scons .)
453
454 .\" .TP
455 .\" -u
456 .\" Traverse up directories until an 
457 .\" .I SConstruct
458 .\" or 
459 .\" .I sconstruct
460 .\" file is found, and use that
461 .\" as the top of the directory tree.  Only targets at or below the
462 .\" current directory will be built.
463
464 .TP
465 -v, --version
466 Print the 
467 .B scons
468 version, copyright information,
469 list of authors, and any other relevant information.
470 Then exit.
471
472 .TP
473 -w, --print-directory
474 Print a message containing the working directory before and
475 after other processing.
476
477 .TP
478 --no-print-directory
479 Turn off -w, even if it was turned on implicitly.
480
481 .\" .TP
482 .\" .RI --write-filenames= file
483 .\" Write all filenames considered into
484 .\" .IR file .
485 .\"
486 .\" .TP
487 .\" .RI -W " file" ", --what-if=" file ", --new-file=" file ", --assume-new=" file
488 .\" Pretend that the target 
489 .\" .I file 
490 .\" has been
491 .\" modified.  When used with the 
492 .\" .B -n
493 .\" option, this
494 .\" show you what would be rebuilt if you were to modify that file.
495 .\" Without 
496 .\" .B -n
497 .\" ... what? XXX
498 .\"
499 .\" .TP
500 .\" --warn-undefined-variables
501 .\" Warn when an undefined variable is referenced.
502 .\"
503 .\" .TP 
504 .\" .RI -Y " repository" ", --repository=" repository
505 .\" Search the specified repository for any input and target
506 .\" files not found in the local directory hierarchy.  Multiple
507 .\" .B -Y
508 .\" options may specified, in which case the
509 .\" repositories are searched in the order specified.
510
511 .SH CONFIGURATION FILE REFERENCE
512 .SS Construction Environments
513 A construction environment is the basic means by which the configuration
514 files communicate build information to 
515 .BR scons .
516 A new construction environment is created using the 
517 .B Environment 
518 function:
519
520 .ES
521 env = Environment()
522 .EE
523
524 Build rules are specified by calling builder methods on a construction
525 environment. The arguments to the builder methods are target (a list of
526 target files) and source (a list of source files). If a string is given
527 for target or source, then 
528 .B scons 
529 interprets it as a space delimited list
530 of files. The following are examples of calling a builder:
531
532 .ES
533 env.Program(target = 'bar', source = 'bar.c foo.c')
534 env.Program('bar', 'bar.c foo.c')
535 env.Program('bar', ['bar.c', 'foo.c'])
536 .EE
537
538 .B scons
539 provides the following builders:
540
541 .IP Object
542 Builds an object file from one or more C/C++ source files. Source files
543 must have one of the following extensions: .c, .C, .cc, .cpp, .cxx, .c++, .C++. 
544 The target object file prefix and suffix (if any) are automatically
545 added. Example:
546
547 .ES
548 env.Object(target = 'bar', source = 'bar.c')
549 .EE
550
551 .IP Program
552 Builds an executable given one or more object files or C/C++ source
553 files. If any C/C++ source files are given, then they will be automatically
554 compiled to object files. The executable prefix and suffix (if any) are
555 automatically added to the target. Example:
556
557 .ES
558 env.Program(target = 'bar', source = 'bar.c foo.o')
559 .EE
560
561 .IP Library
562 Builds a library given one or more object files or C/C++ source
563 files. If any C/C++ source files are given, then they will be automatically
564 compiled to object files. The library prefix and suffix (if any) are
565 automatically added to the target. Example:
566
567 .ES
568 env.Library(target = 'bar', source = 'bar.c foo.o')
569 .EE
570
571 .IP CFile
572 Builds a C source file given a lex (.l) or yacc (.y) input file.
573 The hard-coded suffix .c is
574 automatically added to the target
575 if it is not already present. Example:
576
577 .ES
578 env.CFile(target = 'foo.c', source = 'foo.l') # builds foo.c
579 env.CFile(target = 'bar', source = 'bar.y')   # builds bar.c
580 .EE
581 .LP
582 C/C++ source files are automatically scanned for dependencies by 
583 .B scons
584 so the dependencies do not need to be provided. In addition, all builder
585 targets automatically depend on their sources. An explicit dependency can
586 be specified using the 
587 .B Depends 
588 method of a construction environment (see below).
589
590 Additional Environment methods include:
591
592 .TP
593 .RI Command( target ", " source ", " commands )
594 Executes a specific command
595 (or list of commands)
596 to build a target file or files.
597 This is more convenient
598 than defining a separate Builder object
599 for a single special-case build.
600
601 .ES
602 env.Command('foo.out', 'foo.in',
603             "$FOO_BUILD < $SOURCES > $TARGET")
604 env.Command('bar.out', 'bar.in',
605             ["rm -f $TARGET",
606              "$BAR_BUILD < $SOURCES > $TARGET"])
607 .EE
608
609 .TP
610 .RI Copy([ key = val ", ...])"
611 Return a separate copy of a construction environment.
612 If there are any keyword arguments specified,
613 they are added to the returned copy,
614 overwriting any existing values
615 for the keywords.
616
617 .ES
618 env2 = env.Copy()
619 env3 = env.Copy(CCFLAGS = '-g')
620 .EE
621
622 .TP
623 .RI Depends( target ", " dependency )
624 Specifies an explicit dependency;
625 the target file(s) will be rebuilt
626 whenever the dependency file(s) has changed.
627 This should only be necessary
628 for cases where the dependency
629 is not caught by a Scanner
630 for the file.
631
632 .ES
633 env.Depends('foo', 'other-input-file-for-foo')
634 .EE
635
636 .TP
637 .RI Dictionary([ vars ])
638 Returns a dictionary object
639 containing copies of all of the
640 construction variables in the environment.
641 If there are any variable names specified,
642 only the specified construction
643 variables are returned in the dictionary.
644
645 .ES
646 dict = env.Dictionary()
647 cc_dict = env.Dictionary('CC', 'CCFLAGS', 'CCCOM')
648 .EE
649
650 .TP
651 .RI Install( dir ", " source )
652 Installs one or more files in a destination directory.
653 The file names remain the same.
654
655 .ES
656 env.Install(dir = '/usr/local/bin', source = 'foo bar')
657 .EE
658
659 .TP
660 .RI InstallAs( target ", " source )
661 Installs one or more files as specific file names,
662 allowing changing a file name as part of the
663 installation.
664 It is an error if the target and source
665 list different numbers of files.
666
667 .ES
668 env.InstallAs(target = '/usr/local/bin/foo',
669               source = 'foo_debug')
670 env.InstallAs(target = '../lib/libfoo.a ../lib/libbar.a',
671               source = 'libFOO.a libBAR.a')
672 .EE
673
674 .TP
675 .RI Update( key = val ", [...])"
676 Updates the contents of an environment
677 with the specified keyword arguments.
678
679 .ES
680 env.Update(CCFLAGS = '-g', FOO = 'foo.xxx')
681 .EE
682
683 .SS Construction Variables
684
685 A construction environment has an associated dictionary of construction
686 variables that are used by built-in or user-supplied build rules. A number
687 of useful construction variables are automatically defined by scons for
688 each supported platform, and additional construction variables can be defined
689 by the user. The following is a list of the automatically defined construction
690 variables:
691
692 .IP AR
693 The static library command.
694
695 .IP ARFLAGS
696 General options passed to the static library command.
697
698 .IP ARCOM
699 The command line used to generate a static library from object files.
700
701 .IP BUILDERS
702 A list of the available builders.
703 [CFile, Object, Program, Library] by default.
704
705 .IP CC 
706 The C compiler.
707
708 .IP CCFLAGS 
709 General options that are passed to the C compiler.
710
711 .IP CCCOM 
712 The command line used to compile a C source file to an object file.
713
714 .IP CPPPATH
715 The list of directories that the C preprocessor will search for include
716 directories. The C/C++ implicit dependency scanner will search these
717 directories for include files. Don't explicitly put include directory
718 arguments in CCFLAGS or CXXFLAGS because the result will be non-portable
719 and the directories will not be searched by the depedency scanner. Note:
720 directory names in CPPPATH will be looked-up relative to the SConscript
721 directory when they are used in a command. To force 
722 .B scons
723 to look-up a directory relative to the root of the source tree use #:
724
725 .ES
726 env = Environment(CPPPATH='#/include')
727 .EE
728
729 .IP
730 The directory look-up can also be forced using the 
731 .BR Dir ()
732 function:
733
734 .ES
735 include = Dir('include')
736 env = Environment(CPPPATH=include)
737 .EE
738
739 .IP CXX
740 The C++ compiler.
741
742 .IP CXXFLAGS 
743 General options that are passed to the C++ compiler.
744
745 .IP CXXCOM
746 The command line used to compile a C++ source file to an object file.
747
748 .IP ENV
749 A dictionary of environment variables
750 to use when invoking commands.
751 Note that, by default,
752 .B scons
753 does
754 .I not
755 propogate the environment in force when you
756 execute
757 .B scons
758 to the commands used to build target files.
759 This is so that builds will be guaranteed
760 repeatable regardless of the environment
761 variables set at the time
762 .B scons
763 is invoked.
764
765 If you want to propogate your
766 environment variables
767 to the commands executed
768 to build target files,
769 you must do so explictly:
770
771 .ES
772 import os
773 env = Environment(ENV = os.environ)
774 .EE
775
776 .RS
777 Note that you can choose only to propogate
778 certain environment variables.
779 A common example is
780 the system
781 .B PATH
782 environment variable,
783 so that
784 .B scons
785 uses the same utilities
786 as the invoking shell (or other process):
787 .RE
788
789 .ES
790 import os
791 env = Environment(ENV = {'PATH' : os.environ['PATH']})
792 .EE
793
794 .IP INCPREFIX
795 The prefix used to specify an include directory on the C compiler command
796 line.
797
798 .IP INCSUFFIX
799 The suffix used to specify an include directory on the C compiler command
800 line.
801
802 .IP LEX
803 The lexical analyzer generator.
804
805 .IP LEXFLAGS
806 General options passed to the lexical analyzer generator.
807
808 .IP LEXCOM
809 The command line used to call the lexical analyzer generator
810 to generate a source file.
811
812 .IP LIBDIRPREFIX
813 The prefix used to specify a library directory on the linker command line.
814
815 .IP LIBDIRASUFFIX
816 The suffix used to specify a library directory on the linker command line.
817
818 .IP LIBLINKPREFIX
819 The prefix used to specify a library to link on the linker command line.
820
821 .IP LIBLINKSUFFIX
822 The suffix used to specify a library to link on the linker command line.
823
824 .IP LIBPREFIX
825 The prefix used for library file names.
826
827 .IP LIBSUFFIX 
828 The suffix used for library file names.
829
830 .IP LINK
831 The linker.
832
833 .IP LINKFLAGS
834 General options passed to the linker.
835
836 .IP LINKCOM
837 The command line used to link object files into an executable.
838
839 .IP OBJPREFIX 
840 The prefix used for object file names.
841
842 .IP OBJSUFFIX 
843 The suffix used for object file names.
844
845 .IP PROGPREFIX
846 The prefix used for executable file names.
847
848 .IP PROGSUFFIX
849 The suffix used for executable file names.
850
851 .IP SCANNERS
852 A list of the available implicit dependency scanners. [CScan] by default.
853
854 .IP YACC
855 The parser generator.
856
857 .IP YACCFLAGS
858 General options passed to the parser generator.
859
860 .IP YACCCOM
861 The command line used to call the parser generator
862 to generate a source file.
863
864 .LP
865 Construction variables can be retrieved and set using the 
866 .B Dictionary 
867 method of the construction environment:
868
869 .ES
870 dict = env.Dictionary()
871 dict["CC"] = "cc"
872 .EE
873
874 Construction variables can also be passed to the construction environment
875 constructor:
876
877 .ES
878 env = Environment(CC="cc")
879 .EE
880
881 or when copying a construction environment using the 
882 .B Copy 
883 method:
884
885 .ES
886 env2 = env.Copy(CC="cl.exe")
887 .EE
888
889 .SS Other Functions
890
891 .B scons
892 also provides various additional functions,
893 not associated with a construction environment,
894 that configuration files can use:
895
896 .TP
897 .RI BuildDir( build_dir ", " src_dir ", [" duplicate ])
898 This specifies a build directory to use for all derived files.  
899 .I build_dir
900 specifies the build directory to be used for all derived files that would
901 normally be built under
902 .IR src_dir .
903 Multiple build directories can be set up for multiple build variants, for
904 example. 
905 .B scons
906 will link or copy (depending on the platform) all the source files into the
907 build directory if 
908 .I duplicate
909 is set to 1 (the default). If 
910 .I duplicate
911 is set to 0, then 
912 .B scons 
913 will not copy or link any source files, which may cause build problems in
914 certain situations (e.g. C source files that are generated by the
915 build). 
916 .IR duplicate =0
917 is usually safe, and is always more efficient than 
918 .IR duplicate =1.
919
920 .TP 
921 .RI Default( targets )
922 This specifies a list of default targets. Default targets will be built by
923 .B scons
924 if no explicit targets are given on the comamnd line. Multiple targets can
925 be specified either as a space delimited string of target file names or as
926 seperate arguments.
927 Target names with white space may be be enclosed in an
928 array to prevent the string from being split into
929 separate file names.
930 .BR Default ()
931 will also accept the return value of any of the ccnstruction environment
932 builder methods.
933 Example:
934
935 .ES
936 Default('foo', 'bar', 'baz', ['file with whitespace'])
937 .EE
938
939 .TP
940 .RI Dir( name ", [" directory ])
941 This returns an object that represents a given directory 
942 .IR name . 
943 .I name
944 can be a relative or absolute path. 
945 .I directory
946 is an optional directory that will be used as the parent directory. 
947
948 .TP
949 .RI Export( vars )
950 This tells 
951 .B scons
952 to export a list of variables from the current
953 configuration file to all other configuration files. The exported variables
954 are kept in a global collection, so subsequent exports
955 will over-write previous exports that have the same name. 
956 Multiple variable names can be passed to
957 .BR Export ()
958 in a space delimited string or as seperate arguments. Example:
959
960 .ES
961 Export("env")
962 .EE
963
964 .TP 
965 .RI File( name ", [" directory ])
966 This returns an object that represents a given file 
967 .IR name . 
968 .I name
969 can be a relative or absolute path. 
970 .I directory
971 is an optional directory that will be used as the parent directory. 
972
973 .TP
974 .RI Help( text )
975 This specifies help text to be printed if the 
976 .B -h 
977 argument is given to
978 .BR scons .
979 .B scons
980 will exit after printing out the help text.
981
982 .TP 
983 .RI Import( vars )
984 This tells 
985 .B scons
986 to import a list of variables into the current configuration file. This
987 will import variables that were exported with
988 .BR Export ()
989 or in the 
990 .I exports
991 argument to 
992 .BR SConscript ().
993 Variables exported by 
994 .BR SConscript ()
995 have precedence. Multiple variable names can be passed to 
996 .BR Import ()
997 in a space delimited string or as seperate arguments. Example:
998
999 .ES
1000 Import("env")
1001 .EE
1002
1003 .TP
1004 .RI Return( vars )
1005 This tells
1006 .B scons
1007 what variable(s) to use as the return value(s) of the current configuration
1008 file. These variables will be returned to the "calling" configuration file
1009 as the return value(s) of 
1010 .BR SConscript ().
1011 Multiple variable names can be passed to 
1012 .BR Return ()
1013 in a space delimited string or as seperate arguments. Example:
1014
1015 .ES
1016 Return("foo")
1017 .EE
1018
1019 .TP
1020 .RI SConscript( script ", [" exports ])
1021 This tells
1022 .B scons
1023 to execute
1024 .I script
1025 as a configuration file. The optional 
1026 .I exports
1027 argument provides a list of variable names to export to
1028 .IR script ". " exports
1029 can also be a space delimited string of variables names. 
1030 .I script
1031 must use the
1032 .BR Import ()
1033 function to import the variables. Any variables returned by 
1034 .I script 
1035 using 
1036 .BR Return ()
1037 will be returned by the call to
1038 .BR SConscript (). 
1039 Examples:
1040
1041 .ES
1042 SConscript('dir/SConscript')
1043 foo = SConscript('subdir/SConscript', "env")
1044 .EE
1045
1046 .TP 
1047 .RI SetCommandHandler( function )
1048
1049 This registers a user
1050 .I function
1051 as the handler
1052 for interpreting and executing command-line strings.
1053 The function must expect three arguments:
1054
1055 .ES
1056 def commandhandler(cmd, args, env):
1057 .EE
1058
1059 .I cmd
1060 is the path to the command to be executed.
1061 .I args
1062 is that arguments to the command.
1063 .I env
1064 is a dictionary of the environment variables
1065 in which the command should be executed.
1066
1067 .SH EXTENDING SCONS
1068 .SS Builder Objects
1069 .B scons
1070 can be extended by adding new builders to a construction
1071 environment using the 
1072 .B Builder 
1073 function. Builder accepts the following
1074 arguments:
1075
1076 .IP name
1077 The name of the builder. This will be the of the construction environment
1078 method used to create an instance of the builder.
1079
1080 .IP action
1081 The command line string used to build the target from the source. 
1082 .B action
1083 can also be a dictionary
1084 mapping source file name suffixes to
1085 any combination of command line strings
1086 (if the builder should accept multiple source file extensions),
1087 Python functions,
1088 or Action objects
1089 (see the next section).
1090
1091 .IP prefix 
1092 The prefix that will be prepended to the target file name.
1093
1094 .IP suffix
1095 The suffix that will be appended to the target file name.
1096
1097 .IP src_suffix
1098 The expected source file name suffix.
1099
1100 .IP src_builder
1101 Specifies a builder to use when a source file name suffix does not match
1102 any of the suffixes of the builder. Using this argument produces a
1103 multi-stage builder.
1104
1105 .SS Action Objects
1106
1107 The Builder function will turn its
1108 .B action
1109 keyword argument into an appropriate
1110 internal Action object.
1111 Occasionally, it may be more efficient
1112 to create an explicit Action object
1113 and use it to initialize multiple
1114 Builder objects,
1115 rather than let each separate Builder object
1116 create a separate Action.
1117
1118 The Action method takes a single argument
1119 and returns an appropriate object for the action
1120 represented by the type of the argument:
1121
1122 .IP Action
1123 If the argument is already an Action object,
1124 the object is simply returned.
1125
1126 .IP String
1127 If the argument is a string,
1128 a command-line Action is returned.
1129
1130 .ES
1131 Action('$CC -c -o $TARGET $SOURCES')
1132 .EE
1133
1134 .IP Function
1135 If the argument is a Python function,
1136 a function Action is returned.
1137 The Python function takes three keyword arguments,
1138 .B target
1139 (the name of the target file),
1140 .B source
1141 (the name of the source file)
1142 and
1143 .BR env
1144 (the construction environment
1145 used for building the target file).
1146 The
1147 .B target
1148 and
1149 .B source
1150 arguments may be lists of strings if there is
1151 more than one target file or source file.
1152 .IP
1153 The function should return
1154 .B 0
1155 or
1156 .B None
1157 to indicate a successful build of the target file(s).
1158 The function may raise an exception
1159 or return a non-zero exit status
1160 to indicate an unsuccessful build.
1161
1162 .ES
1163 def build_it(target = None, source = None, env = None):
1164     # build the target from the source
1165     return 0
1166  
1167 a = Action(build_it)
1168 .EE
1169
1170 .IP List
1171 If the argument is a list,
1172 then a list of Action objects is returned.
1173 An Action object is created as necessary
1174 for each element in the list.
1175 .PP
1176 If the action argument is not one of the above,
1177 None is returned.
1178 .SS Variable Substitution
1179 .B scons
1180 performs construction variable interpolation on the strings that make up
1181 the command line of builders before executing the command.
1182 Variables are introduced by a
1183 .B $
1184 prefix.
1185 Besides construction variables, scons provides the following
1186 variables for each command execution:
1187
1188 .IP TARGET
1189 The file name of the target being built, or the file name of the first 
1190 target if multiple targets are being built.
1191
1192 .IP TARGETS
1193 The file names of all targets being built.
1194
1195 .IP SOURCES
1196 The file names of the sources of the build command.
1197 .LP 
1198 For example, given the construction variable CC='cc', targets=['foo'], and
1199 sources=['foo.c', 'bar.c']:
1200 .ES
1201 action='$CC -c -o $TARGET $SOURCES'
1202 .EE
1203 would produce the command line:
1204 .ES
1205 cc -c -o foo foo.c bar.c
1206 .EE
1207 Variable names may be surrounded by curly braces ({})
1208 to separate the name from the trailing characters.
1209 Within the curly braces, a variable name may have
1210 a Python slice subscript appended to select one
1211 or more items from a list.
1212 In the previous example, the string:
1213 .ES
1214 ${SOURCES[1]}
1215 .EE
1216 would produce:
1217 .ES
1218 bar.c
1219 .EE
1220 Additionally, a variable name may
1221 have the following special
1222 modifiers appended within the enclosing curly braces
1223 to modify the interpolated string:
1224
1225 .IP base
1226 The base path of the file name,
1227 including the directory path
1228 but excluding any suffix.
1229
1230 .IP dir
1231 The name of the directory in which the file exists.
1232
1233 .IP file
1234 The file name,
1235 minus any directory portion.
1236
1237 .IP filebase
1238 Just the basename of the file,
1239 minus any suffix
1240 and minus the directory.
1241
1242 .IP suffix
1243 Just the file suffix.
1244
1245 .LP
1246 For example, the specified target will
1247 expand as follows for the corresponding modifiers:
1248
1249 .ES
1250 $TARGET              => sub/dir/file.x
1251 ${TARGET.base}       => sub/dir/file
1252 ${TARGET.dir}        => sub/dir
1253 ${TARGET.file}       => file.x
1254 ${TARGET.filebase}   => file
1255 ${TARGET.suffix}     => .x
1256 .EE
1257
1258 .\" XXX document how to add user defined scanners. 
1259
1260 .SH EXAMPLES
1261
1262 To help you get started using SCons,
1263 here is a brief overview of some common tasks:
1264
1265 .SS Basic Compilation From a Single Source File
1266
1267 .ES
1268 env = Environment()
1269 env.Program(target = 'foo', source = 'foo.c')
1270 .EE
1271
1272 .SS Basic Compilation From Multiple Source Files
1273
1274 .ES
1275 env = Environment()
1276 env.Program(target = 'foo', source = 'f1.c f2.c f3.c')
1277 .EE
1278
1279 .SS Setting a Compilation Flag
1280
1281 .ES
1282 env = Environment(CCFLAGS = '-g')
1283 env.Program(target = 'foo', source = 'foo.c')
1284 .EE
1285
1286 .SS Search The Local Directory For .h Files
1287
1288 Note:  You do
1289 .I not
1290 need to specify -I options by hand.
1291 SCons will construct the right -I options from CPPPATH.
1292
1293 .ES
1294 env = Environment(CPPPATH = ['.'])
1295 env.Program(target = 'foo', source = 'foo.c')
1296 .EE
1297
1298 .SS Search Multiple Directories For .h Files
1299
1300 .ES
1301 env = Environment(CPPPATH = ['include1', 'include2'])
1302 env.Program(target = 'foo', source = 'foo.c')
1303 .EE
1304
1305 .SS Building a Library
1306
1307 .ES
1308 env = Environment()
1309 env.Library(target = 'mylib', source = 'l1.c l2.c')
1310 .EE
1311
1312 .SS Linking a Local Library Into a Program
1313
1314 .ES
1315 env = Environment(LIBS = 'mylib', LIBPATH = ['.'])
1316 env.Library(target = 'mylib', source = 'l1.c l2.c')
1317 env.Program(target = 'prog', source = 'p1.c p2.c')
1318 .EE
1319
1320 .SS Defining Your Own Builder Object
1321
1322 You
1323 .I must
1324 specify a "name" keyword argument for the builder,
1325 as that becomes the Environment method name
1326 you use to call the builder.
1327 Notice also that you can leave off the suffixes,
1328 and the builder will add them automatically.
1329
1330 .ES
1331 bld = Builder(name = 'PDFBuilder',
1332               action = 'pdftex < $SOURCES > $TARGET'
1333               suffix = '.pdf',
1334               src_suffix = '.tex')
1335 env = Environment(BUILDERS = [bld])
1336 env.PDFBuilder(target = 'foo.pdf', source = 'foo.tex')
1337
1338 # The following creates "bar.pdf" from "bar.text"
1339 env.PDFBuilder(target = 'bar', source = 'bar')
1340 .EE
1341
1342 .SS Creating a Hierarchical Build
1343
1344 Notice that the file names specified in a subdirectory
1345 are relative to that subdirectory.
1346
1347 .ES
1348 SConstruct:
1349
1350     env = Environment()
1351     env.Program(target = 'foo', source = 'foo.c')
1352
1353     SConscript('sub/SConscript')
1354
1355 sub/SConscript:
1356
1357     env = Environment()
1358     # Builds sub/foo from sub/foo.c
1359     env.Program(target = 'foo', source = 'foo.c')
1360
1361     SConscript('dir/SConscript')
1362
1363 sub/dir/SConscript:
1364
1365     env = Environment()
1366     # Builds sub/dir/foo from sub/dir/foo.c
1367     env.Program(target = 'foo', source = 'foo.c')
1368 .EE
1369
1370 .SS Sharing Variables Between SConscript Files
1371
1372 You must explicitly Export() and Import() variables that
1373 you want to share between SConscript files.
1374
1375 .ES
1376 SConstruct:
1377
1378     env = Environment()
1379     env.Program(target = 'foo', source = 'foo.c')
1380
1381     Export("env")
1382     SConscript('subdirectory/SConscript')
1383
1384 subdirectory/SConscript:
1385
1386     Import("env")
1387     env.Program(target = 'foo', source = 'foo.c')
1388 .EE
1389
1390 .SS Building Multiple Variants From the Same Source
1391
1392 Use the BuildDir() method to establish
1393 one or more separate build directories for
1394 a given source directory,
1395 then use the SConscript() method
1396 to specify the SConscript files
1397 in the build directories:
1398
1399 .ES
1400 SConstruct:
1401
1402     Export("ccflags")
1403
1404     ccflags = '-DFOO'
1405     BuildDir('foo', 'src')
1406     SConscript('foo/SConscript')
1407
1408     ccflags = '-DBAR'
1409     BuildDir('bar', 'src')
1410     SConscript('bar/SConscript')
1411
1412 src/SConscript:
1413
1414     Import("ccflags")
1415     env = Environment(CCFLAGS = ccflags)
1416     env.Program(target = 'src', source = 'src.c')
1417 .EE
1418
1419 Note the use of the Export() method
1420 to set the "ccflags" variable to a different
1421 value for each variant build.
1422
1423 .SH ENVIRONMENT
1424
1425 .IP SCONS_LIB_DIR
1426 Specifies the directory that contains the SCons Python module directory
1427 (e.g. /home/aroach/scons-src-0.01/src/engine).
1428
1429 .IP SCONSFLAGS
1430 A string of options that will be used by scons in addition to those passed
1431 on the command line.
1432
1433 .SH "SEE ALSO"
1434 .B scons
1435 User Manual,
1436 .B scons
1437 Design Document,
1438 .B scons
1439 source code.
1440
1441 .SH AUTHORS
1442 Steven Knight <knight@baldmt.com>
1443 .br
1444 Anthony Roach <aroach@electriceyeball.com>
1445