]> git.donarmstrong.com Git - debhelper.git/blob - dh_movefiles
Merge branch 'master' into buildsystems
[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, and you are recommended to use
30 it instead of dh_movefiles.
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, specifying 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(options => {
71         "sourcedir=s" => \$dh{SOURCEDIR},       
72 });
73
74 my $ret=0;
75
76 foreach my $package (@{$dh{DOPACKAGES}}) {
77         my $tmp=tmpdir($package);
78         my $files=pkgfile($package,"files");
79
80         my $sourcedir="debian/tmp";
81         if ($dh{SOURCEDIR}) {
82                 if ($dh{SOURCEDIR}=~m:^/:) {
83                         error("The sourcedir must be a relative filename, not starting with `/'.");
84                 }
85                 $sourcedir=$dh{SOURCEDIR};
86         }
87
88         if (! -d $sourcedir) {
89                 error("$sourcedir does not exist.");
90         }
91
92         my @tomove;
93
94         # debian/files has a different purpose, so ignore it.
95         if ($files && $files ne "debian/files" ) {
96                 @tomove=filearray($files, $sourcedir);
97         }
98         
99         if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
100                 push @tomove, @ARGV;
101         }
102
103         if (@tomove && $tmp eq $sourcedir) {
104                 error("I was asked to move files from $sourcedir to $sourcedir. Perhaps you should set DH_COMPAT=2?");
105         }
106
107         # Now we need to expand wildcards in @tomove.
108         # This is only necessary in pre-v3 land -- as of v3, the
109         # expension is automatically done by filearray().
110         if (@tomove && compat(2)) {
111                 my @filelist=();
112                 foreach (@tomove) {
113                         push @filelist, glob("$sourcedir/$_");
114                 }
115                 @tomove=@filelist;
116         }
117         else {
118                 # However, filearray() does not add the sourcedir,
119                 # which we need.
120                 @tomove = map { "$sourcedir/$_" } @tomove;
121         }
122
123         if (@tomove) {
124                 if (! -d $tmp) {
125                         doit("install","-d",$tmp);
126                 }
127
128                 doit("rm","-f","debian/movelist");
129                 foreach (@tomove) {
130                         my $file=$_;
131                         if (! -e $file && ! -l $file && ! $dh{NO_ACT}) {
132                                 $ret=1;
133                                 warning("$file not found (supposed to put it in $package)");
134                         }
135                         else {
136                                 $file=~s:^\Q$sourcedir\E/+::;
137                                 my $cmd="(cd $sourcedir >/dev/null ; find $file ! -type d ";
138                                 if ($dh{EXCLUDE_FIND}) {
139                                         $cmd.="-a ! \\( $dh{EXCLUDE_FIND} \\) ";
140                                 }
141                                 $cmd.="-print || true) >> debian/movelist";
142                                 complex_doit($cmd);
143                         }
144                 }
145                 my $pwd=`pwd`;
146                 chomp $pwd;
147                 complex_doit("(cd $sourcedir >/dev/null ; tar --create --files-from=$pwd/debian/movelist --file -) | (cd $tmp >/dev/null ;tar xpf -)");
148                 # --remove-files is not used above because tar then doesn't
149                 # preserve hard links
150                 complex_doit("(cd $sourcedir >/dev/null ; tr '\\n' '\\0' < $pwd/debian/movelist | xargs -0  -i rm -f '{}')");
151                 doit("rm","-f","debian/movelist");
152         }
153 }
154
155 # If $ret is set, we wern't actually able to find some 
156 # files that were specified to be moved, and we should
157 # exit with the code in $ret. This program puts off 
158 # exiting with an error until all files have been tried
159 # to be moved, because this makes it easier for some 
160 # packages that arn't always sure exactly which files need
161 # to be moved.
162 exit $ret;
163
164 =head1 SEE ALSO
165
166 L<debhelper(7)>
167
168 This program is a part of debhelper.
169
170 =head1 AUTHOR
171
172 Joey Hess <joeyh@debian.org>
173
174 =cut