]> git.donarmstrong.com Git - debhelper.git/blob - dh_clean
Merge branch 'master' into buildsystems
[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 things like 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(options => {
61         "dirs-only" => \$dh{D_FLAG},
62 });
63 inhibit_log();
64
65 if ($dh{K_FLAG}) {
66         # dh_prep will be emulated (mostly) by the code below.
67         # TODO deprecation warning
68 }
69
70 foreach my $package (@{$dh{DOPACKAGES}}) {
71         my $tmp=tmpdir($package);
72         my $ext=pkgext($package);
73
74         if (! $dh{D_FLAG}) {
75                 doit("rm","-f","debian/${ext}substvars")
76                         unless excludefile("debian/${ext}substvars");
77                 
78                 # These are all debhelper temp files, and so it is safe to 
79                 # wildcard them.
80                 complex_doit("rm -f debian/$ext*.debhelper");
81                 
82                 if (! $dh{K_FLAG}) {
83                         doit("rm","-f","debian/${ext}debhelper.log");
84                 }
85         }
86         
87         doit ("rm","-rf",$tmp."/")
88                 unless excludefile($tmp);
89 }
90
91 if (! $dh{D_FLAG}) {
92         if (@ARGV) {
93                 doit("rm","-f","--",@ARGV);
94         }
95
96         if (! $dh{K_FLAG}) {
97                 if (!compat(6) && -e "debian/clean") {
98                         my @clean=grep { ! excludefile($_) }
99                                 filearray("debian/clean", ".");
100                         doit("rm","-f","--",@clean) if @clean;
101                 }
102
103                 doit("rm","-f","debian/files")
104                         unless excludefile("debian/files");
105         }
106
107         # See if some files that would normally be deleted are excluded.
108         my $find_options='';
109         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
110                 $find_options="! \\( $dh{EXCLUDE_FIND} \\) -a";
111         }
112
113         # Remove other temp files.
114         complex_doit("find . $find_options \\( \\( -type f -a \\
115                 \\( -name '#*#' -o -name '.*~' -o -name '*~' -o -name DEADJOE \\
116                  -o -name '*.orig' -o -name '*.rej' -o -name '*.bak' \\
117                  -o -name '.*.orig' -o -name .*.rej -o -name '.SUMS' \\
118                  -o -name TAGS -o \\( -path '*/.deps/*' -a -name '*.P' \\) \\
119                 \\) -exec rm -f {} \\; \\) -o \\
120                 \\( -type d -a -name autom4te.cache -prune -exec rm -rf {} \\; \\) \\)");
121 }
122
123 doit('rm', '-rf', 'debian/tmp') if -x 'debian/tmp' && ! compat(1) &&
124                                    ! excludefile("debian/tmp");
125
126 if (!compat(6) && !$dh{K_FLAG}) {
127         complex_doit('rm -f *-stamp');
128 }
129
130 =head1 SEE ALSO
131
132 L<debhelper(7)>
133
134 This program is a part of debhelper.
135
136 =head1 AUTHOR
137
138 Joey Hess <joeyh@debian.org>
139
140 =cut