]> git.donarmstrong.com Git - debhelper.git/blob - dh_clean
dh_clean: Do not delete *-stamp files in -k mode in v7. Closes: #489918
[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 is deprecated, use L<dh_prep(1)> instead.
40
41 =item B<-d>, B<--dirs-only>
42
43 Only clean the package build directories, do not clean up any other files
44 at all.
45
46 =item B<-X>I<item> B<--exclude=>I<item>
47
48 Exclude files that contain "item" anywhere in their filename from being
49 deleted, even if they would normally be deleted. You may use this option
50 multiple times to build up a list of things to exclude.
51
52 =item I<file ...>
53
54 Delete these files too.
55
56 =back
57
58 =cut
59
60 init();
61 inhibit_log();
62
63 if ($dh{K_FLAG}) {
64         # dh_prep will be emulated (mostly) by the code below.
65         # TODO deprecation warning
66 }
67
68 foreach my $package (@{$dh{DOPACKAGES}}) {
69         my $tmp=tmpdir($package);
70         my $ext=pkgext($package);
71
72         if (! $dh{D_FLAG}) {
73                 doit("rm","-f","debian/${ext}substvars")
74                         unless excludefile("debian/${ext}substvars");
75                 
76                 # These are all debhelper temp files, and so it is safe to 
77                 # wildcard them.
78                 complex_doit("rm -f debian/$ext*.debhelper");
79                 
80                 if (! $dh{K_FLAG}) {
81                         doit("rm","-f","debian/${ext}debhelper.log");
82                 }
83         }
84         
85         doit ("rm","-rf",$tmp."/")
86                 unless excludefile($tmp);
87 }
88
89 if (! $dh{D_FLAG}) {
90         if (@ARGV) {
91                 doit("rm","-f","--",@ARGV);
92         }
93
94         if (! $dh{K_FLAG}) {
95                 if (!compat(6) && -e "debian/clean") {
96                         my @clean=grep { ! excludefile($_) }
97                                 filearray("debian/clean", ".");
98                         doit("rm","-f","--",@clean) if @clean;
99                 }
100
101                 doit("rm","-f","debian/files")
102                         unless excludefile("debian/files");
103         }
104
105         # See if some files that would normally be deleted are excluded.
106         my $find_options='';
107         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
108                 $find_options="! \\( $dh{EXCLUDE_FIND} \\) -a";
109         }
110
111         # Remove other temp files.
112         complex_doit("find . $find_options \\( \\( -type f -a \\
113                 \\( -name '#*#' -o -name '.*~' -o -name '*~' -o -name DEADJOE \\
114                  -o -name '*.orig' -o -name '*.rej' -o -name '*.bak' \\
115                  -o -name '.*.orig' -o -name .*.rej -o -name '.SUMS' \\
116                  -o -name TAGS -o \\( -path '*/.deps/*' -a -name '*.P' \\) \\
117                 \\) -exec rm -f {} \\; \\) -o \\
118                 \\( -type d -a -name autom4te.cache -prune -exec rm -rf {} \\; \\) \\)");
119 }
120
121 doit('rm', '-rf', 'debian/tmp') if -x 'debian/tmp' && ! compat(1) &&
122                                    ! excludefile("debian/tmp");
123
124 if (!compat(6) && !$dh{K_FLAG}) {
125         complex_doit('rm -f *-stamp');
126 }
127
128 =head1 SEE ALSO
129
130 L<debhelper(7)>
131
132 This program is a part of debhelper.
133
134 =head1 AUTHOR
135
136 Joey Hess <joeyh@debian.org>
137
138 =cut