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:
13 The above copyright notice and this permission notice shall be included
14 in all copies or substantial portions of the Software.
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.
28 There are two occasions when &SCons; will,
29 by default, remove target files.
30 The first is when &SCons; determines that
31 an target file needs to be rebuilt
32 and removes the existing version of the target
34 The second is when &SCons; is invoked with the
35 <literal>-c</literal> option to "clean"
36 a tree of its built targets.
38 These behaviours can be suppressed with the
39 &Precious; and &NoClean; functions, respectively.
44 <title>Preventing target removal during build: the &Precious; Function</title>
48 By default, &SCons; removes targets before building them.
49 Sometimes, however, this is not what you want.
50 For example, you may want to update a library incrementally,
51 not by having it deleted and then rebuilt from all
52 of the constituent object files.
53 In such cases, you can use the
54 &Precious; method to prevent
55 &SCons; from removing the target before it is built:
60 env = Environment(RANLIBCOM='')
61 lib = env.Library('foo', ['f1.c', 'f2.c', 'f3.c'])
67 Although the output doesn't look any different,
68 &SCons; does not, in fact,
69 delete the target library before rebuilding it:
74 % <userinput>scons -Q</userinput>
78 ar rc libfoo.a f1.o f2.o f3.o
83 &SCons; will, however, still delete files marked as &Precious;
84 when the <literal>-c</literal> option is used.
91 <title>Preventing target removal during clean: the &NoClean; Function</title>
95 By default, &SCons; removes all built targets when invoked
96 with the <literal>-c</literal> option to clean a source tree
98 Sometimes, however, this is not what you want.
99 For example, you may want to remove only intermediate generated files
100 (such as object files),
101 but leave the final targets
105 In such cases, you can use the &NoClean; method to prevent &SCons;
106 from removing a target during a clean:
111 env = Environment(RANLIBCOM='')
112 lib = env.Library('foo', ['f1.c', 'f2.c', 'f3.c'])
118 Notice that the <filename>libfoo.a</filename>
119 is not listed as a removed file:
124 % <userinput>scons -Q</userinput>
128 ar rc libfoo.a f1.o f2.o f3.o
129 % <userinput>scons -c</userinput>
130 scons: Reading SConscript files ...
131 scons: done reading SConscript files.
132 scons: Cleaning targets ...
136 scons: done cleaning targets.
142 <title>Removing additional files during clean: the &Clean; Function</title>
146 There may be additional files that you want removed
147 when the <literal>-c</literal> option is used,
148 but which &SCons; doesn't know about
149 because they're not normal target files.
150 For example, perhaps a command you invoke
151 creates a log file as
152 part of building the target file you want.
153 You would like the log file cleaned,
154 but you don't want to have to teach
155 SCons that the command
162 You can use the &Clean; function to arrange for additional files
163 to be removed when the <literal>-c</literal> option is used.
164 Notice, however, that the &Clean; function takes two arguments,
165 and the <emphasis>second</emphasis> argument
166 is the name of the additional file you want cleaned
167 (<filename>foo.log</filename> in this example):
172 t = Command('foo.out', 'foo.in', 'build -o $TARGET $SOURCE')
178 The first argument is the target with which you want
179 the cleaning of this additional file associated.
180 In the above example,
181 we've used the return value from the
184 <filename>foo.out</filename>
187 <filename>foo.out</filename> target is cleaned
188 by the <literal>-c</literal> option,
189 the <filename>foo.log</filename> file
190 will be removed as well:
195 % <userinput>scons -Q</userinput>
196 build -o foo.out foo.in
197 % <userinput>scons -Q -c</userinput>