13.3. Removing additional files during clean: the `Clean` Function
Prev | Chapter 13. Controlling Removal of Targets | Next

## 13.3. Removing additional files during clean: the `Clean` Function

There may be additional files that you want removed when the `-c` option is used, but which SCons doesn't know about because they're not normal target files. For example, perhaps a command you invoke creates a log file as part of building the target file you want. You would like the log file cleaned, but you don't want to have to teach SCons that the command "builds" two files.

You can use the `Clean` function to arrange for additional files to be removed when the `-c` option is used. Notice, however, that the `Clean` function takes two arguments, and the second argument is the name of the additional file you want cleaned (`foo.log` in this example):

    t = Command('foo.out', 'foo.in', 'build -o $TARGET $SOURCE')
    Clean(t, 'foo.log')

The first argument is the target with which you want the cleaning of this additional file associated. In the above example, we've used the return value from the `Command` function, which represents the `foo.out` target. Now whenever the `foo.out` target is cleaned by the `-c` option, the `foo.log` file will be removed as well:

    % scons -Q
    build -o foo.out foo.in
    % scons -Q -c
    Removed foo.out
    Removed foo.log

Prev | Up | Next
13.2. Preventing target removal during clean: the `NoClean` Function | Home | Chapter 14. Hierarchical Builds