]> git.donarmstrong.com Git - debhelper.git/blob - dh_clean
r473: * dh_clean: clean up temp files used by earlier versons of debhelper.
[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   dh_clean [debhelper options] [-k] [-d] [file ...] [-Xitem]
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, such as debian/substvars, debian/files, and any detritus left
21 behind by other debhelper commands. It also removes common files that
22 should not appear in a debian diff:
23   #*# *~ DEADJOE *.orig *.rej *.SUMS TAGS core .deps/* *.P
24
25 =head1 OPTIONS
26
27 =over 4
28
29 =item B<-k>, B<--keep>
30
31 Do not delete debian/files. When do you want to use this? Anytime you have a
32 debian/rules that has 2 binary targets that build different .deb packages;
33 for example, one target is binary-arch, and the other is binary-indep, or
34 one target builds the shared library, and the other the -dev package. If you
35 didn't use -k in these cases, then debian/files would be deleted in the
36 middle, and your changes file will only contain the last binary package that
37 was built.
38
39 =item B<-d>, B<--dirs-only>
40
41 Only clean the package build directories, do not clean up any other files
42 at all.
43
44 =item B<-X>I<item> B<--exclude=>I<item>
45
46 Exclude files that contain "item" anywhere in their filename from being
47 deleted, even if they would normally be deleted. You may use this option
48 multiple times to build up a list of things to exclude.
49
50 =item I<file ...>
51
52 Delete these files too.
53
54 =back
55
56 =cut
57
58 init();
59
60 foreach my $package (@{$dh{DOPACKAGES}}) {
61         my $tmp=tmpdir($package);
62         my $ext=pkgext($package);
63
64         if (! $dh{D_FLAG}) {
65                 doit("rm","-f","debian/${ext}substvars",
66                         "debian/${ext}postinst.debhelper",
67                         "debian/${ext}postrm.debhelper",
68                         "debian/${ext}preinst.debhelper",
69                         "debian/${ext}prerm.debhelper");
70         }
71         
72         doit ("rm","-rf",$tmp);
73 }
74
75 if (! $dh{D_FLAG}) {
76         if (@ARGV) {
77                 doit("rm","-f","--",@ARGV);
78         }
79
80         if (! $dh{K_FLAG}) {
81                 doit("rm","-f","debian/files");
82         }
83
84         # Remove some files that were left around by older versions of
85         # debhelper, just in case someone upgrades in the middle of a
86         # build.
87         doit("rm","-f","debian/substvars",
88                 "debian/postinst.debhelper",
89                 "debian/postrm.debhelper",
90                 "debian/preinst.debhelper",
91                 "debian/prerm.debhelper");
92
93         # See if some files that would normally be deleted are excluded.
94         my $find_options='';
95         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
96                 $find_options="-a ! ( $dh{EXCLUDE_FIND} )";
97         }
98
99         # Remove other temp files.
100         # (The \s+ is important, \s won't work because find would get null
101         # parameters). Note that you _don't_ quote wildcards used by find
102         # in here.
103         doit(split(/\s+/,"find . -type f -a
104                 ( -name #*# -o -name *~ -o -name DEADJOE
105                  -o -name *.orig -o -name *.rej -o -name *.bak
106                  -o -name .*.orig -o -name .*.rej -o -name .SUMS
107                  -o -name TAGS -o -name core -o ( -path */.deps/* -a -name *.P )
108                 ) $find_options -exec rm -f {} ;"));
109 }
110
111 doit('rm', '-rf', 'debian/tmp') if -x 'debian/tmp' && ! compat(1);
112
113 =head1 SEE ALSO
114
115 L<debhelper(1)>
116
117 This program is a part of debhelper.
118
119 =head1 AUTHOR
120
121 Joey Hess <joeyh@debian.org>
122
123 =cut