]> git.donarmstrong.com Git - debhelper.git/blob - dh_clean
add note about dh_clean being last
[debhelper.git] / dh_clean
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_clean - clean up package build directories
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14 B<dh_clean> [S<I<debhelper options>>] [B<-k>] [B<-d>] [B<-X>I<item>] [S<I<file ...>>]
15
16 =head1 DESCRIPTION
17
18 dh_clean is a debhelper program that is responsible for cleaning up after a
19 package is built. It removes the package build directories, and removes some
20 other files including debian/files, and any detritus left behind by other
21 debhelper commands. It also removes common files that should not appear in a
22 debian diff:
23   #*# *~ DEADJOE *.orig *.rej *.SUMS TAGS .deps/* *.P *-stamp
24
25 The debian/clean file can list other files to be removed.
26
27 It does not run "make clean" to clean up after the build process. Use
28 L<dh_auto_clean(1)> to do that.
29
30 dh_clean (or "dh clean") should be the last debhelper command run in the
31 clean target in debian/rules.
32
33 =head1 OPTIONS
34
35 =over 4
36
37 =item B<-k>, B<--keep>
38
39 This causes L<dh_prep(1)> to be run instead of dh_clean, for backwards
40 compatibility.
41
42 =item B<-d>, B<--dirs-only>
43
44 Only clean the package build directories, do not clean up any other files
45 at all.
46
47 =item B<-X>I<item> B<--exclude=>I<item>
48
49 Exclude files that contain "item" anywhere in their filename from being
50 deleted, even if they would normally be deleted. You may use this option
51 multiple times to build up a list of things to exclude.
52
53 =item I<file ...>
54
55 Delete these files too.
56
57 =back
58
59 =cut
60
61 init();
62 inhibit_log();
63
64 if ($dh{K_FLAG}) {
65         # dh_prep will be emulated (mostly) by the code below.
66         # TODO deprecation warning
67 }
68
69 foreach my $package (@{$dh{DOPACKAGES}}) {
70         my $tmp=tmpdir($package);
71         my $ext=pkgext($package);
72
73         if (! $dh{D_FLAG}) {
74                 doit("rm","-f","debian/${ext}substvars")
75                         unless excludefile("debian/${ext}substvars");
76                 
77                 # These are all debhelper temp files, and so it is safe to 
78                 # wildcard them.
79                 complex_doit("rm -f debian/$ext*.debhelper");
80                 
81                 if (! $dh{K_FLAG}) {
82                         doit("rm","-f","debian/${ext}debhelper.log");
83                 }
84         }
85         
86         doit ("rm","-rf",$tmp."/")
87                 unless excludefile($tmp);
88 }
89
90 if (! $dh{D_FLAG}) {
91         if (@ARGV) {
92                 doit("rm","-f","--",@ARGV);
93         }
94
95         if (! $dh{K_FLAG}) {
96                 if (!compat(6) && -e "debian/clean") {
97                         my @clean=grep { ! excludefile($_) }
98                                 filearray("debian/clean", ".");
99                         doit("rm","-f","--",@clean) if @clean;
100                 }
101
102                 doit("rm","-f","debian/files")
103                         unless excludefile("debian/files");
104         }
105
106         # See if some files that would normally be deleted are excluded.
107         my $find_options='';
108         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
109                 $find_options="! \\( $dh{EXCLUDE_FIND} \\) -a";
110         }
111
112         # Remove other temp files.
113         complex_doit("find . $find_options \\( \\( -type f -a \\
114                 \\( -name '#*#' -o -name '.*~' -o -name '*~' -o -name DEADJOE \\
115                  -o -name '*.orig' -o -name '*.rej' -o -name '*.bak' \\
116                  -o -name '.*.orig' -o -name .*.rej -o -name '.SUMS' \\
117                  -o -name TAGS -o \\( -path '*/.deps/*' -a -name '*.P' \\) \\
118                 \\) -exec rm -f {} \\; \\) -o \\
119                 \\( -type d -a -name autom4te.cache -prune -exec rm -rf {} \\; \\) \\)");
120 }
121
122 doit('rm', '-rf', 'debian/tmp') if -x 'debian/tmp' && ! compat(1) &&
123                                    ! excludefile("debian/tmp");
124
125 if (!compat(6)) {
126         complex_doit('rm -f *-stamp');
127 }
128
129 =head1 SEE ALSO
130
131 L<debhelper(7)>
132
133 This program is a part of debhelper.
134
135 =head1 AUTHOR
136
137 Joey Hess <joeyh@debian.org>
138
139 =cut