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:
59 <scons_example name="precious-ex1">
60 <file name="SConstruct" printme="1">
61 env = Environment(RANLIBCOM='')
62 lib = env.Library('foo', ['f1.c', 'f2.c', 'f3.c'])
78 Although the output doesn't look any different,
79 &SCons; does not, in fact,
80 delete the target library before rebuilding it:
84 <scons_output example="precious-ex1">
85 <scons_output_command>scons -Q</scons_output_command>
90 &SCons; will, however, still delete files marked as &Precious;
91 when the <literal>-c</literal> option is used.
98 <title>Preventing target removal during clean: the &NoClean; Function</title>
102 By default, &SCons; removes all built targets when invoked
103 with the <literal>-c</literal> option to clean a source tree
105 Sometimes, however, this is not what you want.
106 For example, you may want to remove only intermediate generated files
107 (such as object files),
108 but leave the final targets
112 In such cases, you can use the &NoClean; method to prevent &SCons;
113 from removing a target during a clean:
117 <scons_example name="noclean-ex1">
118 <file name="SConstruct" printme="1">
119 env = Environment(RANLIBCOM='')
120 lib = env.Library('foo', ['f1.c', 'f2.c', 'f3.c'])
136 Notice that the <filename>libfoo.a</filename>
137 is not listed as a removed file:
141 <scons_output example="noclean-ex1">
142 <scons_output_command>scons -Q</scons_output_command>
143 <scons_output_command>scons -c</scons_output_command>
149 <title>Removing additional files during clean: the &Clean; Function</title>
153 There may be additional files that you want removed
154 when the <literal>-c</literal> option is used,
155 but which &SCons; doesn't know about
156 because they're not normal target files.
157 For example, perhaps a command you invoke
158 creates a log file as
159 part of building the target file you want.
160 You would like the log file cleaned,
161 but you don't want to have to teach
162 SCons that the command
169 You can use the &Clean; function to arrange for additional files
170 to be removed when the <literal>-c</literal> option is used.
171 Notice, however, that the &Clean; function takes two arguments,
172 and the <emphasis>second</emphasis> argument
173 is the name of the additional file you want cleaned
174 (<filename>foo.log</filename> in this example):
178 <scons_example name="clean-ex1">
179 <file name="S" printme="1">
180 t = Command('foo.out', 'foo.in', 'build -o $TARGET $SOURCE')
183 <file name="SConstruct">
184 env = DefaultEnvironment()
186 env['ENV']['PATH'] = env['ENV']['PATH'] + os.pathsep + os.getcwd()
192 <file name="foo.log">
195 <file name="build" chmod="0755">
202 The first argument is the target with which you want
203 the cleaning of this additional file associated.
204 In the above example,
205 we've used the return value from the
208 <filename>foo.out</filename>
211 <filename>foo.out</filename> target is cleaned
212 by the <literal>-c</literal> option,
213 the <filename>foo.log</filename> file
214 will be removed as well:
218 <scons_output example="clean-ex1">
219 <scons_output_command>scons -Q</scons_output_command>
220 <scons_output_command>scons -Q -c</scons_output_command>