]> git.donarmstrong.com Git - debhelper.git/blob - dh_clean
dh_clean: In v7 mode, read debian/clean and delete all files listed therein.
[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. When do you want to use this? Anytime you have a
37 debian/rules that has 2 binary targets that build different .deb packages;
38 for example, one target is binary-arch, and the other is binary-indep, or
39 one target builds the shared library, and the other the -dev package. If you
40 didn't use -k in these cases, then debian/files would be deleted in the
41 middle, and your changes file will only contain the last binary package that
42 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         
78         doit ("rm","-rf",$tmp."/")
79                 unless excludefile($tmp);
80 }
81
82 if (! $dh{D_FLAG}) {
83         if (@ARGV) {
84                 doit("rm","-f","--",@ARGV);
85         }
86         
87         if (!compat(6) && -e "debian/clean") {
88                 my @clean=grep { ! excludefile($_) }
89                         filearray("debian/clean", ".");
90                 doit("rm","-f","--",@clean) if @clean;
91         }
92
93         if (! $dh{K_FLAG}) {
94                 doit("rm","-f","debian/files")
95                         unless excludefile("debian/files");
96         }
97
98         # See if some files that would normally be deleted are excluded.
99         my $find_options='';
100         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
101                 $find_options="! \\( $dh{EXCLUDE_FIND} \\) -a";
102         }
103
104         # Remove other temp files.
105         complex_doit("find . $find_options \\( \\( -type f -a \\
106                 \\( -name '#*#' -o -name '.*~' -o -name '*~' -o -name DEADJOE \\
107                  -o -name '*.orig' -o -name '*.rej' -o -name '*.bak' \\
108                  -o -name '.*.orig' -o -name .*.rej -o -name '.SUMS' \\
109                  -o -name TAGS -o \\( -path '*/.deps/*' -a -name '*.P' \\) \\
110                 \\) -exec rm -f {} \\; \\) -o \\
111                 \\( -type d -a -name autom4te.cache -prune -exec rm -rf {} \\; \\) \\)");
112 }
113
114 doit('rm', '-rf', 'debian/tmp') if -x 'debian/tmp' && ! compat(1) &&
115                                    ! excludefile("debian/tmp");
116
117 =head1 SEE ALSO
118
119 L<debhelper(7)>
120
121 This program is a part of debhelper.
122
123 =head1 AUTHOR
124
125 Joey Hess <joeyh@debian.org>
126
127 =cut