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