Fix the Requires() examples by adding a sleep command to the
[scons.git] / doc / user / depends.in
1 <!--
2
3   __COPYRIGHT__
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   <para>
27
28   So far we've seen how &SCons; handles one-time builds.
29   But one of the main functions of a build tool like &SCons;
30   is to rebuild only what is necessary
31   when source files change--or, put another way,
32   &SCons; should <emphasis>not</emphasis>
33   waste time rebuilding things that don't need to be rebuilt.
34   You can see this at work simply by re-invoking &SCons;
35   after building our simple &hello; example:
36
37   </para>
38
39   <scons_example name="ex1">
40     <file name="SConstruct">
41     Program('hello.c')
42     </file>
43     <file name="hello.c">
44     int main() { printf("Hello, world!\n"); }
45     </file>
46   </scons_example>
47
48   <scons_output example="ex1" os="posix">
49      <scons_output_command>scons -Q</scons_output_command>
50      <scons_output_command>scons -Q</scons_output_command>
51   </scons_output>
52
53   <para>
54
55   The second time it is executed,
56   &SCons; realizes that the &hello; program
57   is up-to-date with respect to the current &hello_c; source file,
58   and avoids rebuilding it.
59   You can see this more clearly by naming
60   the &hello; program explicitly on the command line:
61
62   </para>
63
64   <scons_output example="ex1" os="posix">
65      <scons_output_command>scons -Q hello</scons_output_command>
66      <scons_output_command>scons -Q hello</scons_output_command>
67   </scons_output>
68
69   <para>
70
71   Note that &SCons; reports <literal>"...is up to date"</literal>
72   only for target files named explicitly on the command line,
73   to avoid cluttering the output.
74
75   </para>
76
77   <section>
78   <title>Deciding When an Input File Has Changed:  the &Decider; Function</title>
79
80     <para>
81
82     Another aspect of avoiding unnecessary rebuilds
83     is the fundamental build tool behavior
84     of <emphasis>rebuilding</emphasis>
85     things when an input file changes,
86     so that the built software is up to date.
87     By default,
88     &SCons; keeps track of this through an
89     MD5 &signature;, or checksum, of the contents of each file,
90     although you can easily configure
91     &SCons; to use the
92     modification times (or time stamps)
93     instead.
94     You can even specify your own Python function
95     for deciding if an input file has changed.
96
97     </para>
98
99     <section>
100     <title>Using MD5 Signatures to Decide if a File Has Changed</title>
101
102       <para>
103
104       By default,
105       &SCons; keeps track of whether a file has changed
106       based on an MD5 checksum of the file's contents,
107       not the file's modification time.
108       This means that you may be surprised by the
109       default &SCons; behavior if you are used to the
110       &Make; convention of forcing
111       a rebuild by updating the file's modification time
112       (using the &touch; command, for example):
113
114       </para>
115
116       <scons_output example="ex1" os="posix">
117          <scons_output_command>scons -Q hello</scons_output_command>
118          <scons_output_command>touch hello.c</scons_output_command>
119          <scons_output_command>scons -Q hello</scons_output_command>
120       </scons_output>
121
122       <para>
123
124       Even though the file's modification time has changed,
125       &SCons; realizes that the contents of the
126       &hello_c; file have <emphasis>not</emphasis> changed,
127       and therefore that the &hello; program
128       need not be rebuilt.
129       This avoids unnecessary rebuilds when,
130       for example, someone rewrites the
131       contents of a file without making a change.
132       But if the contents of the file really do change,
133       then &SCons; detects the change
134       and rebuilds the program as required:
135
136       </para>
137
138       <scons_output example="ex1" os="posix">
139          <scons_output_command>scons -Q hello</scons_output_command>
140          <scons_output_command output="    [CHANGE THE CONTENTS OF hello.c]">edit hello.c</scons_output_command>
141          <scons_output_command>scons -Q hello</scons_output_command>
142       </scons_output>
143
144       <para>
145
146       Note that you can, if you wish,
147       specify this default behavior
148       (MD5 signatures) explicitly
149       using the &Decider; function as follows:
150
151       </para>
152
153       <sconstruct>
154         Program('hello.c')
155         Decider('MD5')
156       </sconstruct>
157
158       <para>
159
160       You can also use the string <literal>'content'</literal>
161       as a synonym for <literal>'MD5'</literal>
162       when calling the &Decider; function.
163
164       </para>
165
166       <section>
167       <title>Ramifications of Using MD5 Signatures</title>
168
169         <para>
170
171         Using MD5 signatures to decide if an input file has changed
172         has one surprising benefit:
173         if a source file has been changed
174         in such a way that the contents of the
175         rebuilt target file(s)
176         will be exactly the same as the last time
177         the file was built,
178         then any "downstream" target files
179         that depend on the rebuilt-but-not-changed target
180         file actually need not be rebuilt.
181
182         </para>
183
184         <para>
185
186         So if, for example,
187         a user were to only change a comment in a &hello_c; file,
188         then the rebuilt &hello_o; file
189         would be exactly the same as the one previously built
190         (assuming the compiler doesn't put any build-specific
191         information in the object file).
192         &SCons; would then realize that it would not
193         need to rebuild the &hello; program as follows:
194
195         </para>
196
197         <scons_output example="ex1" os="posix">
198            <scons_output_command>scons -Q hello</scons_output_command>
199            <scons_output_command output="  [CHANGE A COMMENT IN hello.c]" edit="STRIP CCCOM line">edit hello.c</scons_output_command>
200            <scons_output_command>scons -Q hello</scons_output_command>
201         </scons_output>
202
203         <para>
204
205         In essence, &SCons;
206         "short-circuits" any dependent builds
207         when it realizes that a target file
208         has been rebuilt to exactly the same file as the last build.
209         This does take some extra processing time
210         to read the contents of the target (&hello_o;) file,
211         but often saves time when the rebuild that was avoided
212         would have been time-consuming and expensive.
213
214         </para>
215
216       </section>
217
218     </section>
219
220     <section>
221     <title>Using Time Stamps to Decide If a File Has Changed</title>
222
223       <para>
224
225       If you prefer, you can
226       configure &SCons; to use the modification time
227       of a file, not the file contents,
228       when deciding if a target needs to be rebuilt.
229       &SCons; gives you two ways to use time stamps
230       to decide if an input file has changed
231       since the last time a target has been built.
232
233       </para>
234
235       <para>
236
237       The most familiar way to use time stamps
238       is the way &Make; does:
239       that is, have &SCons; decide
240       that a target must be rebuilt
241       if a source file's modification time is
242       <emphasis>newer</emphasis>
243       than the target file.
244       To do this, call the &Decider;
245       function as follows:
246
247       </para>
248
249       <scons_example name="newer">
250         <file name="SConstruct" printme="1">
251         Program('hello.c')
252         Decider('timestamp-newer')
253         </file>
254         <file name="hello.c">
255         int main() { printf("Hello, world!\n"); }
256         </file>
257       </scons_example>
258
259       <para>
260
261       This makes &SCons; act like &Make;
262       when a file's modification time is updated
263       (using the &touch; command, for example):
264
265       </para>
266
267       <scons_output example="newer" os="posix">
268          <scons_output_command>scons -Q hello</scons_output_command>
269          <scons_output_command>touch hello.c</scons_output_command>
270          <scons_output_command>scons -Q hello</scons_output_command>
271       </scons_output>
272
273       <para>
274
275       And, in fact, because this behavior is the same
276       as the behavior of &Make;,
277       you can also use the string <literal>'make'</literal>
278       as a synonym for <literal>'timestamp-newer'</literal>
279       when calling the &Decider; function:
280
281       </para>
282
283       <sconstruct>
284         Program('hello.c')
285         Decider('make')
286       </sconstruct>
287
288       <para>
289
290       One drawback to using times stamps exactly like &Make;
291       is that if an input file's modification time suddenly
292       becomes <emphasis>older</emphasis> than a target file,
293       the target file will not be rebuilt.
294       This can happen if an old copy of a source file is restored
295       from a backup archive, for example.
296       The contents of the restored file will likely be different
297       than they were the last time a dependent target was built,
298       but the target won't be rebuilt
299       because the modification time of the source file
300       is not newer than the target.
301
302       </para>
303
304       <para>
305
306       Because &SCons; actually stores information
307       about the source files' time stamps whenever a target is built,
308       it can handle this situation by checking for
309       an exact match of the source file time stamp,
310       instead of just whether or not the source file
311       is newer than the target file.
312       To do this, specify the argument
313       <literal>'timestamp-match'</literal>
314       when calling the &Decider; function:
315
316       </para>
317
318       <scons_example name="match">
319         <file name="SConstruct" printme="1">
320         Program('hello.c')
321         Decider('timestamp-match')
322         </file>
323         <file name="hello.c">
324         int main() { printf("Hello, world!\n"); }
325         </file>
326       </scons_example>
327
328       <para>
329
330       When configured this way,
331       &SCons; will rebuild a target whenever
332       a source file's modification time has changed.
333       So if we use the <literal>touch -t</literal>
334       option to change the modification time of
335       &hello_c; to an old date (January 1, 1989),
336       &SCons; will still rebuild the target file:
337
338       </para>
339
340       <scons_output example="match" os="posix">
341          <scons_output_command>scons -Q hello</scons_output_command>
342          <scons_output_command>touch -t 198901010000 hello.c</scons_output_command>
343          <scons_output_command>scons -Q hello</scons_output_command>
344       </scons_output>
345
346       <para>
347
348       In general, the only reason to prefer
349       <literal>timestamp-newer</literal>
350       instead of
351       <literal>timestamp-match</literal>,
352       would be if you have some specific reason
353       to require this &Make;-like behavior of 
354       not rebuilding a target when an otherwise-modified
355       source file is older.
356
357       </para>
358
359     </section>
360
361     <section>
362     <title>Deciding If a File Has Changed Using Both MD Signatures and Time Stamps</title>
363
364       <para>
365
366       As a performance enhancement,
367       &SCons; provides a way to use
368       MD5 checksums of file contents
369       but to read those contents
370       only when the file's timestamp has changed.
371       To do this, call the &Decider;
372       function with <literal>'MD5-timestamp'</literal>
373       argument as follows:
374
375       </para>
376
377       <scons_example name="MD5-timestamp">
378         <file name="SConstruct" printme="1">
379         Program('hello.c')
380         Decider('MD5-timestamp')
381         </file>
382         <file name="hello.c">
383         int main() { printf("Hello, world!\n"); }
384         </file>
385       </scons_example>
386
387       <para>
388
389       So configured, &SCons will still behave like
390       it does when using <literal>Decider('MD5')</literal>:
391
392       </para>
393
394       <!--
395
396       We want to generate the output as follows,
397       but our "surrogate" system for generating the
398       output seems to get this wrong.
399       Just in-line the output for now.
400
401       <scons_output example="MD5-timestamp" os="posix">
402          <scons_output_command>scons -Q hello</scons_output_command>
403          <scons_output_command>touch hello.c</scons_output_command>
404          <scons_output_command>scons -Q hello</scons_output_command>
405        <scons_output_command output="    [CHANGE THE CONTENTS OF hello.c]">edit hello.c</scons_output_command>
406          <scons_output_command>scons -Q hello</scons_output_command>
407       </scons_output>
408
409       -->
410
411       <screen>
412          % <userinput>scons -Q hello</userinput>
413          cc -o hello.o -c hello.c
414          cc -o hello hello.o
415          % <userinput>touch hello.c</userinput>
416          % <userinput>scons -Q hello</userinput>
417          scons: `hello' is up to date.
418          % <userinput>edit hello.c</userinput>
419              [CHANGE THE CONTENTS OF hello.c]
420          % <userinput>scons -Q hello</userinput>
421          cc -o hello.o -c hello.c
422          cc -o hello hello.o
423       </screen>
424
425       <para>
426
427       However, the second call to &SCons; in the above output,
428       when the build is up-to-date,
429       will have been performed by simply looking at the
430       modification time of the &hello_c; file,
431       not by opening it and performing
432       an MD5 checksum calcuation on its contents.
433       This can significantly speed up many up-to-date builds.
434
435       </para>
436
437       <para>
438
439       The only drawback to using
440       <literal>Decider('MD5-timestamp')</literal>
441       is that &SCons; will <emphasis>not</emphasis>
442       rebuild a target file if a source file was modified
443       within one second of the last time &SCons; built the file.
444       While most developers are programming,
445       this isn't a problem in practice,
446       since it's unlikely that someone will have built
447       and then thought quickly enough to make a substantive
448       change to a source file within one second.
449       Certain build scripts or
450       continuous integration tools may, however,
451       rely on the ability to apply changes to files
452       automatically and then rebuild as quickly as possible,
453       in which case use of
454       <literal>Decider('MD5-timestamp')</literal>
455       may not be appropriate.
456
457       </para>
458
459     </section>
460
461     <section>
462     <title>Writing Your Own Custom &Decider; Function</title>
463
464       <para>
465
466       The different string values that we've passed to
467       the &Decider; function are essentially used by &SCons;
468       to pick one of several specific internal functions
469       that implement various ways of deciding if a dependency
470       (usually a source file)
471       has changed since a target file has been built.
472       As it turns out,
473       you can also supply your own function
474       to decide if a dependency has changed.
475
476       </para>
477
478       <para>
479
480       For example, suppose we have an input file
481       that contains a lot of data,
482       in some specific regular format,
483       that is used to rebuild a lot of different target files,
484       but each target file really only depends on
485       one particular section of the input file.
486       We'd like to have each target file depend on
487       only its section of the input file.
488       However, since the input file may contain a lot of data,
489       we want to open the input file only if its timestamp has changed.
490       This could done with a custom
491       &Decider; function that might look something like this:
492
493       </para>
494
495       <scons_example name="function">
496         <file name="SConstruct" printme="1">
497         Program('hello.c')
498         def decide_if_changed(dependency, target, prev_ni):
499             if self.get_timestamp() != prev_ni.timestamp:
500                 dep = str(dependency)
501                 tgt = str(target)
502                 if specific_part_of_file_has_changed(dep, tgt):
503                     return True
504             return False
505         Decider(decide_if_changed)
506         </file>
507         <file name="hello.c">
508         int main() { printf("Hello, world!\n"); }
509         </file>
510       </scons_example>
511
512       <para>
513
514       Note that in the function definition,
515       the <varname>dependency</varname>
516       (input file) is the first argument,
517       and then the &target;.
518       Both of these are passed to the functions as
519       SCons &Node; objects,
520       which we convert to strings using the Python
521       <function>str()</function>.
522
523       </para>
524
525       <para>
526
527       The third argument, <varname>prev_ni</varname>,
528       is an object that holds the
529       signature or timestamp information
530       that was recorded about the dependency
531       the last time the target was built.
532       A <varname>prev_ni</varname> object can hold
533       different information,
534       depending on the type of thing that the
535       <varname>dependency</varname> argument represents.
536       For normal files,
537       the <varname>prev_ni</varname> object
538       has the following attributes:
539
540       </para>
541
542       <variablelist>
543
544         <varlistentry>
545         <term>.csig</term>
546
547         <listitem>
548         <para>
549         The <emphasis>content signature</emphasis>,
550         or MD5 checksum, of the contents of the
551         <varname>dependency</varname>
552         file the list time the &target; was built.
553         </para>
554         </listitem>
555
556         </varlistentry>
557
558         <varlistentry>
559         <term>.size</term>
560
561         <listitem>
562         <para>
563         The size in bytes of the <varname>dependency</varname>
564         file the list time the target was built.
565         </para>
566         </listitem>
567
568         </varlistentry>
569
570         <varlistentry>
571         <term>.timestamp</term>
572
573         <listitem>
574         <para>
575         The modification time of the <varname>dependency</varname>
576         file the list time the &target; was built.
577         </para>
578         </listitem>
579
580         </varlistentry>
581
582       </variablelist>
583
584       <para>
585
586       Note that ignoring some of the arguments
587       in your custom &Decider; function
588       is a perfectly normal thing to do,
589       if they don't impact the way you want to
590       decide if the dependency file has changed.
591
592       </para>
593
594     </section>
595
596     <section>
597     <title>Mixing Different Ways of Deciding If a File Has Changed</title>
598
599       <para>
600
601       The previous examples have all demonstrated calling
602       the global &Decider; function
603       to configure all dependency decisions that &SCons; makes.
604       Sometimes, however, you want to be able to configure
605       different decision-making for different targets.
606       When that's necessary, you can use the
607       <function>env.Decider</function>
608       method to affect only the configuration
609       decisions for targets built with a
610       specific construction environment.
611
612       </para>
613
614       <para>
615
616       For example, if we arbitrarily want to build
617       one program using MD5 checkums
618       and another using file modification times
619       from the same source
620       we might configure it this way:
621
622       </para>
623
624       <scons_example name="mixing">
625         <file name="SConstruct" printme="1">
626         env1 = Environment(CPPPATH = ['.'])
627         env2 = env1.Clone()
628         env2.Decider('timestamp-match')
629         env1.Program('prog-MD5', 'program1.c')
630         env2.Program('prog-timestamp', 'program2.c')
631         </file>
632         <file name="program1.c">
633         #include "inc.h"
634         int main() { printf("Hello, world!\n"); }
635         </file>
636         <file name="program2.c">
637         #include "inc.h"
638         int main() { printf("Hello, world!\n"); }
639         </file>
640         <file name="inc.h">
641         #define INC     1
642         </file>
643       </scons_example>
644
645       <para>
646
647       If both of the programs include the same
648       <filename>inc.h</filename> file,
649       then updating the modification time of
650       <filename>inc.h</filename>
651       (using the &touch; command)
652       will cause only <filename>prog-timestamp</filename>
653       to be rebuilt:
654
655       </para>
656
657       <scons_output example="mixing" os="posix">
658          <scons_output_command>scons -Q</scons_output_command>
659          <scons_output_command>touch inc.h</scons_output_command>
660          <scons_output_command>scons -Q</scons_output_command>
661       </scons_output>
662
663     </section>
664
665   </section>
666
667   <section>
668   <title>Older Functions for Deciding When an Input File Has Changed</title>
669
670     <para>
671
672     &SCons; still supports two functions that used to be the
673     primary methods for configuring the
674     decision about whether or not an input file has changed.
675     Although they're not officially deprecated yet,
676     their use is discouraged,
677     mainly because they rely on a somewhat
678     confusing distinction between how
679     source files and target files are handled.
680     These functions are documented here mainly in case you
681     encounter them in existing &SConscript; files.
682
683     </para>
684   
685     <section>
686     <title>The &SourceSignatures; Function</title>
687
688       <para>
689
690       The &SourceSignatures; function is fairly straightforward,
691       and supports two different argument values
692       to configure whether source file changes should be decided
693       using MD5 signatures:
694
695       </para>
696
697       <sconstruct>
698         Program('hello.c')
699         SourceSignatures('MD5')
700       </sconstruct>
701
702       <para>
703
704       Or using time stamps:
705
706       </para>
707
708       <sconstruct>
709         Program('hello.c')
710         SourceSignatures('timestamp')
711       </sconstruct>
712
713       <para>
714
715       These are roughly equivalent to specifying
716       <function>Decider('MD5')</function>
717       or
718       <function>Decider('timestamp-match')</function>,
719       respectively,
720       although it only affects how SCons makes
721       decisions about dependencies on
722       <emphasis>source</emphasis> files--that is,
723       files that are not built from any other files.
724
725       </para>
726
727     </section>
728
729     <section>
730     <title>The &TargetSignatures; Function</title>
731
732       <para>
733
734       The &TargetSignatures; function
735       specifies how &SCons; decides
736       when a target file has changed
737       <emphasis>when it is used as a
738       dependency of (input to) another target</emphasis>--that is,
739       the &TargetSignatures; function configures
740       how the signatures of "intermediate" target files
741       are used when deciding if a "downstream" target file
742       must be rebuilt.
743       <footnote><para>
744       This easily-overlooked distinction between
745       how &SCons; decides if the target itself must be rebuilt
746       and how the target is then used to decide if a different
747       target must be rebuilt is one of the confusing
748       things that has led to the &TargetSignatures;
749       and &SourceSignatures; functions being
750       replaced by the simpler &Decider; function.
751       </para></footnote>
752
753       </para>
754
755       <para>
756
757       The &TargetSignatures; function supports the same
758       <literal>'MD5'</literal> and <literal>'timestamp'</literal>
759       argument values that are supported by the &SourceSignatures;,
760       with the same meanings, but applied to target files.
761       That is, in the example:
762
763       </para>
764
765       <sconstruct>
766         Program('hello.c')
767         TargetSignatures('MD5')
768       </sconstruct>
769
770       <para>
771
772       The MD5 checksum of the &hello_o; target file
773       will be used to decide if it has changed since the last
774       time the "downstream" &hello; target file was built.
775       And in the example:
776       
777       </para>
778
779       <sconstruct>
780         Program('hello.c')
781         TargetSignatures('timestamp')
782       </sconstruct>
783
784       <para>
785
786       The modification time of the &hello_o; target file
787       will be used to decide if it has changed since the last
788       time the "downstream" &hello; target file was built.
789
790       </para>
791
792       <para>
793
794       The &TargetSignatures; function supports
795       two additional argument values:
796       <literal>'source'</literal> and <literal>'build'</literal>.
797       The <literal>'source'</literal> argument
798       specifies that decisions involving
799       whether target files have changed
800       since a previous build
801       should use the same behavior
802       for the decisions configured for source files
803       (using the &SourceSignatures; function).
804       So in the example:
805
806       </para>
807
808       <sconstruct>
809         Program('hello.c')
810         TargetSignatures('source')
811         SourceSignatures('timestamp')
812       </sconstruct>
813
814       <para>
815
816       All files, both targets and sources,
817       will use modification times
818       when deciding if an input file
819       has changed since the last
820       time a target was built.
821
822       </para>
823
824       <para>
825
826       Lastly, the <literal>'build'</literal> argument
827       specifies that &SCons; should examine
828       the build status of a target file
829       and always rebuild a "downstream" target
830       if the target file was itself rebuilt,
831       without re-examining the contents or timestamp
832       of the newly-built target file.
833       If the target file was not rebuilt during
834       this &scons; invocation,
835       then the target file will be examined
836       the same way as configured by
837       the &SourceSignature; call
838       to decide if it has changed.
839
840       </para>
841
842       <para>
843
844       This mimics the behavior of
845       <literal>build signatures</literal>
846       in earlier versions of &SCons;.
847       A &buildsignature; re-combined
848       signatures of all the input files
849       that went into making the target file,
850       so that the target file itself
851       did not need to have its contents read
852       to compute an MD5 signature.
853       This can improve performance for some configurations,
854       but is generally not as effective as using
855       <literal>Decider('MD5-timestamp')</literal>.
856
857       </para>
858
859     </section>
860
861   </section>
862
863   <section>
864   <title>Implicit Dependencies:  The &cv-CPPPATH; Construction Variable</title>
865
866     <para>
867
868     Now suppose that our "Hello, World!" program
869     actually has an <literal>#include</literal> line
870     to include the &hello_h; file in the compilation:
871
872     </para>
873
874     <scons_example name="include">
875       <file name="SConstruct">
876        Program('hello.c', CPPPATH = '.')
877       </file>
878       <file name="hello.c" printme="1">
879        #include &lt;hello.h&gt;
880        int
881        main()
882        {
883            printf("Hello, %s!\n", string);
884        }
885       </file>
886       <file name="hello.h">
887        #define string    "world"
888       </file>
889     </scons_example>
890
891     <para>
892
893     And, for completeness, the &hello_h; file looks like this:
894
895     </para>
896
897     <scons_example_file example="include"  name="hello.h">
898     </scons_example_file>
899
900     <para>
901
902     In this case, we want &SCons; to recognize that,
903     if the contents of the &hello_h; file change,
904     the &hello; program must be recompiled.
905     To do this, we need to modify the
906     &SConstruct; file like so:
907
908     </para>
909
910     <scons_example_file example="include"  name="SConstruct">
911     </scons_example_file>
912
913     <para>
914
915     The &cv-link-CPPPATH; value
916     tells &SCons; to look in the current directory
917     (<literal>'.'</literal>)
918     for any files included by C source files
919     (<filename>.c</filename> or <filename>.h</filename> files).
920     With this assignment in the &SConstruct; file:
921
922     </para>
923
924     <scons_output example="include" os="posix">
925        <scons_output_command>scons -Q hello</scons_output_command>
926        <scons_output_command>scons -Q hello</scons_output_command>
927        <scons_output_command output="    [CHANGE THE CONTENTS OF hello.h]">edit hello.h</scons_output_command>
928        <scons_output_command>scons -Q hello</scons_output_command>
929     </scons_output>
930
931     <para>
932
933     First, notice that &SCons;
934     added the <literal>-I.</literal> argument
935     from the &cv-CPPPATH; variable
936     so that the compilation would find the
937     &hello_h; file in the local directory.
938
939     </para>
940
941     <para>
942
943     Second, realize that &SCons; knows that the &hello;
944     program must be rebuilt
945     because it scans the contents of
946     the &hello_c; file
947     for the <literal>#include</literal> lines that indicate
948     another file is being included in the compilation.
949     &SCons; records these as
950     <emphasis>implicit dependencies</emphasis>
951     of the target file,
952     Consequently,
953     when the &hello_h; file changes,
954     &SCons; realizes that the &hello_c; file includes it,
955     and rebuilds the resulting &hello; program
956     that depends on both the &hello_c; and &hello_h; files.
957
958     </para>
959
960     <para>
961
962     Like the &cv-link-LIBPATH; variable,
963     the &cv-CPPPATH; variable
964     may be a list of directories,
965     or a string separated by
966     the system-specific path separation character
967     (':' on POSIX/Linux, ';' on Windows).
968     Either way, &SCons; creates the
969     right command-line options
970     so that the following example:
971
972     </para>
973
974     <scons_example name="ex5">
975       <file name="SConstruct" printme="1">
976        Program('hello.c', CPPPATH = ['include', '/home/project/inc'])
977       </file>
978       <file name="hello.c">
979       int main() { printf("Hello, world!\n"); }
980       </file>
981     </scons_example>
982
983     <para>
984
985     Will look like this on POSIX or Linux:
986
987     </para>
988
989     <scons_output example="ex5" os="posix">
990        <scons_output_command>scons -Q hello</scons_output_command>
991     </scons_output>
992
993     <para>
994
995     And like this on Windows:
996
997     </para>
998
999     <scons_output example="ex5" os="win32">
1000        <scons_output_command>scons -Q hello.exe</scons_output_command>
1001     </scons_output>
1002
1003   </section>
1004
1005   <section>
1006   <title>Caching Implicit Dependencies</title>
1007
1008     <para>
1009
1010     Scanning each file for <literal>#include</literal> lines
1011     does take some extra processing time.
1012     When you're doing a full build of a large system,
1013     the scanning time is usually a very small percentage
1014     of the overall time spent on the build.
1015     You're most likely to notice the scanning time,
1016     however, when you <emphasis>rebuild</emphasis>
1017     all or part of a large system:
1018     &SCons; will likely take some extra time to "think about"
1019     what must be built before it issues the
1020     first build command
1021     (or decides that everything is up to date
1022     and nothing must be rebuilt).
1023
1024  <!--
1025  Isn't this expensive? The answer is, it depends. If you do a full build of a
1026  large system, the scanning time is insignificant. If you do a rebuild of a
1027  large system, then Cons will spend a fair amount of time thinking about it
1028  before it decides that nothing has to be done (although not necessarily more
1029  time than make!). The good news is that Cons makes it very easy to
1030  intelligently subset your build, when you are working on localized changes.
1031  -->
1032
1033     </para>
1034
1035     <para>
1036
1037     In practice, having &SCons; scan files saves time
1038     relative to the amount of potential time
1039     lost to tracking down subtle problems
1040     introduced by incorrect dependencies.
1041     Nevertheless, the "waiting time"
1042     while &SCons; scans files can annoy
1043     individual developers waiting for their builds to finish.
1044     Consequently, &SCons; lets you cache
1045     the implicit dependencies
1046     that its scanners find,
1047     for use by later builds.
1048     You can do this by specifying the
1049     &implicit-cache; option on the command line:
1050
1051     </para>
1052
1053     <scons_output example="ex1">
1054        <scons_output_command>scons -Q --implicit-cache hello</scons_output_command>
1055        <scons_output_command>scons -Q hello</scons_output_command>
1056     </scons_output>
1057
1058     <para>
1059
1060     If you don't want to specify &implicit-cache;
1061     on the command line each time,
1062     you can make it the default behavior for your build
1063     by setting the &implicit_cache; option
1064     in an &SConscript; file:
1065
1066     </para>
1067
1068     <sconstruct>
1069        SetOption('implicit_cache', 1)
1070     </sconstruct>
1071
1072     <para>
1073
1074     &SCons; does not cache implicit dependencies like this by default
1075     because the &implicit-cache; causes &SCons; to simply use the implicit
1076     dependencies stored during the last run, without any checking
1077     for whether or not those dependencies are still correct.
1078     Specifically, this means &implicit-cache; instructs &SCons;
1079     to <emphasis>not</emphasis> rebuild "correctly" in the
1080     following cases:
1081
1082
1083     </para>
1084
1085     <itemizedlist>
1086
1087       <listitem>
1088         <para>
1089
1090         When &implicit-cache; is used, &SCons; will ignore any changes that
1091         may have been made to search paths
1092         (like &cv-CPPPATH; or &cv-LIBPATH;,).
1093         This can lead to &SCons; not rebuilding a file if a change to
1094         &cv-CPPPATH; would normally cause a different, same-named file from
1095         a different directory to be used.
1096
1097         </para>
1098       </listitem>
1099
1100       <listitem>
1101         <para>
1102
1103         When &implicit-cache; is used, &SCons; will not detect if a
1104         same-named file has been added to a directory that is earlier in
1105         the search path than the directory in which the file was found
1106         last time.
1107
1108         </para>
1109       </listitem>
1110
1111     </itemizedlist>
1112
1113     <section>
1114     <title>The &implicit-deps-changed; Option</title>
1115
1116       <para>
1117
1118       When using cached implicit dependencies,
1119       sometimes you want to "start fresh"
1120       and have &SCons; re-scan the files
1121       for which it previously cached the dependencies.
1122       For example,
1123       if you have recently installed a new version of
1124       external code that you use for compilation,
1125       the external header files will have changed
1126       and the previously-cached implicit dependencies
1127       will be out of date.
1128       You can update them by
1129       running &SCons; with the &implicit-deps-changed; option:
1130
1131       </para>
1132
1133       <scons_output example="ex1">
1134          <scons_output_command>scons -Q --implicit-deps-changed hello</scons_output_command>
1135          <scons_output_command>scons -Q hello</scons_output_command>
1136       </scons_output>
1137
1138       <para>
1139
1140       In this case, &SCons; will re-scan all of the implicit dependencies
1141       and cache updated copies of the information.
1142
1143       </para>
1144
1145     </section>
1146
1147     <section>
1148     <title>The &implicit-deps-unchanged; Option</title>
1149
1150       <para>
1151
1152       By default when caching dependencies,
1153       &SCons; notices when a file has been modified
1154       and re-scans the file for any updated
1155       implicit dependency information.
1156       Sometimes, however, you may want
1157       to force &SCons; to use the cached implicit dependencies,
1158       even if the source files changed.
1159       This can speed up a build for example,
1160       when you have changed your source files
1161       but know that you haven't changed
1162       any <literal>#include</literal> lines.
1163       In this case,
1164       you can use the &implicit-deps-unchanged; option:
1165
1166       </para>
1167
1168       <scons_output example="ex1">
1169          <scons_output_command>scons -Q --implicit-deps-unchanged hello</scons_output_command>
1170          <scons_output_command>scons -Q hello</scons_output_command>
1171       </scons_output>
1172
1173       <para>
1174
1175       In this case,
1176       &SCons; will assume that the cached implicit
1177       dependencies are correct and
1178       will not bother to re-scan changed files.
1179       For typical builds after small,
1180       incremental changes to source files,
1181       the savings may not be very big,
1182       but sometimes every bit of
1183       improved performance counts.
1184
1185       </para>
1186
1187     </section>
1188
1189     <!--
1190
1191     <section>
1192     <title>XXX max drift</title>
1193
1194       XXX SetOption('max_drift')
1195
1196     </section>
1197
1198     -->
1199
1200   </section>
1201
1202   <section>
1203   <title>Explicit Dependencies:  the &Depends; Function</title>
1204
1205     <para>
1206
1207     Sometimes a file depends on another file
1208     that is not detected by an &SCons; scanner.
1209     For this situation,
1210     &SCons; allows you to specific explicitly that one file
1211     depends on another file,
1212     and must be rebuilt whenever that file changes.
1213     This is specified using the &Depends; method:
1214
1215     </para>
1216
1217     <programlisting>
1218        hello = Program('hello.c')
1219        Depends(hello, 'other_file')
1220     </programlisting>
1221
1222     <!-- XXX mention that you can use arrays for target and source? -->
1223
1224     <screen>
1225        % <userinput>scons -Q hello</userinput>
1226        cc -c hello.c -o hello.o
1227        cc -o hello hello.o
1228        % <userinput>scons -Q hello</userinput>
1229        scons: `hello' is up to date.
1230        % <userinput>edit other_file</userinput>
1231            [CHANGE THE CONTENTS OF other_file]
1232        % <userinput>scons -Q hello</userinput>
1233        cc -c hello.c -o hello.o
1234        cc -o hello hello.o
1235     </screen>
1236
1237     <para>
1238
1239     Note that the dependency
1240     (the second argument to &Depends;)
1241     may also be a list of Node objects
1242     (for example, as returned by a call to a Builder):
1243
1244     </para>
1245
1246     <programlisting>
1247        hello = Program('hello.c')
1248        goodbye = Program('goodbye.c')
1249        Depends(hello, goodbye)
1250     </programlisting>
1251
1252     <para>
1253
1254     in which case the dependency or dependencies
1255     will be built before the target(s):
1256
1257     </para>
1258
1259     <screen>
1260        % <userinput>scons -Q hello</userinput>
1261        cc -c goodbye.c -o goodbye.o
1262        cc -o goodbye goodbye.o
1263        cc -c hello.c -o hello.o
1264        cc -o hello hello.o
1265     </screen>
1266
1267   </section>
1268
1269   <section>
1270   <title>Dependencies From External Files:  the &ParseDepends;
1271   Function</title>
1272
1273     <para>
1274
1275     &SCons; has built-in scanners for a number of languages. Sometimes
1276     these scanners fail to extract certain implicit dependencies due
1277     to limitations of the scanner implementation.
1278
1279     </para>
1280
1281     <para>
1282
1283     The following example illustrates a case where the built-in C
1284     scanner is unable to extract the implicit dependency on a header
1285     file.
1286
1287     </para>
1288
1289     <scons_example name="macroinc">
1290       <file name="hello.c" printme="1">
1291       #define FOO_HEADER &lt;foo.h&gt;
1292       #include FOO_HEADER
1293
1294       int main() {
1295           return FOO;
1296       }
1297       </file>
1298       <file name="SConstruct">
1299       Program('hello', 'hello.c', CPPPATH='.')
1300       </file>
1301       <file name="foo.h">
1302       #define FOO 42
1303       </file>
1304     </scons_example>
1305
1306     <scons_output example="macroinc" os="posix">
1307       <scons_output_command>scons -Q</scons_output_command>
1308       <scons_output_command output="   [CHANGE CONTENTS OF foo.h]"
1309       >edit foo.h</scons_output_command>
1310       <scons_output_command>scons -Q</scons_output_command>
1311     </scons_output>
1312
1313     <para>
1314
1315     Apparently, the scanner does not know about the header dependency.
1316     Being not a full-fledged C preprocessor, the scanner does not
1317     expand the macro.
1318
1319     </para>
1320
1321     <para>
1322
1323     In these cases, you may also use the compiler to extract the
1324     implicit dependencies. &ParseDepends; can parse the contents of
1325     the compiler output in the style of &Make;, and explicitly
1326     establish all of the listed dependencies.
1327
1328     </para>
1329
1330     <para>
1331
1332     The following example uses &ParseDepends; to process a compiler
1333     generated dependency file which is generated as a side effect
1334     during compilation of the object file:
1335
1336     </para>
1337
1338     <!-- XXX The ParseDepends example below fakes proper working by a
1339     priori specification of the dependency file. The produced hello.d
1340     file is not found (or used) for unknown reasons. -->
1341
1342     <scons_example name="parsedep">
1343       <file name="hello.c">
1344       #define FOO_HEADER &lt;foo.h&gt;
1345       #include FOO_HEADER
1346
1347       int main() {
1348           return FOO;
1349       }
1350       </file>
1351       <file name="SConstruct" printme="1">
1352       obj = Object('hello.c', CCFLAGS='-MD -MF hello.d', CPPPATH='.')
1353       SideEffect('hello.d', obj)
1354       ParseDepends('hello.d')
1355       Program('hello', obj)
1356       </file>
1357       <file name="foo.h">
1358       #define FOO 42
1359       </file>
1360       <file name="hello.d">
1361       hello.o: hello.c foo.h
1362       </file>
1363     </scons_example>
1364
1365     <scons_output example="parsedep" os="posix">
1366       <scons_output_command>scons -Q</scons_output_command>
1367       <scons_output_command output="   [CHANGE CONTENTS OF foo.h]"
1368       >edit foo.h</scons_output_command>
1369       <scons_output_command>scons -Q</scons_output_command>
1370     </scons_output>
1371
1372     <para>
1373
1374     Parsing dependencies from a compiler-generated
1375     <filename>.d</filename> file has a chicken-and-egg problem, that
1376     causes unnecessary rebuilds:
1377
1378     </para>
1379
1380     <scons_example name="parsedeprebuild">
1381       <file name="hello.c">
1382       #define FOO_HEADER &lt;foo.h&gt;
1383       #include FOO_HEADER
1384
1385       int main() {
1386           return FOO;
1387       }
1388       </file>
1389       <file name="SConstruct">
1390       obj = Object('hello.c', CCFLAGS='-MD -MF hello.d', CPPPATH='.')
1391       SideEffect('hello.d', obj)
1392       ParseDepends('hello.d')
1393       Program('hello', obj)
1394       </file>
1395       <file name="foo.h">
1396       #define FOO 42
1397       </file>
1398     </scons_example>
1399
1400     <!--
1401     <scons_output example="parsedeprebuild" os="posix">
1402       <scons_output_command>scons -Q</scons_output_command>
1403       <scons_output_command>scons -Q</scons_output_command>
1404       <scons_output_command>scons -Q</scons_output_command>
1405     </scons_output>
1406     -->
1407
1408     <screen>
1409       % <userinput>scons -Q</userinput>
1410       cc -o hello.o -c -MD -MF hello.d -I. hello.c
1411       cc -o hello hello.o
1412       % <userinput>scons -Q --debug=explain</userinput>
1413       scons: rebuilding `hello.o' because `foo.h' is a new dependency
1414       cc -o hello.o -c -MD -MF hello.d -I. hello.c
1415       % <userinput>scons -Q</userinput>
1416       scons: `.' is up to date.
1417     </screen>
1418
1419     <para>
1420
1421     In the first pass, the dependency file is generated while the
1422     object file is compiled. At that time, &SCons; does not know about
1423     the dependency on <filename>foo.h</filename>. In the second pass,
1424     the object file is regenerated because <filename>foo.h</filename>
1425     is detected as a new dependency.
1426
1427     </para>
1428
1429     <para>
1430
1431     &ParseDepends; immediately reads the specified file at invocation
1432     time and just returns if the file does not exist. A dependency
1433     file generated during the build process is not automatically
1434     parsed again. Hence, the compiler-extracted dependencies are not
1435     stored in the signature database during the same build pass. This
1436     limitation of &ParseDepends; leads to unnecessary recompilations.
1437     Therefore, &ParseDepends; should only be used if scanners are not
1438     available for the employed language or not powerful enough for the
1439     specific task.
1440
1441     </para>
1442
1443   </section>
1444
1445   <section>
1446   <title>Ignoring Dependencies:  the &Ignore; Function</title>
1447
1448     <para>
1449
1450     Sometimes it makes sense
1451     to not rebuild a program,
1452     even if a dependency file changes.
1453     In this case,
1454     you would tell &SCons; specifically
1455     to ignore a dependency as follows:
1456
1457     </para>
1458
1459     <scons_example name="ignore">
1460       <file name="SConstruct" printme="1">
1461       hello_obj=Object('hello.c')
1462       hello = Program(hello_obj)
1463       Ignore(hello_obj, 'hello.h')
1464       </file>
1465       <file name="hello.c">
1466       #include "hello.h"
1467       int main() { printf("Hello, %s!\n", string); }
1468       </file>
1469       <file name="hello.h">
1470       #define string    "world"
1471       </file>
1472     </scons_example>
1473
1474     <!-- XXX mention that you can use lists for target and source? -->
1475
1476     <!--
1477     <scons_output example="ignore">
1478       <scons_output_command>scons -Q hello</scons_output_command>
1479       <scons_output_command>scons -Q hello</scons_output_command>
1480       <scons_output_command output="    [CHANGE THE CONTENTS OF hello.h]">edit hello.h</scons_output_command>
1481       <scons_output_command>scons -Q hello</scons_output_command>
1482       XXX THIS EXAMPLE SHOULD BE UP-TO-DATE! XXX
1483     </scons_output>
1484     -->
1485
1486     <screen>
1487       % <userinput>scons -Q hello</userinput>
1488       cc -c -o hello.o hello.c
1489       cc -o hello hello.o
1490       % <userinput>scons -Q hello</userinput>
1491       scons: `hello' is up to date.
1492       % <userinput>edit hello.h</userinput>
1493         [CHANGE THE CONTENTS OF hello.h]
1494       % <userinput>scons -Q hello</userinput>
1495       scons: `hello' is up to date.
1496     </screen>
1497
1498     <para>
1499
1500     Now, the above example is a little contrived,
1501     because it's hard to imagine a real-world situation
1502     where you wouldn't want to rebuild &hello;
1503     if the &hello_h; file changed.
1504     A more realistic example
1505     might be if the &hello;
1506     program is being built in a
1507     directory that is shared between multiple systems
1508     that have different copies of the
1509     &stdio_h; include file.
1510     In that case,
1511     &SCons; would notice the differences between
1512     the different systems' copies of &stdio_h;
1513     and would rebuild &hello;
1514     each time you change systems.
1515     You could avoid these rebuilds as follows:
1516
1517     </para>
1518
1519     <programlisting>
1520        hello = Program('hello.c', CPPPATH=['/usr/include'])
1521        Ignore(hello, '/usr/include/stdio.h')
1522     </programlisting>
1523
1524     <para>
1525     &Ignore; can also be used to prevent a generated file from being built 
1526     by default. This is due to the fact that directories depend on 
1527     their contents.  So to ignore a generated file from the default build, 
1528     you specify that the directory should ignore the generated file.
1529     Note that the file will still be built if the user specifically 
1530     requests the target on scons command line, or if the file is
1531     a dependency of another file which is requested and/or is built
1532     by default.
1533     </para>
1534
1535     <scons_example name="ignore_explicit">
1536       <file name="SConstruct" printme="1">
1537       hello_obj=Object('hello.c')
1538       hello = Program(hello_obj)
1539       Ignore('.',[hello,hello_obj])
1540       </file>
1541       <file name="hello.c">
1542       #include "stdio.h"
1543       int main() { printf("Hello!\n"); }
1544       </file>
1545     </scons_example>
1546
1547     <scons_output example="ignore_explicit" os="posix">
1548       <scons_output_command>scons -Q</scons_output_command>
1549       <scons_output_command>scons -Q hello</scons_output_command>
1550       <scons_output_command>scons -Q hello</scons_output_command>
1551     </scons_output>
1552   </section>
1553
1554   <section>
1555   <title>Order-Only Dependencies:  the &Requires; Function</title>
1556
1557     <para>
1558
1559     Occasionally,
1560     it may be useful to specify that a certain
1561     file or directory must, if necessary,
1562     be built or created before some other target is built,
1563     but that changes to that file or directory
1564     do <emphasis>not</emphasis>
1565     require that the target itself be rebuilt.
1566     Such a relationship is called an
1567     <emphasis>order-only dependency</emphasis>
1568     because it only affects the order in which
1569     things must be built--the dependency before the target--but
1570     it is not a strict dependency relationship
1571     because the target should not
1572     change in response to changes in the dependent file.
1573
1574     </para>
1575
1576     <para>
1577
1578     For example, suppose that you want to create a file
1579     every time you run a build
1580     that identifies the time the build was performed,
1581     the version number, etc.,
1582     and which is included in every program that you build.
1583     The version file's contents will change every build.
1584     If you specify a normal dependency relationship,
1585     then every program that depends on
1586     that file would be rebuilt every time you ran &SCons;.
1587     For example, we could use some Python code in
1588     a &SConstruct; file to create a new <filename>version.c</filename> file
1589     with a string containing the current date every time
1590     we run &SCons;,
1591     and then link a program with the resulting object file
1592     by listing <filename>version.c</filename> in the sources:
1593
1594     </para>
1595
1596     <scons_example name="no-Requires">
1597       <file name="SConstruct" printme="1">
1598       import time
1599
1600       version_c_text = """
1601       char *date = "%s";
1602       """ % time.ctime(time.time())
1603       open('version.c', 'w').write(version_c_text)
1604
1605       hello = Program(['hello.c', 'version.c'])
1606       </file>
1607       <file name="hello.c">
1608       extern char *date;
1609       int main() { printf("Hello, %s!  I was built: %s\n", date); }
1610       </file>
1611     </scons_example>
1612
1613     <para>
1614
1615     If we list <filename>version.c</filename> as an actual source file,
1616     though, then the <filename>version.o</filename> file
1617     will get rebuilt every time we run &SCons;
1618     (because the &SConstruct; file itself changes
1619     the contents of <filename>version.c</filename>)
1620     and the <filename>hello</filename> executable
1621     will get re-linked every time
1622     (because the <filename>version.o</filename> file changes):
1623
1624     </para>
1625
1626     <scons_output example="no-Requires">
1627       <scons_output_command>scons -Q hello</scons_output_command>
1628       <scons_output_command>sleep 1</scons_output_command>
1629       <scons_output_command>scons -Q hello</scons_output_command>
1630       <scons_output_command>sleep 1</scons_output_command>
1631       <scons_output_command>scons -Q hello</scons_output_command>
1632     </scons_output>
1633
1634     <para>
1635
1636     (Note that for the above example to work,
1637     we &sleep; for one second in between each run,
1638     so that the &SConstruct; file will create a
1639     <filename>version.c</filename> file with a time string
1640     that's one second later than the previous run.)
1641
1642     </para>
1643
1644     <para>
1645
1646     One solution is to use the &Requires; function
1647     to specify that the <filename>version.o</filename>
1648     must be rebuilt before it is used by the link step,
1649     but that changes to <filename>version.o</filename>
1650     should not actually cause the <filename>hello</filename>
1651     executable to be re-linked:
1652
1653     </para>
1654
1655     <scons_example name="Requires">
1656       <file name="SConstruct" printme="1">
1657       import time
1658
1659       version_c_text = """
1660       char *date = "%s";
1661       """ % time.ctime(time.time())
1662       open('version.c', 'w').write(version_c_text)
1663
1664       version_obj = Object('version.c')
1665
1666       hello = Program('hello.c',
1667                       LINKFLAGS = str(version_obj[0]))
1668
1669       Requires(hello, version_obj)
1670       </file>
1671       <file name="hello.c">
1672       extern char *date;
1673       int main() { printf("Hello, %s!  I was built: %s\n", date); }
1674       </file>
1675     </scons_example>
1676
1677     <para>
1678
1679     Notice that because we can no longer list <filename>version.c</filename>
1680     as one of the sources for the <filename>hello</filename> program,
1681     we have to find some other way to get it into the link command line.
1682     For this example, we're cheating a bit and stuffing the
1683     object file name (extracted from <literal>version_obj</literal>
1684     list returned by the &b-Object; call)
1685     into the &cv-link-LINKFLAGS; variable,
1686     because &cv-LINKFLAGS; is already included
1687     in the &cv-link-LINKCOM; command line.
1688
1689     </para>
1690
1691     <para>
1692
1693     With these changes,
1694     we get the desired behavior of only
1695     re-linking the <filename>hello</filename> executable
1696     when the <filename>hello.c</filename> has changed,
1697     even though the <filename>version.o</filename> is rebuilt
1698     (because the &SConstruct; file still changes the
1699     <filename>version.c</filename> contents directly each run):
1700
1701     </para>
1702
1703     <scons_output example="Requires">
1704       <scons_output_command>scons -Q hello</scons_output_command>
1705       <scons_output_command>sleep 1</scons_output_command>
1706       <scons_output_command>scons -Q hello</scons_output_command>
1707       <scons_output_command>sleep 1</scons_output_command>
1708       <scons_output_command output="    [CHANGE THE CONTENTS OF hello.c]">edit hello.c</scons_output_command>
1709       <scons_output_command>scons -Q hello</scons_output_command>
1710       <scons_output_command>sleep 1</scons_output_command>
1711       <scons_output_command>scons -Q hello</scons_output_command>
1712     </scons_output>
1713
1714   </section>
1715
1716   <section>
1717   <title>The &AlwaysBuild; Function</title>
1718
1719     <para>
1720
1721     How &SCons; handles dependencies can also be affected
1722     by the &AlwaysBuild; method.
1723     When a file is passed to the &AlwaysBuild; method,
1724     like so:
1725
1726     </para>
1727
1728     <scons_example name="AlwaysBuild">
1729       <file name="SConstruct" printme="1">
1730       hello = Program('hello.c')
1731       AlwaysBuild(hello)
1732       </file>
1733       <file name="hello.c">
1734       int main() { printf("Hello, %s!\n", string); }
1735       </file>
1736     </scons_example>
1737
1738     <para>
1739
1740     Then the specified target file (&hello; in our example)
1741     will always be considered out-of-date and
1742     rebuilt whenever that target file is evaluated
1743     while walking the dependency graph:
1744
1745     </para>
1746
1747     <scons_output example="AlwaysBuild">
1748       <scons_output_command>scons -Q</scons_output_command>
1749       <scons_output_command>scons -Q</scons_output_command>
1750     </scons_output>
1751
1752     <para>
1753
1754     The &AlwaysBuild; function has a somewhat misleading name,
1755     because it does not actually mean the target file will
1756     be rebuilt every single time &SCons; is invoked.
1757     Instead, it means that the target will, in fact,
1758     be rebuilt whenever the target file is encountered
1759     while evaluating the targets specified on
1760     the command line (and their dependencies).
1761     So specifying some other target on the command line,
1762     a target that does <emphasis>not</emphasis>
1763     itself depend on the &AlwaysBuild; target,
1764     will still be rebuilt only if it's out-of-date
1765     with respect to its dependencies:
1766
1767     </para>
1768
1769     <scons_output example="AlwaysBuild">
1770       <scons_output_command>scons -Q</scons_output_command>
1771       <scons_output_command>scons -Q hello.o</scons_output_command>
1772     </scons_output>
1773
1774     <!--
1775
1776       XXX AlwaysBuild() and Alias Nodes
1777
1778       XXX AlwaysBuild() and Dir Nodes
1779
1780       XXX AlwaysBuild() with no sources
1781
1782     -->
1783
1784   </section>
1785
1786   <!--
1787
1788   <section>
1789   <title>The &Salt; Method</title>
1790
1791     <para>
1792
1793     XXX Salt() (are we going to implement this ?)
1794
1795         original Cons classic POD documentation:
1796
1797 =head2 The C<Salt> method
1798
1799 The C<Salt> method adds a constant value to the signature calculation
1800 for every derived file.  It is invoked as follows:
1801
1802   Salt $string;
1803
1804 Changing the Salt value will force a complete rebuild of every derived
1805 file.  This can be used to force rebuilds in certain desired
1806 circumstances.  For example,
1807
1808   Salt `uname -s`;
1809
1810 Would force a complete rebuild of every derived file whenever the
1811 operating system on which the build is performed (as reported by C<uname
1812 -s>) changes.
1813
1814     </para>
1815
1816   </section>
1817
1818   -->