]> git.donarmstrong.com Git - debhelper.git/blob - dh_clean
remove exit
[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
24
25 It does not run "make clean" to clean up after the build process. Use
26 L<dh_auto_clean(1)> to do that.
27
28 The debian/clean file can list other files to be removed.
29
30 =head1 OPTIONS
31
32 =over 4
33
34 =item B<-k>, B<--keep>
35
36 Do not delete debian/files, or files listed in debian/clean. When do you
37 want to use this? Anytime you have a debian/rules that has 2 binary targets
38 that build different .deb packages; for example, one target is binary-arch,
39 and the other is binary-indep, or one target builds the shared library, and
40 the other the -dev package. If you didn't use -k in these cases, then
41 debian/files would be deleted in the middle, and your changes file will
42 only contain the last binary package that was built.
43
44 =item B<-d>, B<--dirs-only>
45
46 Only clean the package build directories, do not clean up any other files
47 at all.
48
49 =item B<-X>I<item> B<--exclude=>I<item>
50
51 Exclude files that contain "item" anywhere in their filename from being
52 deleted, even if they would normally be deleted. You may use this option
53 multiple times to build up a list of things to exclude.
54
55 =item I<file ...>
56
57 Delete these files too.
58
59 =back
60
61 =cut
62
63 init();
64
65 foreach my $package (@{$dh{DOPACKAGES}}) {
66         my $tmp=tmpdir($package);
67         my $ext=pkgext($package);
68
69         if (! $dh{D_FLAG}) {
70                 doit("rm","-f","debian/${ext}substvars")
71                         unless excludefile("debian/${ext}substvars");
72                 
73                 # These are all debhelper temp files, and so it is safe to 
74                 # wildcard them.
75                 complex_doit("rm -f debian/$ext*.debhelper");
76                 
77                 if (! $dh{K_FLAG}) {
78                         doit("rm","-f","debian/${ext}debhelper.log");
79                 }
80         }
81         
82         doit ("rm","-rf",$tmp."/")
83                 unless excludefile($tmp);
84 }
85
86 if (! $dh{D_FLAG}) {
87         if (@ARGV) {
88                 doit("rm","-f","--",@ARGV);
89         }
90
91         if (! $dh{K_FLAG}) {
92                 if (!compat(6) && -e "debian/clean") {
93                         my @clean=grep { ! excludefile($_) }
94                                 filearray("debian/clean", ".");
95                         doit("rm","-f","--",@clean) if @clean;
96                 }
97
98                 doit("rm","-f","debian/files")
99                         unless excludefile("debian/files");
100         }
101
102         # See if some files that would normally be deleted are excluded.
103         my $find_options='';
104         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
105                 $find_options="! \\( $dh{EXCLUDE_FIND} \\) -a";
106         }
107
108         # Remove other temp files.
109         complex_doit("find . $find_options \\( \\( -type f -a \\
110                 \\( -name '#*#' -o -name '.*~' -o -name '*~' -o -name DEADJOE \\
111                  -o -name '*.orig' -o -name '*.rej' -o -name '*.bak' \\
112                  -o -name '.*.orig' -o -name .*.rej -o -name '.SUMS' \\
113                  -o -name TAGS -o \\( -path '*/.deps/*' -a -name '*.P' \\) \\
114                 \\) -exec rm -f {} \\; \\) -o \\
115                 \\( -type d -a -name autom4te.cache -prune -exec rm -rf {} \\; \\) \\)");
116 }
117
118 doit('rm', '-rf', 'debian/tmp') if -x 'debian/tmp' && ! compat(1) &&
119                                    ! excludefile("debian/tmp");
120
121 =head1 SEE ALSO
122
123 L<debhelper(7)>
124
125 This program is a part of debhelper.
126
127 =head1 AUTHOR
128
129 Joey Hess <joeyh@debian.org>
130
131 =cut