1a1e3354d0679985e8b6a84b8607d5afea4b25a2
[scons.git] / doc / design / engine.xml
1 <!--
2
3   Copyright (c) 2001, 2002, 2003 Steven Knight
4
5   Permission is hereby granted, free of charge, to any person obtaining
6   a copy of this software and associated documentation files (the
7   "Software"), to deal in the Software without restriction, including
8   without limitation the rights to use, copy, modify, merge, publish,
9   distribute, sublicense, and/or sell copies of the Software, and to
10   permit persons to whom the Software is furnished to do so, subject to
11   the following conditions:
12
13   The above copyright notice and this permission notice shall be included
14   in all copies or substantial portions of the Software.
15
16   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17   KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18   WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20   LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 -->
25
26 <section id="sect-principles">
27  <title>General Principles</title>
28
29  <section>
30   <title>Keyword arguments</title>
31   
32   <para>
33
34    All methods and functions in this API will support the use of keyword
35    arguments in calls, for the sake of explicitness and readability.
36    For brevity in the hands of experts, most methods and functions
37    will also support positional arguments for their most-commonly-used
38    arguments.  As an explicit example, the following two lines will each
39    arrange for an executable program named <filename>foo</filename> (or
40    <filename>foo.exe</filename> on a Win32 system) to be compiled from
41    the <filename>foo.c</filename> source file:
42
43   </para>
44
45         <programlisting>
46         env.Program(target = 'foo', source = 'foo.c')
47
48         env.Program('foo', 'foo.c')
49         </programlisting>
50
51  </section>
52
53  <section>
54   <title>Internal object representation</title>
55
56   <para>
57
58    All methods and functions use internal (Python) objects that
59    represent the external objects (files, for example) for which they
60    perform dependency analysis.
61
62   </para>
63
64   <para>
65
66    All methods and functions in this API that accept an external object
67    as an argument will accept <emphasis>either</emphasis> a string
68    description or an object reference.  For example, the two following
69    two-line examples are equivalent:
70
71   </para>
72
73         <programlisting>
74         env.Object(target = 'foo.o', source = 'foo.c')
75         env.Program(target = 'foo', 'foo.o')    # builds foo from foo.o
76
77         foo_obj = env.Object(target = 'foo.o', source = 'foo.c')
78         env.Program(target = 'foo', foo_obj)    # builds foo from foo.o
79         </programlisting>
80
81  </section>
82
83 </section>
84
85
86
87 <section id="sect-envs">
88  <title>&ConsEnvs</title>
89
90  <para>
91
92   A &consenv; is the basic means by which a software system interacts
93   with the &SCons; Python API to control a build process.
94
95  </para>
96
97  <para>
98
99   A &consenv; is an object with associated methods for generating target
100   files of various types (&Builder; objects), other associated object
101   methods for automatically determining dependencies from the contents
102   of various types of source files (&Scanner; objects), and a dictionary
103   of values used by these methods.
104
105  </para>
106
107  <para>
108
109   Passing no arguments to the &Environment; instantiation creates a
110   &consenv; with default values for the current platform:
111
112  </para>
113
114         <programlisting>
115         env = Environment()
116         </programlisting>
117
118  <section>
119   <title>&Consvars;</title>
120
121   <para>
122
123    A &consenv; has an associated dictionary of &consvars; that control how
124    the build is performed.  By default, the &Environment; method creates
125    a &consenv; with values that make most software build "out of the box"
126    on the host system.  These default values will be generated at the
127    time &SCons; is installed using functionality similar to that provided
128    by GNU &Autoconf;.
129    <footnote>
130     <para>
131      It would be nice if we could avoid re-inventing the wheel here by
132      using some other Python-based tool &Autoconf replacement--like what
133      was supposed to come out of the Software Carpentry configuration
134      tool contest.  It will probably be most efficient to roll our own
135      logic initially and convert if something better does come along.
136     </para>
137    </footnote>
138    At a minimum, there will be pre-configured sets of default values
139    that will provide reasonable defaults for UNIX and Windows NT.
140
141   </para>
142
143   <para>
144
145    The default &consenv; values may be overridden when a new &consenv; is
146    created by specifying keyword arguments:
147
148   </para>
149
150         <programlisting>
151         env = Environment(CC =          'gcc',
152                           CCFLAGS =    '-g',
153                           CPPPATH =    ['.', 'src', '/usr/include'],
154                           LIBPATH =    ['/usr/lib', '.'])
155         </programlisting>
156
157  </section>
158
159  <section>
160   <title>Fetching &consvars;</title>
161
162   <para>
163
164    A copy of the dictionary of &consvars; can be returned using
165    the &Dictionary; method:
166
167   </para>
168
169         <programlisting>
170         env = Environment()
171         dict = env.Dictionary()
172         </programlisting>
173
174   <para>
175
176    If any arguments are supplied, then just the corresponding value(s)
177    are returned:
178
179   </para>
180
181         <programlisting>
182         ccflags = env.Dictionary('CCFLAGS')
183         cc, ld = env.Dictionary('CC', 'LD')
184         </programlisting>
185
186  </section>
187
188  <section>
189   <title>Copying a &consenv;</title>
190
191   <para>
192
193    A method exists to return a copy of an existing environment, with
194    any overridden values specified as keyword arguments to the method:
195
196   </para>
197
198         <programlisting>
199         env = Environment()
200         debug = env.Copy(CCFLAGS = '-g')
201         </programlisting>
202
203  </section>
204
205  <section>
206   <title>Multiple &consenvs;</title>
207
208   <para>
209
210    Different external objects often require different build
211    characteristics.  Multiple &consenvs; may be defined, each with
212    different values:
213
214   </para>
215
216         <programlisting>
217         env = Environment(CCFLAGS = '')
218         debug = Environment(CCFLAGS = '-g')
219         env.Make(target = 'hello', source = 'hello.c')
220         debug.Make(target = 'hello-debug', source = 'hello.c')
221         </programlisting>
222
223   <para>
224
225    Dictionaries of values from multiple &consenvs; may be passed to the
226    &Environment; instantiation or the &Copy; method, in which case the
227    last-specified dictionary value wins:
228
229   </para>
230
231         <programlisting>
232         env1 = Environment(CCFLAGS = '-O', LDFLAGS = '-d')
233         env2 = Environment(CCFLAGS = '-g')
234         new = Environment(env1.Dictionary(), env2.Dictionary())
235         </programlisting>
236
237   <para>
238
239    The <varname>new</varname> environment in the above example retains
240    <literal>LDFLAGS = '-d'</literal> from the <varname>env1</varname>
241    environment, and <literal>CCFLAGS = '-g'</literal> from the
242    <varname>env2</varname> environment.
243
244   </para>
245
246   <!--
247
248         hardware details
249         current directory
250         OS environment variables
251         compilers and options,
252         aliases for commands,
253         versions of tools
254
255         environment overrides a la Cons
256
257         compilation options
258
259         cross compilation via selection of tool+options
260
261         paths for header files (specify alternate path)
262
263         accomodate smart compilers that can tell you
264         "I know how to turn .c or .ccp into .o",
265         "I know how to turn .f into .o"
266
267    -->
268
269  </section>
270
271  <section>
272   <title>Variable substitution</title>
273
274   <para>
275
276    Within a construction command, any variable from the &consenv; may
277    be interpolated by prefixing the name of the construction with
278    <symbol>$</symbol>:
279
280   </para>
281
282         <programlisting>
283         MyBuilder = Builder(command = "$XX $XXFLAGS -c $_INPUTS -o $target")
284
285         env.Command(targets = 'bar.out', sources = 'bar.in',
286                     command = "sed '1d' < $source > $target")
287         </programlisting>
288
289   <para>
290
291    Variable substitution is recursive:  the command line is expanded
292    until no more substitutions can be made.
293
294   </para>
295
296   <para>
297
298    Variable names following the <symbol>$</symbol> may be enclosed in
299    braces.  This can be used to concatenate an interpolated value with an
300    alphanumeric character:
301
302   </para>
303
304         <programlisting>
305         VerboseBuilder = Builder(command = "$XX -${XXFLAGS}v > $target")
306         </programlisting>
307
308   <para>
309
310    The variable within braces may contain a pair of parentheses
311    after a Python function name to be evaluated (for example,
312    <literal>${map()}</literal>).  &SCons; will interpolate the return
313    value from the function (presumably a string):
314
315   </para>
316
317         <programlisting>
318         env = Environment(FUNC = myfunc)
319         env.Command(target = 'foo.out', source = 'foo.in',
320                     command = "${FUNC($<)}")
321         </programlisting>
322
323   <para>
324
325    If a referenced variable is not defined in the &consenv;,
326    the null string is interpolated.
327
328   </para>
329
330   <para>
331
332    The following special variables can also be used:
333
334   </para>
335
336   <variablelist>
337
338    <varlistentry>
339     <term><literal>$targets</literal></term>
340     <listitem>
341      <para>
342
343       All target file names.  If multiple targets are specified in an
344       array, <literal>$targets</literal> expands to the entire list of
345       targets, separated by a single space.
346
347     </para>
348
349     <para>
350
351       Individual targets from a list may be extracted by enclosing
352       the <literal>targets</literal> keyword in braces and using the
353       appropriate Python array index or slice:
354
355     </para>
356
357         <programlisting>
358         ${targets[0]}     # expands to the first target
359
360         ${targets[1:]}    # expands to all but the first target
361
362         ${targets[1:-1]}  # expands to all but the first and last targets
363         </programlisting>
364
365     </listitem>
366    </varlistentry>
367
368    <varlistentry>
369     <term><literal>$target</literal></term>
370     <listitem>
371      <para>
372
373       A synonym for <literal>${targets[0]}</literal>, the first target
374       specified.
375
376      </para>
377     </listitem>
378    </varlistentry>
379
380    <varlistentry>
381     <term><literal>$sources</literal></term>
382     <listitem>
383      <para>
384
385       All input file names.  Any input file names that
386       are used anywhere else on the current command
387       line (via <literal>${sources[0]}</literal>,
388       <literal>${sources{[1]}</literal>, etc.) are removed from the
389       expanded list.
390
391      </para>
392     </listitem>
393    </varlistentry>
394
395   </variablelist>
396
397   <para>
398
399    Any of the above special variables may be enclosed in braces and
400    followed immediately by one of the following attributes to select just
401    a portion of the expanded path name:
402
403   </para>
404
405   <variablelist>
406
407    <varlistentry>
408     <term><literal>.base</literal></term>
409     <listitem>
410      <para>
411
412       Basename: the directory plus the file name, minus any file suffix.
413
414      </para>
415     </listitem>
416    </varlistentry>
417
418    <varlistentry>
419     <term><literal>.dir</literal></term>
420     <listitem>
421      <para>
422
423       The directory in which the file lives.  This is a relative path,
424       where appropriate.
425
426      </para>
427     </listitem>
428    </varlistentry>
429
430    <varlistentry>
431     <term><literal>.file</literal></term>
432     <listitem>
433      <para>
434
435       The file name, minus any directory portion.
436
437      </para>
438     </listitem>
439    </varlistentry>
440
441    <varlistentry>
442     <term><literal>.suffix</literal></term>
443     <listitem>
444      <para>
445
446       The file name suffix (that is, the right-most dot in the file name,
447       and all characters to the right of that).
448
449      </para>
450     </listitem>
451    </varlistentry>
452
453    <varlistentry>
454     <term><literal>.filebase</literal></term>
455     <listitem>
456      <para>
457
458       The file name (no directory portion), minus any file suffix.
459
460      </para>
461     </listitem>
462    </varlistentry>
463
464    <varlistentry>
465     <term><literal>.abspath</literal></term>
466     <listitem>
467      <para>
468
469       The absolute path to the file.
470
471      </para>
472     </listitem>
473    </varlistentry>
474
475   </variablelist>
476
477  </section>
478
479 </section>
480
481
482
483 <section id="sect-builders">
484  <title>&Builder; Objects</title>
485
486  <para>
487
488   By default, &SCons; supplies (and uses) a number of pre-defined
489   &Builder; objects:
490
491  </para>
492
493  <informaltable>
494   <tgroup cols="2">
495   <tbody>
496
497    <row>
498     <entry>&Object;</entry>
499     <entry>compile or assemble an object file</entry>
500    </row>
501
502    <row>
503     <entry>&Library;</entry>
504     <entry>archive files into a library</entry>
505    </row>
506
507    <row>
508     <entry>&SharedLibrary;</entry>
509     <entry>archive files into a shared library</entry>
510    </row>
511
512    <row>
513     <entry>&Program;</entry>
514     <entry>link objects and/or libraries into an executable</entry>
515    </row>
516
517    <row>
518     <entry>&MakeBuilder;</entry>
519     <entry>build according to file suffixes; see below</entry>
520    </row>
521
522   </tbody>
523   </tgroup>
524  </informaltable>
525
526 <!--
527 &Library; and &SharedLibrary; have nearly identical
528 semantics, just different
529 tools and &consenvs (paths, etc.) that they use.
530 In other words, you can construct a shared library
531 using just the &Library; &Builder; object
532 with a different environment.
533 I think that's a better way to do it.
534 Feedback?
535 -->
536
537  <para>
538
539   A &consenv; can be explicitly initialized with associated &Builder;
540   objects that will be bound to the &consenv; object:
541
542  </para>
543
544         <programlisting>
545         env = Environment(BUILDERS = ['Object', 'Program'])
546         </programlisting>
547
548  <para>
549
550   &Builder; objects bound to a &consenv; can be called directly as
551   methods.  When invoked, a &Builder; object returns a (list of) objects
552   that it will build:
553
554  </para>
555
556         <programlisting>
557         obj = env.Object(target ='hello.o', source = 'hello.c')
558         lib = env.Library(target ='libfoo.a',
559                           source = ['aaa.c', 'bbb.c'])
560         slib = env.SharedLibrary(target ='libbar.so',
561                                  source = ['xxx.c', 'yyy.c'])
562         prog = env.Program(target ='hello',
563                            source = ['hello.o', 'libfoo.a', 'libbar.so'])
564         </programlisting>
565
566  <section>
567   <title>Specifying multiple inputs</title>
568
569   <para>
570
571    Multiple input files that go into creating a target file may be passed
572    in as a single string, with the individual file names separated by
573    white space:
574
575   </para>
576
577         <programlisting>
578         env.Library(target = 'foo.a', source = 'aaa.c bbb.c ccc.c')
579         env.Object(target = 'yyy.o', source = 'yyy.c')
580         env.Program(target = 'bar', source = 'xxx.c yyy.o foo.a')
581         </programlisting>
582
583   <para>
584
585    Alternatively, multiple input files that go into creating a target
586    file may be passed in as an array.  This allows input files to be
587    specified using their object representation:
588
589   </para>
590
591         <programlisting>
592         env.Library(target = 'foo.a', source = ['aaa.c', 'bbb.c', 'ccc.c'])
593         yyy_obj = env.Object(target = 'yyy.o', source = 'yyy.c')
594         env.Program(target = 'bar', source = ['xxx.c', yyy_obj, 'foo.a'])
595         </programlisting>
596
597    <para>
598
599     Individual string elements within an array of input files are
600     <emphasis>not</emphasis> further split into white-space separated
601     file names.  This allows file names that contain white space to
602     be specified by putting the value into an array:
603
604         <programlisting>
605         env.Program(target = 'foo', source = ['an input file.c'])
606         </programlisting>
607
608    </para>
609
610  </section>
611
612  <section>
613   <title>Specifying multiple targets</title>
614
615   <para>
616
617    Conversely, the generated target may be a string listing multiple
618    files separated by white space:
619
620   </para>
621
622         <programlisting>
623         env.Object(target = 'grammar.o y.tab.h', source = 'grammar.y')
624         </programlisting>
625
626   <para>
627
628    An array of multiple target files can be used to mix string and object
629    representations, or to accomodate file names that contain white space:
630
631   </para>
632
633         <programlisting>
634         env.Program(target = ['my program'], source = 'input.c')
635         </programlisting>
636
637  </section>
638
639  <section>
640   <title>File prefixes and suffixes</title>
641
642   <para>
643
644    For portability, if the target file name does not already have an
645    appropriate file prefix or suffix, the &Builder; objects will
646    append one appropriate for the file type on the current system:
647
648   </para>
649
650         <programlisting>
651         # builds 'hello.o' on UNIX, 'hello.obj' on Windows NT:
652         obj = env.Object(target ='hello', source = 'hello.c')
653
654         # builds 'libfoo.a' on UNIX, 'foo.lib' on Windows NT:
655         lib = env.Library(target ='foo', source = ['aaa.c', 'bbb.c'])
656
657         # builds 'libbar.so' on UNIX, 'bar.dll' on Windows NT:
658         slib = env.SharedLibrary(target ='bar', source = ['xxx.c', 'yyy.c'])
659
660         # builds 'hello' on UNIX, 'hello.exe' on Windows NT:
661         prog = env.Program(target ='hello',
662                            source = ['hello.o', 'libfoo.a', 'libbar.so'])
663         </programlisting>
664
665  </section>
666
667  <section>
668   <title>&Builder; object exceptions</title>
669
670   <para>
671
672    &Builder; objects raise the following exceptions on error:
673
674  <!--
675  LIST THESE ONCE WE FIGURE OUT WHAT THEY ARE FROM CODING THEM.
676  -->
677
678   </para>
679  </section>
680
681  <section>
682   <title>User-defined &Builder; objects</title>
683
684   <para>
685
686    Users can define additional &Builder; objects for specific external
687    object types unknown to &SCons;.  A &Builder; object may build its
688    target by executing an external command:
689
690   </para>
691
692         <programlisting>
693         WebPage = Builder(command = 'htmlgen $HTMLGENFLAGS $sources > $target',
694                           suffix = '.html',
695                           src_suffix = '.in')
696         </programlisting>
697
698   <para>
699
700    Alternatively, a &Builder; object may also build its target by
701    executing a Python function:
702
703    </para>
704
705         <programlisting>
706         def update(dest):
707                 # [code to update the object]
708                 return 1
709
710         OtherBuilder1 = Builder(function = update,
711                                 src_suffix = ['.in', '.input'])
712         </programlisting>
713
714    <para>
715    
716    An optional argument to pass to the function may be specified:
717
718   </para>
719
720         <programlisting>
721         def update_arg(dest, arg):
722                 # [code to update the object]
723                 return 1
724
725         OtherBuilder2 = Builder(function = update_arg,
726                                 function_arg = 'xyzzy',
727                                 src_suffix = ['.in', '.input'])
728         </programlisting>
729
730   <para>
731
732    Both an external command and an internal function may be specified,
733    in which case the function will be called to build the object first,
734    followed by the command line.
735
736   </para>
737
738  <!--
739  NEED AN EXAMPLE HERE.
740  -->
741
742   <para>
743
744    User-defined &Builder; objects can be used like the default &Builder;
745    objects to initialize &consenvs;.
746
747   </para>
748
749         <programlisting>
750         WebPage = Builder(command = 'htmlgen $HTMLGENFLAGS $sources > $target',
751                           suffix = '.html',
752                           src_suffix = '.in')
753         env = Environment(BUILDERS = ['WebPage'])
754         env.WebPage(target = 'foo.html', source = 'foo.in')
755         # Builds 'bar.html' on UNIX, 'bar.htm' on Windows NT:
756         env.WebPage(target = 'bar', source = 'bar.in')
757         </programlisting>
758
759   <para>
760
761    The command-line specification can interpolate variables from the
762    &consenv;; see "Variable substitution," above.
763
764   </para>
765
766   <para>
767
768    A &Builder; object may optionally be initialized with a list of:
769
770   </para>
771
772    <itemizedlist>
773      <listitem>
774      <para>
775
776        the prefix of the target file (e.g., 'lib' for libraries)
777
778      </para>
779      </listitem>
780
781      <listitem>
782      <para>
783
784        the suffix of the target file (e.g., '.a' for libraries)
785
786      </para>
787      </listitem>
788
789      <listitem>
790      <para>
791
792        the expected suffixes of the input files
793        (e.g., '.o' for object files)
794
795      </para>
796      </listitem>
797    </itemizedlist>
798
799    <para>
800
801     These arguments are used in automatic
802     dependency analysis and to generate output file names that don't
803     have suffixes supplied explicitly.
804
805   </para>
806  </section>
807
808  <section>
809   <title>Copying &Builder; Objects</title>
810
811   <para>
812
813    A &Copy; method exists to return a copy of an existing &Builder;
814    object, with any overridden values specified as keyword arguments to
815    the method:
816
817   </para>
818
819         <programlisting>
820         build = Builder(function = my_build)
821         build_out = build.Copy(suffix = '.out')
822         </programlisting>
823
824   <para>
825
826    Typically, &Builder; objects will be supplied by a tool-master or
827    administrator through a shared &consenv;.
828
829   </para>
830  </section>
831
832  <section>
833   <title>Special-purpose build rules</title>
834
835   <para>
836
837    A pre-defined &Command; builder exists to associate a target file with
838    a specific command or list of commands for building the file:
839
840   </para>
841
842         <programlisting>
843         env.Command(target = 'foo.out', source = 
844                     command = 'foo.in', "foo.process $sources > $target")
845
846         commands = [    "bar.process -o .tmpfile $sources",
847                         "mv .tmpfile $target" ]
848         env.Command(target = 'bar.out', source = 'bar.in', command = commands)
849         </programlisting>
850
851   <para>
852    This is useful when it's too cumbersome to create a &Builder;
853    object just to build a single file in a special way.
854
855   </para>
856  </section>
857
858  <section>
859   <title>The &MakeBuilder; &Builder;</title>
860
861   <para>
862
863    A pre-defined &Builder; object named &MakeBuilder; exists to make
864    simple builds as easy as possible for users, at the expense of
865    sacrificing some build portability.
866
867   </para>
868
869   <para>
870
871    The following minimal example builds the 'hello' program from the
872    'hello.c' source file:
873
874   </para>
875
876         <programlisting>
877         Environment().Make('hello', 'hello.c')
878         </programlisting>
879
880   <para>
881
882    Users of the &MakeBuilder; &Builder; object are not required to
883    understand intermediate steps involved in generating a file--for
884    example, the distinction between compiling source code into an object
885    file, and then linking object files into an executable.  The details
886    of intermediate steps are handled by the invoked method.  Users that
887    need to, however, can specify intermediate steps explicitly:
888
889   </para>
890
891         <programlisting>
892         env = Environment()
893         env.Make(target = 'hello.o', source = 'hello.c')
894         env.Make(target = 'hello', source = 'hello.o')
895         </programlisting>
896
897   <para>
898
899    The &MakeBuilder; method understands the file suffixes specified and
900    "does the right thing" to generate the target object and program
901    files, respectively.  It does this by examining the specified output
902    suffixes for the &Builder; objects bound to the environment.
903
904   </para>
905
906   <para>
907
908    Because file name suffixes in the target and source file names
909    must be specified, the &MakeBuilder; method can't be used
910    portably across operating systems.  In other words, for the
911    example above, the &MakeBuilder; builder will not generate
912    <filename>hello.exe</filename> on Windows NT.
913
914   </para>
915
916  </section>
917
918  <section>
919   <title>&Builder; maps</title>
920
921 <!--
922 Do we even need this anymore?
923 Now that the individual builders
924 have specified <literal>suffix</literal>
925 and <literal>src_suffix</literal> values,
926 all of the information we need to support
927 the &MakeBuilder; builder is right there in the environment.
928 I think this is a holdover from before I
929 added the <literal>suffix</literal> arguments.
930 If you want &MakeBuilder; to do something different,
931 you set it up with another environment...
932 -->
933
934   <para>
935
936    The <function>env.Make</function> method "does the right thing" to
937    build different file types because it uses a dictionary from the
938    &consenv; that maps file suffixes to the appropriate &Builder; object.
939    This &BUILDERMAP; can be initialized at instantiation:
940
941   </para>
942
943         <programlisting>
944         env = Environment(BUILDERMAP = {
945                                 '.o' : Object,
946                                 '.a' : Library,
947                                 '.html' : WebPage,
948                                 '' : Program,
949                         })
950         </programlisting>
951
952   <para>
953
954    With the &BUILDERMAP; properly initialized, the
955    <function>env.Make</function> method can be used to build additional
956    file types:
957
958   </para>
959
960         <programlisting>
961         env.Make(target = 'index.html', source = 'index.input')
962         </programlisting>
963
964   <para>
965
966    &Builder; objects referenced in the &BUILDERMAP; do not need to be
967    listed separately in the &BUILDERS; variable.  The &consenv; will
968    bind the union of the &Builder; objects listed in both variables.
969
970   </para>
971
972  <!--
973
974    YYY support scanners which detect files which haven't been generated yet
975
976  -->
977
978  </section>
979
980 </section>
981
982
983
984 <section id="sect-deps">
985  <title>Dependencies</title>
986
987  <section>
988   <title>Automatic dependencies</title>
989
990   <para>
991
992    By default, &SCons; assumes that a target file has <literal>automatic
993    dependencies</literal> on the:
994
995   </para>
996
997   <blockquote>
998    <simplelist>
999
1000     <member>tool used to build the target file</member>
1001
1002     <member>contents of the input files</member>
1003
1004     <member>command line used to build the target file</member>
1005
1006    </simplelist>
1007   </blockquote>
1008
1009   <para>
1010
1011    If any of these changes, the target file will be rebuilt.
1012
1013   </para>
1014  </section>
1015
1016  <section>
1017   <title>Implicit dependencies</title>
1018
1019   <para>
1020
1021    Additionally, &SCons; can scan the contents of files for
1022    <literal>implicit dependencies</literal> on other files.  For
1023    example, &SCons; will scan the contents of a <filename>.c</filename>
1024    file and determine that any object created from it is
1025    dependent on any <filename>.h</filename> files specified via
1026    <literal>#include</literal>.  &SCons;, therefore, "does the right
1027    thing" without needing to have these dependencies listed explicitly:
1028
1029   </para>
1030
1031         <programlisting>
1032         % cat Construct
1033         env = Environment()
1034         env.Program('hello', 'hello.c')
1035         % cat hello.c
1036         #include "hello_string.h"
1037         main()
1038         {
1039                 printf("%s\n", STRING);
1040         }
1041         % cat > hello_string.h
1042         #define STRING  "Hello, world!\n"
1043         % scons .
1044         gcc -c hello.c -o hello.o
1045         gcc -o hello hello.c
1046         % ./hello
1047         Hello, world!
1048         % cat > hello_string.h
1049         #define STRING  "Hello, world, hello!\n"
1050         % scons .
1051         gcc -c hello.c -o hello.o
1052         gcc -o hello hello.c
1053         % ./hello
1054         Hello, world, hello!
1055         %
1056         </programlisting>
1057
1058  </section>
1059
1060  <section>
1061   <title>Ignoring dependencies</title>
1062
1063   <para>
1064
1065    Undesirable <literal>automatic dependencies</literal> or
1066    <literal>implicit dependencies</literal> may be ignored:
1067
1068   </para>
1069
1070         <programlisting>
1071         env.Program(target = 'bar', source = 'bar.c')
1072         env.Ignore('bar', '/usr/bin/gcc', 'version.h')
1073         </programlisting>
1074
1075   <para>
1076
1077    In the above example, the <filename>bar</filename> program will not
1078    be rebuilt if the <filename>/usr/bin/gcc</filename> compiler or the
1079    <filename>version.h</filename> file change.
1080
1081   </para>
1082  </section>
1083
1084  <section>
1085   <title>Explicit dependencies</title>
1086
1087   <para>
1088
1089    Dependencies that are unknown to &SCons; may be specified explicitly
1090    in an &SCons; configuration file:
1091
1092   </para>
1093
1094         <programlisting>
1095         env.Dependency(target = 'output1', dependency = 'input_1 input_2')
1096         env.Dependency(target = 'output2', dependency = ['input_1', 'input_2'])
1097         env.Dependency(target = 'output3', dependency = ['white space input'])
1098
1099         env.Dependency(target = 'output_a output_b', dependency = 'input_3')
1100         env.Dependency(target = ['output_c', 'output_d'], dependency = 'input_4')
1101         env.Dependency(target = ['white space output'], dependency = 'input_5')
1102         </programlisting>
1103
1104   <para>
1105
1106    Just like the <literal>target</literal> keyword argument, the
1107    <literal>dependency</literal> keyword argument may be specified as a
1108    string of white-space separated file names, or as an array.
1109
1110   </para>
1111
1112   <para>
1113
1114    A dependency on an &SCons; configuration file itself may be specified
1115    explicitly to force a rebuild whenever the configuration file changes:
1116
1117   </para>
1118
1119         <programlisting>
1120         env.Dependency(target = 'archive.tar.gz', dependency = 'SConstruct')
1121         </programlisting>
1122
1123  </section>
1124
1125 </section>
1126
1127
1128
1129 <section id="sect-scanners">
1130  <title>&Scanner; Objects</title>
1131
1132  <para>
1133
1134   Analagous to the previously-described &Builder; objects, &SCons;
1135   supplies (and uses) &Scanner; objects to search the contents of
1136   a file for implicit dependency files:
1137
1138  </para>
1139
1140  <informaltable>
1141   <tgroup cols="2">
1142   <tbody>
1143
1144    <row>
1145     <entry>CScan</entry>
1146     <entry>scan .{c,C,cc,cxx,cpp} files for #include dependencies</entry>
1147    </row>
1148
1149   </tbody>
1150   </tgroup>
1151  </informaltable>
1152
1153  <para>
1154
1155   A &consenv; can be explicitly initialized with
1156   associated &Scanner; objects:
1157
1158  </para>
1159
1160         <programlisting>
1161         env = Environment(SCANNERS = ['CScan', 'M4Scan'])
1162         </programlisting>
1163
1164  <para>
1165
1166   &Scanner; objects bound to a &consenv; can be
1167   associated directly with specified files:
1168
1169  </para>
1170
1171         <programlisting>
1172         env.CScan('foo.c', 'bar.c')
1173         env.M4Scan('input.m4')
1174         </programlisting>
1175
1176  <section>
1177   <title>User-defined &Scanner; objects</title>
1178
1179   <para>
1180
1181    A user may define a &Scanner; object to scan a type of file for
1182    implicit dependencies:
1183
1184   </para>
1185
1186         <programlisting>
1187         def scanner1(file_contents):
1188                 # search for dependencies
1189                 return dependency_list
1190
1191         FirstScan = Scanner(function = scanner1)
1192         </programlisting>
1193
1194   <para>
1195
1196    The scanner function must return a list of dependencies that its finds
1197    based on analyzing the file contents it is passed as an argument.
1198
1199   </para>
1200
1201   <para>
1202
1203    The scanner function, when invoked, will be passed the calling
1204    environment.  The scanner function can use &consenvs; from the passed
1205    environment to affect how it performs its dependency scan--the
1206    canonical example being to use some sort of search-path construction
1207    variable to look for dependency files in other directories:
1208
1209   </para>
1210
1211         <programlisting>
1212         def scanner2(file_contents, env):
1213                 path = env.{'SCANNERPATH'}      # XXX
1214                 # search for dependencies using 'path'
1215                 return dependency_list
1216
1217         SecondScan = Scanner(function = scanner2)
1218         </programlisting>
1219
1220   <para>
1221
1222    The user may specify an additional argument when the &Scanner; object
1223    is created.  When the scanner is invoked, the additional argument
1224    will be passed to the scanner funciton, which can be used in any way
1225    the scanner function sees fit:
1226
1227   </para>
1228
1229         <programlisting>
1230         def scanner3(file_contents, env, arg):
1231                 # skip 'arg' lines, then search for dependencies
1232                 return dependency_list
1233
1234         Skip_3_Lines_Scan = Scanner(function = scanner2, argument = 3)
1235         Skip_6_Lines_Scan = Scanner(function = scanner2, argument = 6)
1236         </programlisting>
1237
1238  </section>
1239
1240  <section>
1241   <title>Copying &Scanner; Objects</title>
1242
1243   <para>
1244
1245    A method exists to return a copy of an existing &Scanner; object,
1246    with any overridden values specified as keyword arguments to the
1247    method:
1248
1249   </para>
1250
1251         <programlisting>
1252         scan = Scanner(function = my_scan)
1253         scan_path = scan.Copy(path = '%SCANNERPATH')
1254         </programlisting>
1255
1256   <para>
1257
1258    Typically, &Scanner; objects will be supplied by a tool-master or
1259    administrator through a shared &consenv;.
1260
1261   </para>
1262  </section>
1263
1264  <section>
1265   <title>&Scanner; maps</title>
1266
1267 <!--
1268 If the &BUILDERMAP; proves unnecessary,
1269 we could/should get rid of this one, too,
1270 by adding a parallel <literal>src_suffix</literal>
1271 argument to the &Scanner; factory...
1272 Comments?
1273 -->
1274
1275   <para>
1276
1277    Each &consenv; has a &SCANNERMAP;, a dictionary that associates
1278    different file suffixes with a scanner object that can be used to
1279    generate a list of dependencies from the contents of that file.  This
1280    &SCANNERMAP; can be initialized at instantiation:
1281
1282   </para>
1283
1284         <programlisting>
1285         env = Environment(SCANNERMAP = {
1286                                 '.c' : CScan,
1287                                 '.cc' : CScan,
1288                                 '.m4' : M4Scan,
1289                         })
1290         </programlisting>
1291
1292   <para>
1293
1294    &Scanner; objects referenced in the &SCANNERMAP; do not need to
1295    be listed separately in the &SCANNERS; variable.  The &consenv;
1296    will bind the union of the &Scanner; objects listed
1297    in both variables.
1298
1299   </para>
1300
1301  </section>
1302
1303 </section>
1304
1305
1306
1307 <section id="sect-targets">
1308  <title>Targets</title>
1309
1310  <para>
1311
1312   The methods in the build engine API described so far merely
1313   establish associations that describe file dependencies, how a
1314   file should be scanned, etc.  Since the real point is to actually
1315   <emphasis>build</emphasis> files, &SCons; also has methods that
1316   actually direct the build engine to build, or otherwise manipulate,
1317   target files.
1318
1319  </para>
1320
1321  <section>
1322   <title>Building targets</title>
1323   <para>
1324
1325    One or more targets may be built as follows:
1326
1327   </para>
1328
1329         <programlisting>
1330         env.Build(target = ['foo', 'bar'])
1331         </programlisting>
1332
1333   <para>
1334
1335    Note that specifying a directory (or other collective object) will
1336    cause all subsidiary/dependent objects to be built as well:
1337
1338   </para>
1339
1340         <programlisting>
1341         env.Build(target = '.')
1342
1343         env.Build(target = 'builddir')
1344         </programlisting>
1345
1346   <para>
1347
1348    By default, &SCons; explicitly removes a target file before
1349    invoking the underlying function or command(s) to build it.
1350
1351   </para>
1352  </section>
1353
1354  <section>
1355   <title>Removing targets</title>
1356
1357   <para>
1358
1359    A "cleanup" operation of removing generated (target) files is
1360    performed as follows:
1361
1362   </para>
1363
1364         <programlisting>
1365         env.Clean(target = ['foo', 'bar'])
1366         </programlisting>
1367
1368   <para>
1369
1370    Like the &Build; method, the &Clean; method may be passed a
1371    directory or other collective object, in which case the subsidiary
1372    target objects under the directory will be removed:
1373
1374   </para>
1375
1376         <programlisting>
1377         env.Clean(target = '.')
1378
1379         env.Clean(target = 'builddir')
1380         </programlisting>
1381
1382   <para>
1383
1384    (The directories themselves are not removed.)
1385
1386   </para>
1387  </section>
1388  
1389  <section>
1390   <title>Suppressing cleanup removal of build-targets</title>
1391
1392   <para>
1393     
1394     By default, &SCons; explicitly removes all build-targets
1395     when invoked to perform "cleanup". Files that should not be 
1396     removed during "cleanup" can be specified via the
1397     &NoClean; method:
1398     
1399   </para>
1400   
1401   <programlisting>
1402     env.Library(target = 'libfoo.a', source = ['aaa.c', 'bbb.c', 'ccc.c'])
1403     env.NoClean('libfoo.a')
1404   </programlisting>
1405   
1406   <para>
1407     
1408     The NoClean operation has precedence over the Clean operation.
1409     A target that is specified as both Clean and NoClean, will not 
1410     be removed during a clean.
1411     
1412     In the following example, target 'foo' will not be removed 
1413     during "cleanup":
1414     
1415     <programlisting>
1416       env.Clean(target = 'foo')
1417       env.NoClean('foo')
1418     </programlisting>
1419     
1420     
1421   </para>
1422   
1423  </section>
1424  
1425  <section>
1426   <title>Suppressing build-target removal</title>
1427
1428   <para>
1429
1430    As mentioned, by default, &SCons; explicitly removes a target
1431    file before invoking the underlying function or command(s) to build
1432    it.  Files that should not be removed before rebuilding can be
1433    specified via the &Precious; method:
1434
1435   </para>
1436
1437         <programlisting>
1438         env.Library(target = 'libfoo.a', source = ['aaa.c', 'bbb.c', 'ccc.c'])
1439         env.Precious('libfoo.a')
1440         </programlisting>
1441
1442  </section>
1443
1444  <section>
1445   <title>Default targets</title>
1446
1447   <para>
1448
1449    The user may specify default targets that will be built if there are no
1450    targets supplied on the command line:
1451
1452   </para>
1453
1454         <programlisting>
1455         env.Default('install', 'src')
1456         </programlisting>
1457
1458   <para>
1459
1460    Multiple calls to the &Default; method (typically one per &SConscript;
1461    file) append their arguments to the list of default targets.
1462
1463   </para>
1464  </section>
1465
1466  <section>
1467   <title>File installation</title>
1468
1469   <para>
1470
1471    Files may be installed in a destination directory:
1472
1473   </para>
1474
1475         <programlisting>
1476         env.Install('/usr/bin', 'program1', 'program2')
1477         </programlisting>
1478
1479   <para>
1480
1481    Files may be renamed on installation:
1482
1483   </para>
1484
1485         <programlisting>
1486         env.InstallAs('/usr/bin/xyzzy', 'xyzzy.in')
1487         </programlisting>
1488
1489   <para>
1490
1491    Multiple files may be renamed on installation by specifying
1492    equal-length lists of target and source files:
1493
1494   </para>
1495
1496         <programlisting>
1497         env.InstallAs(['/usr/bin/foo', '/usr/bin/bar'],
1498                         ['foo.in', 'bar.in'])
1499         </programlisting>
1500
1501  </section>
1502
1503  <section>
1504   <title>Target aliases</title>
1505
1506   <para>
1507
1508    In order to provide convenient "shortcut" target names that expand to
1509    a specified list of targets, aliases may be established:
1510
1511   </para>
1512
1513         <programlisting>
1514         env.Alias(alias = 'install',
1515                   targets = ['/sbin', '/usr/lib', '/usr/share/man'])
1516         </programlisting>
1517
1518   <para>
1519
1520    In this example, specifying a target of <literal>install</literal>
1521    will cause all the files in the associated directories to be built
1522    (that is, installed).
1523
1524   </para>
1525
1526   <para>
1527
1528    An &Alias; may include one or more other &Aliases; in its list:
1529
1530   </para>
1531
1532         <programlisting>
1533         env.Alias(alias = 'libraries', targets = ['lib'])
1534         env.Alias(alias = 'programs', targets = ['libraries', 'src'])
1535         </programlisting>
1536
1537  </section>
1538
1539 </section>
1540
1541
1542
1543 <section id="sect-custom">
1544  <title>Customizing output</title>
1545
1546 <!--
1547 Take this whole section with a grain of salt.
1548 I whipped it up without a great deal of thought
1549 to try to add a "competitive advantage"
1550 for the second round of the Software Carpentry contest.
1551 In particular, hard-coding the
1552 analysis points and the keywords that specify them
1553 feels inflexible,
1554 but I can't think of another way it would be
1555 done effectively.
1556 I dunno, maybe this is fine as it is...
1557 -->
1558
1559  <para>
1560
1561   The &SCons; API supports the ability to customize, redirect, or
1562   suppress its printed output through user-defined functions.
1563   &SCons; has several pre-defined points in its build process at
1564   which it calls a function to (potentially) print output.  User-defined
1565   functions can be specified for these call-back points when &Build;
1566   or &Clean;is invoked:
1567
1568  </para>
1569
1570         <programlisting>
1571         env.Build(target = '.',
1572                on_analysis = dump_dependency,
1573                pre_update = my_print_command,
1574                post_update = my_error_handler)
1575                on_error = my_error_handler)
1576         </programlisting>
1577
1578  <para>
1579
1580   The specific call-back points are:
1581
1582  </para>
1583
1584  <variablelist>
1585
1586   <varlistentry>
1587    <term><literal>on_analysis</literal></term>
1588    <listitem>
1589     <para>
1590
1591      Called for every object, immediately after the object has been
1592      analyzed to see if it's out-of-date.  Typically used to print a
1593      trace of considered objects for debugging of unexpected dependencies.
1594
1595     </para>
1596    </listitem>
1597   </varlistentry>
1598
1599   <varlistentry>
1600    <term><literal>pre_update</literal></term>
1601    <listitem>
1602     <para>
1603
1604      Called for every object that has been determined to be out-of-date
1605      before its update function or command is executed.  Typically used
1606      to print the command being called to update a target.
1607
1608     </para>
1609    </listitem>
1610   </varlistentry>
1611
1612   <varlistentry>
1613    <term><literal>post_update</literal></term>
1614    <listitem>
1615     <para>
1616
1617      Called for every object after its update function or command has
1618      been executed.  Typically used to report that a top-level specified
1619      target is up-to-date or was not remade.
1620
1621     </para>
1622    </listitem>
1623   </varlistentry>
1624
1625   <varlistentry>
1626    <term><literal>on_error</literal></term>
1627    <listitem>
1628     <para>
1629
1630      Called for every error returned by an update function or command.
1631      Typically used to report errors with some string that will be
1632      identifiable to build-analysis tools.
1633
1634     </para>
1635    </listitem>
1636   </varlistentry>
1637
1638  </variablelist>
1639
1640  <para>
1641
1642   Functions for each of these call-back points all take the same
1643   arguments:
1644
1645  </para>
1646
1647         <programlisting>
1648         my_dump_dependency(target, level, status, update, dependencies)
1649         </programlisting>
1650
1651  <para>
1652
1653   where the arguments are:
1654
1655  </para>
1656
1657  <variablelist>
1658
1659   <varlistentry>
1660    <term><literal>target</literal></term>
1661    <listitem>
1662     <para>
1663
1664      The target object being considered.
1665
1666     </para>
1667    </listitem>
1668   </varlistentry>
1669
1670   <varlistentry>
1671    <term><literal>level</literal></term>
1672    <listitem>
1673     <para>
1674
1675      Specifies how many levels the dependency analysis has
1676      recursed in order to consider the <literal>target</literal>.
1677      A value of <literal>0</literal> specifies a top-level
1678      <literal>target</literal> (that is, one passed to the
1679      &Build; or &Clean; method).  Objects which a top-level
1680      <literal>target</literal> is directly dependent upon have a
1681      <literal>level</literal> of <1>, their direct dependencies have a
1682      <literal>level</literal> of <2>, etc.  Typically used to indent
1683      output to reflect the recursive levels.
1684
1685     </para>
1686    </listitem>
1687   </varlistentry>
1688
1689   <varlistentry>
1690    <term><literal>status</literal></term>
1691    <listitem>
1692     <para>
1693
1694      A string specifying the current status of the target
1695      (<literal>"unknown"</literal>, <literal>"built"</literal>,
1696      <literal>"error"</literal>, <literal>"analyzed"</literal>, etc.).  A
1697      complete list will be enumerated and described during implementation.
1698
1699     </para>
1700    </listitem>
1701   </varlistentry>
1702
1703   <varlistentry>
1704    <term><literal>update</literal></term>
1705    <listitem>
1706     <para>
1707
1708      The command line or function name that will be (or has been) executed
1709      to update the <literal>target</literal>.
1710
1711     </para>
1712    </listitem>
1713   </varlistentry>
1714
1715   <varlistentry>
1716    <term><literal>dependencies</literal></term>
1717    <listitem>
1718     <para>
1719
1720      A list of direct dependencies of the target.
1721
1722     </para>
1723    </listitem>
1724   </varlistentry>
1725
1726  </variablelist>
1727
1728 </section>
1729
1730
1731
1732 <section id="separate">
1733  <title>Separate source and build trees</title>
1734
1735 <!--
1736 I've never liked Cons' use of the name <literal>Link</literal>
1737 for this functionality,
1738 mainly because the term is overloaded
1739 with linking object files into an executable.
1740 Yet I've never come up with anything better.
1741 Any suggestions?
1742 -->
1743
1744 <!--
1745 Also, I made this an &Environment; method because
1746 it logically belongs in the API reference
1747 (the build engine needs to know about it),
1748 and I thought it was clean to have
1749 everything in the build-engine API
1750 be called through an &Environment; object.
1751 But <literal>&Link</literal> isn't really
1752 associated with a specific environment
1753 (the &Cons; classic implementation just
1754 leaves it as a bare function call),
1755 so maybe we should just follow that example
1756 and not call it through an environment...
1757 -->
1758
1759  <para>
1760
1761   &SCons; allows target files to be built completely separately from
1762   the source files by "linking" a build directory to an underlying
1763   source directory:
1764
1765  </para>
1766
1767         <programlisting>
1768         env.Link('build', 'src')
1769
1770         SConscript('build/SConscript')
1771         </programlisting>
1772
1773  <para>
1774
1775   &SCons; will copy (or hard link) necessary files (including the
1776   &SConscript; file) into the build directory hierarchy.  This allows the
1777   source directory to remain uncluttered by derived files.
1778
1779  </para>
1780
1781 </section>
1782
1783
1784
1785 <section id="sect-variant">
1786  <title>Variant builds</title>
1787
1788  <para>
1789
1790   The &Link; method may be used in conjunction with multiple
1791   &consenvs; to support variant builds.  The following
1792   &SConstruct; and &SConscript; files would build separate debug and
1793   production versions of the same program side-by-side:
1794
1795  </para>
1796
1797         <programlisting>
1798         % cat SConstruct
1799         env = Environment()
1800         env.Link('build/debug', 'src')
1801         env.Link('build/production', 'src')
1802         flags = '-g'
1803         SConscript('build/debug/SConscript', Export(env))
1804         flags = '-O'
1805         SConscript('build/production/SConscript', Export(env))
1806         % cat src/SConscript
1807         env = Environment(CCFLAGS = flags)
1808         env.Program('hello', 'hello.c')
1809         </programlisting>
1810
1811  <para>
1812
1813   The following example would build the appropriate program for the current
1814   compilation platform, without having to clean any directories of object
1815   or executable files for other architectures:
1816
1817  </para>
1818
1819         <programlisting>
1820         % cat SConstruct
1821         build_platform = os.path.join('build', sys.platform)
1822         Link(build_platform, 'src')
1823         SConscript(os.path.join(build_platform, 'SConscript'))
1824         % cat src/SConscript
1825         env = Environment
1826         env.Program('hello', 'hello.c')
1827         </programlisting>
1828
1829 </section>
1830
1831
1832
1833 <section id="sect-repositories">
1834  <title>Code repositories</title>
1835
1836 <!--
1837 Like &Link;, &Repository; and &Local; are part of the
1838 API reference, but not really tied to any specific environment.
1839 Is it better to be consistent about calling
1840 everything in the API through an environment,
1841 or to leave these independent so as
1842 not to complicate their calling interface?
1843 -->
1844
1845  <para>
1846
1847   &SCons; may use files from one or more shared code repositories in order
1848   to build local copies of changed target files.  A repository would
1849   typically be a central directory tree, maintained by an integrator,
1850   with known good libraries and executables.
1851
1852  </para>
1853
1854         <programlisting>
1855         Repository('/home/source/1.1', '/home/source/1.0')
1856         </programlisting>
1857
1858  <para>
1859
1860   Specified repositories will be searched in-order for any file
1861   (configuration file, input file, target file) that does not exist
1862   in the local directory tree.  When building a local target file,
1863   &SCons; will rewrite path names in the build command to use the
1864   necessary repository files.  This includes modifying lists of
1865   <option>-I</option> or <option>-L</option> flags to specify an
1866   appropriate set of include paths for dependency analysis.
1867
1868  </para>
1869  <para>
1870
1871   &SCons; will modify the Python <varname>sys.path</varname> variable to
1872   reflect the addition of repositories to the search path, so that any
1873   imported modules or packages necessary for the build can be found in a
1874   repository, as well.
1875
1876  </para>
1877  <para>
1878
1879   If an up-to-date target file is found in a code repository, the file
1880   will not be rebuilt or copied locally.  Files that must exist locally
1881   (for example, to run tests) may be specified:
1882
1883  </para>
1884
1885         <programlisting>
1886         Local('program', 'libfoo.a')
1887         </programlisting>
1888
1889  <para>
1890
1891   in which case &SCons; will copy or link an up-to-date copy of the
1892   file from the appropriate repository.
1893
1894  </para>
1895
1896 </section>
1897
1898
1899
1900 <section id="sect-caching">
1901  <title>Derived-file caching</title>
1902
1903 <!--
1904 There should be extensions to this part of the API for
1905 auxiliary functions like cleaning the cache.
1906 -->
1907
1908  <para>
1909
1910   &SCons; can maintain a cache directory of target files which may be
1911   shared among multiple builds.  This reduces build times by allowing
1912   developers working on a project together to share common target
1913   files:
1914
1915  </para>
1916
1917         <programlisting>
1918         Cache('/var/tmp/build.cache/i386')
1919         </programlisting>
1920
1921  <para>
1922
1923   When a target file is generated, a copy is added to the cache.
1924   When generating a target file, if &SCons; determines that a file
1925   that has been built with the exact same dependencies already exists
1926   in the specified cache, &SCons; will copy the cached file rather
1927   than re-building the target.
1928
1929  </para>
1930  <para>
1931
1932   Command-line options exist to modify the &SCons; caching behavior
1933   for a specific build, including disabling caching, building
1934   dependencies in random order, and displaying commands as if cached
1935   files were built.
1936
1937  </para>
1938
1939 </section>
1940
1941
1942
1943 <section id="sect-jobs">
1944  <title>Job management</title>
1945
1946 <!--
1947 This has been completely superseded by
1948 the more sophisticated &Task; manager
1949 that Anthony Roach has contributed.
1950 I need to write that up...
1951 -->
1952
1953  <para>
1954
1955   A simple API exists to inform the Build Engine how many jobs may
1956   be run simultaneously:
1957
1958  </para>
1959
1960         <programlisting>
1961         Jobs(limit = 4)
1962         </programlisting>
1963
1964 </section>