]> git.donarmstrong.com Git - debhelper.git/blob - dh_clean
dh_auto_install: New program, automates running make install, or using setup.py to...
[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 =head1 OPTIONS
29
30 =over 4
31
32 =item B<-k>, B<--keep>
33
34 Do not delete debian/files. When do you want to use this? Anytime you have a
35 debian/rules that has 2 binary targets that build different .deb packages;
36 for example, one target is binary-arch, and the other is binary-indep, or
37 one target builds the shared library, and the other the -dev package. If you
38 didn't use -k in these cases, then debian/files would be deleted in the
39 middle, and your changes file will only contain the last binary package that
40 was built.
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
63 foreach my $package (@{$dh{DOPACKAGES}}) {
64         my $tmp=tmpdir($package);
65         my $ext=pkgext($package);
66
67         if (! $dh{D_FLAG}) {
68                 doit("rm","-f","debian/${ext}substvars")
69                         unless excludefile("debian/${ext}substvars");
70                 
71                 # These are all debhelper temp files, and so it is safe to 
72                 # wildcard them.
73                 complex_doit("rm -f debian/$ext*.debhelper");
74         }
75         
76         doit ("rm","-rf",$tmp."/")
77                 unless excludefile($tmp);
78 }
79
80 if (! $dh{D_FLAG}) {
81         if (@ARGV) {
82                 doit("rm","-f","--",@ARGV);
83         }
84
85         if (! $dh{K_FLAG}) {
86                 doit("rm","-f","debian/files")
87                         unless excludefile("debian/files");
88         }
89
90         # See if some files that would normally be deleted are excluded.
91         my $find_options='';
92         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
93                 $find_options="! \\( $dh{EXCLUDE_FIND} \\) -a";
94         }
95
96         # Remove other temp files.
97         complex_doit("find . $find_options \\( \\( -type f -a \\
98                 \\( -name '#*#' -o -name '.*~' -o -name '*~' -o -name DEADJOE \\
99                  -o -name '*.orig' -o -name '*.rej' -o -name '*.bak' \\
100                  -o -name '.*.orig' -o -name .*.rej -o -name '.SUMS' \\
101                  -o -name TAGS -o \\( -path '*/.deps/*' -a -name '*.P' \\) \\
102                 \\) -exec rm -f {} \\; \\) -o \\
103                 \\( -type d -a -name autom4te.cache -prune -exec rm -rf {} \\; \\) \\)");
104 }
105
106 doit('rm', '-rf', 'debian/tmp') if -x 'debian/tmp' && ! compat(1) &&
107                                    ! excludefile("debian/tmp");
108
109 =head1 SEE ALSO
110
111 L<debhelper(7)>
112
113 This program is a part of debhelper.
114
115 =head1 AUTHOR
116
117 Joey Hess <joeyh@debian.org>
118
119 =cut