]> git.donarmstrong.com Git - debhelper.git/blob - dh_movefiles
Typo. Closes: #653339
[debhelper.git] / dh_movefiles
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_movefiles - move files out of debian/tmp into subpackages
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14 B<dh_movefiles> [S<I<debhelper options>>] [B<--sourcedir=>I<dir>] [B<-X>I<item>] S<I<file> ...>]
15
16 =head1 DESCRIPTION
17
18 B<dh_movefiles> is a debhelper program that is responsible for moving files
19 out of F<debian/tmp> or some other directory and into other package build
20 directories. This may be useful if your package has a F<Makefile> that installs
21 everything into F<debian/tmp>, and you need to break that up into subpackages.
22
23 Note: B<dh_install> is a much better program, and you are recommended to use
24 it instead of B<dh_movefiles>.
25
26 =head1 FILES
27
28 =over 4
29
30 =item debian/I<package>.files
31
32 Lists the files to be moved into a package, separated by whitespace. The
33 filenames listed should be relative to F<debian/tmp/>. You can also list
34 directory names, and the whole directory will be moved.
35
36 =back
37
38 =head1 OPTIONS
39
40 =over 4
41
42 =item B<--sourcedir=>I<dir>
43
44 Instead of moving files out of F<debian/tmp> (the default), this option makes
45 it move files out of some other directory. Since the entire contents of
46 the sourcedir is moved, specifying something like B<--sourcedir=/> is very
47 unsafe, so to prevent mistakes, the sourcedir must be a relative filename;
48 it cannot begin with a `B</>'.
49
50 =item B<-Xitem>, B<--exclude=item>
51
52 Exclude files that contain B<item> anywhere in their filename from
53 being installed.
54
55 =item I<file> ...
56
57 Lists files to move. The filenames listed should be relative to
58 F<debian/tmp/>. You can also list directory names, and the whole directory will
59 be moved. It is an error to list files here unless you use B<-p>, B<-i>, or B<-a> to
60 tell B<dh_movefiles> which subpackage to put them in.
61
62 =back
63
64 =head1 NOTES
65
66 Note that files are always moved out of F<debian/tmp> by default (even if you
67 have instructed debhelper to use a compatibility level higher than one,
68 which does not otherwise use debian/tmp for anything at all). The idea
69 behind this is that the package that is being built can be told to install
70 into F<debian/tmp>, and then files can be moved by B<dh_movefiles> from that
71 directory. Any files or directories that remain are ignored, and get
72 deleted by B<dh_clean> later.
73
74 =cut
75
76 init(options => {
77         "sourcedir=s" => \$dh{SOURCEDIR},       
78 });
79
80 my $ret=0;
81
82 foreach my $package (@{$dh{DOPACKAGES}}) {
83         my $tmp=tmpdir($package);
84         my $files=pkgfile($package,"files");
85
86         my $sourcedir="debian/tmp";
87         if ($dh{SOURCEDIR}) {
88                 if ($dh{SOURCEDIR}=~m:^/:) {
89                         error("The sourcedir must be a relative filename, not starting with `/'.");
90                 }
91                 $sourcedir=$dh{SOURCEDIR};
92         }
93
94         if (! -d $sourcedir) {
95                 error("$sourcedir does not exist.");
96         }
97
98         my @tomove;
99
100         # debian/files has a different purpose, so ignore it.
101         if ($files && $files ne "debian/files" ) {
102                 @tomove=filearray($files, $sourcedir);
103         }
104         
105         if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
106                 push @tomove, @ARGV;
107         }
108
109         if (@tomove && $tmp eq $sourcedir) {
110                 error("I was asked to move files from $sourcedir to $sourcedir. Perhaps you should set DH_COMPAT=2?");
111         }
112
113         # Now we need to expand wildcards in @tomove.
114         # This is only necessary in pre-v3 land -- as of v3, the
115         # expension is automatically done by filearray().
116         if (@tomove && compat(2)) {
117                 my @filelist=();
118                 foreach (@tomove) {
119                         push @filelist, glob("$sourcedir/$_");
120                 }
121                 @tomove=@filelist;
122         }
123         else {
124                 # However, filearray() does not add the sourcedir,
125                 # which we need.
126                 @tomove = map { "$sourcedir/$_" } @tomove;
127         }
128
129         if (@tomove) {
130                 if (! -d $tmp) {
131                         doit("install","-d",$tmp);
132                 }
133
134                 doit("rm","-f","debian/movelist");
135                 foreach (@tomove) {
136                         my $file=$_;
137                         if (! -e $file && ! -l $file && ! $dh{NO_ACT}) {
138                                 $ret=1;
139                                 warning("$file not found (supposed to put it in $package)");
140                         }
141                         else {
142                                 $file=~s:^\Q$sourcedir\E/+::;
143                                 my $cmd="(cd $sourcedir >/dev/null ; find $file ! -type d ";
144                                 if ($dh{EXCLUDE_FIND}) {
145                                         $cmd.="-a ! \\( $dh{EXCLUDE_FIND} \\) ";
146                                 }
147                                 $cmd.="-print || true) >> debian/movelist";
148                                 complex_doit($cmd);
149                         }
150                 }
151                 my $pwd=`pwd`;
152                 chomp $pwd;
153                 complex_doit("(cd $sourcedir >/dev/null ; tar --create --files-from=$pwd/debian/movelist --file -) | (cd $tmp >/dev/null ;tar xpf -)");
154                 # --remove-files is not used above because tar then doesn't
155                 # preserve hard links
156                 complex_doit("(cd $sourcedir >/dev/null ; tr '\\n' '\\0' < $pwd/debian/movelist | xargs -0 rm -f)");
157                 doit("rm","-f","debian/movelist");
158         }
159 }
160
161 # If $ret is set, we wern't actually able to find some 
162 # files that were specified to be moved, and we should
163 # exit with the code in $ret. This program puts off 
164 # exiting with an error until all files have been tried
165 # to be moved, because this makes it easier for some 
166 # packages that arn't always sure exactly which files need
167 # to be moved.
168 exit $ret;
169
170 =head1 SEE ALSO
171
172 L<debhelper(7)>
173
174 This program is a part of debhelper.
175
176 =head1 AUTHOR
177
178 Joey Hess <joeyh@debian.org>
179
180 =cut