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